Skip to content
Permalink
Browse files

add tags, and ability to disable channel

  • Loading branch information...
gc committed May 14, 2019
1 parent 6dfd020 commit b52e6ca033564b8429f86a272258c653e5a424d1
@@ -0,0 +1,24 @@
const { Command } = require('klasa');

module.exports = class extends Command {

constructor(...args) {
super(...args, {
runIn: ['text'],
permissionLevel: 6,
description: 'Disable the bot in a channel.',
usage: '<disable|enable>'
});
}

async run(msg, [input]) {
if (input === 'disable') {
await msg.channel.settings.update('onlyStaffCanUseCommands', true);
return msg.send(`Channel disabled. Staff can still use commands in this channel.`);
} else {
await msg.channel.settings.update('onlyStaffCanUseCommands', false);
return msg.send(`Channel enabled. Anyone can use commands in this channel now.`);
}
}

};
@@ -1,6 +1,5 @@
const { Command } = require('klasa');
const fetch = require('node-fetch');
const { MessageEmbed } = require('discord.js');

module.exports = class extends Command {

@@ -20,11 +19,7 @@ module.exports = class extends Command {
.then(res => res.text())
.then(async res => await this.cmlErrorCheck(msg, res) || parseInt(res.split(',')[1].split('.')[0]).toLocaleString());

const embed = new MessageEmbed()
.setColor(3120895)
.setDescription(`**${username}**'s Time to 200m All is **${time}** hours.`);

return msg.send({ embed });
return msg.sendLocale('TTM_RESULT', [username, time]);
}

};
@@ -1,11 +1,60 @@
const { Command } = require('klasa');
const { Command, util: { toTitleCase, codeBlock } } = require('klasa');

module.exports = class extends Command {

constructor(...args) {
super(...args, {
enabled: false
runIn: ['text'],
permissionLevel: 10,
guarded: true,
subcommands: true,
description: language => language.get('COMMAND_CONF_SERVER_DESCRIPTION'),
usage: '<set|show|remove|reset> (key:key) (value:value) [...]',
usageDelim: ' '
});

this
.createCustomResolver('key', (arg, possible, message, [action]) => {
if (action === 'show' || arg) return arg;
throw message.language.get('COMMAND_CONF_NOKEY');
})
.createCustomResolver('value', (arg, possible, message, [action]) => {
if (!['set', 'remove'].includes(action) || arg) return arg;
throw message.language.get('COMMAND_CONF_NOVALUE');
});
}

show(message, [key]) {
const path = this.client.gateways.guilds.getPath(key, { avoidUnconfigurable: true, errors: false, piece: null });
if (!path) return message.sendLocale('COMMAND_CONF_GET_NOEXT', [key]);
if (path.piece.type === 'Folder') {
return message.sendLocale('COMMAND_CONF_SERVER', [
key ? `: ${key.split('.').map(toTitleCase).join('/')}` : '',
codeBlock('asciidoc', message.guild.settings.list(message, path.piece))
]);
}
return message.sendLocale('COMMAND_CONF_GET', [path.piece.path, message.guild.settings.resolveString(message, path.piece)]);
}

async set(message, [key, ...valueToSet]) {
const status = await message.guild.settings.update(key, valueToSet.join(' '), message.guild, { avoidUnconfigurable: true, action: 'add' });
return this.check(message, key, status) || message.sendLocale('COMMAND_CONF_UPDATED', [key, message.guild.settings.resolveString(message, status.updated[0].piece)]);
}

async remove(message, [key, ...valueToRemove]) {
const status = await message.guild.settings.update(key, valueToRemove.join(' '), message.guild, { avoidUnconfigurable: true, action: 'remove' });
return this.check(message, key, status) || message.sendLocale('COMMAND_CONF_UPDATED', [key, message.guild.settings.resolveString(message, status.updated[0].piece)]);
}

async reset(message, [key]) {
const status = await message.guild.settings.reset(key, message.guild, true);
return this.check(message, key, status) || message.sendLocale('COMMAND_CONF_RESET', [key, message.guild.settings.resolveString(message, status.updated[0].piece)]);
}

check(message, key, { errors, updated }) {
if (errors.length) return message.sendMessage(String(errors[0]));
if (!updated.length) return message.sendLocale('COMMAND_CONF_NOCHANGE', [key]);
return null;
}

};
@@ -0,0 +1,68 @@
const { Util } = require('discord.js');
const { Command } = require('klasa');

