mirror of
https://github.com/janderedev/automod.git
synced 2024-12-22 18:55:28 +00:00
cocainer
This commit is contained in:
parent
6b0f9f421d
commit
2fbdcf26d7
|
@ -12,7 +12,6 @@ export default {
|
||||||
aliases: [ 'admins', 'manager', 'managers' ],
|
aliases: [ 'admins', 'manager', 'managers' ],
|
||||||
description: 'Allow users to control the bot\'s configuration',
|
description: 'Allow users to control the bot\'s configuration',
|
||||||
syntax: SYNTAX,
|
syntax: SYNTAX,
|
||||||
serverOnly: true,
|
|
||||||
run: async (message: Message, args: string[]) => {
|
run: async (message: Message, args: string[]) => {
|
||||||
if (!hasPerm(message.member!, 'ManageServer'))
|
if (!hasPerm(message.member!, 'ManageServer'))
|
||||||
return message.reply('You need **ManageServer** permission to use this command.');
|
return message.reply('You need **ManageServer** permission to use this command.');
|
||||||
|
|
|
@ -6,7 +6,6 @@ export default {
|
||||||
name: 'debug',
|
name: 'debug',
|
||||||
aliases: null,
|
aliases: null,
|
||||||
description: 'give info helpful for development and debugging',
|
description: 'give info helpful for development and debugging',
|
||||||
serverOnly: false,
|
|
||||||
run: (message: Message, args: string[]) => {
|
run: (message: Message, args: string[]) => {
|
||||||
message.reply(`Server ID: ${message.channel?.server_id || 'None'}\n`
|
message.reply(`Server ID: ${message.channel?.server_id || 'None'}\n`
|
||||||
+ `Channel ID: ${message.channel_id}\n`
|
+ `Channel ID: ${message.channel_id}\n`
|
||||||
|
|
|
@ -8,7 +8,6 @@ export default {
|
||||||
description: 'Evaluate JS code',
|
description: 'Evaluate JS code',
|
||||||
restrict: 'BOTOWNER',
|
restrict: 'BOTOWNER',
|
||||||
removeEmptyArgs: false,
|
removeEmptyArgs: false,
|
||||||
serverOnly: false,
|
|
||||||
run: async (message: Message, args: string[]) => {
|
run: async (message: Message, args: string[]) => {
|
||||||
let cmd = `let { client } = require("../..");`
|
let cmd = `let { client } = require("../..");`
|
||||||
+ `let axios = require("axios").default;`
|
+ `let axios = require("axios").default;`
|
||||||
|
|
|
@ -6,7 +6,6 @@ export default {
|
||||||
name: 'ping',
|
name: 'ping',
|
||||||
aliases: null,
|
aliases: null,
|
||||||
description: 'ping pong',
|
description: 'ping pong',
|
||||||
serverOnly: false,
|
|
||||||
run: async (message: Message, args: string[]) => {
|
run: async (message: Message, args: string[]) => {
|
||||||
let now = Date.now();
|
let now = Date.now();
|
||||||
message.reply(`Measuring...`)
|
message.reply(`Measuring...`)
|
||||||
|
|
|
@ -13,7 +13,6 @@ export default {
|
||||||
aliases: null,
|
aliases: null,
|
||||||
description: 'modify prefix',
|
description: 'modify prefix',
|
||||||
syntax: SYNTAX,
|
syntax: SYNTAX,
|
||||||
serverOnly: true,
|
|
||||||
run: async (message: Message, args: string[]) => {
|
run: async (message: Message, args: string[]) => {
|
||||||
let config: ServerConfig = (await client.db.get('servers').findOne({ id: message.channel?.server_id })) ?? {};
|
let config: ServerConfig = (await client.db.get('servers').findOne({ id: message.channel?.server_id })) ?? {};
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ export default {
|
||||||
name: 'settings',
|
name: 'settings',
|
||||||
aliases: [ 'setting' ],
|
aliases: [ 'setting' ],
|
||||||
description: 'change antispam settings',
|
description: 'change antispam settings',
|
||||||
serverOnly: false,
|
|
||||||
run: async (message: Message, args: string[]) => {
|
run: async (message: Message, args: string[]) => {
|
||||||
if (!isBotManager(message.member!)) return message.reply(NO_MANAGER_MSG);
|
if (!isBotManager(message.member!)) return message.reply(NO_MANAGER_MSG);
|
||||||
|
|
||||||
|
@ -22,12 +21,21 @@ export default {
|
||||||
max_msg: 5,
|
max_msg: 5,
|
||||||
timeframe: 3,
|
timeframe: 3,
|
||||||
action: ModerationAction.Delete,
|
action: ModerationAction.Delete,
|
||||||
channels: [ '01FHJD5D2PBRTEVPNFM1FRY85J' ],
|
channels: null,
|
||||||
|
} as AntispamRule,
|
||||||
|
{
|
||||||
|
id: ulid(),
|
||||||
|
max_msg: 4,
|
||||||
|
timeframe: 3,
|
||||||
|
action: ModerationAction.Warn,
|
||||||
|
channels: null,
|
||||||
} as AntispamRule
|
} as AntispamRule
|
||||||
]
|
]
|
||||||
} as AutomodSettings;
|
} as AutomodSettings;
|
||||||
|
|
||||||
client.db.get('servers')
|
client.db.get('servers')
|
||||||
.update({ id: message.channel?.server_id }, { $set: { automodSettings: settings } });
|
.update({ id: message.channel?.server_id }, { $set: { automodSettings: settings } });
|
||||||
|
|
||||||
|
message.reply('Default config restored');
|
||||||
}
|
}
|
||||||
} as Command;
|
} as Command;
|
||||||
|
|
|
@ -8,7 +8,6 @@ export default {
|
||||||
description: 'Run code in a shell',
|
description: 'Run code in a shell',
|
||||||
restrict: 'BOTOWNER',
|
restrict: 'BOTOWNER',
|
||||||
removeEmptyArgs: false,
|
removeEmptyArgs: false,
|
||||||
serverOnly: false,
|
|
||||||
run: async (message: Message, args: string[]) => {
|
run: async (message: Message, args: string[]) => {
|
||||||
let cmd = args.join(' ');
|
let cmd = args.join(' ');
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ export default {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
aliases: [ 'testalias' ],
|
aliases: [ 'testalias' ],
|
||||||
description: 'epic test command',
|
description: 'epic test command',
|
||||||
serverOnly: false,
|
|
||||||
run: (message: Message, args: string[]) => {
|
run: (message: Message, args: string[]) => {
|
||||||
message.reply('I am here');
|
message.reply('I am here');
|
||||||
}
|
}
|
||||||
|
|
114
src/bot/commands/whitelist.ts
Normal file
114
src/bot/commands/whitelist.ts
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
import { Message } from "revolt.js/dist/maps/Messages";
|
||||||
|
import { User } from "revolt.js/dist/maps/Users";
|
||||||
|
import { client } from "../..";
|
||||||
|
import Command from "../../struct/Command";
|
||||||
|
import ServerConfig from "../../struct/ServerConfig";
|
||||||
|
import { isBotManager, NO_MANAGER_MSG, parseUser } from "../util";
|
||||||
|
|
||||||
|
const SYNTAX = '';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'whitelist',
|
||||||
|
aliases: [],
|
||||||
|
description: 'Allow users or roles to bypass moderation rules',
|
||||||
|
syntax: SYNTAX,
|
||||||
|
run: async (message: Message, args: string[]) => {
|
||||||
|
let config: ServerConfig = await client.db.get('servers').findOne({ id: message.channel?.server_id }) || {}
|
||||||
|
if (!config.whitelist) config.whitelist = { users: [], roles: [], managers: true }
|
||||||
|
|
||||||
|
if (!isBotManager(message.member!)) return message.reply(NO_MANAGER_MSG);
|
||||||
|
|
||||||
|
let user: User|null, role: string|undefined;
|
||||||
|
switch(args[0]?.toLowerCase()) {
|
||||||
|
case 'add':
|
||||||
|
case 'set':
|
||||||
|
if (!args[1]) return message.reply('You need to spefify a user or role name.');
|
||||||
|
|
||||||
|
role = Object.entries(message.channel?.server?.roles ?? {})
|
||||||
|
.find((r) => r[1].name?.toLowerCase() == args[1].toLowerCase()
|
||||||
|
|| r[0] == args[1].toUpperCase())
|
||||||
|
?.[0];
|
||||||
|
|
||||||
|
if (role) {
|
||||||
|
if (config.whitelist!.roles?.includes(role))
|
||||||
|
return message.reply('That role is already whitelisted.');
|
||||||
|
|
||||||
|
config.whitelist!.roles = [role, ...(config.whitelist!.roles ?? [])];
|
||||||
|
await client.db.get('servers').update({ id: message.channel?.server_id }, { $set: { whitelist: config.whitelist } });
|
||||||
|
return message.reply(`Added role to whitelist!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
user = await parseUser(args[1])
|
||||||
|
if (user == null) return message.reply('I can\'t find that user or role.');
|
||||||
|
if (user.bot != null) return message.reply('Bots cannot be whitelisted.');
|
||||||
|
if (config.whitelist!.users?.includes(user._id))
|
||||||
|
return message.reply('That user is already whitelisted.');
|
||||||
|
|
||||||
|
config.whitelist!.users = [user._id, ...(config.whitelist!.users ?? [])];
|
||||||
|
await client.db.get('servers').update({ id: message.channel?.server_id }, { $set: { whitelist: config.whitelist } });
|
||||||
|
return message.reply('Added user to whitelist!');
|
||||||
|
break;
|
||||||
|
case 'rm':
|
||||||
|
case 'del':
|
||||||
|
case 'remove':
|
||||||
|
case 'delete':
|
||||||
|
if (!args[1]) return message.reply('You need to spefify a user or role name.');
|
||||||
|
|
||||||
|
role = Object.entries(message.channel?.server?.roles ?? {})
|
||||||
|
.find((r) => r[1].name?.toLowerCase() == args[1].toLowerCase()
|
||||||
|
|| r[0] == args[1].toUpperCase())
|
||||||
|
?.[0];
|
||||||
|
|
||||||
|
if (role) {
|
||||||
|
if (!config.whitelist!.roles?.includes(role))
|
||||||
|
return message.reply('That role is not whitelisted.');
|
||||||
|
|
||||||
|
config.whitelist!.roles = config.whitelist!.roles.filter(r => r != role);
|
||||||
|
await client.db.get('servers').update({ id: message.channel?.server_id }, { $set: { whitelist: config.whitelist } });
|
||||||
|
return message.reply(`Removed role from whitelist!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
user = await parseUser(args[1])
|
||||||
|
if (user == null) return message.reply('I can\'t find that user or role.');
|
||||||
|
if (!config.whitelist!.users?.includes(user._id))
|
||||||
|
return message.reply('That user is not whitelisted.');
|
||||||
|
|
||||||
|
config.whitelist!.users = config.whitelist!.users.filter(u => u != user?._id);
|
||||||
|
await client.db.get('servers').update({ id: message.channel?.server_id }, { $set: { whitelist: config.whitelist } });
|
||||||
|
return message.reply('Removed user from whitelist!');
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
case 'ls':
|
||||||
|
case 'list':
|
||||||
|
case 'show':
|
||||||
|
let str = `## Whitelisted users\n`
|
||||||
|
+ `### Users\n`;
|
||||||
|
|
||||||
|
if (config.whitelist.users?.length) {
|
||||||
|
config.whitelist.users?.forEach((u, index) => {
|
||||||
|
if (index < 15) str += `* <@${u}>\n`;
|
||||||
|
if (index == 15) str += `**${index - 15} more user${config.whitelist?.users?.length == 16 ? '' : 's'}**\n`;
|
||||||
|
});
|
||||||
|
} else str += `**No whitelisted users**\n`;
|
||||||
|
|
||||||
|
str += `\u200b\n### Roles\n`;
|
||||||
|
|
||||||
|
if (config.whitelist.roles?.length) {
|
||||||
|
config.whitelist.roles
|
||||||
|
?.map(r => message.channel?.server?.roles?.[r]?.name || `Unknown role (${r})`)
|
||||||
|
.forEach((r, index) => {
|
||||||
|
if (index < 15) str += `* ${r}\n`;
|
||||||
|
if (index == 15) str += `**${config.whitelist!.roles!.length - 15} more role${config.whitelist?.roles?.length == 16 ? '' : 's'}**\n`;
|
||||||
|
});
|
||||||
|
} else str += `**No whitelisted roles**\n`;
|
||||||
|
|
||||||
|
str += `\u200b\nAdmins and bot managers: **${config.whitelist.managers === false ? 'No' : 'Yes'}**`;
|
||||||
|
|
||||||
|
message.reply(str)
|
||||||
|
?.catch(e => message.reply(String(e)));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
message.reply(`Command syntax: ${SYNTAX}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} as Command;
|
|
@ -3,6 +3,7 @@ import { client } from "../..";
|
||||||
import ModerationAction from "../../struct/antispam/ModerationAction";
|
import ModerationAction from "../../struct/antispam/ModerationAction";
|
||||||
import ServerConfig from "../../struct/ServerConfig";
|
import ServerConfig from "../../struct/ServerConfig";
|
||||||
import logger from "../logger";
|
import logger from "../logger";
|
||||||
|
import { isBotManager } from "../util";
|
||||||
|
|
||||||
let msgCountStore: Map<string, { users: any }> = new Map();
|
let msgCountStore: Map<string, { users: any }> = new Map();
|
||||||
|
|
||||||
|
@ -22,6 +23,10 @@ async function antispam(message: Message): Promise<boolean> {
|
||||||
msgCountStore.set(rule.id, { users: {} });
|
msgCountStore.set(rule.id, { users: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message.author?.bot != null) break;
|
||||||
|
if (serverRules.whitelist?.users?.includes(message.author_id)) break;
|
||||||
|
if (message.member?.roles?.filter(r => serverRules.whitelist?.roles?.includes(r)).length) break;
|
||||||
|
if (serverRules.whitelist?.managers !== false && isBotManager(message.member!)) break;
|
||||||
if (rule.channels?.indexOf(message.channel_id) == -1) break;
|
if (rule.channels?.indexOf(message.channel_id) == -1) break;
|
||||||
|
|
||||||
let store = msgCountStore.get(rule.id)!;
|
let store = msgCountStore.get(rule.id)!;
|
||||||
|
|
|
@ -6,7 +6,10 @@ import path from 'path';
|
||||||
import ServerConfig from "../../struct/ServerConfig";
|
import ServerConfig from "../../struct/ServerConfig";
|
||||||
import { antispam } from "./antispam";
|
import { antispam } from "./antispam";
|
||||||
|
|
||||||
const DEFAULT_PREFIX = process.env['PREFIX'] ?? '/';
|
const DEFAULT_PREFIX = process.env['PREFIX']
|
||||||
|
?? process.env['BOT_PREFIX']
|
||||||
|
?? process.env['COMMAND_PREFIX']
|
||||||
|
?? '/';
|
||||||
|
|
||||||
let commands: Command[] = fs.readdirSync(path.join(__dirname, '..', 'commands'))
|
let commands: Command[] = fs.readdirSync(path.join(__dirname, '..', 'commands'))
|
||||||
.filter(file => file.endsWith('.js'))
|
.filter(file => file.endsWith('.js'))
|
||||||
|
@ -14,7 +17,10 @@ let commands: Command[] = fs.readdirSync(path.join(__dirname, '..', 'commands'))
|
||||||
|
|
||||||
client.on('message', async message => {
|
client.on('message', async message => {
|
||||||
logger.debug(`Message -> ${message.content}`);
|
logger.debug(`Message -> ${message.content}`);
|
||||||
if (typeof message.content != 'string' || message.author_id == client.user?._id || !message.channel) return;
|
|
||||||
|
if (typeof message.content != 'string' ||
|
||||||
|
message.author_id == client.user?._id ||
|
||||||
|
!message.channel?.server) return;
|
||||||
|
|
||||||
// Send message through anti spam check
|
// Send message through anti spam check
|
||||||
if (!antispam(message)) return;
|
if (!antispam(message)) return;
|
||||||
|
@ -50,10 +56,6 @@ client.on('message', async message => {
|
||||||
// Create document for server in DB, if not already present
|
// Create document for server in DB, if not already present
|
||||||
if (JSON.stringify(config) == '{}') await client.db.get('servers').insert({ id: message.channel?.server_id });
|
if (JSON.stringify(config) == '{}') await client.db.get('servers').insert({ id: message.channel?.server_id });
|
||||||
|
|
||||||
if (cmd.serverOnly && !message.channel?.server) {
|
|
||||||
return message.reply('This command is not available in direct messages.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd.removeEmptyArgs !== false) {
|
if (cmd.removeEmptyArgs !== false) {
|
||||||
args = args.filter(a => a.length > 0);
|
args = args.filter(a => a.length > 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,10 @@ async function parseUser(text: string): Promise<User|null> {
|
||||||
if (user) return user;
|
if (user) return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uid) return await client.users.fetch(uid) || null;
|
try {
|
||||||
else return null;
|
if (uid) return await client.users.fetch(uid) || null;
|
||||||
|
else return null;
|
||||||
|
} catch(e) { return null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function isBotManager(member: Member) {
|
async function isBotManager(member: Member) {
|
||||||
|
|
|
@ -6,7 +6,6 @@ class Command {
|
||||||
restrict?: 'BOTOWNER' | null;
|
restrict?: 'BOTOWNER' | null;
|
||||||
removeEmptyArgs?: boolean | null;
|
removeEmptyArgs?: boolean | null;
|
||||||
run: Function;
|
run: Function;
|
||||||
serverOnly: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Command;
|
export default Command;
|
||||||
|
|
|
@ -6,6 +6,11 @@ class ServerConfig {
|
||||||
spaceAfterPrefix: boolean | undefined;
|
spaceAfterPrefix: boolean | undefined;
|
||||||
automodSettings: AutomodSettings | undefined;
|
automodSettings: AutomodSettings | undefined;
|
||||||
botManagers: string[] | undefined;
|
botManagers: string[] | undefined;
|
||||||
|
whitelist: {
|
||||||
|
users: string[] | undefined,
|
||||||
|
roles: string[] | undefined,
|
||||||
|
managers: boolean | undefined,
|
||||||
|
} | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ServerConfig;
|
export default ServerConfig;
|
||||||
|
|
Loading…
Reference in a new issue