Change messages for logging

This commit is contained in:
Frostbide
2025-05-25 19:28:24 -07:00
parent 408e72472c
commit 84230e0d44
2 changed files with 20 additions and 4 deletions

View File

@@ -7,6 +7,8 @@ function main(ctx) {
bot.database = {
db: null,
async loadDataBase() {
if (!host || !port)
return console.error('Database missing host or port in config');
this.db = new Client({
host,
port,
@@ -17,7 +19,7 @@ function main(ctx) {
try {
await this.db.connect();
console.log('Connected to PostgreSQL.');
console.log('Connected to PostgreSQL');
const createMessages = `
CREATE TABLE IF NOT EXISTS messages (

View File

@@ -15,7 +15,10 @@ function main(ctx) {
new Map(guildInvites.map((inv) => [inv.code, inv.uses]))
);
} catch (err) {
bot.logger.log(`Could not fetch invites for ${guild.name}:`, err);
bot.logger.log(
`Error fetching invites for guild ${guild.name}:`,
err
);
}
});
@@ -73,7 +76,7 @@ function main(ctx) {
new Map(newInvites.map((inv) => [inv.code, inv.uses]))
);
} catch (err) {
bot.logger.log(`Error managing invite for ${member.user.tag}:`, err);
bot.logger.log(`Guild join error from ${member.user.tag}:`, err);
}
});
@@ -120,7 +123,7 @@ function main(ctx) {
return result.rows?.[0]?.total_uses || 0;
},
async getLeaderboard(guildId, amount = 10) {
async getUserLeaderboard(guildId, amount = 10) {
const result = await database.db.query(
`SELECT userid, SUM(uses) AS total_uses
FROM inviteCount
@@ -136,6 +139,17 @@ function main(ctx) {
}));
},
async getInviteLeaderboard(guildId, amount = 10) {
const result = await database.db.query(
`SELECT userid, SUM(uses) AS total_uses`,
[guildId, amount]
);
return result.rows.map((row) => ({
userId: row.userid,
uses: row.total_uses,
}));
},
async setLogChannel(guildId, channelId) {
await database.db.query(
`INSERT INTO inviteConfig (serverid, channelid, enabled)