From 02aef5eaffbfb3dadad41819dd19f4f9b5fdd9f8 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Sun, 28 Jul 2024 07:15:25 +1000 Subject: [PATCH] Improvements to index.ts --- docker-compose.yml | 2 +- package.json | 2 +- src/index.ts | 29 +++++++++++++++++------------ yarn.lock | 10 +++++----- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 266839d..258b1ff 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ services: cache: container_name: daggerbot-redis - image: redis/redis-stack-server:7.2.0-v10 + image: redis/redis-stack-server:7.4.0-rc2 restart: unless-stopped ports: - 6379:6379/tcp diff --git a/package.json b/package.json index 3edcbc3..914d80b 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ }, "devDependencies": { "@types/ms": "0.7.34", - "@types/node": "20.14.11", + "@types/node": "20.14.12", "@types/node-cron": "3.0.11", "typescript": "5.4.5" } diff --git a/src/index.ts b/src/index.ts index 184c9a4..8473e9d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -75,14 +75,17 @@ setInterval(async()=>{ Logger.console('log', 'DailyMsgs', `Pushed [${formattedDate}, ${total}]`) // Send notification to #bot-log that the data has been pushed to database. - const commands = await client.guilds.cache.get(client.config.dcServer.id)?.commands.fetch(); - if (commands) (client.channels.resolve(client.config.dcServer.channels.bot_log) as Discord.TextChannel).send({embeds: [ - new client.embed().setDescription(`Pushed the following\ndata to x.name === 'rank').id}>`).setFields( - {name: 'Day', value: formattedDate.toString(), inline: true}, - {name: 'Messages', value: Intl.NumberFormat('en-us').format(total).toString(), inline: true} - ).setColor(client.config.embedColor) - ]}); - else Logger.console('log', 'DailyMsgs', 'Rank command not found, cannot send notification in channel') + try { + const commands = await client.guilds.cache.get(client.config.dcServer.id)?.commands.fetch(); + if (commands) (client.channels.cache.get(client.config.dcServer.channels.bot_log) as Discord.TextChannel).send({embeds: [ + new client.embed().setDescription(`Pushed the following\ndata to x.name === 'rank').id}>`).setFields( + {name: 'Day', value: formattedDate.toString(), inline: true}, + {name: 'Messages', value: Intl.NumberFormat('en-us').format(total).toString(), inline: true} + ).setColor(client.config.embedColor) + ]}); + } catch { + Logger.console('log', 'DailyMsgs', 'Rank command not found, cannot send notification in channel'); + } } } }, 5000) @@ -104,18 +107,20 @@ if (!client.config.botSwitches.logs) { }; client.on('raw', async (packet:RawGatewayPacket)=>{ if (rawSwitches[packet.t] || packet.t !== 'MESSAGE_UPDATE') return; - if (packet.d.guild_id != client.config.dcServer.id || disabledChannels.includes(packet.d.channel_id) || typeof packet.d.content === 'undefined') return; + if (packet.d.guild_id != client.config.dcServer.id || disabledChannels.includes(packet.d.channel_id) || typeof packet.d.content === undefined) return; - const channel = client.channels.cache.get(packet.d.channel_id) as Discord.TextBasedChannel; + const channel: Discord.TextBasedChannel = client.channels.cache.get(packet.d.channel_id) as Discord.TextChannel; // Switched to console.log to prevent useless embed creation that has same content as the original message. - if (!rawSwitches.MESSAGE_UPDATE && !packet.d.author.bot) return Logger.console('log', 'RawEvent:Edit', `Message was edited in #${(channel as Discord.TextChannel).name}`); + if (!rawSwitches.MESSAGE_UPDATE && !packet.d.author.bot) return Logger.console('log', 'RawEvent:Edit', `Message was edited in #${channel.name}`); }); client.on('raw', async (packet:RawGatewayPacket)=>{ if (rawSwitches[packet.t]) return; if (packet.t !== 'MESSAGE_DELETE' || packet.d.guild_id != client.config.dcServer.id || disabledChannels.includes(packet.d.channel_id)) return; - Logger.console('log', 'RawEvent:Del', `Message was deleted in #${(client.channels.resolve(packet.d.channel_id) as Discord.TextChannel).name}`); + const channel: Discord.TextBasedChannel = client.channels.cache.get(packet.d.channel_id) as Discord.TextChannel; + + Logger.console('log', 'RawEvent:Del', `Message was deleted in #${channel.name}`); rawSwitches[packet.t] = true; }); diff --git a/yarn.lock b/yarn.lock index a5ad503..4e22532 100644 --- a/yarn.lock +++ b/yarn.lock @@ -531,12 +531,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:20.14.11": - version: 20.14.11 - resolution: "@types/node@npm:20.14.11" +"@types/node@npm:*, @types/node@npm:20.14.12": + version: 20.14.12 + resolution: "@types/node@npm:20.14.12" dependencies: undici-types: "npm:~5.26.4" - checksum: 10/344e1ce1ed16c86ed1c4209ab4d1de67db83dd6b694a6fabe295c47144dde2c58dabddae9f39a0a2bdd246e95f8d141ccfe848e464884b48b8918df4f7788025 + checksum: 10/9205bf46ef6a99d99cdde9efeb8218cd15803cc407249c2336557cd630b006380dad68c03ee574934414639f8e450044f45530c92788a8e82078bae45ee40f93 languageName: node linkType: hard @@ -663,7 +663,7 @@ __metadata: "@sequelize/postgres": "npm:7.0.0-alpha.41" "@toast/tokenservice-client": "npm:1.2.8" "@types/ms": "npm:0.7.34" - "@types/node": "npm:20.14.11" + "@types/node": "npm:20.14.12" "@types/node-cron": "npm:3.0.11" ansi-colors: "npm:4.1.3" dayjs: "npm:1.11.12"