- [Misc] Update config - [HQ] Minor Client modifications - [Dependencies] Add canvas, discord.js, jsonwebtoken - [Misc] Update package version - [Misc] Add fonts - [HQ] Delete hq-checklives - [CrowdSource] Add crowd client - [Utils] Add image generation - [Utils] Add google - [Utils] Add get tokens
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
import { Client } from 'discord.js';
|
|
import { crowdsource } from '../../config';
|
|
|
|
export default class CrowdClient extends Client {
|
|
constructor(options, client) {
|
|
super(options);
|
|
this.client = client;
|
|
this.login(options.token);
|
|
this.on('message', (msg) => {
|
|
const games = Object.keys(crowdsource.channels);
|
|
games.forEach((g) => {
|
|
const channels = crowdsource.channels[g].map(c => c.id);
|
|
const weights = crowdsource.channels[g].map(c => c.weight);
|
|
if (channels.includes(msg.channel.id)) {
|
|
if (msg.content.match(/[1-3]/g)) {
|
|
const weight = weights[channels.indexOf(msg.channel.id)];
|
|
let m;
|
|
m = msg.content.toLowerCase();
|
|
m = m.split(' ').join('');
|
|
crowdsource.keywords.forEach((k) => {
|
|
k.keywordNum = k.keyword.replace(/{num}/g, m.match(/[1-3]/g)[0]);
|
|
k.keywordNum = k.keywordNum.split(' ').join('');
|
|
if (m === k.keywordNum) client.weights[g][m.match(/[1-3]/g)[0] - 1] += k.weight * weight;
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|