-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
286 lines (261 loc) · 9.35 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
require('dotenv').config();
var token = process.env.TOKEN;
var owner_discord_id = process.env.OWNER_DISCORD_ID;
var channel_id = process.env.LOGGING_CHANNEL_ID;
// NPM MODULES
const commando = require("discord.js-commando");
const path = require("path");
const oneLine = require("common-tags").oneLine;
const sqlite = require("sqlite");
sqlite.open("./database.sqlite3");
const client = new commando.Client({
owner: owner_discord_id,
commandPrefix: "**",
disableEveryone: true,
unknownCommandResponse: false
});
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var bot_prefix = "**";
client.on("ready", async () => {
console.log(`Logged in as ${client.user.tag}`);
client.user.setActivity(
`${bot_prefix}help | Running on ${client.guilds.size} servers`
);
});
// Error handling
client
.on("error", console.error)
.on("warn", console.warn)
.on("debug", console.log);
// Bot status
client
.on("reconnecting", () => {
console.warn("Onyx is reconnecting...");
})
.on("disconnect", () => {
console.warn("Warning! Onyx has disconnected!");
});
// Command specific event listeners that come with the Commando module
client
.on("commandError", (cmd, err) => {
if (err instanceof commando.FriendlyError) return;
var message = `Error in command ${cmd.groupID}:${cmd.memberName}, ${err}`;
client.channels.get(channel_id).send(`@Silvia923#9909 ${message}`);
})
.on("commandBlocked", (msg, reason) => {
console.log(oneLine`
Command ${msg.command ? `${msg.command.groupID}:${msg.command.memberName}` : ""}
blocked; ${reason}
`);
msg.reply("Command has been blocked.");
})
.on("commandPrefixChange", async (guild, prefix) => {
var message = `Prefix ${
prefix === "" ? "removed" : `changed to ${prefix || "the default"}`
} ${guild ? `in guild ${guild.name} (${guild.id})` : "globally"}.`;
client.channels.get(channel_id).send(`@Silvia923#9909 ${message}`);
console.log(`PREFIX CHANGE REQUEST: ${prefix}`);
})
.on("commandStatusChange", (guild, command, enabled) => {
var message = `Command ${command.groupID}:${command.memberName} ${
enabled ? "enabled" : "disabled"
} ${guild ? `in guild ${guild.name} (${guild.id})` : "globally"}.`;
client.channels.get(channel_id).send(`@Silvia923#9909 ${message}`);
})
.on("groupStatusChange", (guild, group, enabled) => {
console.log(oneLine`
Group ${group.id}
${enabled ? "enabled" : "disabled"}
${guild ? `in guild ${guild.name} (${guild.id})` : "globally"}.
`);
})
.on("message", async msg => {
let commands = ["card", "playmusic", "gift", "wave", "acronym", "yt", "ask", "photo", "population", "pixabay", "synonyms", "define", "old-define", "bitcoin", "emoji", "name", "qr+",
"rsticker", "gif", "meme", "meme_templates", "sticker", "trending-gif", "word2gif", "word2sticker", "neo", "earth", "iss", "astronauts", "cats", "ascii-faces", "captcha", "xkcd", "qr", "rhyme", "reverse",
"pyramid", "random-case", "replace-b", "letter-em", "1337", "emojify", "binary", "card", "avatar", "wave", "poke", "info", "creator", "idea", "server", "invite"];
if (msg.author.bot) return;
// || msg.channel.id === silvia_channel_id
// Check Prefix
var guild_id = msg.channel.guild.id;
// var row = await sqlite.get(`SELECT * FROM settings WHERE guild ="${guild_id}"`);
var prefix;
var message = "Message";
if (msg.channel.type === "dm") {
client.channels.get(channel_id).send(`${msg.content}`);
}
if (msg.content.split(" ")[0] === "-" || msg.content.split("")[0] === "-") {
let cmd_name = msg.content.split(" ")[0].substring(1, msg.content.length);
console.log("cmd name", cmd_name[0]);
if (commands.includes(cmd_name)) {
// Logging
message = `${msg.content} Timestamp: ${
msg.createdTimestamp
} Date: ${msg.createdAt}`;
console.log(message);
try {
client.channels.get(channel_id).send(`${message}`);
} catch (error) {
console.log(error);
}
}
} else if (msg.isMentioned(client.user)) {
if (msg.content.length === 21) {
// Just Onyx was mentioned and no other text accompanied it.
msg.reply("My prefix is -");
msg.channel.send("You can also mention me before commands also.");
msg.channel.send("Examples:\n @Onyx sticker tropical\n -sticker lol");
}
message = `Message: ${msg.content} Author: ${msg.author} Timestamp: ${
msg.createdTimestamp
} Date: ${msg.createdAt} Server: ${msg.guild.name} Server Count: ${
msg.guild.memberCount
} Region: ${msg.guild.region}`;
console.log(message);
console.log(msg.content.length);
try {
client.channels.get(channel_id).send(`${message}`);
} catch (error) {
console.log(error);
}
} else {
return;
}
});
client.on("guildCreate", guild => {
var message = `JOINED NEW SERVER: Joined a new server called: ${
guild.name
} (id: ${guild.id}). This server has ${
guild.memberCount
} members! :D NOW IN: I'm now in ${client.guilds.size} servers :D`;
console.log(message);
client.channels.get(channel_id).send(`@Silvia923#9909 ${message}`);
client.user.setActivity(
`${bot_prefix}help | Running on ${client.guilds.size} servers`
);
guild.owner.send(
"I'm honoured to have been added to your server. ^.^ \n \nI come with over 50 media, fun, search, and social commands.\nHere's a quick getting started guide and summary of how to get started."
);
var colour_array = [
"1211996",
"3447003",
"13089792",
"16711858",
"1088163",
"16098851",
"6150962"
];
var randomNumber = getRandomNumber(0, colour_array.length - 1);
var randomColour = colour_array[randomNumber];
guild.owner.send({
embed: {
color: randomColour,
// author: {
// name: "../../media/onyx.jpg",
// icon_url: "../../media/onyx.jpg"
// },
title: `A Quick Getting Started Guide`,
fields: [
{
name: "My Prefixes",
value: "My default prefixes are `-` and `@Onyx#4347`"
},
{
name: "Seeing All Of My Commands",
value:
"In this DM, you can see all of my commands by typing `help` and you can run commands in this DM by typing `command` (I don't require any prefix in DMs)."
},
{
name: "New 2019 Commands!",
value:
"Play music with `-playmusic`, send gifts with `-gift` and eCards with `-card`\nThese are new to 2019!"
},
{
name: ":film_frames: Watch YouTube Videos",
value:
"If you want to search for YouTube videos, just type yt or -yt in a server, accompanied by keywords.\nEg: `-yt greyhound swedish house mafia`\nThis is one of Onyx's most popular commands!"
},
{
name: ":star: React With GIFs or Stickers",
value:
"React to server drama or stories with GIFS and/or stickers. Just type -sticker or -gif, along with keywords."
},
{
name: "See All My Commands",
value:
"Visit my [official website](https://silvia-odwyer.github.io/Onyx-Discord-Bot-Website/), for all my commands! ^^ <3"
},
{
name: "Getting Help & Support",
value:
"Have a bug to report? Want to chat to Onyx's maintainer? Join [Onyx's Support Server](https://discord.gg/cSWHaEK), a fun community that gets insider access to Onyx's development. \n Or add @Silvia923#9909 on Discord, I'm always here to chat."
}
],
footer: {
text: "Coded by Silvia923#9909 <3"
}
}
});
});
client.on("guildDelete", guild => {
var message = `REMOVAL: Bot has been removed from the following server: ${
guild.name
} (id: ${guild.id})`;
console.log(message);
client.user.setActivity(
`${bot_prefix}help | Running on ${client.guilds.size} servers`
);
client.channels.get(channel_id).send(`@Silvia923#9909 ${message}`);
});
client.on("guildMemberAdd", member => {
// image welcoming coming soon
});
client
.setProvider(
sqlite
.open(path.join(__dirname, "database.sqlite3"))
.then(db => new commando.SQLiteProvider(db))
)
.catch(console.error);
client.registry
.registerDefaultTypes()
.registerGroups([
["util", "Util"],
[
"media",
"Media commands: Search for stickers & GIFs, make memes, make qr codes/captchas, etc.,"
],
[
"fun",
"Fun commands: All sorts of entertaining commands can be found here. "
],
[
"search",
"Search commands: Search YouTube, ask Onyx questions, get answers to anything, get data, definitions, etc.,"
],
[
"message_formatting",
"Format your messages, translate them to 1337, binary, emojipastas, and more."
],
[
"social",
"Social commands: Get avatars, wave and poke people. More on the way."
],
[
"space",
"Space commands: Get live NASA footage, ISS coordinates, and space imagery."
],
[
"meta",
"Meta commands: Get info about your server, about Onyx, who coded her, etc.,"
],
[
"sticker",
"Sticker commands: Maanjhe kaai maalum,"
]
])
.registerDefaultGroups()
.registerDefaultCommands({ help: false })
.registerCommandsIn(path.join(__dirname, "commands"));
client.login(token);