class TagCommand extends Command {

constructor(client, store, file, directory) {
super(client, store, file, directory, {
description: 'Allows you to create, remove or show tags.',
runIn: ['text'],
subcommands: true,
usage: '<add|remove|source|list|show:default> (tag:string) [content:...string]',
usageDelim: ' '
});
this.createCustomResolver('string', (arg, possible, message, [action]) => {
if (action === 'list') { return arg; }
return this.client.arguments.get('string').run(arg, possible, message);
});
}

async add(message, [tag, content]) {
const isStaff = await message.hasAtLeastPermissionLevel(6);
if (!message.member || !isStaff) return;
if (!content || content.length === 0) {
return message.send('You must provide content for the tag.');
}
if (message.guild.settings.get('tags').some(_tag => _tag[0] === tag.toLowerCase())) {
return message.send('That tag already exists.');
}
await message.guild.settings.update('tags',
[...message.guild.settings.get('tags'),
[tag.toLowerCase(), content]],
{ action: 'overwrite' });
return message.send(`Added the tag \`${tag}\` with content: \`\`\`${Util.escapeMarkdown(content)}\`\`\``);
}

async remove(message, [tag]) {
const isStaff = await message.hasAtLeastPermissionLevel(6);
if (!message.member || !isStaff) return;
if (!message.guild.settings.get('tags').some(_tag => _tag[0] === tag.toLowerCase())) {
return message.send('That tag doesn\'t exist.');
}
const filtered = message.guild.settings.get('tags').filter(([name]) => name !== tag.toLowerCase());
await message.guild.settings.update('tags', filtered, { action: 'overwrite' });
return message.send(`Removed the tag \`${tag}\``);
}

list(message) {
return message.send(`Tags for this guild are: ${message.guild.settings.get('tags').map(([name]) => name).join(', ')}`);
}

show(message, [tag]) {
const emote = message.guild.settings.get('tags').find(([name]) => name === tag.toLowerCase());
if (!emote) {
return null;
}
return message.send(emote[1]);
}

source(message, [tag]) {
const emote = message.guild.settings.get('tags').find(([name]) => name === tag.toLowerCase());
if (!emote) {
return message.send('That emote doesn\'t exist.');
}
return message.send(`\`\`\`${Util.escapeMarkdown(emote[1])}\`\`\``);
}

}
exports.default = TagCommand;
@@ -5,6 +5,9 @@ const {
clientProperties
} = require('../config');

Client.use(require('@kcp/tags'));
Client.use(require('klasa-textchannel-gateway'));

require('../config/Schemas');

class OldSchoolBot extends Client {
@@ -0,0 +1,12 @@
const { Inhibitor } = require('klasa');

module.exports = class extends Inhibitor {

async run(msg) {
if (msg.channel.settings.get('onlyStaffCanUseCommands')) {
const hasPerm = await msg.hasAtLeastPermissionLevel(6);
if (!hasPerm) throw true;
}
}

};
@@ -0,0 +1,20 @@
const { Inhibitor } = require('klasa');

module.exports = class extends Inhibitor {

async run(message, command) {
const { broke, permission } = await this.client.permissionLevels
.run(message, command.permissionLevel);

if (!permission) {
const isStaff = await message.hasAtLeastPermissionLevel(6);
const channelDisabled = message.channel.settings.onlyStaffCanUseCommands;

if (!channelDisabled || (isStaff && channelDisabled)) {
throw broke ? message.language.get('INHIBITOR_PERMISSIONS') : true;
}
throw true;
}
}

};
@@ -2,6 +2,10 @@ const { PermissionLevels } = require('klasa');

module.exports = new PermissionLevels()
.add(0, () => true)
.add(6,
(message) => message.guild && message.member.permissions.has('BAN_MEMBERS'),
{ fetch: true }
)
.add(7,
(message) => message.guild && message.member.permissions.has('ADMINISTRATOR'),
{ fetch: true }
@@ -0,0 +1,4 @@
const { Client } = require('klasa');

Client.defaultTextChannelSchema
.add('onlyStaffCanUseCommands', 'boolean', { default: false });
@@ -1,3 +1,4 @@
require('./GuildSchema');
require('./UserSchema');
require('./ClientSchema');
require('./TextChannelSchema');
@@ -1,5 +1,7 @@
{
"dependencies": {
"klasa-textchannel-gateway": "github:gc/text-channel-gateway#master",
"@kcp/tags": "^1.0.0",
"bufferutil": "^4.0.1",
"canvas": "^2.4.1",
"canvas-constructor": "^1.1.2",
@@ -23,7 +25,7 @@
"zlib-sync": "^0.1.4"
},
"devDependencies": {
"eslint-config-klasa": "github:dirigeants/klasa-lint",
"eslint": "^5.0.1"
"eslint": "^5.0.1",
"eslint-config-klasa": "github:dirigeants/klasa-lint"
}
}
Oops, something went wrong.

0 comments on commit b52e6ca

Please sign in to comment.
You can’t perform that action at this time.