master
Kit Kasune 4 years ago
parent 6d98489038
commit 6d4ad7d03e
  1. 43
      commands/ar.js
  2. 10
      models/ar.js
  3. 21
      package-lock.json
  4. 1
      package.json
  5. 1
      util/pagination.d.ts
  6. 5
      util/pagination.js
  7. 5
      util/ts/pagination.ts

@ -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 <add|edit|delete|settings>`")
.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}<add|edit|delete|settings|list>\``);}
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);}
}
}
};

@ -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);

21
package-lock.json generated

@ -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",

@ -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"
},

@ -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<Pagination>;
nextPage(): Promise<Pagination>;

@ -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;
}
;

@ -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;
};

Loading…
Cancel
Save