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; }); } } }); }); } }