Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Fix guild count display and handle errors in chat
Browse files Browse the repository at this point in the history
interaction
  • Loading branch information
MrlolDev committed Nov 4, 2023
1 parent 256cb60 commit 588edfb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/bot/commands/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async function buildInfo(bot: Bot, guildId?: BigString): Promise<CreateMessageOp
fields: [
{
name: "Servers 🖥️",
value: `${stats?.guilds ?? Infinity}`,
value: `${stats?.guilds ?? "278.000"}`,
inline: true,
},
{
Expand Down
15 changes: 9 additions & 6 deletions src/bot/commands/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Bot,
ButtonComponent,
ButtonStyles,
Collection,
CreateMessageOptions,
Message,
MessageComponentTypes,
Expand Down Expand Up @@ -39,16 +40,19 @@ export default createCommand({
subscription: 60 * 1000,
},
interaction: async ({ interaction, options, env }) => {
const edit = async (message: CreateMessageOptions) => await interaction.edit(message);
const edit = async (message: CreateMessageOptions) => await interaction.edit(message).catch((...args) => ['chat interaction', interaction, ...args].forEach(x => interaction.bot.logger.warn(x)));
await buildInfo(interaction.bot, interaction.user.id, edit, interaction.guildId, options);
},
message: async ({ message, bot, args, env }) => {
const parser = { getString: () => args.join(" ") } as unknown as OptionResolver;
let previousMsg: Message | undefined;
const edit = async (msg: CreateMessageOptions) => {
// console.log(previousMsg ? previousMsg.id : "no previous message");
if (previousMsg) {
previousMsg = await bot.helpers.editMessage(previousMsg.channelId, previousMsg.id, msg);
if (previousMsg?.id) {
previousMsg = await bot.helpers.editMessage(previousMsg.channelId, previousMsg.id, msg).catch((...args) => {
['chat message', previousMsg, ...args].forEach(x => bot.logger.warn(x))
return undefined;
});
} else {
previousMsg = await bot.helpers.sendMessage(message.channelId, {
...msg,
Expand Down Expand Up @@ -125,9 +129,8 @@ async function buildInfo(
// if last update was more than 1 second ago
lastUpdate = Date.now();
await edit({
content: `${data.result}<${loadingIndicator.emoji.animated ? "a" : ""}:${loadingIndicator.emoji.name}:${
loadingIndicator.emoji.id
}>`,
content: `${data.result}<${loadingIndicator.emoji.animated ? "a" : ""}:${loadingIndicator.emoji.name}:${loadingIndicator.emoji.id
}>`,
});
}
} else {
Expand Down

0 comments on commit 588edfb

Please sign in to comment.