Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/commands/Info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
70 changes: 70 additions & 0 deletions src/commands/Print.ts
Original file line number Diff line number Diff line change
@@ -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<string, number>();
const localRateLimitedChannels = new Map<string, number>();

// 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;