-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
167 lines (137 loc) · 5.34 KB
/
bot.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
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
const { Client, Intents, GatewayIntentBits, SlashCommandBuilder, REST, Routes, Events, EmbedBuilder } = require('discord.js');
const config = require("./config.json");
const { inspect } = require('util');
const express = require('express');
// const util = require('util');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildPresences
]
});
const prefix = "!";
var latestMessage = "";
var latestMessageAuthor = "";
function randomRange(myMin, myMax) {
return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin;
}
async function cleanText(text, client) {
if ( text && text.constructor.name == "Promise" )
text = await text;
if ( typeof text !== "string" )
text = inspect(text, {depth: 1});
return text.replace(client.BOT_TOKEN, "[REDACTED]");
}
client.on("messageCreate", function(message) {
latestMessage = message.content.toString();
latestMessageAuthor = message.author.tag.toString();
console.log(message.author.tag + " - " + message.content)
if (message.author.bot) return;
logToLogs(message.author.tag + " - " + message.content)
if (!message.content.startsWith(prefix)) return;
const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ', 1);
const command = args.shift().toLowerCase();
if (command === "ping") {
message.reply(`fuck off`);
}
else if (command === "rr") {
random = randomRange(1, 6);
if (random == 4){
message.reply("*BANG*");
try {
let testRole = message.guild.roles.cache.find(role => role.id == config.RR_LOSSROLE)
message.member.roles.add(testRole)
} catch (e){
console.log(e);
}
} else {
message.reply("*click*")
}
}
else if (command == "avatar"){
if (args.indexOf("<@") == 0){
message.reply("you gotta give me a user dude (mention them)");
return
}
const user = args.toString().replace("<@", "").replace(">", "")
}
else if (command == "hex"){
const text = args.toString();
const buffer = Buffer.from(text, "utf8");
const hex = buffer.toString("hex").match(/.{1,2}/g).join(" ");
message.reply(`\`\`\`${hex}\`\`\``);
}
else if (command == "eval"){
if (!message.member.roles.cache.has(config.EVALPERMROLE)){
message.reply("you dont have perms.")
} else{
try{
const util = require('util');
const script = args;
let result = '';
const cons = {
log: (...args) => result += (util.format(...args) + '\n'),
};
eval(`((console) => { ${script} })`)(cons);
result = result.replace(client.BOT_TOKEN, "[token]")
// const content = message.content;
// let code = content.match(/^```[^\n]*\n(.+)\n```$/sm);
// code = code ? code[1] : content;
// const eval_func = eval(`${code}`);
// const result = eval(args);
// const clean = (cleanText(result || "", message.client));
result = result.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '').replace("`", "'");
const embed = new EmbedBuilder()
.setTitle("Output")
.setDescription(`\`\`\`${result}\`\`\``)
.setColor("Blue");
message.reply({
embeds: [embed]
});
} catch (err){
const embed = new EmbedBuilder()
.setTitle("Error, you fucked up... noob")
.setDescription(`\`\`\`${err}\`\`\``)
.setColor("Red");
message.reply({
embeds: [embed]
});
}
}
}
else if (command == "run"){
if (message.author.tag.toString() == config.OWNER_TAG){
var spawn = require('child_process').spawn;
var ls = spawn(args.toString().split(" ")[0], args.toString().split(" ", 1)[1]);
ls.stdout.on('data', function (data) {
console.log(data);
});
}
else{
message.reply("no");
}
}
});
client.on("ready", () => {
console.log(`Ready! Logged in as ${client.user.tag}`);
logToLogs(`${client.user.tag} is in your walls (bot started)`)
});
process.on("unhandledException", err => {
console.error(err);
client.channels.cache.get(config.LOGS_CHNNL).send("```xl\n" + err + "\n```");
});
process.on("uncaughtException", err => {
console.error(err);
client.channels.cache.get(config.LOGS_CHNNL).send("```xl\n" + `${err.message}\n\n${err.stack}` + "\n```");
});
function logToLogs(message){
var stripped = message.toString().replace("`", "'")
client.channels.cache.get(config.LOGS_CHNNL).send("```\n" + `${stripped}` + "\n```");
}
client.login(config.BOT_TOKEN);