use ? prefix for tags

This commit is contained in:
Ryan Cao 2022-07-26 21:06:30 +08:00
parent 5b44978ec2
commit 35a64b4f25
No known key found for this signature in database
GPG key ID: 528A2C1B6656B97F
2 changed files with 30 additions and 24 deletions

View file

@ -12,6 +12,7 @@ export const cmd: Command = {
for (const i in tags) {
const tag = tags[i];
let text = '';
if (tag.aliases && tag.aliases[0]) {
text += '**Aliases**: ' + tag.aliases.join(', ') + '\n';
}
@ -21,7 +22,8 @@ export const cmd: Command = {
} else if (tag.embed) {
text += '\n[embedded message]';
}
em.addField(tag.name, text);
em.addField('?' + tag.name, text);
}
await e.reply({ embeds: [em] });

View file

@ -10,6 +10,7 @@ import * as BuildConfig from './constants';
import { commands } from './commands';
import { filterMessage } from './filters';
import { parseLog } from './logs';
import { getLatestMinecraftVersion } from './utils/remoteVersions';
import {
parse as discordParse,
@ -19,10 +20,8 @@ import {
import random from 'just-random';
import { readFile } from 'fs/promises';
import { join } from 'path';
import { green, bold, blue, underline, yellow } from 'kleur/colors';
import 'dotenv/config';
import { getLatestMinecraftVersion } from './utils/remoteVersions';
export interface Command {
name: string;
@ -111,8 +110,10 @@ client.once('ready', async () => {
);
}
const commanded = await parseMsg(e);
const commanded = await parseMsgForCommands(e);
if (commanded) return;
const tagged = await parseMsgForTags(e);
if (tagged) return;
const log = await parseLog(e.content);
if (log != null) {
@ -122,10 +123,8 @@ client.once('ready', async () => {
});
});
async function parseMsg(e: Message) {
const parsed = discordParse(e, '!', {
allowBots: true,
});
async function parseMsgForCommands(e: Message) {
const parsed = discordParse(e, '!', { allowBots: true });
if (!parsed.success) return false;
const cmd = commands.find(
@ -133,22 +132,6 @@ async function parseMsg(e: Message) {
);
if (!cmd) {
// TODO: Do not read tags.json everytime there is a new message
const tag = await getTags().then((r) =>
r.find(
(t) => t.name == parsed.command || t.aliases?.includes(parsed.command)
)
);
if (tag) {
if (tag.text) {
e.reply(tag.text);
} else if (tag.embed) {
const em = new MessageEmbed(tag.embed);
e.reply({ embeds: [em] });
}
return true;
}
return false;
}
@ -167,4 +150,25 @@ async function parseMsg(e: Message) {
return true;
}
async function parseMsgForTags(e: Message) {
const parsed = discordParse(e, '?', { allowBots: true });
if (!parsed.success) return false;
const tag = await getTags().then((r) =>
r.find(
(t) => t.name == parsed.command || t.aliases?.includes(parsed.command)
)
);
if (tag) {
if (tag.text) {
e.reply(tag.text);
} else if (tag.embed) {
const em = new MessageEmbed(tag.embed);
e.reply({ embeds: [em] });
}
return true;
}
}
client.login(process.env.DISCORD_TOKEN);