forked from oldschoolgg/oldschoolbot
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tags, and ability to disable channel
- Loading branch information
Showing
12 changed files
with
2,391 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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.`); | |||
} | |||
} | |||
|
|||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,11 +1,60 @@ | |||
const { Command } = require('klasa'); | const { Command, util: { toTitleCase, codeBlock } } = require('klasa'); | ||
|
|
||
module.exports = class extends Command { | module.exports = class extends Command { | ||
|
|
||
constructor(...args) { | constructor(...args) { | ||
super(...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; | |||
} | } | ||
|
|
||
}; | }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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; | |||
} | |||
} | |||
|
|||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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; | |||
} | |||
} | |||
|
|||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
const { Client } = require('klasa'); | |||
|
|||
Client.defaultTextChannelSchema | |||
.add('onlyStaffCanUseCommands', 'boolean', { default: false }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,4 @@ | |||
require('./GuildSchema'); | require('./GuildSchema'); | ||
require('./UserSchema'); | require('./UserSchema'); | ||
require('./ClientSchema'); | require('./ClientSchema'); | ||
require('./TextChannelSchema'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.