aboutsummaryrefslogtreecommitdiff
path: root/bot.js
blob: 6600c2a3c0e0a1a12d1d58c11964278dd3960dd4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
const Discord = require('discord.js');
const moment = require('moment');
const client = new Discord.Client();
const config = require('./config.json');
const aqVersion = '1.2.3';
const prefix = 'aq:';

const log = message => {

  console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${message}`);

};

const SuggestQuoteStartMessage = '**Quote Suggestion**\n' +
    'Welcome to the quote suggestion process! Please read this before you continue.\n' +
    'Here\'s how this will work.\n\n' +
    '- I\'ll walk you through the process of creating a suggestion on the suggestions channel.\n' +
    '- Just respond to my prompts by typing a message in this DM and sending it.\n' +
    '- At any time, simply respond with `q` to cancel the suggestion.\n\n' +
    'However, please be aware of the following:\n' +
    '- Your Discord Username will be recorded and sent along with the suggestion.\n' +
    '- Your suggestion will be publicly visible.\n' +
    '- Any misuse of this command, including (but not limited to) spam will lead to appropriate discipline from staff.\n\n' +
    '**Here are some things not to suggest because they will be immediately declined.** This counts as misuse of the suggest command, so hit `q` now if you were going to suggest one of these.\n' +
    '- New text/voice channels.\n' +
    '- New bots.\n\n' +
    'Wait 30 seconds, and then respond with `y` if you understood the above.\n' +
    'Please note this feature doesn\'t work **yet**';

let QuoteOfTheDay;
let QuoteOfTheDayExpiry = 0;
let QuoteOfTheDayStartTime;

function GetQuoteOfTheDay(quoteNum = -1) {
  const now = new Date();

  if (QuoteOfTheDayExpiry < now.getTime()) {
    log('[!] Getting new quote of the day...');
    log('[!] This quote expires in 1 day.');

    QuoteOfTheDayStartTime = now;
    QuoteOfTheDayExpiry = now.getTime();
    QuoteOfTheDayExpiry += 86400000;

    QuoteOfTheDay = new Discord.RichEmbed();

    let quo = require('./quotes.json').quotes

    if (quoteNum == -1) {
      quoteNum = Math.floor(Math.random() * 1000) % quo.length;
      quo=quo[quoteNum];
    }

    const author = quo.author;
    const authorImage = quo.authorImage;
    const quote = quo.quote;
    const year = quo.year;
    const url = quo.url;

    QuoteOfTheDay.setAuthor(author, authorImage);
    QuoteOfTheDay.setColor('#939d45');
    QuoteOfTheDay.setDescription(quote);
    QuoteOfTheDay.setFooter('- ' + year);
    QuoteOfTheDay.setURL(url);
  } else {
    log('[!] No need for new quote of the day');
  }


  return QuoteOfTheDay;
}

client.on('ready', () => {
  log('[>] AstralQuote is now ready using version '+ aqVersion +'!');
  client.user.setPresence({
    game: {
      name: 'v.' + aqVersion + ' | ' + prefix + 'help',
      type: 0,
    },
  });
});

function getBoshyTime(guild) {
  if (guild.emojis.exists('name', 'vtBoshyTime')) {
    return '<:vtBoshyTime:' + guild.emojis.find('name', 'vtBoshyTime').id + '>';
  } else {
    return ':warning:';
  }
}

client.on('message', message => {
  if (message.content.indexOf(prefix) !== 0) return;

  const args = message.content.slice(prefix.length).trim().split(/ +/g);

  const command = args.shift().toLowerCase();

  if (command === 'ping') {
    message.channel.send(getBoshyTime(message.guild) + ' PONG! I want to play pong... :\'(');
  } else if (command === 'pong') {
    message.channel.send(getBoshyTime(message.guild) + ' PING!');
  } else if (command === 'isthisthingon') {
    message.channel.send('no 💤');
  } else if (command === 'qotd') {
    const quoteofday = GetQuoteOfTheDay();
    message.channel.send('Here\'s the quote of the day (as of ' + QuoteOfTheDayStartTime.toUTCString() + ')');
    message.channel.sendEmbed(quoteofday);
  } else if (command === 'forcequote') {
    message.delete();
    QuoteOfTheDayExpiry = 0;
    const quoteofday = GetQuoteOfTheDay();
    message.channel.send('New quote of the day!');
    message.channel.sendEmbed(quoteofday);
  } else if (command === 'reboot') {
    /*
    message.channel.send("Goodbye! We'll be back in a moment!").then(messageDeleteTimer);
    log('[?] Reboot Requested. Rebooting...');
    client.destroy();
    DidReboot = true;
    client.login(nope);
*/
    message.channel.send('Good try... But we\'re not letting anyone reboot me yet!');
  } else if (command === 'poweroff') {
    /* Heh really Victor :P
        log(message.guild.roles);
        if (message.guild.roles.get('Moderator').members.keyArray().includes(message.author.username)) {
          message.channel.send("Access Granted");
        } else {
          message.channel.send("Access Denied");
        }*/
        const asyncPowerOff = async () => {
            await message.reply(getBoshyTime(message.guild) + 'AstralQuote is now powering off!');
            console.log('[i] AstralQuote is now powering off...');
            process.exit(0);
        }

    if (message.author.id !== config.ownerID)
        {message.reply('Heh you can\'t turn me off :P');}
            else {
                 asyncPowerOff();
            };

  } else if (command === 'help') {
    // This is the new help
    const embed = new Discord.RichEmbed()
      .setTitle('AstralQuote Commands')
      .setDescription('Every command that you input in this bot you must use the following prefix `' + prefix + '`.\nNOTE: AstralQuote service will be shutdown in `April 10th 4PM EDT`.\n Thanks for using AstralQuote!')
      .setThumbnail('https://cdn.discordapp.com/avatars/373224323529310208/f42227477bc7e5b96ea848abc880a6bf.png?size=2048')
      .setColor('#939d45')
      .addField('- General Commands', 'ping\npong\ninvitebot\nreboot\npoweroff', true)
      .addField('- Info Commands', 'copyright\ncontribute\ninformation')
      .addField('- Quote Commands', 'qotd\nforcequote', true)
      .setFooter('AstralQuote Copyright 2017.');
    message.channel.send(embed);
  } else if (command === 'oldhelp') {
    message.channel.send('Available commands:\n```\n' +
            'aq:ping, aq:pong     Requests AstralQuote to reply with a message\n' +
            'aq:quoteoftheday     Requests AstralQuote for the quote of the day\n' +
            'aq:forcequote        Requests AstralQuote to reset the quote of the day\n' +
            'aq:reboot            Requests AstralQuote to reboot\n' +
            'aq:poweroff          Tells AstralQuote to leave\n```'
    );
  } else if (command === 'easteregg') {
    message.channel.send('```cpp\n' +
            'There are no easter eggs to be found here. Begone!' +
            '\n```');
  } else if (command === 'easterwgg') {
    message.channel.send('```cpp\n' +
            'Ha, you found an easter egg! Take that, aq:easteregg!' +
            '\n```');
  } else if (command === 'contribute') {
    message.reply(':arrow_left: Continue in DMs.');
    message.author.send('I can see you want to help AQ? Welp here\'s the link: https://github.com/ATC-Parody/AstralQuote');
  } else if (command === 'uptime') {
    let timeString;
    let uptime = parseInt(client.uptime);
    uptime = Math.floor(uptime / 1000);
    let uptimeMinutes = Math.floor(uptime / 60);
    let hours = 0;

    while (uptimeMinutes >= 60) {
      hours++;
      uptimeMinutes = uptimeMinutes - 60;
    }

    if (uptimeMinutes < 10) {
      timeString = hours + ':0' + uptimeMinutes;
    } else {
      timeString = hours + ':' + uptimeMinutes;
    }

    message.reply(':clock1: AstralQuote has been up for ' + timeString + ' hours.');
    log('[!] Someone just typed in the uptime command! Here\'s how long i\'ve been up for: ' + timeString + ' hours.');
  } else if (command === 'invitebot') {
    message.reply(':arrow_left: Continue in DMs.');
    const embed = new Discord.RichEmbed();

    embed.setAuthor('AstralQuote', 'https://cdn.discordapp.com/avatars/373224323529310208/f42227477bc7e5b96ea848abc880a6bf.png?size=2048');
    embed.setColor('#939d45');
    embed.setDescription('Ooh! I can see you want to invite me to a server! Here\'s the link: https://discordapp.com/oauth2/authorize?client_id=373224323529310208&scope=bot&permissions=314368');
    embed.setURL('https://discordapp.com/oauth2/authorize?client_id=373224323529310208&scope=bot&permissions=314368');

    message.author.send(embed);
    /* } else if (command === "suggestaquote") {
        var embed = new Discord.RichEmbed();

        embed.setAuthor("AstralQuote", "https://cdn.discordapp.com/avatars/373224323529310208/f42227477bc7e5b96ea848abc880a6bf.png?size=2048");
        embed.setColor("#939d45");
        embed.setDescription("This feature is coming soon!");

        message.channel.send(embed)
        message.author.sendMessage(SuggestQuoteStartMessage); */
  } else if (command === 'information') {
    const embed = new Discord.RichEmbed();

    embed.setAuthor('AstralQuote', 'https://cdn.discordapp.com/avatars/373224323529310208/f42227477bc7e5b96ea848abc880a6bf.png?size=2048');
    embed.setColor('#939d45');
    embed.setDescription('AstralQuote Version: ' + aqVersion);
    embed.setFooter('This was made by TheRandomMelon and vicr123 and modified by Alee.');

    message.channel.send(embed);
  } else if (message.content.startsWith(prefix)) {
    log('[X] ' + message.content + ' [Unrecognised command]');
  }
  /*      var msg;
        switch (Math.floor(Math.random() * 1000) % 8) {
            case 0:
                msg = "Trying to break me, are you?";
                break;
            case 1:
                msg = "Sorry, what was that?";
                break;
            case 2:
                msg = "Oops... I missed that.";
                break;
            case 3:
                msg = "Either you typed something wrong... Or I'm not smart enough to understand you.";
                break;
            case 4:
                msg = "What are you trying to do!?";
                break;
            case 5:
                msg = "Is this the end of AstralQuote?";
                break;
            case 6:
                msg = "Not sure what you mean.";
                break;
            case 7:
                msg = "Pretty sure you didn't expect this message to appear...";
                break;
        }
        message.channel.send(getBoshyTime(message.guild) + " GAH! " + msg + " Refer to "+ prefix +"help for syntax and other stuff.");
    } */
});


client.on('guildCreate', guild => {
  log(`[>] I just joined ${guild.name}. This server has ${guild.memberCount} members.`);

});

client.on('guildDelete', guild => {
  log(`[>] I was removed from ${guild.name}.`);

});

client.login(config.token).catch(
  function() {
    log('[X] Login failed.');
  });