Compare commits

...

5 commits

Author SHA1 Message Date
467d282a3c Removed some useless things 2022-12-18 22:54:26 +01:00
56368acf74 Make it owner only 2022-12-18 22:54:03 +01:00
a8e98740b3 Don't init global variables here 2022-12-18 22:53:50 +01:00
df722f8ffb Init some global variables 2022-12-18 22:53:31 +01:00
cfa6a55d39 Fix rate limit 2022-12-18 22:53:23 +01:00
9 changed files with 42 additions and 30 deletions

View file

@ -9,7 +9,6 @@ export default {
category: 'admin', category: 'admin',
async execute(interaction, args, client) { async execute(interaction, args, client) {
const autoresponseStat = await db.autoresponseStat.findOne({ where: { serverID: interaction.guild.id } }); const autoresponseStat = await db.autoresponseStat.findOne({ where: { serverID: interaction.guild.id } });
console.log(autoresponseStat);
if (!autoresponseStat) { if (!autoresponseStat) {
const body = { serverID: interaction.guild.id, stat: 'enable' }; const body = { serverID: interaction.guild.id, stat: 'enable' };
await db.autoresponseStat.create(body); await db.autoresponseStat.create(body);

View file

@ -1,5 +1,4 @@
import { SlashCommandBuilder } from 'discord.js'; import { SlashCommandBuilder, EmbedBuilder } from 'discord.js';
import { EmbedBuilder } from 'discord.js';
import fetch from 'node-fetch'; import fetch from 'node-fetch';
export default { export default {

View file

@ -29,7 +29,8 @@ export default {
async execute(interaction, args, client) { async execute(interaction, args, client) {
const content = args.content; const content = args.content;
const attachment = args.image; const attachment = args.image;
console.log(args);
console.log(attachment);
if (!content && !attachment) { if (!content && !attachment) {
return interaction.reply({ content: 'Uh oh! You are missing any content for me to tweet!', ephemeral: true }); return interaction.reply({ content: 'Uh oh! You are missing any content for me to tweet!', ephemeral: true });
} }

View file

@ -18,6 +18,7 @@ export default {
.setDescription('Optional attachment.') .setDescription('Optional attachment.')
.setRequired(false)), .setRequired(false)),
category: 'owner', category: 'owner',
ownerOnly: true,
async execute(interaction, args, client) { async execute(interaction, args, client) {
/* Too lazy to implement that now (Watch it rest untouched for months) /* Too lazy to implement that now (Watch it rest untouched for months)
async function uuidv4() { async function uuidv4() {

View file

@ -1,12 +1,12 @@
import { PermissionFlagsBits, InteractionType } from 'discord.js'; import { PermissionFlagsBits, InteractionType } from 'discord.js';
import db from '../../models/index.js'; import db from '../../models/index.js';
const ratelimit = {};
const { ownerId } = process.env; const { ownerId } = process.env;
export default { export default {
name: 'interactionCreate', name: 'interactionCreate',
async execute(interaction) { async execute(interaction) {
const ratelimit = global.ratelimit;
const client = interaction.client; const client = interaction.client;
if (interaction.type !== InteractionType.ApplicationCommand) return; if (interaction.type !== InteractionType.ApplicationCommand) return;
@ -52,26 +52,31 @@ export default {
*/ */
try { try {
if (!ratelimit[userID]) {
ratelimit[userID] = {};
}
const date = new Date(); const date = new Date();
if (ratelimit[userID]) { if (ratelimit[userID][commandName]) {
if (ratelimit[userID].cooldown) { if (ratelimit[userID][commandName].cooldown) {
if (commandName === ratelimit[userID].command && date > ratelimit[userID].cooldown) { if (date > ratelimit[userID][commandName].cooldown) {
ratelimit[userID].limit = 0; ratelimit[userID][commandName].limit = 0;
ratelimit[userID].cooldown = undefined; ratelimit[userID][commandName].cooldown = undefined;
} }
} }
if (commandName === ratelimit[userID].command && command.ratelimit === ratelimit[userID].limit) { if (command.ratelimit === ratelimit[userID][commandName].limit) {
return await interaction.reply({ content: `You are being rate limited. You can try again in ${Math.floor((ratelimit[userID].cooldown - date) / 1000)} seconds.`, ephemeral: true }); return await interaction.reply({ content: `You are being rate limited. You can try again in ${Math.floor((ratelimit[userID][commandName].cooldown - date) / 1000)} seconds.`, ephemeral: true });
} }
} }
if (command.ratelimit) { if (command.ratelimit) {
ratelimit[userID] = { command: commandName, limit: ratelimit[userID] ? ratelimit[userID].limit + 1 : 1 }; ratelimit[userID][commandName] = { limit: ratelimit[userID][commandName] ? ratelimit[userID][commandName].limit + 1 : 1 };
if (command.ratelimit === ratelimit[userID].limit) { if (command.ratelimit === ratelimit[userID][commandName].limit) {
date.setSeconds(date.getSeconds() + command.cooldown); date.setSeconds(date.getSeconds() + command.cooldown);
ratelimit[userID] = { command: commandName, limit: ratelimit[userID].limit, cooldown: date }; ratelimit[userID][commandName] = { limit: ratelimit[userID][commandName].limit, cooldown: date };
} }
} }

View file

@ -5,7 +5,6 @@
import { ApplicationCommandOptionType, EmbedBuilder, PermissionFlagsBits } from 'discord.js'; import { ApplicationCommandOptionType, EmbedBuilder, PermissionFlagsBits } from 'discord.js';
import db from '../../models/index.js'; import db from '../../models/index.js';
import { rand } from '../../utils/rand.js'; import { rand } from '../../utils/rand.js';
const ratelimit = {};
const { ownerId, prefix } = process.env; const { ownerId, prefix } = process.env;
const prefixs = prefix.split(','); const prefixs = prefix.split(',');
@ -313,26 +312,32 @@ export default {
} }
try { try {
const ratelimit = global.ratelimit;
if (!ratelimit[userID]) {
ratelimit[userID] = {};
}
const date = new Date(); const date = new Date();
if (ratelimit[userID]) { if (ratelimit[userID][commandName]) {
if (ratelimit[userID].cooldown) { if (ratelimit[userID][commandName].cooldown) {
if (commandName === ratelimit[userID].command && date > ratelimit[userID].cooldown) { if (date > ratelimit[userID][commandName].cooldown) {
ratelimit[userID].limit = 0; ratelimit[userID][commandName].limit = 0;
ratelimit[userID].cooldown = undefined; ratelimit[userID][commandName].cooldown = undefined;
} }
} }
if (commandName === ratelimit[userID].command && command.ratelimit === ratelimit[userID].limit) { if (command.ratelimit === ratelimit[userID][commandName].limit) {
return await message.reply({ content: `You are being rate limited. You can try again in ${Math.floor((ratelimit[userID].cooldown - date) / 1000)} seconds.`, ephemeral: true }); return await message.reply({ content: `You are being rate limited. You can try again in ${Math.floor((ratelimit[userID][commandName].cooldown - date) / 1000)} seconds.`, ephemeral: true });
} }
} }
if (command.ratelimit) { if (command.ratelimit) {
ratelimit[userID] = { command: commandName, limit: ratelimit[userID] ? ratelimit[userID].limit + 1 : 1 }; ratelimit[userID][commandName] = { limit: ratelimit[userID][commandName] ? ratelimit[userID][commandName].limit + 1 : 1 };
if (command.ratelimit === ratelimit[userID].limit) { if (command.ratelimit === ratelimit[userID][commandName].limit) {
date.setSeconds(date.getSeconds() + command.cooldown); date.setSeconds(date.getSeconds() + command.cooldown);
ratelimit[userID] = { command: commandName, limit: ratelimit[userID].limit, cooldown: date }; ratelimit[userID][commandName] = { limit: ratelimit[userID][commandName].limit, cooldown: date };
} }
} }
message.user = message.author; message.user = message.author;

View file

@ -1,7 +1,6 @@
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder } from 'discord.js';
import fs from 'node:fs'; import fs from 'node:fs';
import db from '../../models/index.js'; import db from '../../models/index.js';
global.boards = {};
export default { export default {
name: 'messageReactionAdd', name: 'messageReactionAdd',

View file

@ -1,7 +1,6 @@
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder } from 'discord.js';
import fs from 'node:fs'; import fs from 'node:fs';
import db from '../../models/index.js'; import db from '../../models/index.js';
global.boards = {};
export default { export default {
name: 'messageReactionRemove', name: 'messageReactionRemove',

View file

@ -5,6 +5,10 @@ export default {
name: 'ready', name: 'ready',
once: true, once: true,
async execute(client) { async execute(client) {
// Init global variables.
global.ratelimit = {};
global.boards = {};
const ytdlpVersion = await new Promise((resolve, reject) => { const ytdlpVersion = await new Promise((resolve, reject) => {
exec('./bin/yt-dlp --version', (err, stdout, stderr) => { exec('./bin/yt-dlp --version', (err, stdout, stderr) => {
if (err) { if (err) {