-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
167 lines (154 loc) · 4.78 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
const { Collection, Client, MessageEmbed } = require("discord.js");
require("discord-reply");
const mongoose = require("mongoose");
const config = require("./config.json");
const prefix = config.prefix;
const token = config.token;
const mongo = config.mongodb;
const fs = require("fs");
const client = new Client({
disableMentions: "everyone",
});
const logs = require("discord-logs");
logs(client);
module.exports = client;
require("events").EventEmitter.defaultMaxListeners = 200;
require("discord-buttons")(client);
client.commands = new Collection();
client.aliases = new Collection();
client.snipes = new Collection();
const emoji = require("./emoji.json");
//top.gg stuff
const Topgg = require("@top-gg/sdk");
const api = new Topgg.Api("token");
setInterval(() => {
api.postStats({
serverCount: client.guilds.cache.size,
shardCount: client.options.shardCount,
});
}, 43200000);
//Mod logs
const modLogsSchema = require("./models/modlogs");
client.modlogs = async function ({ Member, Color, Action, Reason }, message) {
const data = await modLogsSchema.findOne({ Guild: message.guild.id });
if (!data) return;
const channel = await message.guild.channels.cache.get(data.Channel);
const embedLog = new MessageEmbed()
.setAuthor(client.user.tag, client.user.displayAvatarURL())
.setTitle(`Action: ${Action}`)
.setThumbnail(client.user.displayAvatarURL())
.addField("Staff", `${message.author} (${message.author.id})`)
.addField("Member", `${Member} (${Member.id})`)
.addField("Reason", `\`${Reason}\``)
.setColor(Color);
channel.send(embedLog);
};
client.categories = fs.readdirSync("./commands/");
["command"].forEach((handler) => {
require(`./handlers/${handler}`)(client);
});
mongoose
.connect(`${mongo}`, {
useUnifiedTopology: true,
useNewUrlParser: true,
useFindAndModify: false,
})
.then(console.log("Connected to database!"));
const prefixSchema = require("./models/prefix");
/**
* @param {Client} client
*/
client.prefix = async function (message) {
let custom;
const data = await prefixSchema
.findOne({ Guild: message.guild.id })
.catch((err) => console.log(err));
if (data) {
custom = data.Prefix;
} else {
custom = prefix;
}
return custom;
};
//music stuff
const Distube = require("distube");
client.distube = new Distube(client, {
searchSongs: false,
leaveOnFinish: false,
leaveOnStop: false,
});
const status = (queue) =>
`Volume: \`${queue.volume}%\` | Filter: \`${
queue.filter || "Off"
}\` | Loop: \`${
queue.repeatMode
? queue.repeatMode == 2
? "All Queue"
: "This Song"
: "Off"
}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\``;
client.distube
.on("playSong", (message, queue, song) =>
message.channel.send(
new MessageEmbed()
.setColor("GREEN")
.setDescription(
`${emoji.success} Playing \`${song.name}\` - \`${
song.formattedDuration
}\n\`\nRequested by: ${song.user}\n${status(queue)}`,
),
),
)
.on("addSong", (message, queue, song) =>
message.channel.send(
new MessageEmbed()
.setColor("GREEN")
.setDescription(
`${emoji.success} Added ${song.name} - \`${song.formattedDuration}\` to the queue by ${song.user}`,
),
),
)
.on("playList", (message, queue, playlist, song) =>
message.channel.send(
new MessageEmbed()
.setColor("BLURPLE")
.setDescription(
`Play \`${playlist.name}\` playlist (${
playlist.songs.length
} songs).\nRequested by: ${song.user}\nNow playing \`${
song.name
}\` - \`${song.formattedDuration}\`\n${status(queue)}`,
),
),
)
.on("addList", (message, queue, playlist) =>
message.channel.send(
new MessageEmbed()
.setColor("GREEN")
.setDescription(
`${emoji.success} Added \`${playlist.name}\` playlist (${
playlist.songs.length
} songs) to queue\n${status(queue)}`,
),
),
)
// DisTubeOptions.searchSongs = true
.on("searchResult", (message, result) => {
let i = 0;
message.channel.send(
`**Choose an option from below**\n${result
.map(
(song) => `**${++i}**. ${song.name} - \`${song.formattedDuration}\``,
)
.join("\n")}\n*Enter anything else or wait 60 seconds to cancel*`,
);
})
// DisTubeOptions.searchSongs = true
.on("searchCancel", (message) =>
message.channel.send(`${emoji.success} Searching canceled`),
)
.on("error", (message, e) => {
console.error(e);
message.channel.send("An error encountered: " + e);
});
client.login(token);