summaryrefslogtreecommitdiff
path: root/commands/eval.js
blob: 730def99c0522fc9b1046cff59a1c52baf25b382 (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
const Discord = require('discord.js');
exports.run = (client, message, args, config) => {
if(message.author.id !== config.ownerID) return;
const clean = text => {
  if (typeof(text) === "string")
    return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
  else
      return text;
}
const argseval = message.content.split(" ").slice(1);
  try {
    var code = argseval.join(" ");
    var evaled = eval(code);

    if (typeof evaled !== "string")
      evaled = require("util").inspect(evaled);
    message.delete();

    message.channel.send({
      embed: {
        color: 3191350,
        author: {
          name: "Eval is working!",
          icon_url: message.author.displayAvatarURL
        },
        fields: [{
            name: '**:inbox_tray: Input**',
            value: `\`\`\`js\n${code}\n\`\`\``
          },
          {
            name: '**:outbox_tray: Output**',
            value: `\`\`\`js\n${clean(evaled)}\n\`\`\``
          }
        ],
      }
    })
  } catch (err) {
    message.delete();

    message.channel.send({
      embed: {
        color: 3191350,
        author: {
          name: "Error",
          icon_url: message.author.displayAvatarURL
        },
        fields: [{
            name: '**Please check your code.**',
            value: `\`\`\`xl\n${clean(err)}\n\`\`\``
          },
          {
            name: '**Output**',
            value: `\`\`\`js\n${clean(evaled)}\n\`\`\``
          }
        ],
      }
    })
  }
}