-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
137 lines (130 loc) · 5.79 KB
/
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
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
const log = require("./log.js")
const vizion = require('vizion');
const request = require('request');
const Discord = require("discord.js");
const bot = new Discord.Client();
const config = require("./config.json");
const {
isAsyncFunction
} = require("util/types");
branchData = {};
bot.on('ready', () => {
console.log(`Logged in as ${bot.user.tag}`);
if (config.discord.branchchannels) {
request("https://api.github.com/repos/SugarcaneMC/Sugarcane/branches", {
json: true,
headers: {
"User-Agent": `Sugarcane Bot/1.0 (+https://sugarcanemc.org/)`,
"Authorization": config.github.accesstoken
}
}, (err, res, body) => {
if (err || res.statusCode !== 200) console.log(`${res.statusCode}${err?` | ${err}`:""}`);
body.slice().reverse().forEach((branch) => {
nameA = branch.name.replace(/[^\w\-]/gi, "-").toLowerCase();
if (!bot.guilds.cache.get(config.discord.staffguild).channels.cache.find(channel => channel.name.toLowerCase() === nameA)) {
console.log(`Creating new channel for ${branch.name}, called ${nameA}`)
bot.guilds.cache.get(config.discord.staffguild).channels.create(nameA, {
parent: config.discord.branches,
topic: `https://github.com/SugarcaneMC/Sugarcane/tree/${branch.name} Discussion`
});
}
})
})
}
/*This didn't work, I'll fix it later
const autoUpdate = setInterval(() => {
vizion.analyze({
folder: '.'
}, function (err, meta) {
if (err) throw new Error(err);
if (!meta.next_rev) return;
log.log(`Update detected, New revision id is ${meta.next_reg}. Restarting!`, true);
});
}, 30000);
vizion.analyze({
folder: '.'
}, function (err, meta) {
if (err) throw new Error(err);
if (!meta.next_rev) return;
log.log(`Update detected, New revision id is ${meta.next_reg}. Restarting!`, true);
});*/
})
bot.on('guildMemberAdd', (member) => {
switch (member.guild.id) {
case "855918593497759754":
member.roles.add("855981133731856414").catch((err) => {
log.log(err);
})
break;
}
})
bot.on('message', (msg) => {
const prefix = config.discord.prefix;
const args = msg.content.slice(prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if (msg.content.toLowerCase().startsWith(prefix)) {
if (!/^[a-zA-Z0-9]+$/.test(cmd)) return; //This is a temporary fix so the bot doesnt respond to commands that are not alphanumeric, i.e any command (<prefix><command> <arguments>) that contains symbols will be ignored.
//To clarify, arguments with symbols will NOT be ignored, only root commands themselves
switch (cmd) {
// Admin Commands
case "admin":
if (!msg.member.permissions.has("ADMINISTRATOR")) return msg.channel.send(`You cannot do that <@${msg.author.id}>!`);
if (!args[0]) return msg.channel.send(`Please provide a valid subcommand\n\`${prefix}admin <subcommand> [arguments]\``);
switch (args[0]) {
case "restart":
msg.channel.send("Restarting...").then(() => {
bot.destroy();
process.exit(0);
});
break;
case "logs":
var embed = new Discord.MessageEmbed;
embed.setTitle("Latest logs");
log.db.each("SELECT * FROM logs LIMIT 25", (err, row) => {
embed.fields.push({
name: row.timestamp,
value: row.log
});
}, (err) => {
msg.channel.send(embed);
})
break;
default:
msg.channel.send(`\`${args[0]}\` is not a valid subcommand`);
}
break;
case "info":
if (!args[0]) args[0] = "";
switch (args[0].toLowerCase()) {
case "bot":
vizion.analyze({
folder: "."
}, function (err, meta) {
if (err) throw new Error(err);
msg.channel.send({
embed: {
"title": `Info on ${meta.url.substr(19).replace(/.git$/, "")}`,
"description": `[Repo](${meta.url})`,
"color": 38143,
"fields": [{
"name": "Latest Commit",
"value": `URL: ${meta.url.substr(0, meta.url.length - 4)}/commit/${meta.revision}\nBranch: ${meta.branch}\nComment: \`\`\`\n${meta.comment}\`\`\``
}],
"footer": {
"text": "Created (mostly) by Chris Chrome"
}
}
})
});
break;
default:
msg.channel.send(`Please provide a valid category. Currently Available:\n\`bot\` - Latest commit for this bot`);
break;
}
break;
}
}
})
bot.login(config.discord.token).catch((err) => {
log.log(err, true);
});