ability to add and remove participants to events
This commit is contained in:
parent
12f2a4d1d4
commit
c96591c8c7
|
@ -0,0 +1,38 @@
|
|||
const { SlashCommandBuilder, MessageFlags, EmbedBuilder } = require('discord.js');
|
||||
const { updateTournamentsJSON, xhr } = require("../../utils.js");
|
||||
const { tournaments } = require("../../index.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('add_participant')
|
||||
.setDescription('Добавить игрока в список регистрантов/участников в обход всех проверок')
|
||||
.addUserOption(option =>
|
||||
option.setName('user')
|
||||
.setDescription('Пользователь, с которым ассоциируется данный игрок')
|
||||
.setRequired(true))
|
||||
.addStringOption(option =>
|
||||
option.setName('key')
|
||||
.setDescription('Время создания события')
|
||||
.setRequired(true)),
|
||||
async execute(interaction) {
|
||||
const t = tournaments.get(interaction.options.getString('key'));
|
||||
if(!t){interaction.reply({ content: `Нет турнира с таким id`, flags: MessageFlags.Ephemeral }); return}
|
||||
const user = interaction.options.getUser('user');
|
||||
// Checking, if user has linked his TETR.IO account
|
||||
const search = await xhr.get(`https://ch.tetr.io/api/users/search/discord:${user.id}`);
|
||||
if (!search.success || !search.data) {interaction.reply({ content: `Не смог получить данные о челике`, flags: MessageFlags.Ephemeral }); return}
|
||||
|
||||
// Trying to get data about the user
|
||||
const userData = await Promise.all([xhr.get(`https://ch.tetr.io/api/users/${search.data.user._id}`), xhr.get(`https://ch.tetr.io/api/users/${search.data.user._id}/summaries/league`)]);
|
||||
if (!userData[0].success || !userData[1].success){interaction.reply({ content: `Не смог получить данные о челике`, flags: MessageFlags.Ephemeral }); return}
|
||||
|
||||
t.register(user.id, userData[0], userData[1]);
|
||||
interaction.guild.members.addRole({ user: user, reason: `${interaction.user.username} принял его на этот турнир`, role: t.participant_role });
|
||||
if (t.status === 1) {
|
||||
t.check_in(user.id);
|
||||
interaction.guild.members.addRole({ user: user, reason: `${interaction.user.username} принял его на этот турнир`, role: t.checked_in_role });
|
||||
}
|
||||
interaction.reply({ content: `Готово`, flags: MessageFlags.Ephemeral });
|
||||
updateTournamentsJSON();
|
||||
},
|
||||
};
|
|
@ -20,6 +20,8 @@ module.exports = {
|
|||
const msg_channel = await interaction.client.channels.fetch(t.channelID);
|
||||
const msg = await msg_channel.messages.fetch(t.messageID);
|
||||
msg.delete();
|
||||
const check_in_msg = await msg_channel.messages.fetch(t.checkInMessageID);
|
||||
check_in_msg.delete();
|
||||
interaction.reply({ content: `Готово`, flags: MessageFlags.Ephemeral });
|
||||
}catch(e){
|
||||
interaction.reply({ content: `Не всё прошло гладко, но турнир из бота был удален\n\`${e}\``, flags: MessageFlags.Ephemeral });
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
const { SlashCommandBuilder, MessageFlags, EmbedBuilder } = require('discord.js');
|
||||
const { updateTournamentsJSON } = require("../../utils.js");
|
||||
const { tournaments } = require("../../index.js");
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('remove_participant')
|
||||
.setDescription('Удалить игрока из списка регистрантов/участников')
|
||||
.addUserOption(option =>
|
||||
option.setName('user')
|
||||
.setDescription('Пользователь, с которым ассоциируется данный игрок')
|
||||
.setRequired(true))
|
||||
.addStringOption(option =>
|
||||
option.setName('key')
|
||||
.setDescription('Время создания события')
|
||||
.setRequired(true)),
|
||||
async execute(interaction) {
|
||||
const t = tournaments.get(interaction.options.getString('key'));
|
||||
if(!t){interaction.reply({ content: `Нет турнира с таким id`, flags: MessageFlags.Ephemeral }); return}
|
||||
const user = interaction.options.getUser('user');
|
||||
interaction.guild.members.removeRole({ user: user, reason: `${interaction.user.username} удалил его из этого турнира`, role: t.participant_role });
|
||||
t.removeParticipant(user.id);
|
||||
if (t.status === 1){
|
||||
t.removeChecked(user.id);
|
||||
interaction.guild.members.removeRole({ user: user, reason: `${interaction.user.username} удалил его из этого турнира`, role: t.checked_in_role });
|
||||
}
|
||||
updateTournamentsJSON();
|
||||
},
|
||||
};
|
2
index.js
2
index.js
|
@ -137,7 +137,7 @@ client.on('ready', () => {
|
|||
});
|
||||
|
||||
collector.on('remove', async (reaction, user) => {
|
||||
check_in_message.guild.members.addRole({ user: user, reason: "Расхотел участвовать", role: value.checked_in_role });
|
||||
check_in_message.guild.members.removeRole({ user: user, reason: "Расхотел участвовать", role: value.checked_in_role });
|
||||
console.log(`${user.tag} unregistred for a ${value.title} event`);
|
||||
value.removeChecked(user.id);
|
||||
updateTournamentsJSON();
|
||||
|
|
2
utils.js
2
utils.js
|
@ -100,7 +100,7 @@ async function reactionCheck(reaction, user, client, guild, teto, reg_role) {
|
|||
// Checking, if user is from CIS
|
||||
const cisCountries = ["RU", "BY", "AM", "AZ", "KZ", "KG", "MD", "TJ", "UZ", "TM", "UA"];
|
||||
const { blacklist, whitelist } = require("./index.js");
|
||||
if (!teto.international && (!cisCountries.includes(userData[0].data.country) || blacklist.has(user.id)) && !whitelist.has(user.id)){deny('Ваша регистрация отклонена', `${blacklist.includes(userData[0].data._id) ? "По данным, которые есть у нашей организации" : "Судя по вашему профилю в TETR.IO"}, вы не из СНГ`); return}
|
||||
if (!teto.international && (!cisCountries.includes(userData[0].data.country) || blacklist.has(user.id)) && !whitelist.has(user.id)){deny('Ваша регистрация отклонена', `${blacklist.has(userData[0].data._id) ? "По данным, которые есть у нашей организации" : "Судя по вашему профилю в TETR.IO"}, вы не из СНГ`); return}
|
||||
|
||||
// Finally, if everything is ok - add him to participants list
|
||||
teto.register(user.id, userData[0], userData[1]);
|
||||
|
|
Loading…
Reference in New Issue