Add help command, tweaks to multi-message output
This commit is contained in:
parent
1ef645c27d
commit
8a9e10d815
@ -105,7 +105,8 @@
|
||||
"CallExpression": {"arguments": "first"},
|
||||
"ArrayExpression": "first",
|
||||
"ObjectExpression": "first",
|
||||
"ImportDeclaration": "first"
|
||||
"ImportDeclaration": "first",
|
||||
"MemberExpression": 1
|
||||
}
|
||||
],
|
||||
"init-declarations": "warn",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "navys-music-bot",
|
||||
"version": "1.2.2",
|
||||
"version": "1.3.0",
|
||||
"description": "A bot that plays music on discord",
|
||||
"main": "build/index.js",
|
||||
"repository": "https://git.corgi.wtf/Navy.gif/music-bot.git",
|
||||
|
@ -122,24 +122,33 @@ class DiscordClient extends Client
|
||||
this.shutdown();
|
||||
}
|
||||
|
||||
async sendSplitMessage (message: Message, text: string, opts: MessageReplyOptions)
|
||||
async sendSplitMessage (message: Message, text: string, opts?: MessageReplyOptions, delimiter = ' ')
|
||||
{
|
||||
const words = text.split(' ');
|
||||
const segments = text.split(delimiter);
|
||||
const out = [];
|
||||
let tmp = '';
|
||||
for (const word of words)
|
||||
for (const segment of segments)
|
||||
{
|
||||
if (tmp.length + word.length > 2000)
|
||||
if (tmp.length + segment.length >= 1900)
|
||||
{
|
||||
const codeBlock = tmp.match(/```/ug)?.length === 1;
|
||||
if (codeBlock)
|
||||
tmp += '```';
|
||||
out.push(tmp);
|
||||
tmp = word;
|
||||
tmp = '';
|
||||
if (codeBlock)
|
||||
tmp += '```';
|
||||
tmp += segment;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp += ' ' + word;
|
||||
tmp += delimiter + segment;
|
||||
}
|
||||
}
|
||||
if (tmp.match(/```/gu)?.length === 1)
|
||||
tmp += '```';
|
||||
out.push(tmp);
|
||||
|
||||
const [ first, ...rest ] = out;
|
||||
try
|
||||
{
|
||||
@ -232,6 +241,15 @@ class DiscordClient extends Client
|
||||
return this.#musicPlayer;
|
||||
}
|
||||
|
||||
get version ()
|
||||
{
|
||||
const version = process.env.BOT_VERSION;
|
||||
const dev = process.env.NODE_ENV === 'development';
|
||||
if (!version)
|
||||
return 'dev';
|
||||
return version + (dev ? '-dev' : '');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
process.once('message', (msg: IPCMessage) =>
|
||||
|
28
src/client/components/commands/Help.ts
Normal file
28
src/client/components/commands/Help.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { stripIndents } from 'common-tags';
|
||||
import Command from '../../../interfaces/Command.js';
|
||||
import DiscordClient from '../../DiscordClient.js';
|
||||
|
||||
class HelpCommand extends Command
|
||||
{
|
||||
constructor (client: DiscordClient)
|
||||
{
|
||||
super(client, {
|
||||
name: 'help',
|
||||
description: 'Display a brief help message'
|
||||
});
|
||||
}
|
||||
|
||||
async execute ()
|
||||
{
|
||||
return stripIndents`
|
||||
**${this.client.user?.username} v${this.client.version}**
|
||||
A simple music bot.
|
||||
Source: <https://git.corgi.wtf/Navy.gif/music-bot>
|
||||
|
||||
Use \`${this.client.prefix}list commands\` to list available commands.
|
||||
Use \`${this.client.prefix}<command> --help\` to display command specific help.
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
export default HelpCommand;
|
@ -24,7 +24,7 @@ class SearchCommand extends Command
|
||||
});
|
||||
}
|
||||
|
||||
async execute (_message: Message, { map }: CommandArgs)
|
||||
async execute (message: Message, { map }: CommandArgs)
|
||||
{
|
||||
const [ song ] = map.get('song') ?? [];
|
||||
const [ artist ] = map.get('artist') ?? [];
|
||||
@ -38,9 +38,15 @@ class SearchCommand extends Command
|
||||
|
||||
if (!results.length)
|
||||
return 'No results found';
|
||||
return `
|
||||
**Search results:**\n\`\`\`${results.map(result => `\t- [id: ${result.id}] ${result.title} - ${result.artist} (Album: ${result.album ?? 'Unknown'}) [${result.year ?? 'Unknown year'}]`).join('\n')}\`\`\`
|
||||
`;
|
||||
await this.client.sendSplitMessage(
|
||||
message,
|
||||
`
|
||||
**Search results:**\n\`\`\`${results.map(result => `\t- [id: ${result.id}] ${result.title} - ${result.artist} (Album: ${result.album ?? 'Unknown'}) [${result.year ?? 'Unknown year'}]`).join('\n')}\`\`\`
|
||||
`,
|
||||
{ allowedMentions: { repliedUser: false } },
|
||||
'\n'
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@ class Controller
|
||||
|
||||
// this.#options = options;
|
||||
const { shardList, totalShards, execArgv, respawn, debug } = Controller.parseShardOptions(options.shardOptions);
|
||||
process.env.BOT_VERSION = version;
|
||||
|
||||
options.discord.rootDir = options.rootDir;
|
||||
options.discord.logger = options.logger;
|
||||
|
Loading…
Reference in New Issue
Block a user