refactor(events/client): now using the new log system
This commit is contained in:
parent
a02dfb629e
commit
c579048b33
1 changed files with 22 additions and 17 deletions
|
|
@ -4,16 +4,20 @@ import {
|
||||||
PresenceUpdateStatus,
|
PresenceUpdateStatus,
|
||||||
Events,
|
Events,
|
||||||
User,
|
User,
|
||||||
|
Message,
|
||||||
|
DMChannel,
|
||||||
|
Collection,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { prisma } from '@lib/prisma';
|
import { prisma } from '@lib/prisma';
|
||||||
import { Bot as BotPrisma } from '@prisma/client';
|
import { Bot as BotPrisma } from '@prisma/client';
|
||||||
|
import { log } from '@lib/log';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: Events.ClientReady,
|
name: Events.ClientReady,
|
||||||
once: true,
|
once: true,
|
||||||
async execute(client: User) {
|
async execute(client: User) {
|
||||||
try {
|
try {
|
||||||
const botData: BotPrisma = await prisma.bot.findUnique({
|
const botData: BotPrisma | null = await prisma.bot.upsert({
|
||||||
where: {
|
where: {
|
||||||
id: 1,
|
id: 1,
|
||||||
},
|
},
|
||||||
|
|
@ -24,6 +28,10 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
update: {},
|
||||||
|
create: {
|
||||||
|
id: 1,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const newStatus: string = botData.status;
|
const newStatus: string = botData.status;
|
||||||
const tmpType: string = botData.type;
|
const tmpType: string = botData.type;
|
||||||
|
|
@ -35,9 +43,6 @@ export default {
|
||||||
case 'listen':
|
case 'listen':
|
||||||
newType = ActivityType.Listening;
|
newType = ActivityType.Listening;
|
||||||
break;
|
break;
|
||||||
case 'watch':
|
|
||||||
newType = ActivityType.Watching;
|
|
||||||
break;
|
|
||||||
case 'stream':
|
case 'stream':
|
||||||
newType = ActivityType.Streaming;
|
newType = ActivityType.Streaming;
|
||||||
break;
|
break;
|
||||||
|
|
@ -45,7 +50,8 @@ export default {
|
||||||
newType = ActivityType.Competing;
|
newType = ActivityType.Competing;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
newType = ActivityType.Watching;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
const tmpPresence: string = botData.presence;
|
const tmpPresence: string = botData.presence;
|
||||||
let newPresence: PresenceUpdateStatus;
|
let newPresence: PresenceUpdateStatus;
|
||||||
|
|
@ -89,7 +95,8 @@ export default {
|
||||||
const buyerNotification: EmbedBuilder = new EmbedBuilder()
|
const buyerNotification: EmbedBuilder = new EmbedBuilder()
|
||||||
.setTitle(`${client.user.username} running`)
|
.setTitle(`${client.user.username} running`)
|
||||||
.setColor('#008000')
|
.setColor('#008000')
|
||||||
.setDescription(`
|
.setDescription(
|
||||||
|
`
|
||||||
**On:** ${client.guilds.cache.size} guild${client.guilds.cache.size > 1 ? 's' : ''}
|
**On:** ${client.guilds.cache.size} guild${client.guilds.cache.size > 1 ? 's' : ''}
|
||||||
**With:** ${client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)} users
|
**With:** ${client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)} users
|
||||||
`,
|
`,
|
||||||
|
|
@ -97,15 +104,15 @@ export default {
|
||||||
.setTimestamp();
|
.setTimestamp();
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
botData.buyers.map(async (buyer) => {
|
botData.buyers.map(async (buyer: User) => {
|
||||||
try {
|
try {
|
||||||
const user = await client.users.fetch(buyer.id);
|
const user = await client.client.users.fetch(buyer.id);
|
||||||
const dm = await user.createDM();
|
const dm: DMChannel = await user.createDM();
|
||||||
const messages = await dm.messages.fetch({
|
const messages: Collection<string, Message<boolean>> = await dm.messages.fetch({
|
||||||
limit: 20,
|
limit: 20,
|
||||||
});
|
});
|
||||||
const lastBotMsg = messages.find(
|
const lastBotMsg: Message<boolean> | undefined = messages.find(
|
||||||
(m) => m.author.id === client.user!.id,
|
(m: Message): boolean => m.author.id === client.client.user!.id,
|
||||||
);
|
);
|
||||||
if (!lastBotMsg) {
|
if (!lastBotMsg) {
|
||||||
await lastBotMsg.edit({
|
await lastBotMsg.edit({
|
||||||
|
|
@ -120,18 +127,16 @@ export default {
|
||||||
await new Promise((res) => setTimeout(res, 1000));
|
await new Promise((res) => setTimeout(res, 1000));
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.warn(`⚠️ | ${buyer.id} : ${err as Error}`);
|
log.warn(err, `Not able to fetch user ${buyer.id}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error(
|
log.error(err, 'Cannot get the database connection');
|
||||||
`\t⚠️ | Cannot get the database connection!\n\t\t(${err as Error}).`,
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(`✅ | ${client.user.username} is now running under TTS bot`);
|
log.success(`${client.user.username} is now running under TTS bot`);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue