76 lines
2.0 KiB
JavaScript
76 lines
2.0 KiB
JavaScript
const Discord = require("discord.js");
|
|
const Gamedig = require('gamedig');
|
|
const client = new Discord.Client({ partials: [Discord.Partials.Message, Discord.Partials.Channel, Discord.Partials.Reaction], intents: [
|
|
Discord.GatewayIntentBits.Guilds,
|
|
Discord.GatewayIntentBits.GuildMessages,
|
|
Discord.GatewayIntentBits.MessageContent,
|
|
Discord.GatewayIntentBits.GuildMembers,
|
|
] });
|
|
const fs = require('fs');
|
|
const request = require('request');
|
|
const rp = require('request-promise-native');
|
|
const striptags = require('striptags');
|
|
const glob = require('glob');
|
|
const path = require('path');
|
|
const twitter = require('twitter');
|
|
|
|
var markov = require('markov');
|
|
var m = markov(2);
|
|
|
|
let bot_modules = [];
|
|
let triggers = [];
|
|
|
|
async function main() {
|
|
console.log("Loading modules...");
|
|
let modules = glob.sync('./bot-modules/**/module.js');
|
|
|
|
for(const mod of modules) {
|
|
const parts = mod.split('/');
|
|
const mod_name = parts[parts.length-2];
|
|
const mod_cls = require(mod);
|
|
const mod_obj = new mod_cls();
|
|
bot_modules[mod_name] = mod_obj;
|
|
|
|
for(const t of mod_obj.matches) {
|
|
triggers[t] = mod_name;
|
|
}
|
|
|
|
console.log(`## Loaded ${mod_name}`);
|
|
|
|
}
|
|
|
|
console.log(triggers);
|
|
|
|
client.login('MzYyNzU1MzE3MTczNTgzODcy.DK3R1A.8M22ZkNaaoHy-ifBQwVivSU7svY');
|
|
client.on('ready', () => {
|
|
console.log(`Logged into Discord as ${client.user.tag}`);
|
|
});
|
|
client.on('messageCreate', async (msg) => {
|
|
for(const t in triggers) {
|
|
if (msg.content.startsWith(`!${t}`)) {
|
|
console.log(`+ Bot module ${triggers[t]} triggered.`);
|
|
await bot_modules[triggers[t]].action(msg);
|
|
break;
|
|
}
|
|
}
|
|
if (msg.mentions.has(client.user)) {
|
|
console.log(`Bot mentioned.`);
|
|
await bot_modules[triggers['botmention']].action(msg);
|
|
}
|
|
});
|
|
client.on('messageReactionAdd', async (reaction, user) => {
|
|
if (reaction.partial) {
|
|
try {
|
|
await reaction.fetch();
|
|
} catch (err) {
|
|
console.error(error);
|
|
return;
|
|
}
|
|
|
|
}
|
|
await bot_modules['lewd'].react(reaction, user);
|
|
});
|
|
}
|
|
|
|
main();
|