-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Psykka <Psykka@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
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,49 @@ | ||
import type { TextChannel, Message } from "discord.js"; | ||
import { container } from "@sapphire/pieces"; | ||
|
||
export default async function emojiHelper(message: Message) { | ||
const clientEmojis = container.client.emojis.cache; | ||
const emotes = clientEmojis?.map((emoji) => emoji.toString()); | ||
|
||
if (!emotes) return; | ||
|
||
const regex = /(?<!<\w?):(\w+):(?!\d+>)/g; | ||
const content = message.content; | ||
const catchedEmojis = content.match(regex); | ||
|
||
if ( | ||
!catchedEmojis?.length || | ||
catchedEmojis?.every((emoji) => | ||
clientEmojis.every((emojiData) => `:${emojiData.name}:` !== emoji), | ||
) | ||
) | ||
return; | ||
|
||
const fixed = message.content.replace(regex, (match, name) => { | ||
if (emotes.includes(match)) return match; | ||
return ( | ||
clientEmojis.find((emojiData) => emojiData.name === name)?.toString() || | ||
"" | ||
); | ||
}); | ||
|
||
if (fixed.length) { | ||
if (message.deletable) { | ||
message.delete(); | ||
} | ||
|
||
const channel = message.channel as TextChannel; | ||
const member = message.member; | ||
|
||
if (member) { | ||
const webhook = await channel.createWebhook({ | ||
name: member?.displayName ?? member.user.username, | ||
avatar: member.displayAvatarURL({ forceStatic: false }), | ||
reason: "Emoji Helper!", | ||
}); | ||
|
||
await webhook.send(fixed); | ||
webhook.delete(); | ||
} | ||
} | ||
} |
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,41 @@ | ||
import type { Message } from "discord.js"; | ||
|
||
const sites = { | ||
"https://www.youtube.com/shorts/": "https://youtu.be/", | ||
"https://www.youtube.com/watch?v=": "https://youtu.be/", | ||
"https://twitter.com/": "https://vxtwitter.com/", | ||
"https://x.com/": "https://vxtwitter.com/", | ||
"https://www.tiktok.com/": "https://www.vxtiktok.com/", | ||
"https://www.instagram.com/": "https://g.ddinstagram.com/", | ||
"https://www.reddit.com/": "https://rxddit.com/", | ||
}; | ||
|
||
export default function urlHelper(message: Message) { | ||
const content = message.content; | ||
const regex = /(https?:\/\/[^\s]+)/g; | ||
const urls = content.match(regex); | ||
const fixes = Object.entries(sites); | ||
|
||
if ( | ||
!urls || | ||
!urls.length || | ||
urls.every((url) => fixes.every(([site]) => !url.includes(site))) | ||
) | ||
return; | ||
|
||
const fixedUrls = urls.map((url) => { | ||
let newUrl = url; | ||
for (const [site, replacement] of fixes) { | ||
if (newUrl.includes(site)) { | ||
newUrl = newUrl.replace(site, replacement); | ||
} | ||
} | ||
return newUrl; | ||
}); | ||
|
||
message.suppressEmbeds(true); | ||
message.reply({ | ||
content: fixedUrls.join("\n"), | ||
allowedMentions: { repliedUser: false }, | ||
}); | ||
} |
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,25 @@ | ||
import giveXp from "@/events/giveXp.js"; | ||
import urlHelper from "@/events/urlHelper.js"; | ||
import emojiHelper from "@/events/emojiHelper.js"; | ||
import { Listener } from "@sapphire/framework"; | ||
import type { Message } from "discord.js"; | ||
|
||
export class MessageCreate extends Listener { | ||
public constructor( | ||
context: Listener.LoaderContext, | ||
options: Listener.Options, | ||
) { | ||
super(context, { | ||
...options, | ||
event: "messageCreate", | ||
}); | ||
} | ||
|
||
public run(message: Message) { | ||
if (message.author.bot) return; | ||
|
||
urlHelper(message); | ||
emojiHelper(message); | ||
giveXp(message); | ||
} | ||
} |