forked from galnir/Master-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
229 lines (213 loc) · 7.55 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
const { CommandoClient } = require('discord.js-commando');
const { Structures, MessageEmbed, MessageAttachment } = require('discord.js');
const path = require('path');
const { prefix, token, discord_owner_id } = require('./config.json');
const db = require('quick.db');
const Canvas = require('canvas');
Structures.extend('Guild', function(Guild) {
class MusicGuild extends Guild {
constructor(client, data) {
super(client, data);
this.musicData = {
queue: [],
isPlaying: false,
nowPlaying: null,
songDispatcher: null,
skipTimer: false, // only skip if user used leave command
loopSong: false,
loopQueue: false,
volume: 1
};
this.triviaData = {
isTriviaRunning: false,
wasTriviaEndCalled: false,
triviaQueue: [],
triviaScore: new Map()
};
}
}
return MusicGuild;
});
const client = new CommandoClient({
commandPrefix: prefix,
owner: discord_owner_id
});
client.registry
.registerDefaultTypes()
.registerGroups([
['music', ':notes: Music Command Group:'],
['gifs', ':film_frames: Gif Command Group:'],
['other', ':loud_sound: Other Command Group:'],
['guild', ':gear: Guild Related Commands:'],
['speedrun', ':athletic_shoe: Speedrun Related Commands:']
])
.registerDefaultGroups()
.registerDefaultCommands({
eval: false,
prefix: false,
commandState: false
})
.registerCommandsIn(path.join(__dirname, 'commands'));
client.once('ready', () => {
console.log(`${client.user.tag} is Ready!`);
client.user.setActivity(`${prefix}help`, {
type: 'WATCHING',
url: 'https://github.com/galnir/Master-Bot'
});
const Guilds = client.guilds.cache.map(guild => guild.name);
console.log(Guilds, 'Connected!');
// Registering font For Cloud Services
Canvas.registerFont('./resources/welcome/OpenSans-Light.ttf', {
family: 'Open Sans Light'
});
});
client.on('voiceStateUpdate', async (___, newState) => {
if (
newState.member.user.bot &&
!newState.channelID &&
newState.guild.musicData.songDispatcher &&
newState.member.user.id == client.user.id
) {
newState.guild.musicData.queue.length = 0;
newState.guild.musicData.songDispatcher.end();
return;
}
if (
newState.member.user.bot &&
newState.channelID &&
newState.member.user.id == client.user.id &&
!newState.selfDeaf
) {
newState.setSelfDeaf(true);
}
});
client.on('guildMemberAdd', async member => {
const serverSettingsFetch = db.get(member.guild.id);
if (!serverSettingsFetch || serverSettingsFetch == null) return;
const welcomeMsgSettings = serverSettingsFetch.serverSettings.welcomeMsg;
if (welcomeMsgSettings == undefined) return;
if (welcomeMsgSettings.status == 'no') return;
if (welcomeMsgSettings.status == 'yes') {
var applyText = (canvas, text) => {
const ctx = canvas.getContext('2d');
let fontSize = 70;
do {
ctx.font = `${(fontSize -= 10)}px Open Sans Light`; // if the font register changed this needs to match the family Name on line 62
} while (ctx.measureText(text).width > canvas.width - 300);
return ctx.font;
};
// Customizable Welcome Image Options
// Canvas Size Options (Width, Height)
var canvas = await Canvas.createCanvas(
welcomeMsgSettings.imageWidth,
welcomeMsgSettings.imageHeight
);
var ctx = canvas.getContext('2d');
// Background Image Options
var background = await Canvas.loadImage(welcomeMsgSettings.wallpaperURL);
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
// Background Image Border Options
ctx.strokeStyle = '#000000';
ctx.strokeRect(0, 0, canvas.width, canvas.height);
// Upper Text Options
if (welcomeMsgSettings.topImageText == 'default') {
ctx.font = '26px Open Sans Light'; // if the font register changed this needs to match the family Name on line 62
ctx.fillStyle = '#FFFFFF'; // Main Color of the Text on the top of the welcome image
ctx.fillText(
`Welcome to ${member.guild.name}`, //<-- didn't play nice being stored in DB
canvas.width / 2.5,
canvas.height / 3.5
);
ctx.strokeStyle = `#FFFFFF`; // Secondary Color of Text on the top of welcome for depth/shadow the stroke is under the main color
ctx.strokeText(
`Welcome to ${member.guild.name}`, //<-- didn't play nice being stored in DB
canvas.width / 2.5,
canvas.height / 3.5
);
} else {
ctx.font = '26px Open Sans Light'; // if the font register changed this needs to match the family Name on line 62
ctx.fillStyle = '#FFFFFF'; // Main Color of the Text on the top of the welcome image
ctx.fillText(
welcomeMsgSettings.topImageText,
canvas.width / 2.5,
canvas.height / 3.5
);
ctx.strokeStyle = `#FFFFFF`; // Secondary Color of Text on the top of welcome for depth/shadow the stroke is under the main color
ctx.strokeText(
welcomeMsgSettings.topImageText,
canvas.width / 2.5,
canvas.height / 3.5
);
}
// Lower Text Options Defaults
if (welcomeMsgSettings.bottomImageText == 'default') {
ctx.font = applyText(canvas, `${member.displayName}!`);
ctx.fillStyle = '#FFFFFF'; // Main Color for the members name for the welcome image
ctx.fillText(
`${member.displayName}!`, //<-- didn't play nice being stored in DB
canvas.width / 2.5,
canvas.height / 1.8
);
ctx.strokeStyle = `#FF0000`; // Secondary Color for the member name to add depth/shadow to the text
ctx.strokeText(
`${member.displayName}!`, //<-- didn't play nice being stored in DB
canvas.width / 2.5,
canvas.height / 1.8
);
} else {
ctx.font = applyText(canvas, `${member.displayName}!`);
ctx.fillStyle = '#FFFFFF'; // Main Color for the members name for the welcome image
ctx.fillText(
welcomeMsgSettings.bottomImageText,
canvas.width / 2.5,
canvas.height / 1.8
);
ctx.strokeStyle = `#FF0000`; // Secondary Color for the member name to add depth/shadow to the text
ctx.strokeText(
welcomeMsgSettings.bottomImageText,
canvas.width / 2.5,
canvas.height / 1.8
);
}
// Avatar Shape Options
ctx.beginPath();
ctx.arc(125, 125, 100, 0, Math.PI * 2, true); // Shape option (circle)
ctx.closePath();
ctx.clip();
const avatar = await Canvas.loadImage(
member.user.displayAvatarURL({
format: 'jpg'
})
);
ctx.drawImage(avatar, 25, 25, 200, 200);
// Image is Built and Ready
const attachment = new MessageAttachment(
canvas.toBuffer(),
'welcome-image.png'
);
// Welcome Embed Report
var embed = new MessageEmbed()
.setColor(`RANDOM`)
.attachFiles(attachment)
.setImage('attachment://welcome-image.png')
.setFooter(`Type help for a feature list!`)
.setTimestamp();
if (welcomeMsgSettings.embedTitle == 'default') {
embed.setTitle(
`:speech_balloon: Hey ${member.displayName}, You look new to ${member.guild.name}!` //<-- didn't play nice being stored in DB
);
} else embed.setTitle(welcomeMsgSettings.embedTitle);
try {
await member.user.send(embed);
} catch {
console.log(`${member.user.username}'s dms are private`);
}
}
});
// To see your welcome message as if you just joined the Server
client.on('message', message => {
if (message.content === `${prefix}show-welcome-message`) {
client.emit('guildMemberAdd', message.member);
}
});
client.login(token);