paginate ars

master
Kit Kasune 3 years ago
parent 0886be1640
commit edb9082bc2
  1. 35
      .vscode/discordjs.code-snippets
  2. 51
      commands/misc/ar.js

@ -0,0 +1,35 @@
{
// Place your Natsuki workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
"discord.js bot command": {
"scope": "javascript,typescript",
"prefix": "djscmd",
"body": [
"const Discord = require('discord.js');${1:\nconst = require(\"\");\n}",
"module.exports = {",
" name: \"$2\",",
" aliases: [$3],",
" meta: {",
" category: '$4',",
" description: \"$5\",",
" syntax: '`$6`',",
" extra: ${7:null}${8:,\n guildOnly: true}",
" },",
" help: new Discord.MessageEmbed()",
" .setTitle(\"Help -> $9\")",
" .setDescription(\"$10\")${11:\n .addField(\"\", \"\")}",
" .addField(\"Syntax\", \"`$6`\"),",
" async execute(message, msg, args, cmd, prefix, mention, client) {",
" if (!args.length) {return message.channel.send(`Syntax: \\`\\${prefix}$6\\``);}",
" $0",
" }",
"};",
],
"description": "Creates a new command"
}
}

@ -4,6 +4,7 @@ const AR = require('../../models/ar');
const GuildData = require('../../models/guild'); const GuildData = require('../../models/guild');
const ask = require('../../util/ask'); const ask = require('../../util/ask');
const {Pagination} = require('../../util/pagination');
module.exports = { module.exports = {
name: "ar", name: "ar",
@ -27,19 +28,57 @@ module.exports = {
function sortARs(tar) { function sortARs(tar) {
let t = tar.triggers; let t = tar.triggers;
let res = {};
res.paginate = t.length > 10;
let ar = tar.ars; let ar = tar.ars;
if (res.paginate) {
let pages = [];
let cond = false;
let x = 0;
while (true) {
let s = '';
for (let i = 0; i < 10; i++) {
if (ar[(x * 10) + i] === undefined) {cond = true; break;}
s += `\`${(x*10)+i+1}.\` ${t[(x * 10) + i]}\n-> ${ar[(x * 10) + i]}\n\n`;
if ((x * 10) + i >= ar.length) {cond = true; break;}
}
pages.push(new Discord.MessageEmbed()
.setTitle(`Auto-Responses in this Server`)
.setDescription(s)
.setColor('c375f0')
.setTimestamp()
);
if (cond) {break;}
x++;
}
res.pagination = new Pagination(message.channel, pages, message, client, true);
} else {
let s = ''; let s = '';
for (let i=0;i<t.length;i++) {s+=`\`${i+1}.\` ${t[i]}\n-> ${ar[i]}\n\n`;} for (let i=0;i<t.length;i++) {s+=`\`${i+1}.\` ${t[i]}\n-> ${ar[i]}\n\n`;}
return s; res.s = s;
}
return res;
} }
function viewARs(string) { function viewARs(res, mode) {
return new Discord.MessageEmbed() return new Promise(async resolve => {
if (res.paginate) {
if (mode) {res.pagination.pages.forEach(page => page.addField(mode === 'edit' ? "Editing" : 'Deletion', `Please say the **number** of the AR you wish to ${mode}.`));}
let r = await res.pagination.start({endTime: 60000, user: message.author.id});
return resolve(r);
} else {
let string = res.s;
let embed = new Discord.MessageEmbed()
.setTitle("Auto-Responses in this Server") .setTitle("Auto-Responses in this Server")
.setDescription(string) .setDescription(string)
.setColor('c375f0') .setColor('c375f0')
.setFooter("Natsuki", client.user.avatarURL()) .setFooter("Natsuki", client.user.avatarURL())
.setTimestamp(); .setTimestamp();
if (mode) {embed.addField(mode === 'edit' ? "Editing" : 'Deletion', `Please say the **number** of the AR you wish to ${mode}.`);}
let r = await message.channel.send({embeds: [embed]});
return resolve(r);
}
});
} }
if (['a', 'add'].includes(args[0].toLowerCase())) { if (['a', 'add'].includes(args[0].toLowerCase())) {
@ -64,7 +103,7 @@ module.exports = {
if (!tar || !tar.triggers.length) {return message.channel.send("You can't edit any auto-responses... because there aren't any here...");} if (!tar || !tar.triggers.length) {return message.channel.send("You can't edit any auto-responses... because there aren't any here...");}
let sar = sortARs(tar); let sar = sortARs(tar);
await message.channel.send({embeds: [viewARs(sar).addField("Editing", "Please say the **number** of the AR you wish to edit.")]}); await viewARs(sar, 'edit');
let collected; let collected;
try {collected = await message.channel.awaitMessages({filter: m => m.author.id === message.author.id, errors: ['time'], time: 60001, max: 1});} try {collected = await message.channel.awaitMessages({filter: m => m.author.id === message.author.id, errors: ['time'], time: 60001, max: 1});}
catch {return message.channel.send("This question has timed out. Please try again!");} catch {return message.channel.send("This question has timed out. Please try again!");}
@ -89,7 +128,7 @@ module.exports = {
if (!tar || !tar.triggers.length) {return message.channel.send("It's not like this server has any ARs for me to delete in the first place!");} if (!tar || !tar.triggers.length) {return message.channel.send("It's not like this server has any ARs for me to delete in the first place!");}
let sar = sortARs(tar); let sar = sortARs(tar);
await message.channel.send({embeds: [viewARs(sar).addField("Deletion", "Please say the **number** of the AR you wish to delete.")]}); await viewARs(sar, 'delete');
let collected; let collected;
try {collected = await message.channel.awaitMessages({filter: m => m.author.id === message.author.id, errors: ['time'], time: 60000, max: 1});} try {collected = await message.channel.awaitMessages({filter: m => m.author.id === message.author.id, errors: ['time'], time: 60000, max: 1});}
catch {return message.channel.send("This question has timed out. Please try again!");} catch {return message.channel.send("This question has timed out. Please try again!");}
@ -113,7 +152,7 @@ module.exports = {
if (['v', 'view', 'l', 'list'].includes(args[0].toLowerCase())) { if (['v', 'view', 'l', 'list'].includes(args[0].toLowerCase())) {
let tar = await AR.findOne({gid: message.guild.id}); let tar = await AR.findOne({gid: message.guild.id});
if (!tar || !tar.triggers.length) {return message.channel.send("This server has no ARs!");} if (!tar || !tar.triggers.length) {return message.channel.send("This server has no ARs!");}
return message.channel.send({embeds: [viewARs(sortARs(tar))]}); return viewARs(sortARs(tar));
} }
if (['s', 'settings'].includes(args[0].toLowerCase())) { if (['s', 'settings'].includes(args[0].toLowerCase())) {

Loading…
Cancel
Save