diff --git a/example.env b/example.env index 5530947..93c9202 100644 --- a/example.env +++ b/example.env @@ -13,4 +13,5 @@ PATREON_ACCESS_TOKEN="PATREON_ACCESS_TOKEN" # This is the token that Dad Bot use PATREON_CAMPAIN_ID="PATREON_CAMPAIN_ID" # This is the ID of the Patreon campaign that Dad Bot uses to get the list of patrons CLUSTERS="NUM_OF_DADBOT_CLUSTERS" # This is the number of Dad Bot Clusters you are running, this is used for the cluster manager GB_MEM="DADBOT_CLUSTER_GB_MEM" # The amount of memory in GiB that each Dad Bot Cluster should use +PRINTER_TOKEN="PRINTER_TOKEN" # Private thing you won't get. :) # CLUSTER_ID="0" # In case you are only running one cluster, you can set this to 0 here and avoid setting it in the environment variables diff --git a/src/commands/Info.ts b/src/commands/Info.ts index d0acca6..c659110 100644 --- a/src/commands/Info.ts +++ b/src/commands/Info.ts @@ -43,6 +43,7 @@ return JSON.stringify( let time = new ReadableTime(process.uptime() * 1000); let cpu = await CPU(); interaction.createMessage({ + content: 'Support server:\ndiscord.gg/alek-s-cult-456542159210807307', embeds: [ { title: 'Dad Bot Info', diff --git a/src/commands/Print.ts b/src/commands/Print.ts new file mode 100644 index 0000000..0ad3d25 --- /dev/null +++ b/src/commands/Print.ts @@ -0,0 +1,70 @@ +import { OptionBuilder, SlashCommand } from 'oceanic.js-interactions'; +import fetch from 'node-fetch'; +import { MessageFlags } from 'oceanic.js'; + +const localRateLimitedUsers = new Map(); +const localRateLimitedChannels = new Map(); + +// Reap rate limit every now and then to save on RAM. +setInterval(() => { + const now = Date.now(); + + localRateLimitedChannels.forEach((time, channel) => { + if (time < now) localRateLimitedChannels.delete(channel); + }) + + localRateLimitedUsers.forEach((time, user) => { + if (time < now) localRateLimitedUsers.delete(user); + }) +}, 1000 * 60 * 60); + +const print = new SlashCommand( + 'print', + 'Print something on my printer named Steve.', + {}, + { + file: OptionBuilder.Attachment('The image to print. Must be a PNG or a JPEG.', true) + }, + async (interaction, { file }) => { + const now = Date.now(); + + const userRate = localRateLimitedUsers.get(interaction.user.id) ?? 0; + const channelRate = localRateLimitedChannels.get(interaction.channelID) ?? 0; + if (userRate >= now) { + await interaction.createMessage({ + flags: MessageFlags.EPHEMERAL, + content: 'You are trying to use the printer too much! Learn how to share!' + }); + return; + } else if (channelRate >= now) { + await interaction.createMessage({ + content: 'This channel is using the printer too fast! Learn how to share!' + }); + return; + } + + localRateLimitedUsers.set(interaction.user.id, now + (1000 * 60)); + localRateLimitedChannels.set(interaction.channelID, now + (1000 * 60)); + + await interaction.defer(); + const response = await fetch('https://printer.alekeagle.com/print', { + method: 'POST', + headers: { + 'Content-Type': file.contentType, + 'Authorization': process.env.PRINTER_TOKEN + } + }); + + if (response.ok) { + await interaction.createFollowup({ + content: 'Printed! If you want to see me react to it (if I ever post about it) you can see in the support server! discord.gg/alek-s-cult-456542159210807307' + }); + } else { + await interaction.createFollowup({ + content: 'Uh, I think the printer ran out of ink. Try again tomorrow?' + }); + } + }, +); + +export default print;