child command

This commit is contained in:
Lea 2024-05-08 16:15:11 +02:00
parent e67713ad97
commit 9a69d15a1e
Signed by: Lea
GPG key ID: 1BAFFE8347019C42

View file

@ -11,6 +11,7 @@ config();
type Db = {
probation: string[];
blocked: { [key: string]: { blocked: boolean, kick: boolean } };
children: string[];
}
type CommandFlag = {
@ -36,7 +37,7 @@ const CommandFlags: CommandFlag[] = [
},
];
const PREFIX_WORD = '/kibby';
const PREFIX_WORD = process.env.PREFIX_WORD || '/kibby';
const RE_COMMAND_ARGS = /(?<!\\)"[^(?<!\\)"\n]*"|[\S]+/g;
const RE_COMMAND_ARG_QUOTED = /^".*(?<!\\)"$/g;
const RE_QUOTE_BACKSLASH = /\\"/g;
@ -55,6 +56,8 @@ const COMMANDS = {
'unapprove': 'Send users to probation',
'block': 'Troll a user',
'unblock': 'Untroll a user',
'child': 'Mark a user as child',
'notchild': 'Remove user\'s child status',
'sherlock': 'Run a sherlock scan on a username',
}
@ -68,9 +71,10 @@ const client = new Client({ });
client.loginBot(process.env.TOKEN);
db.read().then(() => {
db.data ||= { probation: [], blocked: {} };
db.data ||= { probation: [], blocked: {}, children: [] };
db.data.probation ||= [];
db.data.blocked ||= {};
db.data.children ||= [];
if (Array.isArray(db.data.blocked)) {
console.log('Running migration: db.blocked');
@ -252,6 +256,21 @@ const setProbation = async (member: Member, probation: boolean) => {
}
}
const setChild = async (member: Member, child: boolean) => {
if (child) {
if (member.roles?.includes(process.env.NSFW_ROLE!)) {
await member?.edit({ roles: member.roles.filter(r => r != process.env.NSFW_ROLE) });
}
if (!db.data?.children.includes(member._id.user)) {
db.data?.children.push(member._id.user);
await db.write();
}
} else {
if (db.data?.children.includes(member._id.user)) db.data.children = db.data.children.filter((id) => id != member._id.user);
await db.write();
}
}
client.on('message', async (message) => {
try {
if (!message.content || typeof message.content != 'string') return;
@ -508,6 +527,40 @@ client.on('message', async (message) => {
break;
}
case 'child': {
const members = getMembers(message.channel!.server_id);
const users = await extractUsers(message, args);
if (!users) return message.reply({ embeds: [
embed("No users provided", undefined, "ERROR"),
] });
for (const user of users) {
const member = members.find(m => m._id.user == user._id);
await setChild(member!, true);
}
await message.reply({ embeds: [
embed(`The selected user${users.length != 1 ? 's' : ''} have been marked as child.`),
] });
break;
}
case 'adult':
case 'unchild':
case 'notchild': {
const members = getMembers(message.channel!.server_id);
const users = await extractUsers(message, args);
if (!users) return message.reply({ embeds: [
embed("No users provided", undefined, "ERROR"),
] });
for (const user of users) {
const member = members.find(m => m._id.user == user._id);
await setChild(member!, false);
}
await message.reply({ embeds: [
embed(`The selected user${users.length != 1 ? 's' : ''} have been removed from the child list.`),
] });
break;
}
case 'type': {
if (message.channel?.typing_ids.has(client.user!._id)) {
message.channel.stopTyping();