Skip to content

Commit

Permalink
Automod (#28)
Browse files Browse the repository at this point in the history
* automod permit

* unpermit a user

* infractions

* fix oversite

* fix oversite v2

* Squashed commit of the following:

commit a30f30c
Author: Kath <[email protected]>
Date:   Thu Aug 1 08:51:50 2024 +0800

    update renovate config

commit 550d72a
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Date:   Thu Aug 1 08:37:43 2024 +0800

    chore(deps): update dependency typescript-eslint to v8 (#18)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

commit 922806c
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Date:   Thu Aug 1 08:36:45 2024 +0800

    chore(deps): Update dependency @types/node to ^22.0.2 (#22)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

commit 4fa7789
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Date:   Wed Jul 31 20:36:20 2024 +0800

    chore(deps): Update dependency tsx to ^4.16.3 (#21)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

commit 8c9c717
Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Date:   Wed Jul 31 20:35:47 2024 +0800

    chore(deps): Update dependency mongoose to ^8.5.2 (#20)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* mute/unmute

* Automod System

* Fix automod url regex and logic (#25)

* fix(allowed-urls): update regex and update logic

* update(testfile): add new code to test file

* simply logic

* delete test file

* remove else

* Class based code

* Fix urlTest being flipped

* Move auto-link to mongo

* Refractor automod

* Save attachments when antilink is triggered

* Buttons

---------

Co-authored-by: Zickles <[email protected]>
  • Loading branch information
Kathund and Zickles authored Aug 6, 2024
1 parent 3ef8439 commit eaa079d
Show file tree
Hide file tree
Showing 24 changed files with 1,197 additions and 362 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/config.json
node_modules/
logs/
build/
build/
data/
5 changes: 4 additions & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"teamRole": "TEAM_ROLE_ID",
"devRole": "DEV_ROLE_ID",
"contributorsRole": "CONTRIBUTORS_ROLE_ID",
"supportCategory": "SUPPORT_CATEGORY_ID"
"supportCategory": "SUPPORT_CATEGORY_ID",
"autoModBypassRole": "AUTOMOD_BYPASS_ROLE_ID",
"serverId": "SERVER_ID",
"infractionLogchannel": "INFRACTION_LOG_CHANNEL"
}
7 changes: 4 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default [
sourceType: 'module',
globals: {
...globals.es2022,
...globals.node
...globals.node,
guild: 'writable'
}
},
rules: {
Expand Down Expand Up @@ -44,6 +45,7 @@ export default [
'default-case-last': 'warn',
'no-self-compare': 'error',
'no-new-wrappers': 'error',
'no-fallthrough': 'error',
'no-lone-blocks': 'error',
'no-undef-init': 'error',
'no-else-return': 'warn',
Expand All @@ -56,11 +58,10 @@ export default [
'no-multi-str': 'warn',
'no-lonely-if': 'warn',
'no-new-func': 'error',
'no-console': 'error',
camelcase: 'warn',
'no-var': 'warn',
eqeqeq: 'warn',
semi: 'error'
}
}
];
];
23 changes: 3 additions & 20 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
import { Client, Events, GatewayIntentBits } from 'discord.js';
import deployCommands from './src/functions/deployCommands';
import { execute } from './src/events/ready';
import { token } from './config.json';
import DiscordManager from './src/DiscordManager';
const discord = new DiscordManager();

const client: Client = new Client({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.Guilds
]
});

deployCommands(client);

client.on(Events.ClientReady, () => {
execute(client);
});

client.login(token);
discord.connect();
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
"discord.js": "^14.15.3",
"discord.js-docs": "^0.3.0",
"mongoose": "^8.5.2",
"ms": "^2.1.3",
"node-cron": "^3.0.3",
"winston": "^3.13.1"
},
"devDependencies": {
"@eslint/js": "^9.8.0",
"@types/eslint": "^9.6.0",
"@types/ms": "^0.7.34",
"@types/node-cron": "^3.0.11",
"@types/node": "^22.1.0",
"eslint": "^9.8.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
36 changes: 36 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions src/DiscordManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Client, GatewayIntentBits, Collection, REST, Routes } from 'discord.js';
import InteractionHandler from './handlers/InteractionHandler';
import MessageHandler from './handlers/MessageHandler';
import { token, serverId } from '../config.json';
import CheckPermits from './utils/CheckPermits';
import { SlashCommand } from './types/main';
import { connectDB } from './utils/mongo';
import { readdirSync } from 'fs';
import cron from 'node-cron';

class DiscordManager {
interactionHandler: InteractionHandler;
messageHandler: MessageHandler;
client?: Client;
constructor() {
this.interactionHandler = new InteractionHandler(this);
this.messageHandler = new MessageHandler(this);
}

connect(): void {
this.client = new Client({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.Guilds
]
});

this.deployCommands();
this.client.on('ready', () => this.ready());
this.client.on('messageCreate', (message) => this.messageHandler.onMessage(message));
this.client.on('interactionCreate', (interaction) => this.interactionHandler.onInteraction(interaction));

this.client.login(token).catch((e) => console.log(e));
}

async ready() {
if (!this.client) return;
console.log(`Logged in as ${this.client.user?.username} (${this.client.user?.id})!`);
global.guild = await this.client.guilds.fetch(serverId);
cron.schedule(`* * * * *`, () => CheckPermits());
connectDB();
}

async deployCommands(): Promise<void> {
if (!this.client) return;
this.client.commands = new Collection<string, SlashCommand>();
const commandFiles = readdirSync('./src/commands');
const commands = [];
for (const file of commandFiles) {
const command = await import(`./commands/${file}`);
commands.push(command.data.toJSON());
if (command.data.name) {
this.client.commands.set(command.data.name, command);
}
}
const rest = new REST({ version: '10' }).setToken(token);
const clientID = Buffer.from(token.split('.')[0], 'base64').toString('ascii');
await rest.put(Routes.applicationCommands(clientID), { body: commands });
console.log(`Successfully reloaded ${commands.length} application command(s).`);
}
}

export default DiscordManager;
Loading

0 comments on commit eaa079d

Please sign in to comment.