Skip to content

Commit 9058df6

Browse files
authored
Merge pull request #11 from Ezzud/v1.4.1-fixes
Some changes & news (v1.4.1)
2 parents cb50828 + 3bb5b9d commit 9058df6

19 files changed

+217
-59
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Default prefix is "t!" but he can be changed. You can @Mention the bot to get hi
5252
- t!help | See the bot's help menu
5353
- t!info | See the bot's informations
5454
- t!ping | See the bot's ping
55+
- t!stats | See the bot's stats
5556
</p>
5657

5758
![Commandes de giveaway](https://media.discordapp.net/attachments/740991539148488754/843951992820334633/commands2.png)<br/>
@@ -109,6 +110,7 @@ Le préfixe par défaut est "t!" mais il peut être changé. Vous pouvez aussi r
109110
- t!help | Affiche le menu d'aide
110111
- t!info | Obtenir des informations sur le bot
111112
- t!ping | Voir le ping du bot
113+
- t!stats | Voir les statistiques du bot
112114
</p>
113115

114116
![Commandes de giveaway](https://media.discordapp.net/attachments/740991539148488754/843951992820334633/commands2.png)<br/>

commands/create.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ let mess = collected.first().content
660660
IsRequiredServer: isrequiredserver,
661661
requiredServer: requiredserver,
662662
lang: lang.id,
663+
shardID: client.shard.ids[0],
663664
hostedBy: message.author.id,
664665
rainbow: await data.get(`${message.guild.id}.rainbow`) || false,
665666
requiredServerName: requiredservername
@@ -671,6 +672,11 @@ let mess = collected.first().content
671672
await data.set(`${message.guild.id}.time`, `:x:`)
672673
await data.set(`${message.guild.id}.winnerstr`, `:x:`)
673674
await data.set(`${message.guild.id}.price`, `:x:`)
675+
const stats = new db.table("stats")
676+
if (!await stats.get("creation_count")) {
677+
await stats.set("creation_count", 0)
678+
}
679+
await stats.add(`creation_count`, 1)
674680
}).catch(async (err) => {
675681
console.error(err)
676682
});

commands/help.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports.run = async (client, pf, message, args, manager,json,lang) => {
77
.setThumbnail(client.user.avatarURL())
88
.addField(lang.helpGiveawayFieldTitle, `${lang.helpGiveawayPermission.split("%warning%").join(client.warning)}\n\n${lang.helpGiveawayCreate.split("%pf%").join(pf)}\n${lang.helpGiveawayStart.split("%pf%").join(pf)}\n${lang.helpGiveawayEnd.split("%pf%").join(pf)}\n${lang.helpGiveawayReroll.split("%pf%").join(pf)}\n${lang.helpGiveawayDelete.split("%pf%").join(pf)}\n${lang.helpGiveawayEdit.split("%pf%").join(pf)}\n${lang.helpGiveawayList.split("%pf%").join(pf)}\n\u200B`)
99
.addField(lang.helpConfigFieldTitle, `${lang.helpConfigPermission.split("%warning%").join(client.warning)}\n\n${lang.helpConfigList.split("%pf%").join(pf)}\n${lang.helpConfigPrefix.split("%pf%").join(pf)}\n${lang.helpConfigDMWin.split("%pf%").join(pf)}\n${lang.helpConfigLang.split("%pf%").join(pf)}\n${lang.helpConfigLangList.split("%pf%").join(pf)}\n\u200B`)
10-
.addField(lang.helpInfoFieldTitle, `${lang.helpInfoList.split("%pf%").join(pf)}\n${lang.helpInfoHelp.split("%pf%").join(pf)}\n${lang.helpInfoPing.split("%pf%").join(pf)}\n${lang.helpInfoVote.split("%pf%").join(pf)}\n${lang.helpInfoInvite.split("%pf%").join(pf)}`)
10+
.addField(lang.helpInfoFieldTitle, `${lang.helpInfoList.split("%pf%").join(pf)}\n${lang.helpInfoHelp.split("%pf%").join(pf)}\n${lang.helpInfoStats.split("%pf%").join(pf)}\n${lang.helpInfoPing.split("%pf%").join(pf)}\n${lang.helpInfoVote.split("%pf%").join(pf)}\n${lang.helpInfoInvite.split("%pf%").join(pf)}`)
1111
.setFooter(lang.footer.split("%version%").join(json.version), message.author.avatarURL())
1212
message.channel.send(embed)
1313
}

