summaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/2b2t/2b2t.ts80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/commands/2b2t/2b2t.ts b/src/commands/2b2t/2b2t.ts
new file mode 100644
index 0000000..453ec43
--- /dev/null
+++ b/src/commands/2b2t/2b2t.ts
@@ -0,0 +1,80 @@
+import { Command, CommandoMessage } from 'discord.js-commando';
+import { MessageEmbed } from 'discord.js';
+import { stop } from '../../2b2w/main.js'
+//const queuing = require('../../2b2w/main.js')
+import http from 'http';
+process.chdir('./2b2w/')
+
+global.queueData = "";
+function update() {
+ http.get('http://localhost/update', (resp) => {
+ let data = '';
+ resp.on('data', (chunk) => {
+ data += chunk;
+ });
+ resp.on('end', () => {
+ queueData = JSON.parse(data);
+ console.log(`Recieved data: ${queueData.place}`);
+ if (queueData.place === 'None' || queueData.place === 'undefined') {
+ queueData = 'Please allow a moment or the data to update';
+ }
+ });
+ }).on('error', (err) => {
+ queueData = 'error'
+ });
+ setTimeout(update, 5 * 1000);
+ //setTimeout(timedDiscordUpdate, 30 * 1000)
+}
+
+module.exports = class TwoB2T2B2t extends Command {
+ constructor(client) {
+ super(client, {
+ name: '2b2t',
+ aliases: ['2b', '2b2w', '2l2w'],
+ group: '2b2t',
+ memberName: '2b2t',
+ description: '',
+ args: [
+ {
+ key: 'actionOp',
+ prompt: 'Would you like to update, start or stop?',
+ type: 'string'
+ }
+ ]
+ });
+ }
+ run(msg: CommandoMessage, { actionOp }) {
+ if (actionOp == 'update') {
+ let emb = new MessageEmbed()
+ .setColor(0xFFCC4D)
+ .setTitle('2bored2wait Discord Bridge')
+ .setDescription('Start and stop the queue from Discord.')
+ .addFields(
+ { name: 'Position', value: `You are in position **${queueData.place}**.` },
+ { name: 'ETA', value: `Estimated time until login: **${queueData.ETA}**` }
+ )
+ .setTimestamp(new Date())
+
+ msg.say(emb);
+ } else if (actionOp == 'start') {
+ let emb = new MessageEmbed()
+ .setColor(0xFFCC4D)
+ .setTitle('2bored2wait Discord Bridge')
+ .setDescription('Start and stop the queue from Discord.')
+ .addField('Queue', 'Queue is starting up. Please allow 15 seconds to update.')
+ .setTimestamp(new Date())
+ setTimeout(update, 5 * 1000)
+ msg.channel.send(emb);
+ } else if (actionOp == 'stop') {
+ let emb = new MessageEmbed()
+ .setColor(0xFFCC4D)
+ .addField('Queue', 'Queue is **stopped**.')
+ .setTimestamp(new Date())
+
+ stop()
+ msg.say(emb);
+ } else {
+ msg.reply('That was not an option.')
+ }
+ }
+}; \ No newline at end of file