use ?
prefix for tags
This commit is contained in:
parent
5b44978ec2
commit
35a64b4f25
2 changed files with 30 additions and 24 deletions
|
@ -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] });
|
||||
|
|
50
src/index.ts
50
src/index.ts
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue