Compare commits

..

2 Commits

Author SHA1 Message Date
343ed640ae updated lang strings 2022-02-13 19:35:16 -06:00
b1d01b414e register commands for new guilds 2022-02-13 19:29:10 -06:00
10 changed files with 48 additions and 15 deletions

2
dist/api.js vendored
View File

@@ -204,7 +204,7 @@ async function getPlayerInteraction(interaction) {
await interaction.deferReply();
let data = await getPlayer(username);
if (data === null)
throw (0, util_1.emsg)('Unable to find user');
throw (0, util_1.emsg)('api.noUser');
else
sendPlayerEmbed(interaction, data);
}

1
dist/discord.js vendored
View File

@@ -60,7 +60,6 @@ async function registerCommands(token, clientId, guildIds) {
for (let i = 0; i < guildIds.length; i++) {
try {
await rest.put(v9_1.Routes.applicationGuildCommands(clientId, guildIds[i]), { body: commands });
console.log(`[${guildIds[i]}] registered command`);
}
catch (error) {
console.error(error);

11
dist/index.js vendored
View File

@@ -23,6 +23,7 @@ const discord_js_1 = require("discord.js");
const fs = __importStar(require("fs"));
const api_1 = require("./api");
const discord_1 = require("./discord");
const lang_1 = require("./lang");
const queue_1 = require("./queue");
const util_1 = require("./util");
const CLIENT = new discord_js_1.Client({ intents: [discord_js_1.Intents.FLAGS.GUILDS] });
@@ -31,16 +32,22 @@ console.log(new Date().toISOString() + '\n\n');
//get token
if (!fs.existsSync('./token.txt')) {
fs.writeFileSync('./token.txt', '');
console.error('Missing Discord Token, please enter the bot token into the token file');
console.error(lang_1.Lang.get('error.main.missingToken'));
process.exit(1);
}
const TOKEN = fs.readFileSync('./token.txt').toString();
//discord connections
CLIENT.on('ready', client => {
console.log(`Logged in as ${client.user.tag}`);
console.log(lang_1.Lang.get('main.login', {
user: client.user.tag
}));
client.guilds.fetch().then(guilds => (0, discord_1.registerCommands)(TOKEN, client.user.id, guilds.map(g => g.id)));
(0, queue_1.discordInit)(client);
});
CLIENT.on('guildCreate', guild => {
if (guild.client.user)
(0, discord_1.registerCommands)(TOKEN, guild.client.user.id, guild.id);
});
CLIENT.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand())
return;

9
dist/lang.js vendored
View File

@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.Lang = void 0;
const LANG = {
en: {
main: {
login: 'Logged in as {user}'
},
discord: {
botRestart: 'The bot has just restarted, anybody previously in the queue has been reset',
create: 'A queue for teams of {teamsize} has been created',
@@ -11,6 +14,9 @@ const LANG = {
leave: 'Left the queue'
},
error: {
main: {
missingToken: 'Missing Discord Token, please enter the bot token into the token file'
},
discord: {
noQueue: 'There is not an active queue in this channel, type `/open` to create one',
noChannel: 'Unable to find channel {channelId} for teams of {teamsize}',
@@ -22,6 +28,9 @@ const LANG = {
general: {
noMember: 'Unable to retrieve guild member information, please try again',
noChannel: 'Unable to retrieve text channel information, please try again'
},
api: {
noUser: 'Unable to find user'
}
}
}

7
dist/queue.js vendored
View File

@@ -154,13 +154,14 @@ var QueueCommands;
function queueCreate(interaction) {
(0, util_1.memberIsModThrow)(interaction);
let { channelId } = interaction, teamsize = interaction.options.getInteger('teamsize', true);
if (QUEUE.has(channelId))
let existing = QUEUE.get(channelId);
if (existing)
throw (0, util_1.emsg)(lang_1.Lang.get('error.discord.noCreate', {
teamsize: QUEUE.get(channelId)?.teamsize
teamsize: existing.teamsize.toString()
}));
Queue.create(channelId, teamsize);
interaction.reply(lang_1.Lang.get('discord.create', {
teamsize
teamsize: teamsize.toString()
}));
}
QueueCommands.queueCreate = queueCreate;

View File

@@ -245,7 +245,7 @@ export async function getPlayerInteraction(interaction: CommandInteraction) {
let data = await getPlayer(username);
if (data === null)
throw emsg('Unable to find user');
throw emsg('api.noUser');
else
sendPlayerEmbed(interaction, data);
}

View File

@@ -67,7 +67,6 @@ export async function registerCommands(token: string, clientId: string, guildIds
Routes.applicationGuildCommands(clientId, guildIds[i]),
{ body: commands },
);
console.log(`[${guildIds[i]}] registered command`);
} catch (error) {
console.error(error);
}

View File

@@ -3,6 +3,7 @@ import { Client, Intents } from 'discord.js';
import * as fs from 'fs';
import { getPlayerInteraction } from './api';
import { registerCommands } from './discord';
import { Lang } from './lang';
import { discordInit, QueueCommands } from './queue';
import { errorMessage } from './util';
const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS] });
@@ -13,19 +14,26 @@ console.log(new Date().toISOString()+'\n\n');
//get token
if (!fs.existsSync('./token.txt')) {
fs.writeFileSync('./token.txt', '');
console.error('Missing Discord Token, please enter the bot token into the token file');
console.error(Lang.get('error.main.missingToken'));
process.exit(1);
}
const TOKEN = fs.readFileSync('./token.txt').toString();
//discord connections
CLIENT.on('ready', client => {
console.log(`Logged in as ${client.user.tag}`);
console.log(Lang.get('main.login', {
user: client.user.tag
}));
client.guilds.fetch().then(guilds =>
registerCommands(TOKEN, client.user.id, guilds.map(g => g.id)));
discordInit(client);
});
CLIENT.on('guildCreate', guild => {
if (guild.client.user)
registerCommands(TOKEN, guild.client.user.id, guild.id);
});
CLIENT.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;

View File

@@ -3,6 +3,9 @@ type LangObjWhold = { [langid:string]: LangObj }
const LANG: LangObjWhold = {
en: {
main: {
login: 'Logged in as {user}'
},
discord: {
botRestart: 'The bot has just restarted, anybody previously in the queue has been reset',
create: 'A queue for teams of {teamsize} has been created',
@@ -11,6 +14,9 @@ const LANG: LangObjWhold = {
leave: 'Left the queue'
},
error: {
main: {
missingToken: 'Missing Discord Token, please enter the bot token into the token file'
},
discord: {
noQueue: 'There is not an active queue in this channel, type `/open` to create one',
noChannel: 'Unable to find channel {channelId} for teams of {teamsize}',
@@ -22,6 +28,9 @@ const LANG: LangObjWhold = {
general: {
noMember: 'Unable to retrieve guild member information, please try again',
noChannel: 'Unable to retrieve text channel information, please try again'
},
api: {
noUser: 'Unable to find user'
}
}
}
@@ -45,7 +54,7 @@ export namespace Lang {
* @param id ex: discord.error.noActiveQueue
* @returns language value, defaults to `id` parameter
*/
export function get(id: string, args: {[keys: string]: any} = {}): string {//discord.error.noActiveQueue
export function get(id: string, args: {[keys: string]: string} = {}): string {//discord.error.noActiveQueue
let keySpl = id.split('.').map(k => k.trim()).filter(k => k);

View File

@@ -173,15 +173,16 @@ export namespace QueueCommands {
let {channelId} = interaction,
teamsize = interaction.options.getInteger('teamsize', true);
if (QUEUE.has(channelId))
let existing = QUEUE.get(channelId)
if (existing)
throw emsg(Lang.get('error.discord.noCreate', {
teamsize: QUEUE.get(channelId)?.teamsize
teamsize: existing.teamsize.toString()
}));
Queue.create(channelId, teamsize);
interaction.reply(Lang.get('discord.create', {
teamsize
teamsize: teamsize.toString()
}))
}