Compare commits
2 Commits
17643dc730
...
343ed640ae
| Author | SHA1 | Date | |
|---|---|---|---|
| 343ed640ae | |||
| b1d01b414e |
2
dist/api.js
vendored
2
dist/api.js
vendored
@@ -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
1
dist/discord.js
vendored
@@ -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
11
dist/index.js
vendored
@@ -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
9
dist/lang.js
vendored
@@ -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
7
dist/queue.js
vendored
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
12
src/index.ts
12
src/index.ts
@@ -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;
|
||||
|
||||
|
||||
11
src/lang.ts
11
src/lang.ts
@@ -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);
|
||||
|
||||
|
||||
@@ -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()
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user