This repository has been archived by the owner on Mar 30, 2023. It is now read-only.
forked from IgorKowalczyk/majo.exe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
146 lines (129 loc) · 5.13 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
const Discord = require("discord.js");
const client = new Discord.Client({disableMentions: "everyone"});
// inutilizavel sem a dashboard
/*const fs = require("fs");
const http = require("http");
const db = require("quick.db");
const Enmap = require("enmap"); //load the enmap library
const { dirname } = require("path");*/
const chalk = require("chalk");
const config = require("./config.js");
const Canvas = require('canvas');
const Snowflake = require("snowflake-api");
client.db = require("quick.db");
client.commands = new Discord.Collection();
client.cooldown = new Discord.Collection();
const api = new Snowflake.Client(config.API_TOKEN);
client.snowapi = api;
// Modulo de Boas-vindas
client.on("guildMemberAdd", async member => {
//If not in a guild return
if(!member.guild) return;
//create a new Canvas
const canvas = Canvas.createCanvas(1772, 633);
//make it "2D"
const ctx = canvas.getContext('2d');
//set the Background to the welcome.png
const background = await Canvas.loadImage(`./lib/img/welcome.png`);
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
ctx.strokeStyle = '#f2f2f2';
ctx.strokeRect(0, 0, canvas.width, canvas.height);
//set the first text string
var textString3 = `${member.user.username}`;
//if the text is too big then smaller the text
if (textString3.length >= 14) {
ctx.font = 'bold 100px Genta';
ctx.fillStyle = '#f2f2f2';
ctx.fillText(textString3, 720, canvas.height / 2 + 20);
}
//else dont do it
else {
ctx.font = 'bold 150px Genta';
ctx.fillStyle = '#f2f2f2';
ctx.fillText(textString3, 720, canvas.height / 2 + 20);
}
//define the Discriminator Tag
var textString2 = `#${member.user.discriminator}`;
ctx.font = 'bold 40px Genta';
ctx.fillStyle = '#f2f2f2';
ctx.fillText(textString2, 730, canvas.height / 2 + 58);
//define the Member count
var textString4 = `Member #${member.guild.memberCount}`;
ctx.font = 'bold 60px Genta';
ctx.fillStyle = '#f2f2f2';
ctx.fillText(textString4, 750, canvas.height / 2 + 125);
//get the Guild Name
var textString4 = `${member.guild.name}`;
ctx.font = 'bold 60px Genta';
ctx.fillStyle = '#f2f2f2';
ctx.fillText(textString4, 700, canvas.height / 2 - 150);
//create a circular "mask"
ctx.beginPath();
ctx.arc(315, canvas.height / 2, 250, 0, Math.PI * 2, true);//position of img
ctx.closePath();
ctx.clip();
//define the user avatar
const avatar = await Canvas.loadImage(member.user.displayAvatarURL({ format: 'jpg' }));
//draw the avatar
ctx.drawImage(avatar, 65, canvas.height / 2 - 250, 500, 500);
//get it as a discord attachment
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');
//define the welcome embed
const welcomeembed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setTimestamp()
.setFooter("Bem-vinde", member.guild.iconURL({ dynamic: true }))
.setDescription(`**Bem-vinde ao ${member.guild.name}!**
Oi <@${member.id}>!, Leia e aceite as ${config.CHANNEL_RULES}!`)
.setImage("attachment://welcome-image.png")
.attachFiles(attachment);
//define the welcome channel
const channel = member.guild.channels.cache.find(ch => ch.id === config.CHANNEL_WELCOME);
//send the welcome embed to there
channel.send(welcomeembed);
//member roles add on welcome every single role
let roles = config.ROLES_WELCOME;
for(let i = 0; i < roles.length; i++ )
member.roles.add(roles[i]);
})
// Eventos
client.on("error", console.error);
client.on("warn", console.warn);
// Modulo de XP (level)
client.on("message", async (message) => {
if (!message.guild || message.author.bot) return;
// Handle XP
xp(message);
});
function xp(message) {
if (!client.cooldown.has(`${message.author.id}`) || !(Date.now() - client.cooldown.get(`${message.author.id}`) > config.cooldown)) {
let xp = client.db.add(`xp_${message.author.id}`, 1);
let level = Math.floor(0.3 * Math.sqrt(xp));
let lvl = client.db.get(`level_${message.author.id}`) || client.db.set(`level_${message.author.id}`,1);;
if (level > lvl) {
let newLevel = client.db.set(`level_${message.author.id}`,level);
message.channel.send(`:tada: ${message.author.toString()}, Você acabou de avançar para o nível ${newLevel}!`);
}
client.cooldown.set(`${message.author.id}`, Date.now());
}
}
const token = config.token;
/* Login e comandos */
if (token) {
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
client.queue = new Map();
['command', 'event'].forEach(handler => {
require(`./handlers/${handler}`)(client);
});
client.login(token)
} else {
console.log(chalk.red.bold("Error:") + chalk.red(" Bot token is not provided! To give your bot life, you need to enter token value in the ") + chalk.grey.italic.bold(".env") + chalk.red(" file - ") + chalk.grey.italic.bold("TOKEN=Your_Token ") + chalk.red.underline.bold("REMEMBER: Token is super-secret - do not share it with anyone!"));
}
/* /Login e comandos */
process.on("unhandledRejection", (err) => {
console.error(err);
});
//-------------------//
// Fim (do index.js) //
//-------------------//