diff --git a/readme.md b/readme.md index 4c7a431..a9f52d9 100644 --- a/readme.md +++ b/readme.md @@ -20,11 +20,11 @@ $ export SHICKA_RECORD_DEFAULT_CHANNEL= $ export SHICKA_REFUSAL_DEFAULT_CHANNEL= $ export SHICKA_VERIFICATION_DEFAULT_CHANNEL= $ export SHICKA_VERIFICATION_VERIFIED_ROLE= -$ export SHICKA_HYPERLINK_DEFAULT_ALERT_ACTION_CHANNEL= -$ export SHICKA_HYPERLINK_DEFAULT_EXEMPT_CHANNELS= -$ export SHICKA_HYPERLINK_DEFAULT_EXEMPT_ROLES= -$ export SHICKA_HYPERLINK_REACTION_EMOJI= -$ export SHICKA_HYPERLINK_OVERRIDE_RULES_CHANNEL= +$ export SHICKA_LINK_DEFAULT_ALERT_ACTION_CHANNEL= +$ export SHICKA_LINK_DEFAULT_EXEMPT_CHANNELS= +$ export SHICKA_LINK_DEFAULT_EXEMPT_ROLES= +$ export SHICKA_LINK_REACTION_EMOJI= +$ export SHICKA_LINK_OVERRIDE_RULES_CHANNEL= $ export SHICKA_RULE7_DEFAULT_ALERT_ACTION_CHANNEL= $ export SHICKA_RULE7_DEFAULT_EXEMPT_CHANNELS= $ export SHICKA_RULE7_DEFAULT_EXEMPT_ROLES= @@ -132,6 +132,6 @@ $ npm start ### Rules -- `hyperlink` flags messages which contain a hyperlink as such in the given channel (set to `$SHICKA_HYPERLINK_DEFAULT_ALERT_ACTION_CHANNEL` by default) except when posted in any of the given exempted channels (set to `$SHICKA_HYPERLINK_DEFAULT_EXEMPT_CHANNELS` by default), when posted by non-administrator members having any of the given exempted roles (set to `$SHICKA_HYPERLINK_DEFAULT_EXEMPT_ROLES` by default) or when posted by administrator members +- `link` flags messages which contain a hyperlink as such in the given channel (set to `$SHICKA_LINK_DEFAULT_ALERT_ACTION_CHANNEL` by default) except when posted in any of the given exempted channels (set to `$SHICKA_LINK_DEFAULT_EXEMPT_CHANNELS` by default), when posted by non-administrator members having any of the given exempted roles (set to `$SHICKA_LINK_DEFAULT_EXEMPT_ROLES` by default) or when posted by administrator members - `rule7` flags messages which violate the rule 7 as such in the given channel (set to `$SHICKA_RULE7_DEFAULT_ALERT_ACTION_CHANNEL` by default) except when posted in any of the given exempted channels (set to `$SHICKA_RULE7_DEFAULT_EXEMPT_CHANNELS` by default), when posted by non-administrator members having any of the given exempted roles (set to `$SHICKA_RULE7_DEFAULT_EXEMPT_ROLES` by default) or when posted by administrator members diff --git a/src/compilations.ts b/src/compilations.ts index 10baf2c..f0d1ff5 100644 --- a/src/compilations.ts +++ b/src/compilations.ts @@ -11,8 +11,8 @@ import departureCompilation from "./compilations/departure.js"; import emojiCompilation from "./compilations/emoji.js"; import gateCompilation from "./compilations/gate.js"; import helpCompilation from "./compilations/help.js"; -import hyperlinkCompilation from "./compilations/hyperlink.js"; import leaderboardCompilation from "./compilations/leaderboard.js"; +import linkCompilation from "./compilations/link.js"; import missionCompilation from "./compilations/mission.js"; import outfitCompilation from "./compilations/outfit.js"; import patchCompilation from "./compilations/patch.js"; @@ -44,8 +44,8 @@ type Departure = typeof departureCompilation; type Emoji = typeof emojiCompilation; type Gate = typeof gateCompilation; type Help = typeof helpCompilation; -type Hyperlink = typeof hyperlinkCompilation; type Leaderboard = typeof leaderboardCompilation; +type Link = typeof linkCompilation; type Mission = typeof missionCompilation; type Outfit = typeof outfitCompilation; type Patch = typeof patchCompilation; @@ -64,7 +64,7 @@ type Trailer = typeof trailerCompilation; type Update = typeof updateCompilation; type Verification = typeof verificationCompilation; type Verify = typeof verifyCompilation; -type Compilation = About | Application | Apply | Approval | Approve | Arrival | Bear | Chat | Count | Departure | Emoji | Gate | Help | Hyperlink | Leaderboard | Mission | Outfit | Patch | Patching | Posting | Raw | Record | Refusal | Refuse | Roadmap | Rule7 | Soundtrack | Store | Tracker | Trailer | Update | Verification | Verify; +type Compilation = About | Application | Apply | Approval | Approve | Arrival | Bear | Chat | Count | Departure | Emoji | Gate | Help | Leaderboard | Link | Mission | Outfit | Patch | Patching | Posting | Raw | Record | Refusal | Refuse | Roadmap | Rule7 | Soundtrack | Store | Tracker | Trailer | Update | Verification | Verify; const about: About = aboutCompilation; const application: Application = applicationCompilation; const apply: Apply = applyCompilation; @@ -78,8 +78,8 @@ const departure: Departure = departureCompilation; const emoji: Emoji = emojiCompilation; const gate: Gate = gateCompilation; const help: Help = helpCompilation; -const hyperlink: Hyperlink = hyperlinkCompilation; const leaderboard: Leaderboard = leaderboardCompilation; +const link: Link = linkCompilation; const mission: Mission = missionCompilation; const outfit: Outfit = outfitCompilation; const patch: Patch = patchCompilation; @@ -113,8 +113,8 @@ export type { Emoji, Gate, Help, - Hyperlink, Leaderboard, + Link, Mission, Outfit, Patch, @@ -148,8 +148,8 @@ export { emoji, gate, help, - hyperlink, leaderboard, + link, mission, outfit, patch, diff --git a/src/compilations/hyperlink.ts b/src/compilations/hyperlink.ts deleted file mode 100644 index 3f62180..0000000 --- a/src/compilations/hyperlink.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type {Hyperlink} from "../dependencies.js"; -import type {Localized} from "../utils/string.js"; -import {hyperlink} from "../definitions.js"; -import {compileAll} from "../utils/string.js"; -type HelpWithChannelsLocalizations = Localized<(groups: Hyperlink["helpWithChannels"]) => string>; -type HelpWithoutChannelsLocalizations = Localized<(groups: Hyperlink["helpWithoutChannels"]) => string>; -type HyperlinkCompilation = { - helpWithChannels: HelpWithChannelsLocalizations, - helpWithoutChannels: HelpWithoutChannelsLocalizations, -}; -const helpWithChannelsLocalizations: HelpWithChannelsLocalizations = compileAll(hyperlink["helpWithChannels"]); -const helpWithoutChannelsLocalizations: HelpWithoutChannelsLocalizations = compileAll(hyperlink["helpWithoutChannels"]); -const hyperlinkCompilation: HyperlinkCompilation = { - helpWithChannels: helpWithChannelsLocalizations, - helpWithoutChannels: helpWithoutChannelsLocalizations, -}; -export default hyperlinkCompilation; diff --git a/src/compilations/link.ts b/src/compilations/link.ts new file mode 100644 index 0000000..9ab6d40 --- /dev/null +++ b/src/compilations/link.ts @@ -0,0 +1,17 @@ +import type {Link} from "../dependencies.js"; +import type {Localized} from "../utils/string.js"; +import {link} from "../definitions.js"; +import {compileAll} from "../utils/string.js"; +type HelpWithChannelsLocalizations = Localized<(groups: Link["helpWithChannels"]) => string>; +type HelpWithoutChannelsLocalizations = Localized<(groups: Link["helpWithoutChannels"]) => string>; +type LinkCompilation = { + helpWithChannels: HelpWithChannelsLocalizations, + helpWithoutChannels: HelpWithoutChannelsLocalizations, +}; +const helpWithChannelsLocalizations: HelpWithChannelsLocalizations = compileAll(link["helpWithChannels"]); +const helpWithoutChannelsLocalizations: HelpWithoutChannelsLocalizations = compileAll(link["helpWithoutChannels"]); +const linkCompilation: LinkCompilation = { + helpWithChannels: helpWithChannelsLocalizations, + helpWithoutChannels: helpWithoutChannelsLocalizations, +}; +export default linkCompilation; diff --git a/src/definitions.ts b/src/definitions.ts index 8783bfa..e6d8926 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -12,8 +12,8 @@ import departureDefinition from "./definitions/departure.json" assert {type: "js import emojiDefinition from "./definitions/emoji.json" assert {type: "json"}; import gateDefinition from "./definitions/gate.json" assert {type: "json"}; import helpDefinition from "./definitions/help.json" assert {type: "json"}; -import hyperlinkDefinition from "./definitions/hyperlink.json" assert {type: "json"}; import leaderboardDefinition from "./definitions/leaderboard.json" assert {type: "json"}; +import linkDefinition from "./definitions/link.json" assert {type: "json"}; import missionDefinition from "./definitions/mission.json" assert {type: "json"}; import outfitDefinition from "./definitions/outfit.json" assert {type: "json"}; import patchDefinition from "./definitions/patch.json" assert {type: "json"}; @@ -166,12 +166,6 @@ type Help = { help: Localized, reply: Localized, }; -type Hyperlink = { - ruleName: string, - ruleReason: string, - helpWithChannels: Localized, - helpWithoutChannels: Localized, -}; type Leaderboard = { commandName: string, commandDescription: Localized, @@ -179,6 +173,12 @@ type Leaderboard = { reply: Localized, link: Localized, }; +type Link = { + ruleName: string, + ruleReason: string, + helpWithChannels: Localized, + helpWithoutChannels: Localized, +}; type Mission = { commandName: string, commandDescription: Localized, @@ -327,7 +327,7 @@ type Verify = { reply: Localized, noPermissionReply: Localized, }; -type Definition = About | Application | Apply | Approval | Approve | Arrival | Bear | Chat | Count | Departure | Emoji | Gate | Help | Hyperlink | Leaderboard | Mission | Outfit | Patch | Patching | Posting | Raw | Record | Refusal | Refuse | Roadmap | Rule7 | Soundtrack | Store | Tracker | Trailer | Update | Verification | Verify; +type Definition = About | Application | Apply | Approval | Approve | Arrival | Bear | Chat | Count | Departure | Emoji | Gate | Help | Leaderboard | Link | Mission | Outfit | Patch | Patching | Posting | Raw | Record | Refusal | Refuse | Roadmap | Rule7 | Soundtrack | Store | Tracker | Trailer | Update | Verification | Verify; const about: About = aboutDefinition; const application: Application = applicationDefinition; const apply: Apply = applyDefinition; @@ -341,8 +341,8 @@ const departure: Departure = departureDefinition; const emoji: Emoji = emojiDefinition; const gate: Gate = gateDefinition; const help: Help = helpDefinition; -const hyperlink: Hyperlink = hyperlinkDefinition; const leaderboard: Leaderboard = leaderboardDefinition; +const link: Link = linkDefinition; const mission: Mission = missionDefinition; const outfit: Outfit = outfitDefinition; const patch: Patch = patchDefinition; @@ -376,8 +376,8 @@ export type { Emoji, Gate, Help, - Hyperlink, Leaderboard, + Link, Mission, Outfit, Patch, @@ -411,8 +411,8 @@ export { emoji, gate, help, - hyperlink, leaderboard, + link, mission, outfit, patch, diff --git a/src/definitions/hyperlink.json b/src/definitions/link.json similarity index 96% rename from src/definitions/hyperlink.json rename to src/definitions/link.json index 7c4f96c..fe9e87c 100644 --- a/src/definitions/hyperlink.json +++ b/src/definitions/link.json @@ -1,5 +1,5 @@ { - "ruleName": "hyperlink", + "ruleName": "link", "ruleReason": "Flags messages which contain a hyperlink as such in the given channels", "helpWithChannels": { "en-US": "I flag messages which contain a hyperlink as such in $", diff --git a/src/dependencies.d.ts b/src/dependencies.d.ts index acde8eb..f8787b3 100644 --- a/src/dependencies.d.ts +++ b/src/dependencies.d.ts @@ -11,8 +11,8 @@ import type DepartureDependency from "./dependencies/departure.js"; import type EmojiDependency from "./dependencies/emoji.js"; import type GateDependency from "./dependencies/gate.js"; import type HelpDependency from "./dependencies/help.js"; -import type HyperlinkDependency from "./dependencies/hyperlink.js"; import type LeaderboardDependency from "./dependencies/leaderboard.js"; +import type LinkDependency from "./dependencies/link.js"; import type MissionDependency from "./dependencies/mission.js"; import type OutfitDependency from "./dependencies/outfit.js"; import type PatchDependency from "./dependencies/patch.js"; @@ -44,8 +44,8 @@ type Departure = DepartureDependency; type Emoji = EmojiDependency; type Gate = GateDependency; type Help = HelpDependency; -type Hyperlink = HyperlinkDependency; type Leaderboard = LeaderboardDependency; +type Link = LinkDependency; type Mission = MissionDependency; type Outfit = OutfitDependency; type Patch = PatchDependency; @@ -64,7 +64,7 @@ type Trailer = TrailerDependency; type Update = UpdateDependency; type Verification = VerificationDependency; type Verify = VerifyDependency; -type Dependency = About | Application | Apply | Approval | Approve | Arrival | Bear | Chat | Count | Departure | Emoji | Gate | Help | Hyperlink | Leaderboard | Mission | Outfit | Patch | Patching | Posting | Raw | Record | Refusal | Refuse | Roadmap | Rule7 | Soundtrack | Store | Tracker | Trailer | Update | Verification | Verify; +type Dependency = About | Application | Apply | Approval | Approve | Arrival | Bear | Chat | Count | Departure | Emoji | Gate | Help | Leaderboard | Link | Mission | Outfit | Patch | Patching | Posting | Raw | Record | Refusal | Refuse | Roadmap | Rule7 | Soundtrack | Store | Tracker | Trailer | Update | Verification | Verify; export type {Dependency as default}; export type { About, @@ -80,8 +80,8 @@ export type { Emoji, Gate, Help, - Hyperlink, Leaderboard, + Link, Mission, Outfit, Patch, diff --git a/src/dependencies/hyperlink.d.ts b/src/dependencies/link.d.ts similarity index 72% rename from src/dependencies/hyperlink.d.ts rename to src/dependencies/link.d.ts index 2233eba..a63a667 100644 --- a/src/dependencies/hyperlink.d.ts +++ b/src/dependencies/link.d.ts @@ -2,8 +2,8 @@ type HelpWithChannelsGroups = { channelMentions: () => string, }; type HelpWithoutChannelsGroups = {}; -type HyperlinkDependency = { +type LinkDependency = { helpWithChannels: HelpWithChannelsGroups, helpWithoutChannels: HelpWithoutChannelsGroups, }; -export type {HyperlinkDependency as default}; +export type {LinkDependency as default}; diff --git a/src/emojis/hyperlink.png b/src/emojis/hyperlink.png deleted file mode 100644 index 110f4e0..0000000 Binary files a/src/emojis/hyperlink.png and /dev/null differ diff --git a/src/emojis/hyperlink.svg b/src/emojis/hyperlink.svg deleted file mode 100644 index df47ae6..0000000 --- a/src/emojis/hyperlink.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/emojis/link.png b/src/emojis/link.png new file mode 100644 index 0000000..32cd023 Binary files /dev/null and b/src/emojis/link.png differ diff --git a/src/emojis/link.svg b/src/emojis/link.svg new file mode 100644 index 0000000..11a8969 --- /dev/null +++ b/src/emojis/link.svg @@ -0,0 +1 @@ + diff --git a/src/rules.ts b/src/rules.ts index 846a708..0b2a3d4 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -6,7 +6,7 @@ import type { AutoModerationRuleCreateOptions, } from "discord.js"; import type {Localized} from "./utils/string.js"; -import hyperlinkRule from "./rules/hyperlink.js"; +import linkRule from "./rules/link.js"; import rule7Rule from "./rules/rule7.js"; type AutoModerationRuleData = Omit & { exemptChannels?: string[], @@ -24,7 +24,7 @@ type Rule = { execute(execution: AutoModerationActionExecution): Promise; describe(autoModerationRule: AutoModerationRule): Localized<(groups: {}) => string>; }; -const hyperlink: Rule = hyperlinkRule; +const link: Rule = linkRule; const rule7: Rule = rule7Rule; export type {Rule as default}; export type { @@ -33,6 +33,6 @@ export type { AutoModerationRuleData, }; export { - hyperlink, + link, rule7, }; diff --git a/src/rules/hyperlink.ts b/src/rules/link.ts similarity index 62% rename from src/rules/hyperlink.ts rename to src/rules/link.ts index 2c5279a..dd7d047 100644 --- a/src/rules/hyperlink.ts +++ b/src/rules/link.ts @@ -10,9 +10,9 @@ import type { ThreadChannel, } from "discord.js"; import type {Canvas, CanvasRenderingContext2D, Image} from "canvas"; -import type {Hyperlink as HyperlinkCompilation} from "../compilations.js"; -import type {Hyperlink as HyperlinkDefinition} from "../definitions.js"; -import type {Hyperlink as HyperlinkDependency} from "../dependencies.js"; +import type {Link as LinkCompilation} from "../compilations.js"; +import type {Link as LinkDefinition} from "../definitions.js"; +import type {Link as LinkDependency} from "../dependencies.js"; import type Rule from "../rules.js"; import type {AutoModerationActionExecution, AutoModerationRule, AutoModerationRuleData} from "../rules.js"; import type {Locale, Localized} from "../utils/string.js"; @@ -23,24 +23,24 @@ import { ChannelType, } from "discord.js"; import canvas from "canvas"; -import {hyperlink as hyperlinkCompilation} from "../compilations.js"; -import {hyperlink as hyperlinkDefinition} from "../definitions.js"; +import {link as linkCompilation} from "../compilations.js"; +import {link as linkDefinition} from "../definitions.js"; import {composeAll, localize} from "../utils/string.js"; -type HelpWithChannelsGroups = HyperlinkDependency["helpWithChannels"]; +type HelpWithChannelsGroups = LinkDependency["helpWithChannels"]; const { ruleName, ruleReason, -}: HyperlinkDefinition = hyperlinkDefinition; +}: LinkDefinition = linkDefinition; const { helpWithChannels: helpWithChannelsLocalizations, helpWithoutChannels: helpWithoutChannelsLocalizations, -}: HyperlinkCompilation = hyperlinkCompilation; +}: LinkCompilation = linkCompilation; const { - SHICKA_HYPERLINK_DEFAULT_ALERT_ACTION_CHANNEL, - SHICKA_HYPERLINK_DEFAULT_EXEMPT_CHANNELS, - SHICKA_HYPERLINK_DEFAULT_EXEMPT_ROLES, - SHICKA_HYPERLINK_REACTION_EMOJI, - SHICKA_HYPERLINK_OVERRIDE_RULES_CHANNEL, + SHICKA_LINK_DEFAULT_ALERT_ACTION_CHANNEL, + SHICKA_LINK_DEFAULT_EXEMPT_CHANNELS, + SHICKA_LINK_DEFAULT_EXEMPT_ROLES, + SHICKA_LINK_REACTION_EMOJI, + SHICKA_LINK_OVERRIDE_RULES_CHANNEL, }: NodeJS.ProcessEnv = process.env; const {createCanvas, loadImage}: any = canvas; const ruleTriggerRegexPatterns: string[] = [ @@ -51,13 +51,13 @@ const ruleTriggerRegexPatterns: string[] = [ "", "https?:///*\\S+", ]; -const ruleAlertActionChannel: string = SHICKA_HYPERLINK_DEFAULT_ALERT_ACTION_CHANNEL ?? ""; -const ruleExemptChannels: string[] | null = SHICKA_HYPERLINK_DEFAULT_EXEMPT_CHANNELS != null ? SHICKA_HYPERLINK_DEFAULT_EXEMPT_CHANNELS.split("\n") : null; -const ruleExemptRoles: string[] | null = SHICKA_HYPERLINK_DEFAULT_EXEMPT_ROLES != null ? SHICKA_HYPERLINK_DEFAULT_EXEMPT_ROLES.split("\n") : null; -const ruleRulesChannel: string | null = SHICKA_HYPERLINK_OVERRIDE_RULES_CHANNEL ?? null; -const ruleReactionEmoji: string = SHICKA_HYPERLINK_REACTION_EMOJI ?? ""; +const ruleAlertActionChannel: string = SHICKA_LINK_DEFAULT_ALERT_ACTION_CHANNEL ?? ""; +const ruleExemptChannels: string[] | null = SHICKA_LINK_DEFAULT_EXEMPT_CHANNELS != null ? SHICKA_LINK_DEFAULT_EXEMPT_CHANNELS.split("\n") : null; +const ruleExemptRoles: string[] | null = SHICKA_LINK_DEFAULT_EXEMPT_ROLES != null ? SHICKA_LINK_DEFAULT_EXEMPT_ROLES.split("\n") : null; +const ruleRulesChannel: string | null = SHICKA_LINK_OVERRIDE_RULES_CHANNEL ?? null; +const ruleReactionEmoji: string = SHICKA_LINK_REACTION_EMOJI ?? ""; const ruleAvatar: string = await (async (): Promise => { - const url: string = `data:image/svg+xml;charset=utf-8,`; + const url: string = `data:image/svg+xml;charset=utf-8,`; const image: Image = await loadImage(url); const canvas: Canvas = createCanvas(256, 256); const context: CanvasRenderingContext2D = canvas.getContext("2d"); @@ -65,7 +65,7 @@ const ruleAvatar: string = await (async (): Promise => { const data: string = canvas.toDataURL(); return data; })(); -const hyperlinkRule: Rule = { +const linkRule: Rule = { register(): AutoModerationRuleData { return { name: ruleName, @@ -148,11 +148,6 @@ const hyperlinkRule: Rule = { } } catch {} try { - await message.react("🇭"); - await message.react("🇾"); - await message.react("🇵"); - await message.react("🇪"); - await message.react("🇷"); await message.react("🇱"); await message.react("🇮"); await message.react("🇳"); @@ -192,4 +187,4 @@ const hyperlinkRule: Rule = { })) : helpWithoutChannelsLocalizations; }, }; -export default hyperlinkRule; +export default linkRule;