commands/ping.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ console.log = function(d) {
1414
fs.appendFileSync(`${client.logs_path}`, `\n(${commandname}) ${moment(date).format('MM-D-YYYY hh:mm')} | ${d}`, "UTF-8",{'flags': 'a+'});
1515
log_stdout.write(`SHARD #${client.shard.ids[0]} ` + util.format(d) + '\n');
1616
};
17-
let embed = new Discord.MessageEmbed().setAuthor(message.author.tag, message.author.avatarURL(), `https://github.com/Ezzud/tadaa`).setColor('17F0C9').addField(`\u200B`, lang.pingStart).setFooter(lang.footer.split("%version%").join(json.version))
1817
var messagePing = new Date().getTime() - message.createdTimestamp
18+
let embed = new Discord.MessageEmbed().setAuthor(message.author.tag, message.author.avatarURL(), `https://github.com/Ezzud/tadaa`).setColor('17F0C9').addField(`\u200B`, lang.pingStart).setFooter(lang.footer.split("%version%").join(json.version))
1919
await message.channel.send(embed).then(async (msg) => {
20-
var apiPing = Math.trunc(client.ws.ping)
20+
var apiPing = Math.trunc(client.ws.ping)
2121
let color;
2222
if (apiPing > 500) {
2323
color = 'E3260F'

commands/start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ const data = new db.table("serverInfo")
127127
IsRequiredServer: false,
128128
requiredServer: null,
129129
lang: lang.id,
130+
shardID: client.shard.ids[0],
130131
langfile: lang,
131132
hostedBy: message.author.id,
132133
rainbow: await data.get(`${message.guild.id}.rainbow`) || false,
133134
requiredServerName: null
134135
}).then((gData) => {
135-
console.log(gData.lang)
136136
console.log(`SHARD #${client.shard.ids[0]} - Nouveau giveaway lancé dans le serveur " ${client.guilds.cache.get(gData.guildID).name} "`);
137137
let yembed = new Discord.MessageEmbed().setColor('24E921').setAuthor(message.author.tag, message.author.avatarURL(), `https://github.com/Ezzud/tadaa`).setDescription(lang.startEmbedSuccess.split("%okay%").join(client.okay).split("%channel%").join(`<#${gData.channelID}>`)).setFooter(lang.footer.split("%version%").join(json.version))
138138
message.channel.send(yembed)

commands/stats.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use strict';
2+
const Discord = require("discord.js");
3+
const ms = require('ms');
4+
const moment = require('moment');
5+
const fs = require('fs');
6+
const Topgg = require(`@top-gg/sdk`)
7+
const config = require('../config.json')
8+
const db = require('quick.db')
9+
const stats = new db.table("stats")
10+
11+
var api;
12+
if (config.topggEnabled === true) {
13+
api = new Topgg.Api(config.topggToken)
14+
}
15+
let emojiMap = {
16+
link: "732605373185261629",
17+
dev: "732605373185261608",
18+
sharding: "732605372954575029",
19+
computer: "732607541061877760",
20+
memoire: "732698462822596659",
21+
okay: "732581317098602546",
22+
nope: "732581316880498782",
23+
info: "732581319971831808",
24+
what: "732581319678361662",
25+
support: "760104912372891659",
26+
warn: "732581316217929782"
27+
};
28+
29+
function bts(bytes) {
30+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
31+
if (bytes === 0) return 'n/a'
32+
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10)
33+
if (i === 0) return `${bytes} ${sizes[i]})`
34+
return `${(bytes / (1024 ** i)).toFixed(1)} ${sizes[i]}`
35+
}
36+
const loadings = `<a:erjbgtuezrftetgfret:688433071573565440>`
37+
38+
function getEmoji(name) {
39+
return `<:${name}:${emojiMap[name]}>`;
40+
}
41+
module.exports.run = async (client, pf, message, args, manager,json,lang) => {
42+
if (!await stats.get("command_count")) {
43+
await stats.set("command_count", 0)
44+
}
45+
let command_count = await stats.get("command_count")
46+
47+
if (!await stats.get("creation_count")) {
48+
await stats.set("creation_count", 0)
49+
}
50+
let creation_count = await stats.get("creation_count")
51+
52+
let totalGiveaways = client.giveawaysManager.giveaways.filter((g) => g.guildID !== undefined).length
53+
let totalGiveawaysActive = client.giveawaysManager.giveaways.filter((g) => g.ended !== true).length
54+
let totalGiveawaysEnded = client.giveawaysManager.giveaways.filter((g) => g.ended === true).length
55+
56+
let guildGiveaways = client.giveawaysManager.giveaways.filter((g) => g.guildID === message.guild.id).length
57+
58+
59+
60+
let embed = new Discord.MessageEmbed()
61+
.setAuthor(lang.statsEmbedTitle, message.author.avatarURL())
62+
.setColor("#F18718")
63+
.setThumbnail(client.user.avatarURL())
64+
.addField(lang.statsCommandCount, ` \` ${command_count} \` `, true)
65+
.addField(lang.statsCreationCount, ` \` ${creation_count} \` `)
66+
.addField(lang.statsGiveawaysCount, ` \` ${totalGiveaways} \` (${lang.statsGiveawaysMultiple.split("%active%").join(totalGiveawaysActive).split("%ended%").join(totalGiveawaysEnded)}) `, true)
67+
.addField(lang.statsGiveawaysGuildCount, ` \` ${guildGiveaways} \` `)
68+
.setFooter(lang.footer.split("%version%").join(json.version))
69+
message.channel.send(embed)
70+
}
71+
module.exports.help = {
72+
name: "stats"
73+
}

data/storage/0/giveaways.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/storage/1/giveaways.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/storage/2/giveaways.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/storage/giveaways.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

events/message.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const config = require('../config.json')
2323
const json = require('../package.json')
2424
const fs = require('fs');
2525
const db = require('quick.db')
26+
const stats = new db.table("stats")
2627
const delay = new Set()
2728
const gwDelay = new Set()
2829
const voterGwDelay = new Set()
@@ -36,9 +37,6 @@ var api;
3637
if (config.topggEnabled === true) {
3738
api = new Topgg.Api(config.topggToken)
3839
}
39-
40-
41-
4240
/* /////////////////////////////////////////////////
4341
4442
@@ -86,8 +84,7 @@ module.exports = async (client, message) => {
8684
let noPermembed = new Discord.MessageEmbed().setAuthor(`TADAA`, client.user.avatarURL).setDescription(`${getEmoji("nope")} ${lang.noPermission}`).setColor(`#F67272`).setTimestamp().setFooter(lang.footer.split("%version%").join(json.version), message.author.avatarURL)
8785
return message.author.send(noPermembed);
8886
}
89-
90-
if(config.topggEnabled === true) {
87+
if (config.topggEnabled === true) {
9188
const request = await api.hasVoted(message.author.id)
9289
if (command === 'delete' || command === 'end' || command === 'start' || command === "create") {
9390
if (request === true) {
@@ -129,6 +126,10 @@ module.exports = async (client, message) => {
129126
}
130127
}
131128
let commande_file = client.commands.get(command);
129+
if (!await stats.get("command_count")) {
130+
await stats.set("command_count", 0)
131+
}
132+
await stats.add(`command_count`, 1)
132133
if (commande_file) commande_file.run(client, pf, message, args, manager, json, langage);
133134
}
134135
};

events/messageReactionAdd.js

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = async (client, messageReaction, user) => {
88
try {
99
await messageReaction.fetch();
1010
} catch (error) {
11-
console.log('Erreur: ', error);
11+
console.log('Erreur lors de la récupération de la réaction: ', error);
1212
}
1313
}
1414
if (!user) return;
@@ -41,31 +41,57 @@ module.exports = async (client, messageReaction, user) => {
4141
lang = require(`../lang/${lang}.json`)
4242
if (gw2[0].IsRequiredRole === true) {
4343
let role = guild.roles.cache.find(x => x.id === gw2[0].requiredRole)
44-
if (!role) return;
45-
if (guild.member(user.id).roles.cache.find(x => x.id === role.id)) {} else {
46-
try {
47-
await messageReaction.users.remove(user.id)
48-
const embed = new Discord.MessageEmbed().setAuthor(`${lang.reactError}`, 'https://cdn.discordapp.com/attachments/682274736306126925/740643196878454834/1596653488174.png').setColor('#ED3016').addField(`\u200B`, `${lang.reactNoRole.split("%rolename%").join(role.name)} \n${lang.winButton.split("%link%").join(`https://discordapp.com/channels/${messageReaction.message.guild.id}/${messageReaction.message.channel.id}/${messageReaction.message.id}`)}`)
49-
user.send(embed)
50-
} catch (error) {
51-
console.error(error);
44+
if (role) {
45+
if (guild.member(user.id).roles.cache.find(x => x.id === role.id)) {} else {
46+
try {
47+
await messageReaction.users.remove(user.id)
48+
} catch (error) {
49+
console.error(error);
50+
}
51+
const embed = new Discord.MessageEmbed().setAuthor(`${lang.reactError}`, 'https://ezzud.fr/images/closedFixed.png').setColor('#ED3016').setDescription(`${lang.reactNoRole.split("%rolename%").join(role.name)}`).addField(`\u200B`, `${lang.winButton.split("%link%").join(`https://discordapp.com/channels/${messageReaction.message.guild.id}/${messageReaction.message.channel.id}/${messageReaction.message.id}`)} ${lang.reactErrorMessage}`)
52+
user.send(embed).catch(error => {
53+
if (error.code === 50007) {
54+
console.log(`Erreur: L'utilisateur n'a pas pu être DM`)
55+
}
56+
})
5257
}
53-
return;
5458
}
5559
}
5660
if (gw2[0].IsRequiredServer === true) {
5761
let guild = await client.guilds.fetch(gw2[0].requiredServer)
58-
if (!guild) return;
59-
let member = await guild.members.fetch(user.id)
60-
if (!member) {
61-
try {
62-
await messageReaction.users.remove(user.id)
63-
const embed = new Discord.MessageEmbed().setAuthor(`${lang.reactError}`, 'https://cdn.discordapp.com/attachments/682274736306126925/740643196878454834/1596653488174.png').setColor('#ED3016').addField(`\u200B`, `${lang.reactNoServer.split("%requiredServerName%").join(gw2[0].requiredServerName)} \n${lang.winButton.split("%link%").join(`https://discordapp.com/channels/${messageReaction.message.guild.id}/${messageReaction.message.channel.id}/${messageReaction.message.id}`)} ${lang.reactErrorMessage}`)
64-
user.send(embed)
65-
} catch (error) {
66-
console.error(error);
62+
if (guild) {
63+
var sended = false
64+
let member = await guild.members.fetch(user.id).catch(async err => {
65+
console.log("Error")
66+
if (err.code === 10007) {
67+
try {
68+
await messageReaction.users.remove(user.id)
69+
} catch (error) {
70+
console.error(error);
71+
}
72+
const embed = new Discord.MessageEmbed().setAuthor(`${lang.reactError}`, 'https://ezzud.fr/images/closedFixed.png').setColor('#ED3016').setDescription(`${lang.reactNoServer.split("%requiredServerName%").join(gw2[0].requiredServerName)}`).addField(`\u200B`, `${lang.winButton.split("%link%").join(`https://discordapp.com/channels/${messageReaction.message.guild.id}/${messageReaction.message.channel.id}/${messageReaction.message.id}`)} ${lang.reactErrorMessage}`)
73+
user.send(embed).catch(error => {
74+
if (error.code === 50007) {
75+
console.log(`Erreur: L'utilisateur n'a pas pu être DM`)
76+
}
77+
})
78+
sended = true;
79+
}
80+
})
81+
if (sended === true) return;
82+
if (!member) {
83+
try {
84+
await messageReaction.users.remove(user.id)
85+
} catch (error) {
86+
console.error(error);
87+
}
88+
const embed = new Discord.MessageEmbed().setAuthor(`${lang.reactError}`, 'https://ezzud.fr/images/closedFixed.png').setColor('#ED3016').setDescription(`${lang.reactNoServer.split("%requiredServerName%").join(gw2[0].requiredServerName)}`).addField(`\u200B`, `${lang.winButton.split("%link%").join(`https://discordapp.com/channels/${messageReaction.message.guild.id}/${messageReaction.message.channel.id}/${messageReaction.message.id}`)} ${lang.reactErrorMessage}`)
89+
user.send(embed).catch(error => {
90+
if (error.code === 50007) {
91+
console.log(`Erreur: L'utilisateur n'a pas pu être DM`)
92+
}
93+
})
6794
}
68-
return;
6995
}
7096
}
7197
}

events/ready.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ module.exports = async (client) => {
2020
let prereq;
2121
prereq = await client.shard.fetchClientValues('guilds.cache.size');
2222
prereq = prereq.reduce((p, n) => p + n, 0);
23+
let onServer = client.giveawaysManager.giveaways.filter((g) => g.ended !== true);
24+
onServer = onServer.length
2325
await client.user.setPresence({
2426
activity: {
25-
name: `${config.prefix}help or @${client.user.username}${prereq} guilds • Shard ${count}/${client.shard.count} • v${json.version}`
27+
name: `${config.prefix}help or @${client.user.username}${prereq} guilds • ${onServer} active giveaways`
2628
},
2729
status: 'online'
2830
})
@@ -31,6 +33,8 @@ module.exports = async (client) => {
3133
await api.postStats({
3234
serverCount: prereq,
3335
shardCount: client.shard.count
36+
}).catch(err => {
37+
console.log(err)
3438
})
3539
}
3640
setInterval(async () => {
@@ -42,9 +46,11 @@ module.exports = async (client) => {
4246
let req;
4347
req = await client.shard.fetchClientValues('guilds.cache.size');
4448
req = req.reduce((p, n) => p + n, 0);
49+
let onServer = client.giveawaysManager.giveaways.filter((g) => g.ended !== true);
50+
onServer = onServer.length
4551
await client.user.setPresence({
4652
activity: {
47-
name: `${config.prefix}help or @${client.user.username}${req} guilds • Shard ${count2}/${client.shard.count} • v${json.version}`
53+
name: `${config.prefix}help or @${client.user.username}${prereq} guilds • ${onServer} active giveaways`
4854
},
4955
status: 'online'
5056
})
@@ -53,6 +59,8 @@ module.exports = async (client) => {
5359
await api.postStats({
5460
serverCount: req,
5561
shardCount: client.shard.count
62+
}).catch(err => {
63+
console.log(err)
5664
})
5765
}
5866
}, 300000);

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ manager.on('end', async (giveaway, winners) => {
213213
lang = "fr_FR"
214214
}
215215
lang = require(`./lang/${lang}.json`)
216-
const embedwin = new Discord.MessageEmbed().setAuthor(`${lang.winText}`, icon_url = 'https://cdn.discordapp.com/attachments/682274736306126925/740643196878454834/1596653488174.png').setColor('#EFE106').addField(`\u200B`, `${lang.winPrize.split("%prize%").join(giveaway.prize)}\n${lang.winButton.split("%link%").join(`https://discordapp.com/channels/${giveaway.channel.guild.id}/${giveaway.channel.id}/${giveaway.messageID}`)}`)
216+
const embedwin = new Discord.MessageEmbed().setAuthor(`${lang.winText}`, icon_url = 'https://ezzud.fr/images/openedFixed.png').setColor('#96F221').setDescription(`${lang.winPrize.split("%prize%").join(giveaway.prize)}`).addField(`\u200B`, `${lang.winButton.split("%link%").join(`https://discordapp.com/channels/${giveaway.channel.guild.id}/${giveaway.channel.id}/${giveaway.messageID}`)} ${lang.reactErrorMessage}`)
217217
winners.forEach((member) => {
218218
member.send(embedwin)
219219
});

0 commit comments

Comments
 (0)