Skip to content

Commit

Permalink
feat: automod messages
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnyTheCarrot authored Oct 2, 2023
1 parent 53441ab commit fd29a3f
Show file tree
Hide file tree
Showing 19 changed files with 1,149 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const preview = {
values: [
{
name: "discord-dark",
value: "#424549",
value: "#313338",
},
],
},
Expand Down
12 changes: 8 additions & 4 deletions src/ChatTag/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function isVerifiedBot(flags?: number) {
}

interface TagProps {
author: APIUser;
author: APIUser | "automod";
crossPost: boolean;
referenceGuild: string | undefined;
}
Expand All @@ -40,14 +40,18 @@ function ChatTag({ author, crossPost, referenceGuild }: TagProps) {

const { chatBadge: ChatBadge } = useConfig();

if (ChatBadge !== undefined) {
if (author !== "automod" && ChatBadge !== undefined) {
const chatBadgeResult = ChatBadge({ user: author, TagWrapper: Styles.Tag });
if (chatBadgeResult !== null) return chatBadgeResult;
}

if (!author.bot) return null;
if (author !== "automod" && !author.bot) return null;

if (author.system || referenceGuild === "667560445975986187")
if (
author === "automod" ||
author.system ||
referenceGuild === "667560445975986187"
)
return (
<Styles.Tag className="verified system">
{verified} {t("chatTag.system")}
Expand Down
5 changes: 4 additions & 1 deletion src/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ interface MessageAccessoriesProps {
children?: ReactNode;
}

function MessageAccessories({ children, active }: MessageAccessoriesProps) {
export function MessageAccessories({
children,
active,
}: MessageAccessoriesProps) {
if (!active || !children || Children.count(children) === 0) return <></>;

return <Styles.MessageAccessories>{children}</Styles.MessageAccessories>;
Expand Down
28 changes: 25 additions & 3 deletions src/Message/MessageAuthor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,33 @@ import * as Styles from "./style/author";
import type { APIRole, APIUser, Snowflake } from "discord-api-types/v10";
import { useConfig } from "../core/ConfigContext";
import getDisplayName from "../utils/getDisplayName";
import { useTranslation } from "react-i18next";

interface AutomodAuthorProps {
isAvatarAnimated?: boolean;
}

export function AutomodAuthor({ isAvatarAnimated }: AutomodAuthorProps) {
const {
automodAvatar: { still: avatarStill, animated: avatarAnimated },
} = useConfig();
const { t } = useTranslation();

const automodAvatar = isAvatarAnimated ? avatarAnimated : avatarStill;

return (
<Styles.MessageAuthor>
<Styles.Avatar data={automodAvatar} draggable={false} type="image/png" />
<Styles.Username automod>{t("AutomodAction.username")}</Styles.Username>
<ChatTag author="automod" crossPost={false} referenceGuild={undefined} />
</Styles.MessageAuthor>
);
}

interface MessageAuthorProps
extends ComponentProps<typeof Styles.MessageAuthor> {
author: APIUser;
avatarAnimated?: boolean;
isAvatarAnimated?: boolean;
onlyShowUsername?: boolean;
crossPost?: boolean;
referenceGuild?: Snowflake;
Expand All @@ -22,7 +44,7 @@ interface MessageAuthorProps
function MessageAuthor({
onlyShowUsername,
author,
avatarAnimated,
isAvatarAnimated,
crossPost,
referenceGuild,
guildId,
Expand All @@ -36,7 +58,7 @@ function MessageAuthor({
const avatarUrl =
avatarUrlOverride?.(author) ??
getAvatar(author, {
animated: avatarAnimated ?? false,
animated: isAvatarAnimated ?? false,
});

const displayName = isGuildMember
Expand Down
5 changes: 5 additions & 0 deletions src/Message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import RecipientRemove from "./variants/RecipientRemove";
import ThreadCreated from "./variants/ThreadCreated";
import { useConfig } from "../core/ConfigContext";
import ThreadStarterMessage from "./variants/ThreadStarterMessage";
import AutomodAction from "./variants/AutomodAction";

export interface MessageProps {
isFirstMessage?: boolean;
Expand Down Expand Up @@ -144,6 +145,10 @@ function MessageTypeSwitch(props: Omit<MessageProps, "showButtons">) {
createdAt={props.message.timestamp}
/>
);
case MessageType.AutoModerationAction:
return (
<AutomodAction message={props.message} isHovered={props.isHovered} />
);
default: {
// todo: lock behind a debug mode
const errorMessage: APIMessage = {
Expand Down
9 changes: 9 additions & 0 deletions src/Message/style/author.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ export const Username = styled.withConfig({
verticalAlign: "baseline",
whiteSpace: "nowrap",
lineHeight: `1.375rem`,

variants: {
automod: {
true: {
color: theme.colors.automodUsername,
fontWeight: 600,
},
},
},
});

export const Avatar = styled.withConfig({
Expand Down
69 changes: 68 additions & 1 deletion src/Message/style/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,73 @@ export const MessageHeaderBase = styled.withConfig({
display: "flex",
flexDirection: "row",
alignItems: "center",
flexWrap: "wrap",
});

export const AutomodHeaderText = styled.withConfig({
displayName: "automod-header-text",
componentId: commonComponentId,
})("span", {
marginLeft: theme.space.small,
color: theme.colors.primaryOpacity100,
});

export const AutomodMessageInQuestion = styled.withConfig({
displayName: "automod-message-in-question",
componentId: commonComponentId,
})("div", {
padding: theme.space.xl,
backgroundColor: theme.colors.backgroundSecondary,
borderRadius: 8,
position: "relative",
paddingLeft: 72,
marginTop: theme.space.small,
});

export const AutomodMessageContent = styled.withConfig({
displayName: "automod-message-content",
componentId: commonComponentId,
})("div", {
color: theme.colors.primaryOpacity80,
whiteSpace: "break-spaces",
fontSize: theme.fontSizes.l,
});

export const AutomodMatchInfoContainer = styled.withConfig({
displayName: "automod-match-info-container",
componentId: commonComponentId,
})("span", {
display: "flex",
flexDirection: "row",
color: theme.colors.textMuted,
fontSize: theme.fontSizes.s,
});

export const AutomodMatchInfo = styled.withConfig({
displayName: "automod-match-info",
componentId: commonComponentId,
})("span", {
display: "flex",
flexDirection: "row",
alignItems: "center",

"&:not(:last-child)::after": {
marginLeft: theme.space.large,
marginRight: theme.space.large,
content: "",
display: "inline-block",
width: 4,
height: 4,
backgroundColor: theme.colors.automodDot,
borderRadius: "100%",
},
});

export const AutomodFlaggedKeyword = styled.withConfig({
displayName: "automod-flagged-keyword",
componentId: commonComponentId,
})("span", {
backgroundColor: theme.colors.automodMatchedWord,
});

export namespace MessageContainerStyle {
Expand Down Expand Up @@ -239,7 +306,7 @@ export const MiniUserName = styled.withConfig({
overflow: "hidden",
maxWidth: "25vw",
textOverflow: "ellipsis",
color: theme.colors.primaryOpacity100
color: theme.colors.primaryOpacity100,
});

export const SystemMessage = styled.withConfig({
Expand Down
Loading

0 comments on commit fd29a3f

Please sign in to comment.