Rewrite the bot process in Node/Discord.js (#206)

* Rewrite the bot process in js using discord.js

* remove old go code
This commit is contained in:
Katie Macke 2021-03-31 15:35:07 -04:00 committed by GitHub
parent 55bc84e045
commit 7ec603cf70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 104 additions and 799 deletions

27
packages/bot/bot.js Normal file
View file

@ -0,0 +1,27 @@
const { Client } = require('discord.js');
const botToken = process.env['BOT_TOKEN'];
const allowedBots = process.env['ALLOWED_BOTS']?.split(',') ?? [];
const appUrl = process.env['UI_PUBLIC_URI'] ?? '';
function messageEventListener(message) {
const { author, channel, client, guild, mentions } = message;
if (!guild) {
return;
} // Ignore DMs
if (client.user && !mentions.has(client.user.id)) {
return;
} // Ignore non bot mentions
if (author.bot && !allowedBots.includes(author.id)) {
return;
} // Only respond to allowed bots
const guildId = guild.id;
channel.send(`:beginner: Assign your roles here! ${appUrl}/s/${guildId}`);
}
const client = new Client();
client.on('message', (message) => messageEventListener(message));
client.login(botToken);

9
packages/bot/index.js Normal file
View file

@ -0,0 +1,9 @@
const path = require('path');
require('dotenv').config({ path: path.resolve(__dirname, '../../.env') });
const { ShardingManager } = require('discord.js');
const botToken = process.env['BOT_TOKEN'];
const manager = new ShardingManager('./bot.js', { token: botToken });
manager.spawn();

10
packages/bot/package.json Normal file
View file

@ -0,0 +1,10 @@
{
"name": "@roleypoly/bot",
"version": "0.1.0",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"discord.js": "^12.5.1"
}
}