mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-12 08:14:47 +02:00
Tags
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Tag = require('../../models/Tag');
|
||||
|
||||
module.exports = class TagAddCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'tag-add',
|
||||
aliases: ['add-tag'],
|
||||
group: 'tags',
|
||||
memberName: 'add',
|
||||
description: 'Adds a tag for this server.',
|
||||
guildOnly: true,
|
||||
args: [
|
||||
{
|
||||
key: 'id',
|
||||
prompt: 'What should the ID of the tag be?',
|
||||
type: 'string',
|
||||
max: 50,
|
||||
parse: id => id.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'text',
|
||||
prompt: 'What should the content of the tag be?',
|
||||
type: 'string',
|
||||
max: 1000
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { id, text }) {
|
||||
const tag = await Tag.findOne({ where: { id, guildID: msg.guild.id } });
|
||||
if (tag) return msg.reply(`A tag with the ID **${id}** already exists.`);
|
||||
await Tag.create({
|
||||
userID: msg.author.id,
|
||||
guildID: msg.guild.id,
|
||||
id,
|
||||
text
|
||||
});
|
||||
return msg.reply(`Added the tag **${id}**.`);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Tag = require('../../models/Tag');
|
||||
|
||||
module.exports = class TagEditCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'tag-edit',
|
||||
aliases: ['edit-tag'],
|
||||
group: 'tags',
|
||||
memberName: 'edit',
|
||||
description: 'Edits a tag in this server.',
|
||||
guildOnly: true,
|
||||
args: [
|
||||
{
|
||||
key: 'id',
|
||||
prompt: 'What is the ID of the tag you want to edit?',
|
||||
type: 'string',
|
||||
max: 50,
|
||||
parse: id => id.toLowerCase()
|
||||
},
|
||||
{
|
||||
key: 'text',
|
||||
prompt: 'What should the new content of the tag be?',
|
||||
type: 'string',
|
||||
max: 1000
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { id, text }) {
|
||||
const tag = await Tag.findOne({ where: { id, guildID: msg.guild.id } });
|
||||
if (!tag) return msg.reply(`A tag with the ID **${id}** doesn\'t exist.`);
|
||||
if (!msg.channel.permissionsFor(msg.author).has('MANAGE_MESSAGES') && tag.userID !== msg.author.id) {
|
||||
return msg.reply('You can only edit your own tags.');
|
||||
}
|
||||
await Tag.update({ text }, { where: { id, guild: msg.guild.id } });
|
||||
return msg.reply(`Edited the tag **${id}**.`);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const Tag = require('../../models/Tag');
|
||||
|
||||
module.exports = class TagInfoCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'tag-info',
|
||||
group: 'tags',
|
||||
memberName: 'info',
|
||||
description: 'Responds with detailed information on a tag in this server.',
|
||||
guildOnly: true,
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'id',
|
||||
prompt: 'What is the ID of the tag you want to get information on?',
|
||||
type: 'string',
|
||||
max: 50,
|
||||
parse: id => id.toLowerCase()
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { id }) {
|
||||
const tag = await Tag.findOne({ where: { id, guildID: msg.guild.id } });
|
||||
if (!tag) return msg.reply(`A tag with the ID **${id}** doesn\'t exist.`);
|
||||
let author;
|
||||
try {
|
||||
const authorUser = await this.client.users.fetch(tag.userID);
|
||||
author = authorUser.tag;
|
||||
} catch (err) {
|
||||
author = '???';
|
||||
}
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x00AE86)
|
||||
.setThumbnail(msg.guild.iconURL())
|
||||
.addField('❯ ID', tag.id, true)
|
||||
.addField('❯ Author', author, true)
|
||||
.addField('❯ Created On', new Date(tag.createdAt).toDateString(), true)
|
||||
.addField('❯ Modified On', new Date(tag.updatedAt).toDateString(), true);
|
||||
return msg.embed(embed);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Tag = require('../../models/Tag');
|
||||
|
||||
module.exports = class TagRemoveCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'tag-remove',
|
||||
aliases: ['tag-delete', 'remove-tag', 'delete-tag'],
|
||||
group: 'tags',
|
||||
memberName: 'remove',
|
||||
description: 'Removes a tag for this server.',
|
||||
guildOnly: true,
|
||||
args: [
|
||||
{
|
||||
key: 'id',
|
||||
prompt: 'What is the ID of the tag you want to remove?',
|
||||
type: 'string',
|
||||
max: 50,
|
||||
parse: id => id.toLowerCase()
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { id }) {
|
||||
const tag = await Tag.findOne({ where: { id, guildID: msg.guild.id } });
|
||||
if (!tag) return msg.reply(`A tag with the ID **${id}** doesn\'t exist.`);
|
||||
if (!msg.channel.permissionsFor(msg.author).has('MANAGE_MESSAGES') && tag.userID !== msg.author.id) {
|
||||
return msg.reply('You can only delete your own tags.');
|
||||
}
|
||||
await tag.destroy();
|
||||
return msg.reply(`Removed the tag **${id}**.`);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Tag = require('../../models/Tag');
|
||||
|
||||
module.exports = class TagSourceCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'tag-source',
|
||||
group: 'tags',
|
||||
memberName: 'source',
|
||||
description: 'Responds with the base markdown of a tag in this server.',
|
||||
guildOnly: true,
|
||||
args: [
|
||||
{
|
||||
key: 'id',
|
||||
prompt: 'What is the ID of the tag you want view the source of?',
|
||||
type: 'string',
|
||||
max: 50,
|
||||
parse: id => id.toLowerCase()
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { id }) {
|
||||
const tag = await Tag.findOne({ where: { id, guildID: msg.guild.id } });
|
||||
if (!tag) return msg.reply(`A tag with the ID **${id}** doesn\'t exist.`);
|
||||
return msg.code('md', tag.text);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const Tag = require('../../models/Tag');
|
||||
|
||||
module.exports = class TagCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'tag',
|
||||
group: 'tags',
|
||||
memberName: 'tag',
|
||||
description: 'Responds with a tag in this server.',
|
||||
guildOnly: true,
|
||||
args: [
|
||||
{
|
||||
key: 'id',
|
||||
prompt: 'What is the ID of the tag you want view?',
|
||||
type: 'string',
|
||||
max: 50,
|
||||
parse: id => id.toLowerCase()
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { id }) {
|
||||
const tag = await Tag.findOne({ where: { id, guildID: msg.guild.id } });
|
||||
if (!tag) return msg.reply(`A tag with the ID **${id}** doesn\'t exist.`);
|
||||
return msg.say(tag.text);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user