Compare commits
1 Commits
00c3fa8219
...
alt
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ad4f69f9f |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,4 @@
|
||||
node_modules
|
||||
token.txt
|
||||
queues.json
|
||||
token
|
||||
.DS_Store
|
||||
log
|
||||
@@ -1,10 +1,8 @@
|
||||
<!-- markdownlint-disable MD033 -->
|
||||
|
||||
# 1800queue
|
||||
# 1800queue alt
|
||||
|
||||
## Invite info
|
||||
|
||||
needs: create commands/send messages
|
||||
This version does not run continuously, and requires each tourney to be started with a command
|
||||
|
||||
## Prerequirements
|
||||
|
||||
|
||||
26
dist/discord.js
vendored
26
dist/discord.js
vendored
@@ -6,26 +6,18 @@ const v9_1 = require("discord-api-types/v9");
|
||||
// list of commands to register with discord
|
||||
const commands = [
|
||||
{
|
||||
name: 'open',
|
||||
description: 'open a queue for this channel',
|
||||
name: 'queue',
|
||||
description: 'create a queue',
|
||||
options: [
|
||||
{
|
||||
type: 4,
|
||||
name: 'teamsize',
|
||||
description: 'size of each team',
|
||||
min_value: 1,
|
||||
required: true
|
||||
required: true,
|
||||
min_value: 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'close',
|
||||
description: 'close the queue for this channel'
|
||||
},
|
||||
{
|
||||
name: 'queue',
|
||||
description: 'view queue info'
|
||||
},
|
||||
{
|
||||
name: 'join',
|
||||
description: 'join the active queue'
|
||||
@@ -35,8 +27,12 @@ const commands = [
|
||||
description: 'leave the active queue'
|
||||
},
|
||||
{
|
||||
name: 'stop',
|
||||
description: 'stops the current queue (must have the Manage Messages permission)'
|
||||
name: 'ready',
|
||||
description: 'ready the queue and display team info'
|
||||
},
|
||||
{
|
||||
name: 'cancel',
|
||||
description: 'cancels the current queue (must have the Manage Messages permission)'
|
||||
},
|
||||
{
|
||||
name: 'player',
|
||||
@@ -50,7 +46,7 @@ const commands = [
|
||||
}
|
||||
]
|
||||
}
|
||||
], commandNames = commands.map(c => c.name);
|
||||
];
|
||||
/**
|
||||
* register/reload commands on guild(s)
|
||||
* @param token discord bot token
|
||||
|
||||
41
dist/index.js
vendored
41
dist/index.js
vendored
@@ -29,44 +29,33 @@ const CLIENT = new discord_js_1.Client({ intents: [discord_js_1.Intents.FLAGS.GU
|
||||
//init logs with a timestamp
|
||||
console.log(new Date().toISOString() + '\n\n');
|
||||
//get token
|
||||
if (!fs.existsSync('./token.txt')) {
|
||||
fs.writeFileSync('./token.txt', '');
|
||||
if (!fs.existsSync('./token')) {
|
||||
fs.writeFileSync('./token', '');
|
||||
console.error('Missing Discord Token, please enter the bot token into the token file');
|
||||
process.exit(1);
|
||||
}
|
||||
const TOKEN = fs.readFileSync('./token.txt').toString();
|
||||
const TOKEN = fs.readFileSync('./token').toString();
|
||||
//discord connections
|
||||
CLIENT.on('ready', client => {
|
||||
console.log(`Logged in as ${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('interactionCreate', async (interaction) => {
|
||||
if (!interaction.isCommand())
|
||||
return;
|
||||
try {
|
||||
switch (interaction.commandName) {
|
||||
//mod commands
|
||||
case 'open':
|
||||
await queue_1.QueueCommands.open(interaction);
|
||||
break;
|
||||
case 'close':
|
||||
await queue_1.QueueCommands.close(interaction);
|
||||
break;
|
||||
//general commands
|
||||
case 'queue':
|
||||
await queue_1.QueueCommands.queue(interaction);
|
||||
break;
|
||||
case 'join':
|
||||
await queue_1.QueueCommands.join(interaction);
|
||||
break;
|
||||
case 'leave':
|
||||
await queue_1.QueueCommands.leave(interaction);
|
||||
break;
|
||||
case 'player':
|
||||
await (0, api_1.getPlayerInteraction)(interaction);
|
||||
break;
|
||||
}
|
||||
if (interaction.commandName === 'queue')
|
||||
await (0, queue_1.createQueue)(interaction);
|
||||
else if (interaction.commandName === 'join')
|
||||
await (0, queue_1.joinQueue)(interaction);
|
||||
else if (interaction.commandName === 'leave')
|
||||
await (0, queue_1.leaveQueue)(interaction);
|
||||
else if (interaction.commandName === 'ready')
|
||||
await (0, queue_1.readyQueue)(interaction);
|
||||
else if (interaction.commandName === 'cancel')
|
||||
await (0, queue_1.cancelQueue)(interaction);
|
||||
else if (interaction.commandName === 'player')
|
||||
await (0, api_1.getPlayerInteraction)(interaction);
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof util_1.errorMessage) {
|
||||
|
||||
395
dist/queue.js
vendored
395
dist/queue.js
vendored
@@ -1,222 +1,189 @@
|
||||
"use strict";
|
||||
/* TODO
|
||||
|
||||
join message should contain your current position in the queue, editing it to keep it current
|
||||
*/
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.QueueCommands = exports.discordInit = void 0;
|
||||
exports.cancelQueue = exports.readyQueue = exports.leaveQueue = exports.joinQueue = exports.createQueue = exports.queueContains = exports.getAll = exports.getInfo = void 0;
|
||||
const discord_js_1 = require("discord.js");
|
||||
const fs = __importStar(require("fs"));
|
||||
const util_1 = require("./util");
|
||||
//load queues from file
|
||||
if (!fs.existsSync('./queues.json'))
|
||||
fs.writeFileSync('./queues.json', '{}');
|
||||
const _QUEUE = fs.readFileSync('./queues.json').toString(), QUEUE = new Map();
|
||||
try {
|
||||
let queueJson = JSON.parse(_QUEUE);
|
||||
for (let channelId in queueJson) {
|
||||
let { teamsize } = queueJson[channelId];
|
||||
if (teamsize)
|
||||
QUEUE.set(channelId, { teamsize, players: [] });
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
function SaveQueue() {
|
||||
let queueJson = Object.fromEntries(QUEUE), queueFileJson = {};
|
||||
for (let channelId of QUEUE.keys())
|
||||
queueFileJson[channelId] = { teamsize: queueJson[channelId].teamsize };
|
||||
fs.writeFileSync('./queues.json', JSON.stringify(queueFileJson, null, 2));
|
||||
}
|
||||
async function checkQueue(channel) {
|
||||
let info = QUEUE.get(channel.id);
|
||||
//maps ChannelID to QueueInfo
|
||||
const QUEUE = new Map();
|
||||
/**
|
||||
* get the queueInfo of an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it does not exist
|
||||
* @returns queue info
|
||||
*/
|
||||
function getInfo(interaction) {
|
||||
let info = QUEUE.get(interaction.channelId);
|
||||
if (!info)
|
||||
return;
|
||||
if (info.players.length >= info.teamsize) {
|
||||
let team = info.players.splice(0, info.teamsize).map(m => m.toString());
|
||||
let embed = new discord_js_1.MessageEmbed()
|
||||
.setTitle('Team')
|
||||
.setDescription(team.join('\n'));
|
||||
await channel.send({ embeds: [embed] });
|
||||
}
|
||||
throw (0, util_1.emsg)('There is not an active queue in this channel, type `/queue` to create one');
|
||||
return info;
|
||||
}
|
||||
var Queue;
|
||||
(function (Queue) {
|
||||
function create(channelId, teamsize) {
|
||||
if (!QUEUE.has(channelId)) {
|
||||
QUEUE.set(channelId, { teamsize, players: [] });
|
||||
SaveQueue();
|
||||
}
|
||||
}
|
||||
Queue.create = create;
|
||||
function remove(channelId) {
|
||||
if (QUEUE.has(channelId)) {
|
||||
QUEUE.delete(channelId);
|
||||
SaveQueue();
|
||||
}
|
||||
}
|
||||
Queue.remove = remove;
|
||||
function addPlayer(channelId, member) {
|
||||
if (QUEUE.has(channelId)) {
|
||||
QUEUE.delete(channelId);
|
||||
}
|
||||
}
|
||||
Queue.addPlayer = addPlayer;
|
||||
function removePlayer(channelId, member) {
|
||||
if (QUEUE.has(channelId)) {
|
||||
QUEUE.delete(channelId);
|
||||
}
|
||||
}
|
||||
Queue.removePlayer = removePlayer;
|
||||
})(Queue || (Queue = {}));
|
||||
SaveQueue();
|
||||
async function discordInit(client) {
|
||||
for (let channelId in QUEUE.keys()) {
|
||||
let info = QUEUE.get(channelId), channel = await client.channels.fetch(channelId);
|
||||
if (!info) { //no idea what could cause this but TS complains
|
||||
Queue.remove(channelId);
|
||||
continue;
|
||||
}
|
||||
if (!channel || !(channel instanceof discord_js_1.TextChannel)) {
|
||||
console.error(`Unable to find channel ${channelId} for teams of ${info?.teamsize}`);
|
||||
Queue.remove(channelId);
|
||||
continue;
|
||||
}
|
||||
channel.send('The bot has just restarted and anybody in the queues have been reset');
|
||||
}
|
||||
exports.getInfo = getInfo;
|
||||
/**
|
||||
* compiles all the get functions above
|
||||
* @param interaction
|
||||
* @throws if another get function throws
|
||||
* @returns object containing each
|
||||
*/
|
||||
const getAll = (interaction) => ({
|
||||
member: (0, util_1.getMember)(interaction),
|
||||
channel: (0, util_1.getChannel)(interaction),
|
||||
info: getInfo(interaction)
|
||||
});
|
||||
exports.getAll = getAll;
|
||||
/**
|
||||
* checks if the interaction data is already in the queue
|
||||
* @param interaction
|
||||
* @returns boolean
|
||||
*/
|
||||
function queueContains(interaction) {
|
||||
let { member, info } = (0, exports.getAll)(interaction);
|
||||
if (info.players.map(m => m.id).includes(member.id))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
exports.discordInit = discordInit;
|
||||
var QueueCommands;
|
||||
(function (QueueCommands) {
|
||||
/**
|
||||
* get the queueInfo of an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it does not exist
|
||||
* @returns queue info
|
||||
*/
|
||||
function getInfo(interaction) {
|
||||
let info = QUEUE.get(interaction.channelId);
|
||||
if (!info)
|
||||
throw (0, util_1.emsg)('There is not an active queue in this channel, type `/queue` to create one');
|
||||
return info;
|
||||
}
|
||||
/**
|
||||
* compiles all the get functions above
|
||||
* @param interaction
|
||||
* @throws if another get function throws
|
||||
* @returns object containing each
|
||||
*/
|
||||
const getAll = (interaction) => ({
|
||||
member: (0, util_1.getMember)(interaction),
|
||||
channel: (0, util_1.getChannel)(interaction),
|
||||
info: getInfo(interaction)
|
||||
exports.queueContains = queueContains;
|
||||
/**
|
||||
* creates the timeout for the queue
|
||||
* @param interaction
|
||||
* @returns time timeout identifier
|
||||
*/
|
||||
function setQueueTimeout(interaction) {
|
||||
let channel = (0, util_1.getChannel)(interaction);
|
||||
return setTimeout(() => {
|
||||
clearQueue(interaction);
|
||||
channel.send('Queue has been reset due to inactivity');
|
||||
}, 5 * 60 * 1000); //5 minutes
|
||||
}
|
||||
/**
|
||||
* updates the rich embed for the current queue
|
||||
* @param interaction
|
||||
*/
|
||||
async function sendQueueEmbed(interaction, closed = false) {
|
||||
let info = getInfo(interaction), origInteraction = info.initiator.interaction;
|
||||
let embed = new discord_js_1.MessageEmbed()
|
||||
.setTitle('Queue')
|
||||
.setAuthor({
|
||||
name: info.initiator.member.displayName,
|
||||
iconURL: info.initiator.member.displayAvatarURL({ dynamic: true })
|
||||
})
|
||||
.addField('Team Size', info.teamsize.toString(), true)
|
||||
.addField('Players Joined', info.players.length.toString(), true)
|
||||
.setFooter({ text: closed ? 'queue is finished' : 'type /join' });
|
||||
if (origInteraction.deferred || origInteraction.replied)
|
||||
await origInteraction.editReply({ embeds: [embed] });
|
||||
else
|
||||
await origInteraction.reply({ embeds: [embed] });
|
||||
}
|
||||
/**
|
||||
* sends the list of teams
|
||||
* @param interaction
|
||||
*/
|
||||
async function sendTeamsEmbed(interaction, teams) {
|
||||
let embed = new discord_js_1.MessageEmbed()
|
||||
.setTitle('Teams');
|
||||
teams.forEach((team, i) => {
|
||||
team.map(m => m.user.tag);
|
||||
embed.addField(`Title ${i + 1}`, team.join('\n'));
|
||||
});
|
||||
/**
|
||||
* checks if the interaction data is already in the queue
|
||||
* @param interaction
|
||||
* @returns boolean
|
||||
*/
|
||||
function queueContains(interaction) {
|
||||
let { member, info } = getAll(interaction);
|
||||
if (info.players.map(m => m.id).includes(member.id))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
QueueCommands.queueContains = queueContains;
|
||||
/**
|
||||
* creates a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be left
|
||||
*/
|
||||
function queueCreate(interaction) {
|
||||
(0, util_1.memberIsModThrow)(interaction);
|
||||
let { channelId } = interaction, teamsize = interaction.options.getInteger('teamsize', true);
|
||||
if (QUEUE.has(channelId))
|
||||
throw (0, util_1.emsg)(`There is already an active queue in this channel for teams of ${QUEUE.get(channelId)?.teamsize}`);
|
||||
Queue.create(channelId, teamsize);
|
||||
interaction.reply(`A queue for teams of ${teamsize} has been started`);
|
||||
}
|
||||
QueueCommands.queueCreate = queueCreate;
|
||||
/**
|
||||
* opens a queue
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be left
|
||||
*/
|
||||
async function open(interaction) {
|
||||
queueCreate(interaction);
|
||||
}
|
||||
QueueCommands.open = open;
|
||||
/**
|
||||
* closes a queue
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be joined
|
||||
*/
|
||||
async function close(interaction) {
|
||||
(0, util_1.memberIsModThrow)(interaction);
|
||||
QUEUE.delete(interaction.channelId);
|
||||
await interaction.reply('Queue has been reset');
|
||||
}
|
||||
QueueCommands.close = close;
|
||||
/**
|
||||
* gives info about the queue
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be left
|
||||
*/
|
||||
async function queue(interaction) {
|
||||
let info = getInfo(interaction);
|
||||
let embed = new discord_js_1.MessageEmbed()
|
||||
.setTitle('Active Queue')
|
||||
.addField('Team Size', info.teamsize.toString(), true)
|
||||
.addField('Players Joined', info.players.length.toString(), true)
|
||||
.setFooter({ text: 'type /join' });
|
||||
await interaction.reply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
QueueCommands.queue = queue;
|
||||
/**
|
||||
* joins a queue
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be readied
|
||||
*/
|
||||
async function join(interaction) {
|
||||
let { member, info, channel } = getAll(interaction);
|
||||
if (queueContains(interaction))
|
||||
throw (0, util_1.emsg)('You are already in the queue');
|
||||
info.players.push(member);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
await interaction.reply('Joined the queue');
|
||||
checkQueue(channel);
|
||||
}
|
||||
QueueCommands.join = join;
|
||||
/**
|
||||
* leaves a queue
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be reset
|
||||
*/
|
||||
async function leave(interaction) {
|
||||
let { member, info } = getAll(interaction);
|
||||
if (!queueContains(interaction))
|
||||
throw (0, util_1.emsg)('You aren\'t in the queue');
|
||||
info.players.splice(info.players.indexOf(member), 1);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
await interaction.reply('Left the queue');
|
||||
}
|
||||
QueueCommands.leave = leave;
|
||||
})(QueueCommands = exports.QueueCommands || (exports.QueueCommands = {}));
|
||||
interaction.reply({ embeds: [embed] });
|
||||
}
|
||||
/**
|
||||
* sends the list of teams
|
||||
* @param interaction
|
||||
*/
|
||||
async function clearQueue(interaction) {
|
||||
let info = getInfo(interaction);
|
||||
sendQueueEmbed(interaction, true);
|
||||
clearTimeout(info.timeout);
|
||||
QUEUE.delete(interaction.channelId);
|
||||
}
|
||||
/**
|
||||
* creates a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be created
|
||||
*/
|
||||
async function createQueue(interaction) {
|
||||
let member = (0, util_1.getMember)(interaction), { channelId } = interaction, teamsize = interaction.options.getInteger('teamsize', true);
|
||||
if (QUEUE.has(channelId))
|
||||
throw (0, util_1.emsg)('There is already an active queue in this channel, ' + (queueContains(interaction) ? 'and you are already in it' : 'type `/join` to join'));
|
||||
QUEUE.set(channelId, {
|
||||
players: [
|
||||
member
|
||||
],
|
||||
initiator: {
|
||||
interaction,
|
||||
member
|
||||
},
|
||||
teamsize: teamsize,
|
||||
timeout: setQueueTimeout(interaction)
|
||||
});
|
||||
sendQueueEmbed(interaction);
|
||||
}
|
||||
exports.createQueue = createQueue;
|
||||
/**
|
||||
* joins a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be joined
|
||||
*/
|
||||
async function joinQueue(interaction) {
|
||||
let { member, info } = (0, exports.getAll)(interaction);
|
||||
if (queueContains(interaction))
|
||||
throw (0, util_1.emsg)('You are already in the active queue');
|
||||
info.players.push(member);
|
||||
clearTimeout(info.timeout);
|
||||
info.timeout = setQueueTimeout(interaction);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
sendQueueEmbed(interaction);
|
||||
await interaction.reply('Joined the queue');
|
||||
}
|
||||
exports.joinQueue = joinQueue;
|
||||
/**
|
||||
* leaves a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be left
|
||||
*/
|
||||
async function leaveQueue(interaction) {
|
||||
let { member, info } = (0, exports.getAll)(interaction);
|
||||
if (!queueContains(interaction))
|
||||
throw (0, util_1.emsg)('You aren\'t in the active queue');
|
||||
info.players.splice(info.players.indexOf(member), 1);
|
||||
clearTimeout(info.timeout);
|
||||
info.timeout = setQueueTimeout(interaction);
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
sendQueueEmbed(interaction);
|
||||
await interaction.reply('Left the queue');
|
||||
}
|
||||
exports.leaveQueue = leaveQueue;
|
||||
/**
|
||||
* readys a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be readied
|
||||
*/
|
||||
async function readyQueue(interaction) {
|
||||
let { member, info } = (0, exports.getAll)(interaction), { initiator } = info;
|
||||
if (member.id !== initiator.member.id)
|
||||
throw (0, util_1.emsg)('Only the queue initiator can ready the queue');
|
||||
clearQueue(interaction);
|
||||
if (info.players.filter(m => m.id !== initiator.member.id).length === 0)
|
||||
throw (0, util_1.emsg)('Nobody signed up for the queue, the queue has been reset');
|
||||
//team data
|
||||
let playerlist = (0, util_1.shuffle)(info.players), teams = [];
|
||||
//fill team data
|
||||
for (let i = 0; i < playerlist.length; i += info.teamsize)
|
||||
teams.push(playerlist.slice(i, i + info.teamsize));
|
||||
sendTeamsEmbed(interaction, teams);
|
||||
}
|
||||
exports.readyQueue = readyQueue;
|
||||
/**
|
||||
* readys a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be reset
|
||||
*/
|
||||
async function cancelQueue(interaction) {
|
||||
let { info, member, channel } = (0, exports.getAll)(interaction);
|
||||
if (!member.permissionsIn(channel).has('MANAGE_MESSAGES'))
|
||||
throw (0, util_1.emsg)('You do not have permission to run this command');
|
||||
clearQueue(interaction);
|
||||
await interaction.reply('Queue has been reset');
|
||||
}
|
||||
exports.cancelQueue = cancelQueue;
|
||||
|
||||
12
dist/util.js
vendored
12
dist/util.js
vendored
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.memberIsModThrow = exports.memberIsMod = exports.getChannel = exports.getMember = exports.emsg = exports.errorMessage = exports.shuffle = void 0;
|
||||
exports.getChannel = exports.getMember = exports.emsg = exports.errorMessage = exports.shuffle = void 0;
|
||||
const discord_js_1 = require("discord.js");
|
||||
/**
|
||||
* shuffles an array
|
||||
@@ -64,13 +64,3 @@ function getChannel(interaction) {
|
||||
return channel;
|
||||
}
|
||||
exports.getChannel = getChannel;
|
||||
function memberIsMod(interaction) {
|
||||
let member = getMember(interaction);
|
||||
return member.permissionsIn(interaction.channelId).has('MANAGE_MESSAGES');
|
||||
}
|
||||
exports.memberIsMod = memberIsMod;
|
||||
function memberIsModThrow(interaction) {
|
||||
if (!memberIsMod(interaction))
|
||||
throw (0, exports.emsg)('Member is not a moderator');
|
||||
}
|
||||
exports.memberIsModThrow = memberIsModThrow;
|
||||
|
||||
6
package-lock.json
generated
6
package-lock.json
generated
@@ -1,21 +1,21 @@
|
||||
{
|
||||
"name": "1800queue",
|
||||
"name": "1800queue-alt",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "1800queue",
|
||||
"name": "1800queue-alt",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@discordjs/rest": "^0.3.0",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"discord-api-types": "^0.26.1",
|
||||
"discord.js": "^13.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^17.0.13",
|
||||
"discord-api-types": "^0.26.1",
|
||||
"npm-watch": "^0.11.0",
|
||||
"ts-node": "^10.4.0",
|
||||
"typescript": "^4.5.5"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "1800queue",
|
||||
"name": "1800queue-alt",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
@@ -33,12 +33,12 @@
|
||||
"@types/node": "^17.0.13",
|
||||
"npm-watch": "^0.11.0",
|
||||
"ts-node": "^10.4.0",
|
||||
"discord-api-types": "^0.26.1",
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@discordjs/rest": "^0.3.0",
|
||||
"cheerio": "^1.0.0-rc.10",
|
||||
"discord-api-types": "^0.26.1",
|
||||
"discord.js": "^13.6.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ cd ../..
|
||||
npm install
|
||||
|
||||
#discord token
|
||||
[ ! -f "token.txt" ] && touch "token.txt"
|
||||
[ ! -f "token" ] && touch "token"
|
||||
|
||||
if [ ! -s "token.txt" ]
|
||||
if [ ! -s "token" ]
|
||||
then
|
||||
printf "Enter your discord bot token: "
|
||||
read token
|
||||
printf $token > "token.txt"
|
||||
printf $token > "token"
|
||||
fi
|
||||
@@ -4,12 +4,12 @@
|
||||
cd %~f0\..\..\..\
|
||||
|
||||
@REM discord token
|
||||
if not exist "token.txt" copy NUL "token.txt"
|
||||
if not exist "token" copy NUL "token"
|
||||
|
||||
for /f %%i in ("token.txt") do set size=%%~zi
|
||||
for /f %%i in ("token") do set size=%%~zi
|
||||
if %size% equ 0 (
|
||||
set /p token="Enter your discord bot token: "
|
||||
echo | set /p=%id% > "token.txt"
|
||||
echo | set /p=%id% > "token"
|
||||
)
|
||||
|
||||
@REM run
|
||||
|
||||
@@ -4,27 +4,18 @@ import { Routes } from 'discord-api-types/v9';
|
||||
// list of commands to register with discord
|
||||
const commands = [
|
||||
{
|
||||
name: 'open',
|
||||
description: 'open a queue for this channel',
|
||||
name: 'queue',
|
||||
description: 'create a queue',
|
||||
options: [
|
||||
{
|
||||
type: 4, //INTEGER
|
||||
name: 'teamsize',
|
||||
description: 'size of each team',
|
||||
min_value: 1,
|
||||
required: true
|
||||
required: true,
|
||||
min_value: 1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'close',
|
||||
description: 'close the queue for this channel'
|
||||
},
|
||||
|
||||
{
|
||||
name: 'queue',
|
||||
description: 'view queue info'
|
||||
},
|
||||
{
|
||||
name: 'join',
|
||||
description: 'join the active queue'
|
||||
@@ -34,8 +25,12 @@ const commands = [
|
||||
description: 'leave the active queue'
|
||||
},
|
||||
{
|
||||
name: 'stop',
|
||||
description: 'stops the current queue (must have the Manage Messages permission)'
|
||||
name: 'ready',
|
||||
description: 'ready the queue and display team info'
|
||||
},
|
||||
{
|
||||
name: 'cancel',
|
||||
description: 'cancels the current queue (must have the Manage Messages permission)'
|
||||
},
|
||||
{
|
||||
name: 'player',
|
||||
@@ -49,8 +44,7 @@ const commands = [
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
commandNames = commands.map(c => c.name);
|
||||
];
|
||||
|
||||
/**
|
||||
* register/reload commands on guild(s)
|
||||
|
||||
46
src/index.ts
46
src/index.ts
@@ -3,7 +3,7 @@ import { Client, Intents } from 'discord.js';
|
||||
import * as fs from 'fs';
|
||||
import { getPlayerInteraction } from './api';
|
||||
import { registerCommands } from './discord';
|
||||
import { discordInit, QueueCommands } from './queue';
|
||||
import { cancelQueue, createQueue, joinQueue, leaveQueue, readyQueue } from './queue';
|
||||
import { errorMessage } from './util';
|
||||
const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
||||
|
||||
@@ -11,19 +11,18 @@ const CLIENT = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
||||
console.log(new Date().toISOString()+'\n\n');
|
||||
|
||||
//get token
|
||||
if (!fs.existsSync('./token.txt')) {
|
||||
fs.writeFileSync('./token.txt', '');
|
||||
if (!fs.existsSync('./token')) {
|
||||
fs.writeFileSync('./token', '');
|
||||
console.error('Missing Discord Token, please enter the bot token into the token file');
|
||||
process.exit(1);
|
||||
}
|
||||
const TOKEN = fs.readFileSync('./token.txt').toString();
|
||||
const TOKEN = fs.readFileSync('./token').toString();
|
||||
|
||||
//discord connections
|
||||
CLIENT.on('ready', client => {
|
||||
console.log(`Logged in as ${client.user.tag}`);
|
||||
client.guilds.fetch().then(guilds =>
|
||||
registerCommands(TOKEN, client.user.id, guilds.map(g => g.id)));
|
||||
discordInit(client);
|
||||
});
|
||||
|
||||
CLIENT.on('interactionCreate', async interaction => {
|
||||
@@ -31,31 +30,18 @@ CLIENT.on('interactionCreate', async interaction => {
|
||||
|
||||
try {
|
||||
|
||||
switch (interaction.commandName) {
|
||||
|
||||
//mod commands
|
||||
case 'open':
|
||||
await QueueCommands.open(interaction);
|
||||
break;
|
||||
case 'close':
|
||||
await QueueCommands.close(interaction);
|
||||
break;
|
||||
|
||||
//general commands
|
||||
case 'queue':
|
||||
await QueueCommands.queue(interaction);
|
||||
break;
|
||||
case 'join':
|
||||
await QueueCommands.join(interaction);
|
||||
break;
|
||||
case 'leave':
|
||||
await QueueCommands.leave(interaction);
|
||||
break;
|
||||
case 'player':
|
||||
await getPlayerInteraction(interaction);
|
||||
break;
|
||||
|
||||
}
|
||||
if (interaction.commandName === 'queue')
|
||||
await createQueue(interaction);
|
||||
else if (interaction.commandName === 'join')
|
||||
await joinQueue(interaction);
|
||||
else if (interaction.commandName === 'leave')
|
||||
await leaveQueue(interaction);
|
||||
else if (interaction.commandName === 'ready')
|
||||
await readyQueue(interaction);
|
||||
else if (interaction.commandName === 'cancel')
|
||||
await cancelQueue(interaction);
|
||||
else if (interaction.commandName === 'player')
|
||||
await getPlayerInteraction(interaction);
|
||||
|
||||
} catch (e) {
|
||||
|
||||
|
||||
442
src/queue.ts
442
src/queue.ts
@@ -1,266 +1,236 @@
|
||||
/* TODO
|
||||
import { CommandInteraction, GuildMember, MessageEmbed } from "discord.js";
|
||||
import { emsg, getChannel, getMember, queueInfo, shuffle } from "./util";
|
||||
|
||||
join message should contain your current position in the queue, editing it to keep it current
|
||||
*/
|
||||
//maps ChannelID to QueueInfo
|
||||
const QUEUE = new Map<string, queueInfo>();
|
||||
|
||||
import { Client, CommandInteraction, GuildMember, MessageEmbed, TextChannel } from "discord.js";
|
||||
import * as fs from 'fs';
|
||||
import { emsg, getChannel, getMember, memberIsModThrow, queueInfo, queueInfoBase } from "./util";
|
||||
|
||||
//load queues from file
|
||||
if (!fs.existsSync('./queues.json'))
|
||||
fs.writeFileSync('./queues.json', '{}');
|
||||
|
||||
const _QUEUE = fs.readFileSync('./queues.json').toString(),
|
||||
QUEUE = new Map<string, queueInfo>();
|
||||
|
||||
try {
|
||||
|
||||
let queueJson = JSON.parse(_QUEUE);
|
||||
|
||||
for (let channelId in queueJson) {
|
||||
let {teamsize} = queueJson[channelId] as queueInfoBase;
|
||||
if (teamsize)
|
||||
QUEUE.set(channelId, { teamsize, players: [] })
|
||||
}
|
||||
|
||||
} catch(e) {}
|
||||
|
||||
function SaveQueue() {
|
||||
|
||||
let queueJson = Object.fromEntries(QUEUE),
|
||||
queueFileJson: {[keys: string]: queueInfoBase} = {};
|
||||
|
||||
for (let channelId of QUEUE.keys())
|
||||
queueFileJson[channelId] = { teamsize: queueJson[channelId].teamsize };
|
||||
|
||||
fs.writeFileSync('./queues.json', JSON.stringify(queueFileJson, null, 2));
|
||||
|
||||
}
|
||||
|
||||
async function checkQueue(channel: TextChannel) {
|
||||
let info = QUEUE.get(channel.id);
|
||||
/**
|
||||
* get the queueInfo of an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it does not exist
|
||||
* @returns queue info
|
||||
*/
|
||||
export function getInfo(interaction: CommandInteraction): queueInfo {
|
||||
let info = QUEUE.get(interaction.channelId);
|
||||
|
||||
if (!info)
|
||||
return;
|
||||
|
||||
if (info.players.length >= info.teamsize) {
|
||||
|
||||
let team = info.players.splice(0, info.teamsize).map(m => m.toString());
|
||||
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle('Team')
|
||||
.setDescription(team.join('\n'));
|
||||
|
||||
await channel.send({embeds: [embed]});
|
||||
|
||||
}
|
||||
throw emsg('There is not an active queue in this channel, type `/queue` to create one');
|
||||
|
||||
return info;
|
||||
}
|
||||
namespace Queue {
|
||||
|
||||
export function create(channelId: string, teamsize: number) {
|
||||
if (!QUEUE.has(channelId)) {
|
||||
QUEUE.set(channelId, {teamsize, players: []});
|
||||
SaveQueue();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* compiles all the get functions above
|
||||
* @param interaction
|
||||
* @throws if another get function throws
|
||||
* @returns object containing each
|
||||
*/
|
||||
export const getAll = (interaction: CommandInteraction) => ({
|
||||
member: getMember(interaction),
|
||||
channel: getChannel(interaction),
|
||||
info: getInfo(interaction)
|
||||
});
|
||||
|
||||
export function remove(channelId: string) {
|
||||
if (QUEUE.has(channelId)) {
|
||||
QUEUE.delete(channelId);
|
||||
SaveQueue();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* checks if the interaction data is already in the queue
|
||||
* @param interaction
|
||||
* @returns boolean
|
||||
*/
|
||||
export function queueContains(interaction: CommandInteraction): boolean {
|
||||
|
||||
export function addPlayer(channelId: string, member: GuildMember) {
|
||||
if (QUEUE.has(channelId)) {
|
||||
QUEUE.delete(channelId);
|
||||
}
|
||||
}
|
||||
let {member, info} = getAll(interaction);
|
||||
|
||||
export function removePlayer(channelId: string, member: GuildMember) {
|
||||
if (QUEUE.has(channelId)) {
|
||||
QUEUE.delete(channelId);
|
||||
}
|
||||
}
|
||||
if (info.players.map(m=>m.id).includes(member.id))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
SaveQueue();
|
||||
/**
|
||||
* creates the timeout for the queue
|
||||
* @param interaction
|
||||
* @returns time timeout identifier
|
||||
*/
|
||||
function setQueueTimeout(interaction: CommandInteraction) {
|
||||
let channel = getChannel(interaction);
|
||||
return setTimeout(() => {
|
||||
clearQueue(interaction);
|
||||
channel.send('Queue has been reset due to inactivity');
|
||||
}, 5*60*1000) //5 minutes
|
||||
}
|
||||
|
||||
export async function discordInit(client: Client) {
|
||||
/**
|
||||
* updates the rich embed for the current queue
|
||||
* @param interaction
|
||||
*/
|
||||
async function sendQueueEmbed(interaction: CommandInteraction, closed: boolean = false) {
|
||||
let info = getInfo(interaction),
|
||||
origInteraction = info.initiator.interaction;
|
||||
|
||||
for (let channelId in QUEUE.keys()) {
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle('Queue')
|
||||
.setAuthor({
|
||||
name: info.initiator.member.displayName,
|
||||
iconURL: info.initiator.member.displayAvatarURL({dynamic: true})
|
||||
})
|
||||
.addField('Team Size', info.teamsize.toString(), true)
|
||||
.addField('Players Joined', info.players.length.toString(), true)
|
||||
.setFooter({text: closed ? 'queue is finished' : 'type /join'});
|
||||
|
||||
let info = QUEUE.get(channelId),
|
||||
channel = await client.channels.fetch(channelId);
|
||||
if (origInteraction.deferred || origInteraction.replied)
|
||||
await origInteraction.editReply({embeds: [embed]});
|
||||
else
|
||||
await origInteraction.reply({embeds: [embed]});
|
||||
}
|
||||
|
||||
if (!info) { //no idea what could cause this but TS complains
|
||||
Queue.remove(channelId);
|
||||
continue;
|
||||
}
|
||||
/**
|
||||
* sends the list of teams
|
||||
* @param interaction
|
||||
*/
|
||||
async function sendTeamsEmbed(interaction: CommandInteraction, teams: GuildMember[][]) {
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle('Teams');
|
||||
|
||||
if (!channel || !(channel instanceof TextChannel)) {
|
||||
console.error(`Unable to find channel ${channelId} for teams of ${info?.teamsize}`);
|
||||
Queue.remove(channelId);
|
||||
continue;
|
||||
}
|
||||
teams.forEach((team, i) => {
|
||||
team.map(m => m.user.tag);
|
||||
embed.addField(`Team ${i+1}`, team.join('\n'))
|
||||
});
|
||||
|
||||
channel.send('The bot has just restarted and anybody in the queues have been reset')
|
||||
interaction.reply({embeds: [embed]});
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* sends the list of teams
|
||||
* @param interaction
|
||||
*/
|
||||
async function clearQueue(interaction: CommandInteraction) {
|
||||
let info = getInfo(interaction);
|
||||
sendQueueEmbed(interaction, true);
|
||||
clearTimeout(info.timeout);
|
||||
QUEUE.delete(interaction.channelId);
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be created
|
||||
*/
|
||||
export async function createQueue(interaction: CommandInteraction) {
|
||||
|
||||
let member = getMember(interaction),
|
||||
{channelId} = interaction,
|
||||
teamsize = interaction.options.getInteger('teamsize', true);
|
||||
|
||||
if (QUEUE.has(channelId))
|
||||
throw emsg('There is already an active queue in this channel, ' + (queueContains(interaction) ? 'and you are already in it' : 'type `/join` to join'));
|
||||
|
||||
QUEUE.set(channelId, {
|
||||
players: [
|
||||
member
|
||||
],
|
||||
initiator: {
|
||||
interaction,
|
||||
member
|
||||
},
|
||||
teamsize: teamsize,
|
||||
timeout: setQueueTimeout(interaction)
|
||||
});
|
||||
|
||||
sendQueueEmbed(interaction);
|
||||
|
||||
}
|
||||
export namespace QueueCommands {
|
||||
|
||||
/**
|
||||
* get the queueInfo of an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it does not exist
|
||||
* @returns queue info
|
||||
*/
|
||||
function getInfo(interaction: CommandInteraction): queueInfo {
|
||||
let info = QUEUE.get(interaction.channelId);
|
||||
/**
|
||||
* joins a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be joined
|
||||
*/
|
||||
export async function joinQueue(interaction: CommandInteraction) {
|
||||
|
||||
if (!info)
|
||||
throw emsg('There is not an active queue in this channel, type `/queue` to create one');
|
||||
let {member, info} = getAll(interaction);
|
||||
|
||||
return info;
|
||||
}
|
||||
if (queueContains(interaction))
|
||||
throw emsg('You are already in the active queue');
|
||||
|
||||
/**
|
||||
* compiles all the get functions above
|
||||
* @param interaction
|
||||
* @throws if another get function throws
|
||||
* @returns object containing each
|
||||
*/
|
||||
const getAll = (interaction: CommandInteraction) => ({
|
||||
member: getMember(interaction),
|
||||
channel: getChannel(interaction),
|
||||
info: getInfo(interaction)
|
||||
});
|
||||
info.players.push(member);
|
||||
clearTimeout(info.timeout);
|
||||
info.timeout = setQueueTimeout(interaction)
|
||||
|
||||
/**
|
||||
* checks if the interaction data is already in the queue
|
||||
* @param interaction
|
||||
* @returns boolean
|
||||
*/
|
||||
export function queueContains(interaction: CommandInteraction): boolean {
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
|
||||
let {member, info} = getAll(interaction);
|
||||
|
||||
if (info.players.map(m=>m.id).includes(member.id))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be left
|
||||
*/
|
||||
export function queueCreate(interaction: CommandInteraction) {
|
||||
memberIsModThrow(interaction);
|
||||
|
||||
let {channelId} = interaction,
|
||||
teamsize = interaction.options.getInteger('teamsize', true);
|
||||
|
||||
if (QUEUE.has(channelId))
|
||||
throw emsg(`There is already an active queue in this channel for teams of ${QUEUE.get(channelId)?.teamsize}`);
|
||||
|
||||
Queue.create(channelId, teamsize);
|
||||
|
||||
interaction.reply(`A queue for teams of ${teamsize} has been started`)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* opens a queue
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be left
|
||||
*/
|
||||
export async function open(interaction: CommandInteraction) {
|
||||
|
||||
queueCreate(interaction);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* closes a queue
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be joined
|
||||
*/
|
||||
export async function close(interaction: CommandInteraction) {
|
||||
memberIsModThrow(interaction);
|
||||
|
||||
QUEUE.delete(interaction.channelId);
|
||||
|
||||
await interaction.reply('Queue has been reset');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* gives info about the queue
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be left
|
||||
*/
|
||||
export async function queue(interaction: CommandInteraction) {
|
||||
|
||||
let info = getInfo(interaction);
|
||||
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle('Active Queue')
|
||||
.addField('Team Size', info.teamsize.toString(), true)
|
||||
.addField('Players Joined', info.players.length.toString(), true)
|
||||
.setFooter({text: 'type /join'});
|
||||
|
||||
await interaction.reply({embeds: [embed], ephemeral: true});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* joins a queue
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be readied
|
||||
*/
|
||||
export async function join(interaction: CommandInteraction) {
|
||||
|
||||
let {member, info, channel} = getAll(interaction);
|
||||
|
||||
if (queueContains(interaction))
|
||||
throw emsg('You are already in the queue');
|
||||
|
||||
info.players.push(member);
|
||||
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
|
||||
await interaction.reply('Joined the queue');
|
||||
|
||||
checkQueue(channel);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* leaves a queue
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be reset
|
||||
*/
|
||||
export async function leave(interaction: CommandInteraction) {
|
||||
|
||||
let {member, info} = getAll(interaction);
|
||||
|
||||
if (!queueContains(interaction))
|
||||
throw emsg('You aren\'t in the queue');
|
||||
|
||||
info.players.splice(info.players.indexOf(member), 1);
|
||||
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
|
||||
await interaction.reply('Left the queue');
|
||||
|
||||
}
|
||||
sendQueueEmbed(interaction);
|
||||
await interaction.reply('Joined the queue');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* leaves a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be left
|
||||
*/
|
||||
export async function leaveQueue(interaction: CommandInteraction) {
|
||||
|
||||
let {member, info} = getAll(interaction);
|
||||
|
||||
if (!queueContains(interaction))
|
||||
throw emsg('You aren\'t in the active queue');
|
||||
|
||||
info.players.splice(info.players.indexOf(member), 1);
|
||||
clearTimeout(info.timeout);
|
||||
info.timeout = setQueueTimeout(interaction)
|
||||
|
||||
QUEUE.set(interaction.channelId, info);
|
||||
|
||||
sendQueueEmbed(interaction);
|
||||
await interaction.reply('Left the queue');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* readys a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be readied
|
||||
*/
|
||||
export async function readyQueue(interaction: CommandInteraction) {
|
||||
|
||||
let {member, info} = getAll(interaction),
|
||||
{initiator} = info;
|
||||
|
||||
if (member.id !== initiator.member.id)
|
||||
throw emsg('Only the queue initiator can ready the queue');
|
||||
|
||||
clearQueue(interaction);
|
||||
|
||||
if (info.players.filter(m => m.id !== initiator.member.id).length === 0)
|
||||
throw emsg('Nobody signed up for the queue, the queue has been reset');
|
||||
|
||||
//team data
|
||||
let playerlist: GuildMember[] = shuffle(info.players),
|
||||
teams: GuildMember[][] = [];
|
||||
|
||||
//fill team data
|
||||
for (let i = 0; i < playerlist.length; i+= info.teamsize)
|
||||
teams.push(playerlist.slice(i, i+info.teamsize));
|
||||
|
||||
sendTeamsEmbed(interaction, teams);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* readys a queue from an interaction
|
||||
* @param interaction
|
||||
* @throws errorMessage class if it cannot be reset
|
||||
*/
|
||||
export async function cancelQueue(interaction: CommandInteraction) {
|
||||
|
||||
let {info, member, channel} = getAll(interaction);
|
||||
|
||||
if (!member.permissionsIn(channel).has('MANAGE_MESSAGES'))
|
||||
throw emsg('You do not have permission to run this command');
|
||||
|
||||
clearQueue(interaction);
|
||||
|
||||
await interaction.reply('Queue has been reset');
|
||||
|
||||
}
|
||||
|
||||
24
src/util.ts
24
src/util.ts
@@ -46,11 +46,14 @@ export const emsg = (msg: string, ephemeral: boolean = true) => new errorMessage
|
||||
|
||||
|
||||
|
||||
export interface queueInfoBase {
|
||||
teamsize: number
|
||||
}
|
||||
export interface queueInfo extends queueInfoBase{
|
||||
players: GuildMember[]
|
||||
export type queueInfo = {
|
||||
players: GuildMember[],
|
||||
initiator: {
|
||||
interaction: CommandInteraction,
|
||||
member: GuildMember
|
||||
},
|
||||
teamsize: number,
|
||||
timeout: NodeJS.Timeout
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,14 +85,3 @@ export function getChannel(interaction: CommandInteraction): TextChannel {
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
|
||||
export function memberIsMod(interaction: CommandInteraction): boolean {
|
||||
let member = getMember(interaction);
|
||||
return member.permissionsIn(interaction.channelId).has('MANAGE_MESSAGES');
|
||||
}
|
||||
|
||||
export function memberIsModThrow(interaction: CommandInteraction) {
|
||||
if (!memberIsMod(interaction))
|
||||
throw emsg('Member is not a moderator');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user