forked from martian17/adminScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
145 lines (121 loc) · 3.88 KB
/
main.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
/*
?select user [JoinedAt > -3 hours] | ban
?select message : time > -3 hours : user == "sussyBaka" | delete
>> 135 messages will be deleted. if you are sure, type ?commit
?select message [time > -3 hours] [user == "sussyBaka"] | delete
?select message time > -3 hours user == "sussyBaka" | delete
?msgs => select message : time > -3 hours : user == "sussyBaka"
?msgs | length | echo
>> 135
?msgs | echo
>> ...displays all 135 messages
?msgs | delete
>> 135 messages will be deleted. if you are sure, type ?commit
?commit
>>message deleted
?clear log
*/
const Discord = require('discord.js');
let getClient = function(Discord){
let flags = Discord.Intents.FLAGS;
const client = new Discord.Client({
intents: [
flags.GUILDS, flags.GUILD_MESSAGES
] /*["GUILDS", "GUILD_MESSAGES"]*/
});
/*
let wrapper = Object.create(client);
let evts = {};
let targets = "ready,message".split(",");
targets.map(t=>{
evts[t] = [];
client.on(t,function(a,b,c,d,e,f){
evts[t].map(cb=>{
console.log("cb called");
cb(a,b,c,d,e,f)
});
});
});
client.on = function(evt,cb){
evts[evt].push(cb)
};*/
return client;
};
const client = getClient(Discord);
require('dotenv').config();
client.login(process.env.TOKEN);
let Bot = require("bot.js");
let main = async function(){
let bot = (new Bot(client,"?"));
bot.
bot.onReady(()=>{
console.log(`Logged in as ${client.user.tag}!`);
const guilds = bot.client.guilds.cache;
initmsgs.push("guilds: "+JSON.stringify(guilds.map(g=>g.name)));
//sending it to every channels
guilds.map(guild=>{
//GUILD_CATEGORY
//GUILD_CATEGORY
//GUILD_TEXT
//GUILD_VOICE
guild.channels.cache.filter(channel=>{
channel.type === "GUILD_TEXT";
}).map(channel=>{
console.log(channel.type);
channel.send(initmsgs.join("\n"));
});
});
});
bot.sub("id").sub("set").addFunc(async function(msg,argv){
if(argv[0]){
let newid = argv[0];
try{
await updateIdStr(newid);//sideefect: mutates idstr if successful
bot.prefix = idstr;
msg.channel.send("idstr update success. New idstr: "+idstr);
}catch(err){
msg.channel.send("idstr "+newid+": update failed. current id: "+idstr);
}
}
});
bot.sub("ip").addFunc(function(msg, argv) {
exec("curl -s ifconfig.me", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
}else if (stderr) {
console.log(`stderr: ${stderr}`);
}
msg.channel.send("the current ip address is: " + stdout);
});
});
bot.sub("eval").addFunc(function(msg, argv){
let content = msg.content.slice(idstr.length+" eval".length).trim();
try{
eval(content);
msg.channel.send("eval success");
}catch(err){
console.log(err);
msg.channel.send("eval error: "+err);
}
});
//all bots
slash.sub("id").addFunc(function(msg,argv){
console.log("adasdfasdf");
msg.channel.send("idstr: "+idstr);
});
slash.sub("showinfo").addFunc(function(msg,argv){
exec("curl -s ifconfig.me", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
}else if (stderr) {
console.log(`stderr: ${stderr}`);
}
let lines = [
"ip: " + stdout,
"idstr: "+idstr
];
msg.channel.send(lines.join("\n"));
});
});
};
main();