mirror of
https://github.com/xHyroM/bun-discord-bot.git
synced 2024-12-26 14:01:07 +01:00
feat: nickcname moderation
This commit is contained in:
parent
47a186fd7d
commit
fa4a844dcb
3 changed files with 32 additions and 0 deletions
|
@ -1,3 +1,4 @@
|
|||
import "./ready.ts";
|
||||
import "./interaction_create.ts";
|
||||
import "./message_create.ts";
|
||||
import "./nickname_moderation.ts";
|
||||
|
|
25
src/listeners/nickname_moderation.ts
Normal file
25
src/listeners/nickname_moderation.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { Events, GuildMember } from "discord.js";
|
||||
import { defineListener } from "../loaders/listeners.ts";
|
||||
import { silently } from "../util.ts";
|
||||
|
||||
defineListener({
|
||||
event: Events.GuildMemberAdd,
|
||||
run: (member: GuildMember) => moderateNick(member)
|
||||
});
|
||||
|
||||
defineListener({
|
||||
event: Events.GuildMemberUpdate,
|
||||
run: (_: GuildMember, newMember: GuildMember) => moderateNick(newMember)
|
||||
});
|
||||
|
||||
async function moderateNick(member: GuildMember) {
|
||||
const name = member.displayName;
|
||||
const normalizedName = name.normalize("NFKC").replace(/^[!$#@%^`&*()]+/, "");
|
||||
|
||||
if (name !== normalizedName) {
|
||||
silently(member.edit({
|
||||
nick: normalizedName,
|
||||
reason: "lame username"
|
||||
}));
|
||||
}
|
||||
}
|
|
@ -1,3 +1,9 @@
|
|||
export function safeSlice<T>(array: T[], length: number) {
|
||||
return array.length > length ? array.slice(0, length) : array;
|
||||
}
|
||||
|
||||
export async function silently<T>(value: Promise<T>) {
|
||||
try {
|
||||
await value;
|
||||
} catch {}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue