Add tags command

This commit is contained in:
Wessel T
2019-02-19 21:03:23 +01:00
parent f617e7e947
commit 66b6c92c98
14 changed files with 266 additions and 121 deletions

View File

@@ -7,7 +7,7 @@
# follow the licensing. - Wessel #
#-------------[ Configurable values ]-------------#
# db - <String>: The db URI (Mongo) #
# debug - <Number[0-3]>: The logging level #
# debug - <Number[0-3]>: The logging leven #
# nightly - <Boolean>: Run inside of dev mode #
# discord: #
# enabled - <Boolean>: Enable/disable client #
@@ -72,6 +72,12 @@ discord :
birb : true
lizard : true
penguin : true
# Category : TAGS
tag : true
tags : true
tag-add : true
tag-del : true
tag-source : true
# Category : GAMES
splatoon : true
# Category : DEVELOPER

View File

@@ -24,6 +24,8 @@ info :
multi : 0x34363C # Dark
single: 0x34363C # Dark
tags: 0x7289DA # Blurple
image :
cat : 0x7289DA # Blurple
dog : 0x7289DA # Blurple

View File

@@ -51,6 +51,11 @@ tags:
3: <:wumpus_love:506200781549076482>
4: <:wumpus_love:506200781549076482>
5: <:wumpus_love:506200781549076482>
list:
0 : <:wumpus_blob:541629681120837648>
1 : <:ok_hand:497396122416054287>
2 : <:wumpus_love:506200781549076482>
logs :
ready: '<:spacewump:542723940997529641>'

View File

@@ -164,6 +164,14 @@ tags:
source: '$[emoji#1] **Here''s the source to `$[tag:name]`**: ```$[tag:content]```'
all:
none: '$[emoji#0] There are no tags yet, type `$[tag:cmd]` to create one!'
list:
- '$[emoji#1] All available tags in **$[guild:name]**:'
- ''
- '$[tag:list]'
extend: '$[emoji#2] [Click here for a list of all tags]($[tag:full])'
add:
success: '$[emoji#1] Your tag (`$[tag:name]`) has been created'
invalid: '$[emoji#2] You''ve provided an invalid name for your tag (*It may already exist or it''s the name/alias of a command*)'

View File

@@ -163,7 +163,15 @@ tags:
exec: '$[emoji#0] Geen etiketten gevonden met uw zoekopdracht'
source: '$[emoji#1] **Hier is de bron voor `$[tag:name]`**: ```$[tag:content]```'
all:
none: '$[emoji#0] Er zijn nog geen etiketten, typ `$[tag:cmd]` om er een aan te maken!'
list:
- '$[emoji#1] Alle toegangbare etiketten in **$[guild:name]**:'
- ''
- '$[tag:list]'
extend: '$[emoji#2] [klik hier voor een list met al de etiketten]($[tag:full])'
add:
success: '$[emoji#1] Uw etiket (`$[tag:name]`) is aangemaakt'
invalid: '$[emoji#2] U hebt een ongeldige naam opgegeven voor uw etiket (*deze kan al bestaan of is de naam/alias van een commando*)'

View File

@@ -6,7 +6,7 @@ module.exports = class TagAdd extends DiscordCommand {
constructor(bot) {
super(bot, {
name : 'tag-add',
syntax : 'tag-add <...name:str> <..content:string>',
syntax : 'tag-add <...name:str> | <..content:string>',
aliases : [ 'tagadd', 'addtag', 'createtag', 'tagcreate', 'maketag', 'make-tag', 'tag-create' ],
argument : [ '<...name:str>', '<..content:string>' ],
description : 'Create a tag',

View File

@@ -35,7 +35,7 @@ module.exports = class TagDel extends DiscordCommand {
const res = await this.bot.collector.awaitMessage(msg.channel.id, msg.author.id, 30e3);
if (res && res.content.toLowerCase() === 'y' || res.content.toLowerCase() === 'ye' || res.content.toLowerCase() === 'yes') {
mess.edit(this._localize(msg.author.locale.tags.delete.busy, { name: tag.name.replace(/`/g, '`\u200b') }));
if (mess) mess.edit(this._localize(msg.author.locale.tags.delete.busy, { name: tag.name.replace(/`/g, '`\u200b') }));
this.bot.m.connection.collection('dTags').deleteOne({ name: tag.name, 'author.guild': msg.channel.guild.id });
if (mess) {
mess.delete().catch(() => { return; });
@@ -43,7 +43,9 @@ module.exports = class TagDel extends DiscordCommand {
msg.channel.createMessage(this._localize(msg.author.locale.tags.delete.done, { name: tag.name.replace(/`/g, '`\u200b') }));
} else {
return mess.edit(this._localize(msg.author.locale.cancelled));
if (mess) {
return mess.edit(this._localize(msg.author.locale.cancelled));
}
}
}

View File

@@ -17,6 +17,10 @@ module.exports = class Tag extends DiscordCommand {
guildOnly : true,
permissions : []
});
this.mutable = {
MAX_INT32: 2147483647
};
}
async execute(msg, args) {
@@ -26,6 +30,7 @@ module.exports = class Tag extends DiscordCommand {
}
msg.channel.createMessage(tag.content);
this.bot.m.connection.collection('dTags').findOneAndUpdate({ name: tag.name, 'author.guild': msg.channel.guild.id }, { $set: { uses: tag.uses < this.mutable.MAX_INT32 ? +1 : this.mutable.MAX_INT32 } });
}
_localize(msg) {

View File

@@ -0,0 +1,106 @@
const { DiscordCommand } = require('../../../core');
const w = require('wumpfetch');
const { table } = require('table');
module.exports = class Tags extends DiscordCommand {
constructor(bot) {
super(bot, {
name : 'tags',
syntax : 'tags',
aliases : [],
argument : [],
description : 'A list of all tags',
hidden : false,
enabled : true,
cooldown : 2500,
category : 'Tags',
ownerOnly : false,
guildOnly : true,
permissions : []
});
this.mutable = {
LIMIT: 35,
BASE_URL: 'https://hastebin.com',
TABLE_CONFIG: {
border: {
topBody: `-`,
topJoin: `+`,
topLeft: `+`,
topRight: `+`,
bottomBody: `-`,
bottomJoin: `+`,
bottomLeft: `+`,
bottomRight: `+`,
bodyLeft: `|`,
bodyRight: `|`,
bodyJoin: `|`,
joinBody: `-`,
joinLeft: `+`,
joinRight: `+`,
joinJoin: `+`
},
drawHorizontalLine: (_, s) => {
return _ === 0 || _ === 1 || _ === s;
}
}
};
}
async execute(msg) {
let data = [ [ 'Tag', 'Author', 'Used' ] ];
const tags = await this.bot.schema.tag.find({ 'author.guild': msg.channel.guild.id }).sort({ used: -1 });
if (!tags || tags === null || tags.length <= 0) {
return msg.channel.createMessage(this._localize(msg.author.locale.tags.all.none, { prefix: msg.prefix }));
}
const extData = {
tags: Array.list(tags.map((v) => `${v.name.replace(/\*/g, '*\u200b').replace(/`/g, '*\u200b')} (\`${v.uses}\`)`).slice(0, this.mutable.LIMIT), '**,** ', '**and** '),
guild: msg.channel.guild.name
};
if (tags.length > this.mutable.LIMIT) {
tags.map((v) => data.push([ v.name, `${v.author.name}#${v.author.discrim}`, v.uses ]));
let res = await w(`${this.mutable.BASE_URL}/documents`, { method: 'POST', data: table(data, this.mutable.TABLE_CONFIG) }).send();
res = res.json();
extData.tags += `\n${this._localize(msg.author.locale.tags.all.extend, { extend: `${this.mutable.BASE_URL}/raw/${res.key}.txt` })}`;
}
msg.channel.createMessage({
embed: {
color: this.bot.col['tags'],
description: this._localize(msg.author.locale.tags.all.list.join('\n'), extData)
}
});
}
_localize(msg, extData) {
if (extData) {
if (extData.guild) {
msg = msg.replace(/\$\[guild:name]/g, extData.guild);
}
if (extData.tags) {
msg = msg.replace(/\$\[tag:list]/g, extData.tags);
}
if (extData.extend) {
msg = msg.replace(/\$\[tag:full]/g, extData.extend);
}
if (extData.prefix) {
msg = msg.replace(/\$\[tag:cmd]/g, `${extData.prefix}${this.bot.cmds.get('tag-add').extData.syntax}`);
}
}
return msg
.replace(/\$\[emoji#0]/g, this.bot.emote('tags', 'list', '0'))
.replace(/\$\[emoji#1]/g, this.bot.emote('tags', 'list', '1'))
.replace(/\$\[emoji#2]/g, this.bot.emote('tags', 'list', '2'));
}
};

View File

@@ -34,7 +34,7 @@ module.exports = class CommandRegistry {
if (categories[i].endsWith('md')) return;
readdir(`${directory}/${categories[i]}`, (err, cmds) => {
if (err) process.handleError(err, 'LoadError', cyan('Discord'));
this.bot.print(1, `${cyan('Discord')} >> Loading ${green(cmds.length)} commands from category ${yellow(categories[i])}` );
this.bot.print(2, `${cyan('Discord')} >> Loading ${green(cmds.length)} commands from category ${yellow(categories[i])}` );
cmds.forEach((cmd) => {
try {

View File

@@ -12,26 +12,21 @@ module.exports = class WumpUtil {
fs.mkdir('tmp', 777, (err) => { if (err && err.code !== 'EEXIST') throw err; });
fs.mkdir('tmp/log', 777, (err) => { if (err && err.code !== 'EEXIST') throw err; });
switch (lvl) {
case 1 && conf['debug'] && conf['debug'] >= 1:
console.log(`[${moment(new Date).format( 'HH[:]mm[:]ss' )} / ${process.hash}] ${msg}`);
fs.appendFileSync(log, `[${moment(new Date).format('HH[:]mm[:]ss')} / ${process.hash}] ${strip(msg)}\r\n`);
break;
case 2 && conf['debug'] && conf['debug'] >= 2:
console.log(`[${moment(new Date).format( 'HH[:]mm[:]ss' )} / ${process.hash}] ${msg}`);
fs.appendFileSync(log, `[${moment(new Date).format('HH[:]mm[:]ss')} / ${process.hash}] ${strip(msg)}\r\n`);
break;
case 3 && conf['debug'] && conf['debug'] >= 3:
console.log(`[${moment(new Date).format( 'HH[:]mm[:]ss' )} / ${process.hash}] ${msg}`);
fs.appendFileSync(log, `[${moment(new Date).format('HH[:]mm[:]ss')} / ${process.hash}] ${strip(msg)}\r\n`);
break;
case 4 && conf['debug'] && conf['debug'] >= 4:
console.log(`[${moment(new Date).format( 'HH[:]mm[:]ss' )} / ${process.hash}] ${msg}`);
fs.appendFileSync(log, `[${moment(new Date).format('HH[:]mm[:]ss')} / ${process.hash}] ${strip(msg)}\r\n`);
break;
default:
console.log(`[${moment(new Date).format( 'HH[:]mm[:]ss' )} / ${process.hash}] ${msg}`);
fs.appendFileSync(log, `[${moment(new Date).format('HH[:]mm[:]ss')} / ${process.hash}] ${strip(msg)}\r\n`);
if (lvl === 1 && conf.debug && conf.debug >= 1) {
console.log(`[${moment(new Date).format( 'HH[:]mm[:]ss' )} / ${process.hash}] ${msg}`);
fs.appendFileSync(log, `[${moment(new Date).format('HH[:]mm[:]ss')} / ${process.hash}] ${strip(msg)}\r\n`);
} else if (lvl === 2 && conf.debug && conf.debug >= 2) {
console.log(`[${moment(new Date).format( 'HH[:]mm[:]ss' )} / ${process.hash}] ${msg}`);
fs.appendFileSync(log, `[${moment(new Date).format('HH[:]mm[:]ss')} / ${process.hash}] ${strip(msg)}\r\n`);
} else if (lvl === 3 && conf.debug && conf.debug >= 3) {
console.log(`[${moment(new Date).format( 'HH[:]mm[:]ss' )} / ${process.hash}] ${msg}`);
fs.appendFileSync(log, `[${moment(new Date).format('HH[:]mm[:]ss')} / ${process.hash}] ${strip(msg)}\r\n`);
} else if (lvl === 4 && conf.debug && conf.debug >= 4) {
console.log(`[${moment(new Date).format( 'HH[:]mm[:]ss' )} / ${process.hash}] ${msg}`);
fs.appendFileSync(log, `[${moment(new Date).format('HH[:]mm[:]ss')} / ${process.hash}] ${strip(msg)}\r\n`);
} else if (lvl === 0) {
console.log(`[${moment(new Date).format( 'HH[:]mm[:]ss' )} / ${process.hash}] ${msg}`);
fs.appendFileSync(log, `[${moment(new Date).format('HH[:]mm[:]ss')} / ${process.hash}] ${strip(msg)}\r\n`);
}
}