[Discord] Add discord bot file and hq discord integration
This commit is contained in:
62
src/discord.js
Normal file
62
src/discord.js
Normal file
@@ -0,0 +1,62 @@
|
||||
// import { MessageEmbed } from 'discord.js';
|
||||
import Client from './classes/DiscordClient';
|
||||
import CrowdClient from './classes/CrowdClient';
|
||||
import { discord, crowdsource } from '../config';
|
||||
import 'colors';
|
||||
import hqDiscord from './modules/hq-discord';
|
||||
import { version } from '../package';
|
||||
|
||||
const client = new Client({
|
||||
disabledEvents: ['TYPING_START'],
|
||||
disableEveryone: true,
|
||||
token: discord.token,
|
||||
});
|
||||
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`.green);
|
||||
client.user.setActivity(discord.activity.replace('{VERSION}', version));
|
||||
const crowdClient = new CrowdClient({
|
||||
disabledEvents: ['TYPING_START'],
|
||||
token: crowdsource.userToken,
|
||||
}, client);
|
||||
crowdClient.on('ready', () => {
|
||||
console.log(`Logged in as ${crowdClient.user.tag}!`.green);
|
||||
});
|
||||
});
|
||||
|
||||
client.on('message', (msg) => {
|
||||
if (msg.author.bot) return;
|
||||
if (!msg.content.startsWith(discord.prefix)) return;
|
||||
const args = msg.content.slice(discord.prefix.length).trim().split(/ +/g);
|
||||
const command = args.shift().toLowerCase();
|
||||
if (!discord.admins.includes(msg.author.id)) return;
|
||||
if (command === 'testws') {
|
||||
client.testWs = !client.testWs;
|
||||
msg.channel.send(`Set TestWs to \`${client.testWs}\``);
|
||||
}
|
||||
if (command === 'end') {
|
||||
// eslint-disable-next-line consistent-return
|
||||
if (client.activeGames.length === 0) return msg.channel.send('No games are currently active.');
|
||||
client.activeGames.forEach((game) => {
|
||||
client.emit('ended', { game });
|
||||
});
|
||||
msg.channel.send(`Ended game(s): ${client.activeGames.join(', ')}`);
|
||||
client.activeGames = [];
|
||||
client.hqClients.forEach(c => c.disconnect());
|
||||
if (client.testWs) {
|
||||
client.testWs = false;
|
||||
msg.channel.send(`Set TestWs to \`${client.testWs}\``);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
client.on('live', (data) => {
|
||||
const { game, prize } = data;
|
||||
switch (game) {
|
||||
case 'hq-trivia':
|
||||
hqDiscord(client, prize);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user