@JSer/

GameBot

Nodejs

No description

fork
loading
Files
  • index.js
  • admin.js
  • commands.js
  • package-lock.json
index.js
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
const dotenv = require('dotenv');
const express = require('express');
const app = express();
const Discord = require('discord.js');
const client = new Discord.Client();

app.listen(() => console.log("Server started"));

app.get('/ping', (req, res) => {
  res.send(new Date());
});

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
  client.user.setActivity('$help', { type: 'playing' });
});

const commands = require('./commands.js');

const admin = require('./admin.js');

const admins = [
  "439052807790657557"
];

const blocked = [
  "224588823898619905"
]

client.on('message', async msg => {
  if (!msg.author.bot && !blocked.includes(msg.author.id)) {
    if (msg.content[0] == '$') {
      const params = lex(msg.content);
      const cmd = params
        .shift()
        .toLowerCase()
        .substring(1);

      if (commands[cmd]) {
        const result = commands[cmd].run(params);
        if (result) msg.channel.send(result)
          .then(() => { }, rej => msg.author.send(result));
      } else if (admin[cmd] && admins.includes(msg.author.id)) {
        admin[cmd](params, msg, client);
      } else msg.channel.send("Invalid command: " + cmd + "\nType `$help` for help");
    }

    if (msg.isMentioned(client.user)) msg.reply("What's up?");

    if (msg.content.match(/gamebot/i)) {
      await msg.react(String.fromCodePoint(0x1f1ec));
      await msg.react(String.fromCodePoint(0x1f1e6));
      await msg.react(String.fromCodePoint(0x1f1f2));
      await msg.react(String.fromCodePoint(0x1f1ea));
      await msg.react(String.fromCodePoint(0x1f1e7));
      await msg.react(String.fromCodePoint(0x1f1f4));
      await msg.react(String.fromCodePoint(0x1f1f9));
    }
  }
});

client.login(process.env.token);

function lex(msg) {
  const params = [];
  let tmp = '';
  let inQuotes = false;
  for (let c of msg) {
    if (c == '`') inQuotes = !inQuotes;
    else if (c == ' ' && !inQuotes) {
      if (tmp.length) params.push(tmp);
      tmp = '';
    } else tmp += c;
  }
  if (tmp.length) params.push(tmp);
  return params;
}