1
1
mirror of https://github.com/Burn-E99/GroupUp.git synced 2026-01-07 20:07:54 -05:00

Initial setup for standard events

This commit is contained in:
Ean Milligan (Bastion)
2023-01-11 18:06:20 -05:00
parent 460a7ed557
commit 3e6168a396
14 changed files with 310 additions and 37 deletions

13
src/events/_index.ts Normal file
View File

@ -0,0 +1,13 @@
import { ready } from './ready.ts';
import { guildCreate } from './guildCreate.ts';
import { guildDelete } from './guildDelete.ts';
import { debug } from './debug.ts';
import { messageCreate } from './messageCreate.ts';
export default {
ready,
guildCreate,
guildDelete,
debug,
messageCreate,
};

8
src/events/debug.ts Normal file
View File

@ -0,0 +1,8 @@
import {
// Log4Deno deps
log,
LT,
} from '../../deps.ts';
import utils from '../utils.ts';
export const debug = (dmsg: string) => log(LT.LOG, `Debug Message | ${utils.jsonStringifyBig(dmsg)}`);

40
src/events/guildCreate.ts Normal file
View File

@ -0,0 +1,40 @@
import config from '../../config.ts';
import {
// Discordeno deps
Bot,
Guild,
// Log4Deno deps
log,
LT,
// Discordeno deps
sendMessage,
} from '../../deps.ts';
import { infoColor1 } from '../commandUtils.ts';
import utils from '../utils.ts';
export const guildCreate = (bot: Bot, guild: Guild) => {
log(LT.LOG, `Handling joining guild ${utils.jsonStringifyBig(guild)}`);
sendMessage(bot, config.logChannel, {
embeds: [{
title: 'Guild Joined!',
color: infoColor1,
fields: [
{
name: 'Name:',
value: `${guild.name}`,
inline: true,
},
{
name: 'Id:',
value: `${guild.id}`,
inline: true,
},
{
name: 'Member Count:',
value: `${guild.memberCount}`,
inline: true,
},
],
}],
}).catch((e: Error) => utils.commonLoggers.messageSendError('mod.ts:95', 'Join Guild', e));
};

39
src/events/guildDelete.ts Normal file
View File

@ -0,0 +1,39 @@
import config from '../../config.ts';
import {
// Discordeno deps
Bot,
// Log4Deno deps
log,
LT,
// Discordeno deps
sendMessage,
} from '../../deps.ts';
import { warnColor } from '../commandUtils.ts';
import { dbClient } from '../db.ts';
import utils from '../utils.ts';
export const guildDelete = async (bot: Bot, guildId: bigint) => {
log(LT.LOG, `Handling leaving guild ${utils.jsonStringifyBig(guildId)}`);
try {
await dbClient.execute('DELETE FROM guild_prefix WHERE guildId = ?', [guildId]);
await dbClient.execute('DELETE FROM guild_mod_role WHERE guildId = ?', [guildId]);
await dbClient.execute('DELETE FROM guild_clean_channel WHERE guildId = ?', [guildId]);
} catch (e) {
log(LT.WARN, `Failed to remove guild from DB: ${utils.jsonStringifyBig(e)}`);
}
sendMessage(bot, config.logChannel, {
embeds: [{
title: 'Removed from Guild',
color: warnColor,
fields: [
{
name: 'Id:',
value: `${guildId}`,
inline: true,
},
],
}],
}).catch((e: Error) => utils.commonLoggers.messageSendError('guildDelete.ts:28', 'Leave Guild', e));
};

View File

@ -0,0 +1,17 @@
import config from '../../config.ts';
import { Bot, botId, Message } from '../../deps.ts';
export const messageCreate = async (bot: Bot, message: Message) => {
// Ignore all messages that are not commands
if (message.content.indexOf(config.prefix) !== 0) {
// Handle @bot messages
if (message.mentionedUserIds[0] === botId && (message.content.trim().startsWith(`<@${botId}>`) || message.content.trim().startsWith(`<@!${botId}>`))) {
}
// return as we are done handling this command
return;
}
// Ignore all other bots
if (message.isFromBot) return;
};

62
src/events/ready.ts Normal file
View File

@ -0,0 +1,62 @@
import config from '../../config.ts';
import { LOCALMODE } from '../../flags.ts';
import { ActivityTypes, Bot, BotWithCache, editBotMember, editBotStatus, log, LT, sendMessage } from '../../deps.ts';
import { getRandomStatus, successColor } from '../commandUtils.ts';
import utils from '../utils.ts';
export const ready = (rawBot: Bot) => {
const bot = rawBot as BotWithCache;
log(LT.INFO, `${config.name} Logged in!`);
editBotStatus(bot, {
activities: [{
name: 'Booting up . . .',
type: ActivityTypes.Game,
createdAt: new Date().getTime(),
}],
status: 'online',
});
// Interval to rotate the status text every 30 seconds to show off more commands
setInterval(async () => {
log(LT.LOG, 'Changing bot status');
try {
// Wrapped in try-catch due to hard crash possible
editBotStatus(bot, {
activities: [{
name: getRandomStatus(bot.guilds.size + bot.dispatchedGuildIds.size),
type: ActivityTypes.Game,
createdAt: new Date().getTime(),
}],
status: 'online',
});
} catch (e) {
log(LT.ERROR, `Failed to update status: ${utils.jsonStringifyBig(e)}`);
}
}, 30000);
// setTimeout added to make sure the startup message does not error out
setTimeout(() => {
LOCALMODE && editBotMember(bot, config.devServer, { nick: `LOCAL - ${config.name}` });
editBotStatus(bot, {
activities: [{
name: 'Booting Complete',
type: ActivityTypes.Game,
createdAt: new Date().getTime(),
}],
status: 'online',
});
sendMessage(bot, config.logChannel, {
embeds: [{
title: `${config.name} is now Online`,
color: successColor,
fields: [
{
name: 'Version:',
value: `${config.version}`,
inline: true,
},
],
}],
}).catch((e: Error) => utils.commonLoggers.messageSendError('ready.ts:71', 'Startup', e));
}, 1000);
};