-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(extensions:urlfish): complete support for url scanning and exte…
…nsive configuration
- Loading branch information
1 parent
ba804b4
commit 2f9d850
Showing
5 changed files
with
195 additions
and
17 deletions.
There are no files selected for viewing
8 changes: 2 additions & 6 deletions
8
extensions/urlfish/src/events/message/NormalMessageCreateEventListener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
import EventListener from "@sudobot/core/EventListener"; | ||
import { Events } from "@sudobot/types/ClientEvents"; | ||
import type URLFishService from "../../services/URLFishService"; | ||
import { Message } from "discord.js"; | ||
import type URLFishService from "../../services/URLFishService"; | ||
|
||
export default class NormalMessageCreateEventListener extends EventListener<Events.NormalMessageCreate> { | ||
public readonly name = Events.NormalMessageCreate; | ||
|
||
async execute(message: Message) { | ||
const urlfishService = this.client.getService<URLFishService>("urlfish"); | ||
const links = urlfishService.scanMessage(message); | ||
|
||
if (links.length > 0) { | ||
await message.delete(); | ||
} | ||
urlfishService.verifyMessage(message); | ||
} | ||
} |
8 changes: 2 additions & 6 deletions
8
extensions/urlfish/src/events/message/NormalMessageUpdateEventListener.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
import EventListener from "@sudobot/core/EventListener"; | ||
import { Events } from "@sudobot/types/ClientEvents"; | ||
import type URLFishService from "../../services/URLFishService"; | ||
import { Message } from "discord.js"; | ||
import type URLFishService from "../../services/URLFishService"; | ||
|
||
export default class NormalMessageUpdateEventListener extends EventListener<Events.NormalMessageUpdate> { | ||
public readonly name = Events.NormalMessageUpdate; | ||
|
||
async execute(oldMessage: Message, newMessage: Message) { | ||
const urlfishService = this.client.getService<URLFishService>("urlfish"); | ||
const links = urlfishService.scanMessage(newMessage); | ||
|
||
if (links.length > 0) { | ||
await newMessage.delete(); | ||
} | ||
urlfishService.verifyMessage(newMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
import "module-alias/register"; | ||
|
||
import { Extension } from "@sudobot/core/Extension"; | ||
import { Schema } from "./types/config"; | ||
|
||
export default class URLFish extends Extension {} | ||
export default class URLFish extends Extension { | ||
public override guildConfig() { | ||
return { | ||
urlfish: Schema | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { GuildConfig } from "@sudobot/types/GuildConfigSchema"; | ||
import { zSnowflake } from "@sudobot/types/SnowflakeSchema"; | ||
import { z } from "zod"; | ||
|
||
export const Schema = z | ||
.object({ | ||
enabled: z.boolean().default(false).describe("Whether or not URLFish is enabled"), | ||
channels: z | ||
.object({ | ||
enabled_in: z.array(zSnowflake).describe("Channels to enable URLFish in") | ||
}) | ||
.or( | ||
z.object({ | ||
disabled_in: z.array(zSnowflake).describe("Channels to disable URLFish in") | ||
}) | ||
) | ||
.optional() | ||
.describe("Channels to enable or disable URLFish in"), | ||
log_channel: zSnowflake.optional().describe("Channel to log URLFish events to"), | ||
action: z | ||
.enum(["delete", "warn", "mute", "kick", "ban"]) | ||
.default("delete") | ||
.describe("Action to take when a phishing URL is detected"), | ||
mute_duration: z | ||
.number() | ||
.positive() | ||
.min(1000) | ||
.optional() | ||
.describe("Duration to mute a user for when a phishing URL is detected"), | ||
infraction_reason: z.string().optional().describe("Reason to use when creating an infraction") | ||
}) | ||
.describe("URLFish Configuration") | ||
.optional(); | ||
|
||
export type Config = z.infer<typeof Schema>; | ||
export type GuildConfigForExtension = { | ||
urlfish: Config; | ||
}; | ||
export type GuildConfigWithExtension = GuildConfig & GuildConfigForExtension; | ||
export type ActionToTake = NonNullable<Config>["action"]; |