-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
223 lines (187 loc) · 5.98 KB
/
Copy pathindex.js
File metadata and controls
223 lines (187 loc) · 5.98 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
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
const Discord = require('discord.js');
require('dotenv').config();
const Enmap = require('enmap');
const fs = require("fs");
const mongoose = require("mongoose");
// Set mobile status
Discord.Constants.DefaultOptions.ws.properties.$browser = "Discord Android";
// Create client
const client = new Discord.Client();
const disbut = require('discord-buttons')(client);
client.queue = new Map();
client.clink = new Map();
client.lang = [
"en",
"fr",
]
client.log = [
"on",
"off",
]
// DataBase setup
client.settings = new Enmap({
name: "users",
fetchAll: true,
autoFetch: true,
dataDir: "./db/bot/",
cloneLevel: 'deep'
});
client.webDB = new Enmap({
name: "users",
fetchAll: true,
autoFetch: true,
dataDir: "./db/servers/",
cloneLevel: 'deep'
});
client.TicketDB = new Enmap({
name: "ticket",
fetchAll: true,
autoFetch: true,
dataDir: "./db/ticket/",
cloneLevel: 'deep'
});
client.def = {
channel: "",
status: "off",
role: "",
}
client.TicketUser = new Enmap({
name: "ticket2",
fetchAll: true,
autoFetch: true,
dataDir: "./db/ticket2/",
cloneLevel: 'deep'
});
const defaultSettings = {
prefix: "&",
language: "en",
modLogChannel: "mod-log",
modRole: "Moderator",
adminRole: "Administrator",
welcomeChannel: "welcome",
welcomeMessage: "Say hello to {{user}}, everyone!"
}
const defaultDB = {
commandsrun: 0
}
client.slang = "";
client.on("ready", message => {
console.log('bot ready !');
setInterval(function(){
const stats = [
"&help",
"error-bot.ga",
]
var min = 0;
var max = Math.floor(stats.length);
var stat = stats[Math.floor(Math.random() * (max - min)) + min]
client.user.setActivity(`${stat} | im pro`, {
type: 'WATCHING'
});
}, 1000);
});
// mongoDB connection
// mongoose.connect(process.env.MONGODB_SRV, {
// useNewUrlParser: true,
// useUnifiedTopology: true,
// useFindAndModify: false,
// }).then(() => [
// console.log("connect to mongoDB via mongoose !")
// ])
// client.db = mongoose.connection;
// Gets all directories in the main folder - Only goes 1 down cannot find subfolders of subfolders
function getDirectories() {
return fs.readdirSync('./commands').filter(function subFolder(file) {
return fs.statSync('./commands/' + file).isDirectory();
});
}
// Creates new discord collectoin
client.commands = new Discord.Collection();
// Reads normal .js files in the main dir
let commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
// Loops through all the folders in the main dir and finds those with a .js extension
for (const folder of getDirectories()) {
const folderFiles = fs.readdirSync('./commands/' + folder).filter(file => file.endsWith('.js'));
for (const file of folderFiles) {
console.log(`${file} loaded`)
commandFiles.push([folder, file]);
}
}
// Takes the two different command and folder lists and requires all the commands into an array which then puts it into the collection
for (const file of commandFiles) {
let command;
if (Array.isArray(file)) {
command = require(`./commands/${file[0]}/${file[1]}`);
} else {
command = require(`./commands/${file}`);
}
client.commands.set(command.name, command);
}
//Loads commands categories
client.modules = [
"general",
"mod",
"among us",
"owner",
"fun"
]
// Load modules
fs.readdir(`./modules/`, (err, files) => {
if (err) {
throw err
}
for (const file of files) {
if (!file.endsWith(".js")) continue;
console.log(`loaded ${file}`)
require(`./modules/${file}`)(client);
}
});
// loads config.js
config = require(`${process.cwd()}/config.js`);
client.config = config;
console.log(`loaded config.js`)
//Loads Events
fs.readdir(`${process.cwd()}/events/Discord/`, (err, files) => {
if (err) {
throw err
}
for (const file of files) {
if (!file.endsWith(".js")) continue;
let event = require(`${process.cwd()}/events/Discord/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`${process.cwd()}/events/Discord/${file}`)];
}
});
// This executes when a member joins.
client.on("guildMemberAdd", member => {
// First, ensure the settings exist
client.settings.ensure(member.guild.id, defaultSettings);
// First, get the welcome message using get:
let welcomeMessage = client.settings.get(member.guild.id, "welcomeMessage");
// Our welcome message has a bit of a placeholder, let's fix that:
welcomeMessage = welcomeMessage.replace("{{user}}", member.user.tag)
// we'll send to the welcome channel.
member.guild.channels.cache
.find(channel => channel.name === client.settings.get(member.guild.id, "welcomeChannel"))
.send(welcomeMessage)
.catch(console.error);
});
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});
client.on("guildDelete", guild => {
// When the bot leaves or is kicked, delete settings to prevent stale entries.
client.settings.delete(guild.id);
console.log(`deleted ${guild.name} from the database`)
});
client.on("guildCreate", guild => {
const channel = guild.channels.cache.find(channel => channel.type === 'text' && channel.permissionsFor(guild.me).has("SEND_MESSAGES"))
client.sendEmbed(channel, "New bot joined", "woo thanks for adding me here \n my prefix is & or @Error-Bot \n you can get help by doing &help")
});
try {
client.login();
} catch (e) {
console.error(`Invalid token: ${e}`);
return;
}