refactor(events/client): now using the new log system
This commit is contained in:
parent
6b62e8e24e
commit
a02dfb629e
3 changed files with 31 additions and 30 deletions
|
|
@ -1,13 +1,14 @@
|
|||
import { Events, EmbedBuilder, Guild, GuildChannel, Invite } from 'discord.js';
|
||||
import { prisma } from '@lib/prisma';
|
||||
import { Bot as BotPrisma } from '@prisma/client';
|
||||
import { log } from '@lib/log';
|
||||
|
||||
async function getGuildInvite(guild: Guild): Promise<string> {
|
||||
try {
|
||||
if (guild.vanityURLCode) {
|
||||
return `https://discord.gg/${guild.vanityURLCode}`;
|
||||
}
|
||||
const channel : GuildChannel = guild.channels.cache
|
||||
const channel: GuildChannel = guild.channels.cache
|
||||
.filter(
|
||||
(ch): ch is GuildChannel =>
|
||||
ch.isTextBased() &&
|
||||
|
|
@ -22,7 +23,7 @@ async function getGuildInvite(guild: Guild): Promise<string> {
|
|||
return invite.url;
|
||||
}
|
||||
catch (err) {
|
||||
console.warn(`⚠️ Unable to create an invitation for the ${guild.id} : ${err as Error}`);
|
||||
log.warn(err, `Unable to create an invitation for the ${guild.id}`);
|
||||
return 'No invite available';
|
||||
}
|
||||
}
|
||||
|
|
@ -69,9 +70,7 @@ export default {
|
|||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.error(
|
||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err as Error}).`,
|
||||
);
|
||||
log.error(err, 'Cannot get the database connection');
|
||||
}
|
||||
const botData: BotPrisma | null = await prisma.bot.findUnique({
|
||||
where: {
|
||||
|
|
@ -88,27 +87,27 @@ export default {
|
|||
const buyerNotification: EmbedBuilder = new EmbedBuilder()
|
||||
.setTitle(`${guild.client.user.username} joined a new server`)
|
||||
.setColor('#663399')
|
||||
.setDescription(`
|
||||
.setDescription(
|
||||
`
|
||||
Name: ${guild.name}
|
||||
Owner id: ${guild.ownerId}
|
||||
Invite: ${guild.vanityURLCode || await getGuildInvite(guild)}
|
||||
Invite: ${guild.vanityURLCode || (await getGuildInvite(guild))}
|
||||
Member: ${guild.memberCount}
|
||||
`)
|
||||
`,
|
||||
)
|
||||
.setTimestamp();
|
||||
await Promise.all(
|
||||
botData.buyers.map(async (buyer) => {
|
||||
try {
|
||||
const user = await guild.client.users.fetch(buyer.id);
|
||||
const dm = await user.createDM();
|
||||
await dm.send ({
|
||||
embeds: [
|
||||
buyerNotification,
|
||||
],
|
||||
await dm.send({
|
||||
embeds: [buyerNotification],
|
||||
});
|
||||
await new Promise(res => setTimeout(res, 1000));
|
||||
await new Promise((res) => setTimeout(res, 1000));
|
||||
}
|
||||
catch (err) {
|
||||
console.warn(`⚠️ | ${buyer.id} : ${err as Error}`);
|
||||
log.warn(err, `Unable to fetch ${buyer.id} user`);
|
||||
return;
|
||||
}
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Events, EmbedBuilder, Guild } from 'discord.js';
|
||||
import { Events, EmbedBuilder, Guild, User } from 'discord.js';
|
||||
import { prisma } from '@lib/prisma';
|
||||
import { Bot as BotPrisma } from '@prisma/client';
|
||||
import { log } from '@lib/log';
|
||||
|
||||
export default {
|
||||
name: Events.GuildDelete,
|
||||
|
|
@ -23,26 +24,26 @@ export default {
|
|||
.setFooter({
|
||||
text: guildData.footer,
|
||||
})
|
||||
.setDescription(`
|
||||
.setDescription(
|
||||
`
|
||||
Name: ${guild.name}
|
||||
Owner id: ${guild.ownerId}
|
||||
Member: ${guild.memberCount}
|
||||
`)
|
||||
`,
|
||||
)
|
||||
.setTimestamp();
|
||||
await Promise.all(
|
||||
botData.buyers.map(async (buyer) => {
|
||||
botData.buyers.map(async (buyer: User) => {
|
||||
try {
|
||||
const user = await guild.client.users.fetch(buyer.id);
|
||||
const dm = await user.createDM();
|
||||
await dm.send ({
|
||||
embeds: [
|
||||
buyerNotification,
|
||||
],
|
||||
await dm.send({
|
||||
embeds: [buyerNotification],
|
||||
});
|
||||
await new Promise(res => setTimeout(res, 1000));
|
||||
await new Promise((res) => setTimeout(res, 1000));
|
||||
}
|
||||
catch (err) {
|
||||
console.warn(`⚠️ | ${buyer.id} : ${err as Error}`);
|
||||
log.warn(err, `Not able to fetch user ${buyer.id}`);
|
||||
return;
|
||||
}
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -10,11 +10,14 @@ export default {
|
|||
},
|
||||
});
|
||||
if (guildData.logServer) {
|
||||
let toPrint: string = 'The update of the guild had changes theses thing\n';
|
||||
let toPrint: string =
|
||||
'The update of the guild had changes theses thing\n';
|
||||
const logChannel = await newGuild.client.channels
|
||||
.fetch(guildData.logServer)
|
||||
.catch(() => null);
|
||||
if (!logChannel || !logChannel.isTextBased()) {return;}
|
||||
if (!logChannel || !logChannel.isTextBased()) {
|
||||
return;
|
||||
}
|
||||
if (oldGuild.name !== newGuild.name) {
|
||||
toPrint += `- Name:\n\`${oldGuild.name}\` => \`${newGuild.name}\`\n`;
|
||||
}
|
||||
|
|
@ -46,9 +49,7 @@ export default {
|
|||
})
|
||||
.setDescription(toPrint);
|
||||
logChannel.send({
|
||||
embeds: [
|
||||
toRep,
|
||||
],
|
||||
embeds: [toRep],
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue