-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
122 lines (102 loc) · 3.47 KB
/
main.js
File metadata and controls
122 lines (102 loc) · 3.47 KB
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
const Discord = require("discord.js");
let Adminscript = require("adminscript");
const { spawn } = require('child_process');
//const AdminScript = require("./AdminScript.js/main.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,"?"));
let initmsgs = [];
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"));
});
});
});
let a = bot.sub("adminscript");
bot.sub("exec").addFunc((msg,substr)=>{
console.log("exec called");
msg.reply(substr);
});
let parsecmd = bot.sub("parse");
parsecmd.addFunc((msg,substr)=>{
console.log("\""+substr+"\"");
try{
let ast = Adminscript.parse(substr)[0];
msg.reply("```javascript\n"+JSON.stringify(ast,null,4)+"\n```");
}catch(err){
msg.reply(err+"");
}
});
parsecmd.sub("-e").addFunc((msg,substr)=>{
console.log("\""+substr+"\"");
try{
let ast = Adminscript.parse(substr);
msg.reply("```javascript\n"+JSON.stringify(ast,null,4)+"\n```");
}catch(err){
msg.reply(err+"");
}
});
bot.sub("inspect").addFunc((msg,substr)=>{
let varname = substr.trim();
if("msg substr bot this Adminscript main client".split(" ").indexOf(varname) !== -1){
let variable = eval(varname)//this[varname];
msg.reply("```javascript\n"+JSON.stringify(variable,function(key, val) { return (typeof val === 'function') ? '[function]' : val; },4)+"\n```");
}else{
msg.reply(varname+": access to variable denied");
}
});
bot.sub("update").addFunc(async (msg,substr)=>{
msg.reply("updating itself");
const child = spawn("npm", ["update"]);
for await (const data of child.stdout) {
msg.channel.send(""+data);
};
child.on("exit", code => {
msg.channel.send("Update complete");
msg.channel.send(`Exit code is: ${code}`);
delete require.cache[require.resolve("adminscript")];
Adminscript = require("adminscript");
});
});
};
main();