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',
async execute(interaction, args, client) {
const autoresponseStat = await db.autoresponseStat.findOne({ where: { serverID: interaction.guild.id } });
console.log(autoresponseStat);
if (!autoresponseStat) {
const body = { serverID: interaction.guild.id, stat: 'enable' };
await db.autoresponseStat.create(body);

View file

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

View file

@ -29,7 +29,8 @@ export default {
async execute(interaction, args, client) {
const content = args.content;
const attachment = args.image;
console.log(args);
console.log(attachment);
if (!content && !attachment) {
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.')
.setRequired(false)),
category: 'owner',
ownerOnly: true,
async execute(interaction, args, client) {
/* Too lazy to implement that now (Watch it rest untouched for months)
async function uuidv4() {

View file

@ -1,12 +1,12 @@
import { PermissionFlagsBits, InteractionType } from 'discord.js';
import db from '../../models/index.js';
const ratelimit = {};
const { ownerId } = process.env;
export default {
name: 'interactionCreate',
async execute(interaction) {
const ratelimit = global.ratelimit;
const client = interaction.client;
if (interaction.type !== InteractionType.ApplicationCommand) return;
@ -52,26 +52,31 @@ export default {
*/
try {
if (!ratelimit[userID]) {
ratelimit[userID] = {};
}
const date = new Date();
if (ratelimit[userID]) {
if (ratelimit[userID].cooldown) {
if (commandName === ratelimit[userID].command && date > ratelimit[userID].cooldown) {
ratelimit[userID].limit = 0;
ratelimit[userID].cooldown = undefined;
if (ratelimit[userID][commandName]) {
if (ratelimit[userID][commandName].cooldown) {
if (date > ratelimit[userID][commandName].cooldown) {
ratelimit[userID][commandName].limit = 0;
ratelimit[userID][commandName].cooldown = undefined;
}
}
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][commandName].cooldown - date) / 1000)} seconds.`, ephemeral: true });
}
}
if (commandName === ratelimit[userID].command && command.ratelimit === ratelimit[userID].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 });
}
}
if (command.ratelimit) {
ratelimit[userID] = { command: commandName, limit: ratelimit[userID] ? ratelimit[userID].limit + 1 : 1 };
if (command.ratelimit === ratelimit[userID].limit) {
ratelimit[userID][commandName] = { limit: ratelimit[userID][commandName] ? ratelimit[userID][commandName].limit + 1 : 1 };
if (command.ratelimit === ratelimit[userID][commandName].limit) {
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 db from '../../models/index.js';
import { rand } from '../../utils/rand.js';
const ratelimit = {};
const { ownerId, prefix } = process.env;
const prefixs = prefix.split(',');
@ -313,26 +312,32 @@ export default {
}
try {
const ratelimit = global.ratelimit;
if (!ratelimit[userID]) {
ratelimit[userID] = {};
}
const date = new Date();
if (ratelimit[userID]) {
if (ratelimit[userID].cooldown) {
if (commandName === ratelimit[userID].command && date > ratelimit[userID].cooldown) {
ratelimit[userID].limit = 0;
ratelimit[userID].cooldown = undefined;
if (ratelimit[userID][commandName]) {
if (ratelimit[userID][commandName].cooldown) {
if (date > ratelimit[userID][commandName].cooldown) {
ratelimit[userID][commandName].limit = 0;
ratelimit[userID][commandName].cooldown = undefined;
}
}
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][commandName].cooldown - date) / 1000)} seconds.`, ephemeral: true });
}
}
if (commandName === ratelimit[userID].command && command.ratelimit === ratelimit[userID].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 });
}
}
if (command.ratelimit) {
ratelimit[userID] = { command: commandName, limit: ratelimit[userID] ? ratelimit[userID].limit + 1 : 1 };
if (command.ratelimit === ratelimit[userID].limit) {
ratelimit[userID][commandName] = { limit: ratelimit[userID][commandName] ? ratelimit[userID][commandName].limit + 1 : 1 };
if (command.ratelimit === ratelimit[userID][commandName].limit) {
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;

View file

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

View file

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

View file

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