forked from Galactic/galactic-bot
Merge branch 'master' of https://github.com/Navy-gif/New-GBot
This commit is contained in:
commit
f9495094f3
@ -16,7 +16,7 @@ class LocaleLoader {
|
|||||||
template(locale, index) {
|
template(locale, index) {
|
||||||
|
|
||||||
// console.log(String.raw`${this.languages[locale][index]}`);
|
// console.log(String.raw`${this.languages[locale][index]}`);
|
||||||
return (this.languages[locale] ? this.languages[locale][index] : `Locale \`${locale}\` does not exist.`) || `Entry \`${locale}:${index}\` does not exist.`;
|
return (this.languages[locale] ? this.languages[locale][index] : `Locale \`${locale}\` does not exist.`) || `Language entry \`${locale}:${index}\` does not exist.`;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,9 @@ __**{component} HELP**__
|
|||||||
Shows information about the bot and component usage.
|
Shows information about the bot and component usage.
|
||||||
To show help for commands `{prefix}help [command]`
|
To show help for commands `{prefix}help [command]`
|
||||||
|
|
||||||
|
[C_HELP_404]
|
||||||
|
Dude stop, {component} doesn't exist!
|
||||||
|
|
||||||
//Guild command
|
//Guild command
|
||||||
|
|
||||||
[C_GUILD_DESCRIPTION]
|
[C_GUILD_DESCRIPTION]
|
||||||
|
@ -87,6 +87,10 @@ class DiscordClient extends Client {
|
|||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get prefix() {
|
||||||
|
return this._options.prefix;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = DiscordClient;
|
module.exports = DiscordClient;
|
||||||
|
@ -15,12 +15,12 @@ class Resolver {
|
|||||||
* @returns
|
* @returns
|
||||||
* @memberof Resolver
|
* @memberof Resolver
|
||||||
*/
|
*/
|
||||||
components(str = '', type, exact = true) {
|
components(str = '', type = 'any', exact = true) {
|
||||||
|
|
||||||
const string = str.toLowerCase();
|
const string = str.toLowerCase();
|
||||||
|
|
||||||
const components = this.client.registry.components
|
const components = this.client.registry.components
|
||||||
.filter((c) => c.type === type)
|
.filter((c) => type === 'any' ? ['command', 'setting'].includes(c.type) : c.type === type)
|
||||||
.filter(exact ? filterExact(string) : filterInexact(string)) //eslint-disable-line no-use-before-define
|
.filter(exact ? filterExact(string) : filterInexact(string)) //eslint-disable-line no-use-before-define
|
||||||
.array();
|
.array();
|
||||||
|
|
||||||
@ -28,6 +28,19 @@ class Resolver {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentsByTag(str, type, exact = true) {
|
||||||
|
|
||||||
|
const key = str.toLowerCase();
|
||||||
|
|
||||||
|
const components = this.client.registry.components
|
||||||
|
.filter((c) => c.type === type)
|
||||||
|
.filter(exact ? (c) => c.tags.includes(key) : filterInexactTags(key))
|
||||||
|
.array();
|
||||||
|
|
||||||
|
return components || [];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
timeAgo(diff, extraMin = false, extraHours = false, extraDays = false) {
|
timeAgo(diff, extraMin = false, extraHours = false, extraDays = false) {
|
||||||
|
|
||||||
diff = parseInt(diff);
|
diff = parseInt(diff);
|
||||||
@ -500,4 +513,10 @@ const filterExact = (search) => (comp) => comp.id.toLowerCase() === search ||
|
|||||||
const filterInexact = (search) => (comp) => comp.id.toLowerCase().includes(search) ||
|
const filterInexact = (search) => (comp) => comp.id.toLowerCase().includes(search) ||
|
||||||
comp.resolveable.toLowerCase().includes(search) ||
|
comp.resolveable.toLowerCase().includes(search) ||
|
||||||
comp.aliases && (comp.aliases.some((ali) => `${comp.type}:${ali}`.toLowerCase().includes(search)) ||
|
comp.aliases && (comp.aliases.some((ali) => `${comp.type}:${ali}`.toLowerCase().includes(search)) ||
|
||||||
comp.aliases.some((ali) => ali.toLowerCase().includes(search)));
|
comp.aliases.some((ali) => ali.toLowerCase().includes(search)));
|
||||||
|
|
||||||
|
const filterInexactTags = (search) => (comp) => comp.id.toLowerCase().includes(search.toLowerCase()) ||
|
||||||
|
comp.resolveable.toLowerCase().includes(search.toLowerCase()) ||
|
||||||
|
comp.aliases && (comp.aliases.some((ali) => `${comp.type}:${ali}`.toLowerCase().includes(search.toLowerCase())) ||
|
||||||
|
comp.aliases.some((ali) => ali.toLowerCase().includes(search.toLowerCase())) ||
|
||||||
|
comp.tags.some((tag) => tag.toLowerCase().includes(search.toLowerCase())));
|
@ -34,10 +34,10 @@ class CommandsCommand extends Command {
|
|||||||
params = params.join(' ');
|
params = params.join(' ');
|
||||||
|
|
||||||
const [ mod ] = this.client.resolver.components(params, 'module', false);
|
const [ mod ] = this.client.resolver.components(params, 'module', false);
|
||||||
if(!mod) {
|
if (!mod) {
|
||||||
const [ command ] = this.client.resolver.components(params, 'command', false);
|
const [ command ] = this.client.resolver.components(params, 'command', false);
|
||||||
if (!command) return message.format('C_COMMAND_INVALID');
|
if (!command) return message.format('C_COMMAND_INVALID');
|
||||||
return message._showUsage(command);
|
return message.embed(command.usageEmbed(message, true));
|
||||||
}
|
}
|
||||||
//list module's commands
|
//list module's commands
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ class CommandsCommand extends Command {
|
|||||||
let text = '';
|
let text = '';
|
||||||
|
|
||||||
for(const command of commands.values()) {
|
for(const command of commands.values()) {
|
||||||
text += command.disabled ? `~~${command.name}~~\n` : `${command.name}`; //TODO: Denote disabled commands somehow
|
text += command.disabled ? `~~${command.name}~~\n` : `${command.name}\n`; //TODO: Denote disabled commands somehow
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = {
|
const embed = {
|
||||||
|
@ -22,24 +22,31 @@ class HelpCommand extends Command {
|
|||||||
const [ key ] = params;
|
const [ key ] = params;
|
||||||
let [ result ] = this.client.resolver.components(key, 'command');
|
let [ result ] = this.client.resolver.components(key, 'command');
|
||||||
if (!result) [ result ] = this.client.resolver.components(key, 'setting');
|
if (!result) [ result ] = this.client.resolver.components(key, 'setting');
|
||||||
|
if (!result) result = this.client.resolver.componentsByTag(key, 'any', false);
|
||||||
if (!result) return message.embed({
|
if (!result) return message.embed({
|
||||||
description: message.format('C_HELP_404', { component: key })
|
description: message.format('C_HELP_404', { component: key })
|
||||||
});
|
});
|
||||||
|
|
||||||
//let index = `${result.type.slice(0, 1).toUpperCase()}_${result.name.toUpperCase()}_HELP`;
|
if (result instanceof Array) {
|
||||||
return message.embed({
|
|
||||||
description: message.format('C_HELP_TEMPLATE', {
|
} else return message.embed(result.usageEmbed(message, true));
|
||||||
desc: message.format(result.description),
|
|
||||||
component: result.name.toUpperCase(),
|
// //let index = `${result.type.slice(0, 1).toUpperCase()}_${result.name.toUpperCase()}_HELP`;
|
||||||
text: result.examples.map(ex => `\`{prefix}${result.type === 'command' ? result.name.toLowerCase() : `settings ${result.name.toLowerCase()}`} ${ex}\``).join('\n')
|
// const em = {
|
||||||
}),
|
// description: message.format('C_HELP_TEMPLATE', {
|
||||||
fields: [
|
// desc: message.format(result.description),
|
||||||
{
|
// component: result.name.toUpperCase(),
|
||||||
name: 'Aliases',
|
// text: result.examples.map((ex) => `\`{prefix}${result.type === 'command' ? result.name.toLowerCase() : `settings ${result.name.toLowerCase()}`} ${ex}\``).join('\n')
|
||||||
value: result.aliases.map(al => al.toLowerCase()).join(', ')
|
// })
|
||||||
}
|
// };
|
||||||
]
|
// if (result.aliases.length) em.fields = [
|
||||||
});
|
// {
|
||||||
|
// name: 'Aliases',
|
||||||
|
// value: result.aliases.map((al) => al.toLowerCase()).join(', ')
|
||||||
|
// }
|
||||||
|
// ];
|
||||||
|
|
||||||
|
// return message.embed(em);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const { Observer } = require('../../../interfaces/');
|
const { Observer } = require('../../../interfaces/');
|
||||||
|
const { Util } = require('../../../../util');
|
||||||
|
|
||||||
const CONSTANTS = {};
|
const CONSTANTS = {};
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ class UtilityHook extends Observer {
|
|||||||
this.hooks = [
|
this.hooks = [
|
||||||
['guildMemberAdd', this.welcome.bind(this)],
|
['guildMemberAdd', this.welcome.bind(this)],
|
||||||
['guildMemberAdd', this.autorole.bind(this)]
|
['guildMemberAdd', this.autorole.bind(this)]
|
||||||
]
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +33,12 @@ class UtilityHook extends Observer {
|
|||||||
const { guild } = member;
|
const { guild } = member;
|
||||||
const settings = await guild.settings();
|
const settings = await guild.settings();
|
||||||
const setting = settings.autorole;
|
const setting = settings.autorole;
|
||||||
if(!setting.enabled) return;
|
if (!setting.enabled) return;
|
||||||
|
if (!guild.me.hasPermission('MANAGE_ROLES')) return;
|
||||||
|
|
||||||
|
const _roles = await guild.resolveRoles(setting.roles);
|
||||||
|
const roles = _roles.map((r) => r.id);
|
||||||
|
await member.roles.add(roles, 'Adding autoroles').catch(this.client.logger.error);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,8 +47,8 @@ class UtilityHook extends Observer {
|
|||||||
const { guild, user } = member;
|
const { guild, user } = member;
|
||||||
const settings = await guild.settings();
|
const settings = await guild.settings();
|
||||||
const setting = settings.welcomer;
|
const setting = settings.welcomer;
|
||||||
if(!setting.enabled) return;
|
if (!setting.enabled) return;
|
||||||
|
|
||||||
const channel = await user.createDM();
|
const channel = await user.createDM();
|
||||||
const message = this._replaceTags(setting.message, member);
|
const message = this._replaceTags(setting.message, member);
|
||||||
await channel.send(message).catch();
|
await channel.send(message).catch();
|
||||||
@ -52,13 +58,13 @@ class UtilityHook extends Observer {
|
|||||||
_replaceTags(text, member) {
|
_replaceTags(text, member) {
|
||||||
const { user, guild } = member;
|
const { user, guild } = member;
|
||||||
return text
|
return text
|
||||||
.replace(/\{mention\}/g, `<@${member.id}>`)
|
.replace(/\{mention\}/gu, `<@${member.id}>`)
|
||||||
.replace(/\{tag\}/g, Util.escapeMarkdown(user.tag))
|
.replace(/\{tag\}/gu, Util.escapeMarkdown(user.tag))
|
||||||
.replace(/\{user\}/g, Util.escapeMarkdown(user.username))
|
.replace(/\{user\}/gu, Util.escapeMarkdown(user.username))
|
||||||
.replace(/\{guildsize\}/g, guild.memberCount)
|
.replace(/\{guildsize\}/gu, guild.memberCount)
|
||||||
.replace(/\{guildname\}/g, guild.name)
|
.replace(/\{guildname\}/gu, guild.name)
|
||||||
.replace(/\{accage\}/g, this.client.resolver.timeAgo(Date.now()/1000 - user.createdTimestamp/1000)) //.replace(/a/, '1')
|
.replace(/\{accage\}/gu, this.client.resolver.timeAgo(Date.now()/1000 - user.createdTimestamp/1000)) //.replace(/a/, '1')
|
||||||
.replace(/\{id\}/g, user.id)
|
.replace(/\{id\}/gu, user.id)
|
||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ const Message = Structures.extend('Message', (Message) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.command.showUsage && !this.parameters.length && !Object.values(this.arguments).length) {
|
if (this.command.showUsage && !this.parameters.length && !Object.values(this.arguments).length) {
|
||||||
return this._showUsage();
|
return this.embed(this.command.usageEmbed(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.client.emit('commandExecute', this);
|
this.client.emit('commandExecute', this);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const Component = require('./Component.js');
|
const Component = require('./Component.js');
|
||||||
|
const { stripIndents } = require('common-tags');
|
||||||
|
|
||||||
class Command extends Component {
|
class Command extends Component {
|
||||||
|
|
||||||
@ -54,6 +55,42 @@ class Command extends Component {
|
|||||||
return `${this.module.id}:${this.id}`;
|
return `${this.module.id}:${this.id}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usageEmbed(message, verbose = false) {
|
||||||
|
|
||||||
|
const { guild } = message;
|
||||||
|
const prefix = guild?.prefix || this.client.prefix;
|
||||||
|
const fields = [];
|
||||||
|
|
||||||
|
if (this.examples.length) {
|
||||||
|
fields.push({
|
||||||
|
name: `》${message.format('GENERAL_EXAMPLES')}`,
|
||||||
|
value: this.examples.map((e) => this.rawExamples ? `\`${prefix}${e}\`` : `\`${prefix}${this.name} ${e}\``).join('\n')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (this.aliases.length && verbose) {
|
||||||
|
fields.push({
|
||||||
|
name: `》${message.format('GENERAL_ALIASES')}`,
|
||||||
|
value: this.aliases.join(', ')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (this.arguments.length && verbose) {
|
||||||
|
fields.push({
|
||||||
|
name: `》${message.format('GENERAL_ARGUMENTS')}`,
|
||||||
|
value: this.arguments.map((a) => `\`${a.types.length === 1 && a.types.includes('FLAG') ? '--' : ''}${a.name}${a.usage ? ` ${a.usage}` : ''}\`: ${message.format(`A_${a.name.toUpperCase()}_${this.name.toUpperCase()}_DESCRIPTION`)}`)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
author: {
|
||||||
|
name: `${this.name}${this.module ? ` (${this.module.resolveable})` : ''}`
|
||||||
|
},
|
||||||
|
description: stripIndents`\`${prefix}${this.name}${this.usage ? ` ${this.usage}` : ''}\`${this.guildOnly ? ' *(guild-only)*' : ''}
|
||||||
|
${message.format(this.description)}`,
|
||||||
|
fields
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Command;
|
module.exports = Command;
|
@ -20,6 +20,7 @@ class Setting extends Component {
|
|||||||
|
|
||||||
this.description = opts.description || `S_${opts.name.toUpperCase()}_DESCRIPTION`;
|
this.description = opts.description || `S_${opts.name.toUpperCase()}_DESCRIPTION`;
|
||||||
this.examples = opts.examples || [];
|
this.examples = opts.examples || [];
|
||||||
|
this.rawExamples = Boolean(opts.rawExamples);
|
||||||
this.usage = opts.usage || '';
|
this.usage = opts.usage || '';
|
||||||
this.archivable = opts.archivable === undefined ? true : Boolean(opts.archivable);
|
this.archivable = opts.archivable === undefined ? true : Boolean(opts.archivable);
|
||||||
|
|
||||||
@ -92,6 +93,42 @@ class Setting extends Component {
|
|||||||
get display() {
|
get display() {
|
||||||
return this.name.toLowerCase();
|
return this.name.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usageEmbed(message, verbose = false) {
|
||||||
|
|
||||||
|
const { guild } = message;
|
||||||
|
const prefix = guild?.prefix || this.client.prefix;
|
||||||
|
const fields = [];
|
||||||
|
|
||||||
|
if (this.examples.length) {
|
||||||
|
fields.push({
|
||||||
|
name: `》${message.format('GENERAL_EXAMPLES')}`,
|
||||||
|
value: this.examples.map((e) => this.rawExamples ? `\`${prefix}${e}\`` : `\`${prefix}${this.name} ${e}\``).join('\n')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (this.aliases.length && verbose) {
|
||||||
|
fields.push({
|
||||||
|
name: `》${message.format('GENERAL_ALIASES')}`,
|
||||||
|
value: this.aliases.join(', ')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (this.arguments.length && verbose) {
|
||||||
|
fields.push({
|
||||||
|
name: `》${message.format('GENERAL_ARGUMENTS')}`,
|
||||||
|
value: this.arguments.map((a) => `\`${a.types.length === 1 && a.types.includes('FLAG') ? '--' : ''}${a.name}${a.usage ? ` ${a.usage}` : ''}\`: ${message.format(`A_${a.name.toUpperCase()}_${this.name.toUpperCase()}_DESCRIPTION`)}`)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
author: {
|
||||||
|
name: `${this.name}${this.module ? ` (${this.module.resolveable})` : ''}`
|
||||||
|
},
|
||||||
|
description: stripIndents`\`${prefix}${this.name}${this.usage ? ` ${this.usage}` : ''}\`${this.guildOnly ? ' *(guild-only)*' : ''}
|
||||||
|
${message.format(this.description)}`,
|
||||||
|
fields
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user