From 6d4ad7d03e020393f801e942fbaa7771080557bd Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 15 Jan 2021 22:20:08 -0700 Subject: [PATCH] sync --- commands/ar.js | 43 +++++++++++++++++++++++++++++++++++++++++++ models/ar.js | 10 ++++++++++ package-lock.json | 21 ++++++++++++++------- package.json | 1 + util/pagination.d.ts | 1 + util/pagination.js | 5 +++-- util/ts/pagination.ts | 5 ++++- 7 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 commands/ar.js create mode 100644 models/ar.js diff --git a/commands/ar.js b/commands/ar.js new file mode 100644 index 0000000..f324b05 --- /dev/null +++ b/commands/ar.js @@ -0,0 +1,43 @@ +const Discord = require('discord.js'); + +const AR = require('../models/ar'); +const GuildData = require('../models/guild'); + +const ask = require('../util/ask'); + +module.exports = { + name: "ar", + aliases: ['autoresponse', 'autoresponses'], + meta: { + category: "", + perms: "", + staff: false, + vip: "", + serverPerms: [], + writtenBy: "", + serverOnly: true + }, + tags: [], + help: new Discord.MessageEmbed() + .setTitle("Help -> Auto Responses") + .setDescription("Create and edit automatic responses, which lets the bot say stuff when you say something in your server!") + .addField("Syntax", "`ar `") + .addField("Notice", "This command is server-only, and requires you to be an administrator or have the staff role."), + async execute(message, msg, args, cmd, prefix, mention, client) { + if (!message.guild) {return message.channel.send("You must be in a server in order to use this command.");} + if (!args.length) {return message.channel.send(`Syntax: \`${prefix}\``);} + const tg = await GuildData.findOne({gid: message.guild.id}); + if (['a', 'add', 'e', 'edit', 'delete', 'd'].includes(args[0].toLowerCase()) && (!tg || !tg.staffrole || !tg.staffrole.length || (message.member.roles.cache.has(tg.staffrole) && message.member.permissions.has("ADMINISTRATOR")))) {return message.channel.send("You must have the staff role or be an administrator in this server in order to edit AR settings.");} + + if (['a', 'add'].includes(args[0].toLowerCase())) { + let trigger = await ask(message, "What would you like the trigger to be? This is the message that will make your AR work.", 120000); if (!trigger) {return null;} + if (`${trigger}`.length > 150) {return message.channel.send("Your trigger needs to be less than 150 characters, please!");} + let response = await ask(message, "What would you like my response to be?", 120000); if (!response) {return null;} + if (`${response}`.length > 300) {return message.channel.send("Your response needs to be less than 300 characters, please!");} + + let tar = await AR.findOne({gid: message.guild.id}) || new AR({gid: message.guild.id}); + let h = false; let ar; for (ar of tar.triggers) {if (ar.toLowerCase() === `${trigger}`.toLowerCase()) {h = true;}} + if (!h) {tar.triggers.push(trigger);} + } + } +}; \ No newline at end of file diff --git a/models/ar.js b/models/ar.js new file mode 100644 index 0000000..1380f7e --- /dev/null +++ b/models/ar.js @@ -0,0 +1,10 @@ +const mongoose = require('mongoose'); + +const AR = new mongoose.Schema({ + gid: {type: String, unique: true}, + ars: {type: Object, default: {}}, + triggers: {type: [String], default: []}, + ignoreChs: {type: [String], default: []} +}); + +module.exports = mongoose.model('ar', AR); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index fa35b8d..c2c83aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6117,6 +6117,17 @@ "cjopus": "^0.0.4", "tweetnacl": "^0.14.0", "ws": "^1.1.0" + }, + "dependencies": { + "ws": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/ws/-/ws-1.1.5.tgz", + "integrity": "sha512-o3KqipXNUdS7wpQzBHSe180lBGO60SoK0yVo3CYJgb2MkobuWuBX6dhkYP5ORCLd55y+SaflMOV5fqAB53ux4w==", + "requires": { + "options": ">=0.0.5", + "ultron": "1.0.x" + } + } } }, "discord.js": { @@ -9266,13 +9277,9 @@ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "ws": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/ws/-/ws-1.1.5.tgz", - "integrity": "sha512-o3KqipXNUdS7wpQzBHSe180lBGO60SoK0yVo3CYJgb2MkobuWuBX6dhkYP5ORCLd55y+SaflMOV5fqAB53ux4w==", - "requires": { - "options": ">=0.0.5", - "ultron": "1.0.x" - } + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.2.tgz", + "integrity": "sha512-T4tewALS3+qsrpGI/8dqNMLIVdq/g/85U98HPMa6F0m6xTbvhXU6RCQLqPH3+SlomNV/LdY6RXEbBpMH6EOJnA==" }, "xmlbuilder": { "version": "9.0.7", diff --git a/package.json b/package.json index 869f89d..61ed0bf 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "sqlite3": "^4.2.0", "swwrap": "^1.0.0", "winston": "^3.3.3", + "ws": "^7.4.2", "ytdl-core": "^3.2.2", "ytdl-core-discord": "^1.2.1" }, diff --git a/util/pagination.d.ts b/util/pagination.d.ts index 66739de..dc8d0ec 100644 --- a/util/pagination.d.ts +++ b/util/pagination.d.ts @@ -8,6 +8,7 @@ export declare class Pagination { client: Client; loopPages: boolean; controllers: ControllerData; + timeoutInterval: any; constructor(channel: TextChannel, pages: MessageEmbed[], originalMessage: Message, client: Client, loopPages?: boolean, message?: Message); setPage(page: number): Promise; nextPage(): Promise; diff --git a/util/pagination.js b/util/pagination.js index c05268d..154cc21 100644 --- a/util/pagination.js +++ b/util/pagination.js @@ -100,8 +100,8 @@ class Pagination { this.controllers.enabled = true; this.controllers.endTime = endTime; this.controllers.lastInteraction = new Date(); - setInterval(() => { - if (new Date().getTime() - this.controllers.lastInteraction.getTime() > this.controllers.endTime) { + this.timeoutInterval = setInterval(() => { + if (new Date().getTime() - this.controllers.lastInteraction.getTime() > this.controllers.endTime && this.controllers.enabled) { return this.endControllers(); } }, this.controllers.endTime); @@ -117,6 +117,7 @@ class Pagination { fe.setDescription(`${fe.description}\n\n*This menu has ended, start a new one to interact with it!*`); fe.setFooter(`${fe.footer.text} | Menu ended`, this.client.user.avatarURL()); await this.message.edit(fe); + clearInterval(this.timeoutInterval); return this; } ; diff --git a/util/ts/pagination.ts b/util/ts/pagination.ts index e4d8f24..ae786f6 100644 --- a/util/ts/pagination.ts +++ b/util/ts/pagination.ts @@ -9,6 +9,7 @@ export class Pagination { client: Client; loopPages: boolean = true; controllers: ControllerData = {enabled: false, endTime: null, collector: null, lastInteraction: null}; + timeoutInterval: any; @@ -111,7 +112,7 @@ export class Pagination { this.controllers.endTime = endTime; this.controllers.lastInteraction = new Date(); - setInterval(() => { + this.timeoutInterval = setInterval(() => { if (new Date().getTime() - this.controllers.lastInteraction.getTime() > this.controllers.endTime && this.controllers.enabled) {return this.endControllers();} }, this.controllers.endTime); @@ -129,6 +130,8 @@ export class Pagination { fe.setFooter(`${fe.footer.text} | Menu ended`, this.client.user.avatarURL()); await this.message.edit(fe); + clearInterval(this.timeoutInterval); + return this; };