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();
|
await interaction.deferReply();
|
||||||
let data = await getPlayer(username);
|
let data = await getPlayer(username);
|
||||||
if (data === null)
|
if (data === null)
|
||||||
throw (0, util_1.emsg)('Unable to find user');
|
throw (0, util_1.emsg)('api.noUser');
|
||||||
else
|
else
|
||||||
sendPlayerEmbed(interaction, data);
|
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++) {
|
for (let i = 0; i < guildIds.length; i++) {
|
||||||
try {
|
try {
|
||||||
await rest.put(v9_1.Routes.applicationGuildCommands(clientId, guildIds[i]), { body: commands });
|
await rest.put(v9_1.Routes.applicationGuildCommands(clientId, guildIds[i]), { body: commands });
|
||||||
console.log(`[${guildIds[i]}] registered command`);
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error(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 fs = __importStar(require("fs"));
|
||||||
const api_1 = require("./api");
|
const api_1 = require("./api");
|
||||||
const discord_1 = require("./discord");
|
const discord_1 = require("./discord");
|
||||||
|
const lang_1 = require("./lang");
|
||||||
const queue_1 = require("./queue");
|
const queue_1 = require("./queue");
|
||||||
const util_1 = require("./util");
|
const util_1 = require("./util");
|
||||||
const CLIENT = new discord_js_1.Client({ intents: [discord_js_1.Intents.FLAGS.GUILDS] });
|
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
|
//get token
|
||||||
if (!fs.existsSync('./token.txt')) {
|
if (!fs.existsSync('./token.txt')) {
|
||||||
fs.writeFileSync('./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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
const TOKEN = fs.readFileSync('./token.txt').toString();
|
const TOKEN = fs.readFileSync('./token.txt').toString();
|
||||||
//discord connections
|
//discord connections
|
||||||
CLIENT.on('ready', client => {
|
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)));
|
client.guilds.fetch().then(guilds => (0, discord_1.registerCommands)(TOKEN, client.user.id, guilds.map(g => g.id)));
|
||||||
(0, queue_1.discordInit)(client);
|
(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) => {
|
CLIENT.on('interactionCreate', async (interaction) => {
|
||||||
if (!interaction.isCommand())
|
if (!interaction.isCommand())
|
||||||
return;
|
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;
|
exports.Lang = void 0;
|
||||||
const LANG = {
|
const LANG = {
|
||||||
en: {
|
en: {
|
||||||
|
main: {
|
||||||
|
login: 'Logged in as {user}'
|
||||||
|
},
|
||||||
discord: {
|
discord: {
|
||||||
botRestart: 'The bot has just restarted, anybody previously in the queue has been reset',
|
botRestart: 'The bot has just restarted, anybody previously in the queue has been reset',
|
||||||
create: 'A queue for teams of {teamsize} has been created',
|
create: 'A queue for teams of {teamsize} has been created',
|
||||||
@@ -11,6 +14,9 @@ const LANG = {
|
|||||||
leave: 'Left the queue'
|
leave: 'Left the queue'
|
||||||
},
|
},
|
||||||
error: {
|
error: {
|
||||||
|
main: {
|
||||||
|
missingToken: 'Missing Discord Token, please enter the bot token into the token file'
|
||||||
|
},
|
||||||
discord: {
|
discord: {
|
||||||
noQueue: 'There is not an active queue in this channel, type `/open` to create one',
|
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}',
|
noChannel: 'Unable to find channel {channelId} for teams of {teamsize}',
|
||||||
@@ -22,6 +28,9 @@ const LANG = {
|
|||||||
general: {
|
general: {
|
||||||
noMember: 'Unable to retrieve guild member information, please try again',
|
noMember: 'Unable to retrieve guild member information, please try again',
|
||||||
noChannel: 'Unable to retrieve text channel 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) {
|
function queueCreate(interaction) {
|
||||||
(0, util_1.memberIsModThrow)(interaction);
|
(0, util_1.memberIsModThrow)(interaction);
|
||||||
let { channelId } = interaction, teamsize = interaction.options.getInteger('teamsize', true);
|
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', {
|
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);
|
Queue.create(channelId, teamsize);
|
||||||
interaction.reply(lang_1.Lang.get('discord.create', {
|
interaction.reply(lang_1.Lang.get('discord.create', {
|
||||||
teamsize
|
teamsize: teamsize.toString()
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
QueueCommands.queueCreate = queueCreate;
|
QueueCommands.queueCreate = queueCreate;
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ export async function getPlayerInteraction(interaction: CommandInteraction) {
|
|||||||
|
|
||||||
let data = await getPlayer(username);
|
let data = await getPlayer(username);
|
||||||
if (data === null)
|
if (data === null)
|
||||||
throw emsg('Unable to find user');
|
throw emsg('api.noUser');
|
||||||
else
|
else
|
||||||
sendPlayerEmbed(interaction, data);
|
sendPlayerEmbed(interaction, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ export async function registerCommands(token: string, clientId: string, guildIds
|
|||||||
Routes.applicationGuildCommands(clientId, guildIds[i]),
|
Routes.applicationGuildCommands(clientId, guildIds[i]),
|
||||||
{ body: commands },
|
{ body: commands },
|
||||||
);
|
);
|
||||||
console.log(`[${guildIds[i]}] registered command`);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(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 * as fs from 'fs';
|
||||||
import { getPlayerInteraction } from './api';
|
import { getPlayerInteraction } from './api';
|
||||||
import { registerCommands } from './discord';
|
import { registerCommands } from './discord';
|
||||||
|
import { Lang } from './lang';
|
||||||
import { discordInit, QueueCommands } from './queue';
|
import { discordInit, QueueCommands } from './queue';
|
||||||
import { errorMessage } from './util';
|
import { errorMessage } from './util';
|
||||||
const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
||||||
@@ -13,19 +14,26 @@ console.log(new Date().toISOString()+'\n\n');
|
|||||||
//get token
|
//get token
|
||||||
if (!fs.existsSync('./token.txt')) {
|
if (!fs.existsSync('./token.txt')) {
|
||||||
fs.writeFileSync('./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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
const TOKEN = fs.readFileSync('./token.txt').toString();
|
const TOKEN = fs.readFileSync('./token.txt').toString();
|
||||||
|
|
||||||
//discord connections
|
//discord connections
|
||||||
CLIENT.on('ready', client => {
|
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 =>
|
client.guilds.fetch().then(guilds =>
|
||||||
registerCommands(TOKEN, client.user.id, guilds.map(g => g.id)));
|
registerCommands(TOKEN, client.user.id, guilds.map(g => g.id)));
|
||||||
discordInit(client);
|
discordInit(client);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CLIENT.on('guildCreate', guild => {
|
||||||
|
if (guild.client.user)
|
||||||
|
registerCommands(TOKEN, guild.client.user.id, guild.id);
|
||||||
|
});
|
||||||
|
|
||||||
CLIENT.on('interactionCreate', async interaction => {
|
CLIENT.on('interactionCreate', async interaction => {
|
||||||
if (!interaction.isCommand()) return;
|
if (!interaction.isCommand()) return;
|
||||||
|
|
||||||
|
|||||||
11
src/lang.ts
11
src/lang.ts
@@ -3,6 +3,9 @@ type LangObjWhold = { [langid:string]: LangObj }
|
|||||||
|
|
||||||
const LANG: LangObjWhold = {
|
const LANG: LangObjWhold = {
|
||||||
en: {
|
en: {
|
||||||
|
main: {
|
||||||
|
login: 'Logged in as {user}'
|
||||||
|
},
|
||||||
discord: {
|
discord: {
|
||||||
botRestart: 'The bot has just restarted, anybody previously in the queue has been reset',
|
botRestart: 'The bot has just restarted, anybody previously in the queue has been reset',
|
||||||
create: 'A queue for teams of {teamsize} has been created',
|
create: 'A queue for teams of {teamsize} has been created',
|
||||||
@@ -11,6 +14,9 @@ const LANG: LangObjWhold = {
|
|||||||
leave: 'Left the queue'
|
leave: 'Left the queue'
|
||||||
},
|
},
|
||||||
error: {
|
error: {
|
||||||
|
main: {
|
||||||
|
missingToken: 'Missing Discord Token, please enter the bot token into the token file'
|
||||||
|
},
|
||||||
discord: {
|
discord: {
|
||||||
noQueue: 'There is not an active queue in this channel, type `/open` to create one',
|
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}',
|
noChannel: 'Unable to find channel {channelId} for teams of {teamsize}',
|
||||||
@@ -22,6 +28,9 @@ const LANG: LangObjWhold = {
|
|||||||
general: {
|
general: {
|
||||||
noMember: 'Unable to retrieve guild member information, please try again',
|
noMember: 'Unable to retrieve guild member information, please try again',
|
||||||
noChannel: 'Unable to retrieve text channel 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
|
* @param id ex: discord.error.noActiveQueue
|
||||||
* @returns language value, defaults to `id` parameter
|
* @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);
|
let keySpl = id.split('.').map(k => k.trim()).filter(k => k);
|
||||||
|
|
||||||
|
|||||||
@@ -173,15 +173,16 @@ export namespace QueueCommands {
|
|||||||
let {channelId} = interaction,
|
let {channelId} = interaction,
|
||||||
teamsize = interaction.options.getInteger('teamsize', true);
|
teamsize = interaction.options.getInteger('teamsize', true);
|
||||||
|
|
||||||
if (QUEUE.has(channelId))
|
let existing = QUEUE.get(channelId)
|
||||||
|
if (existing)
|
||||||
throw emsg(Lang.get('error.discord.noCreate', {
|
throw emsg(Lang.get('error.discord.noCreate', {
|
||||||
teamsize: QUEUE.get(channelId)?.teamsize
|
teamsize: existing.teamsize.toString()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Queue.create(channelId, teamsize);
|
Queue.create(channelId, teamsize);
|
||||||
|
|
||||||
interaction.reply(Lang.get('discord.create', {
|
interaction.reply(Lang.get('discord.create', {
|
||||||
teamsize
|
teamsize: teamsize.toString()
|
||||||
}))
|
}))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user