Skip to content

Commit

Permalink
상호작용 실패로 봇이 죽는 버그 수
Browse files Browse the repository at this point in the history
  • Loading branch information
JooDdae committed Feb 19, 2024
1 parent 86c41f4 commit 4f96535
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/commands/updowndefense/updown-random-defense.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ module.exports = {
// botsPermissions: [PermissionFlagsBits.Administrator],
options: [
{
name: '쿼리변경',
description: '변경할 쿼리를 입력해주세요.',
name: '추가쿼리변경',
description: '문제를 선택할 때 사용할 추가 쿼리를 변경합니다.',
type: ApplicationCommandOptionType.String,
},
{
Expand Down
34 changes: 20 additions & 14 deletions src/updowndefense/startNewDefense.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const numberToTier = require('../utils/numberToTier');
const numberToKoTime = require('../utils/numberToKoTime');
const getTimeLimit = require('../utils/getTimeLimit');

const defenseParticipants = new Map();
const defenseParticipants = new Set();
const inButtonProgress = new Set();

/**
*
Expand Down Expand Up @@ -38,10 +39,9 @@ module.exports = async (interaction) => {
return interaction.editReply({ content: `${problemQuery}에 해당하는 문제가 존재하지 않습니다. \`/updown-random-defense [쿼리]\` 명령어를 통해 난이도를 변경하거나 추가 쿼리를 변경해주세요.` });
}


// 디펜스 준비
const randomString = Math.random().toString(15).substring(2, 15) + Math.random().toString(15).substring(2, 15);
defenseParticipants.set(userId, randomString);
defenseParticipants.add(userId);

const problem = problems[0];
const { problemId, titleKo: problemTitle } = problem;
Expand Down Expand Up @@ -154,11 +154,10 @@ module.exports = async (interaction) => {
const submissions = await getSubmissionsBetween(updownDefense.bojId, problemId, lastSubmissionId);
let submissionStatus = '';
for (const submission of submissions) {
if(submissionStatus.length > 0 && submissionStatus.length % 10 === 0) submissionStatus += '\n';

if (submission.submissionResult === 'ac') submissionStatus += '✅';
else if (submission.submissionResult === 'judging' || submission.submissionResult === 'wait' || submission.submissionResult === 'compile') submissionStatus += '⏳';
else submissionStatus += '❌';
if(submissionStatus.length % 11 === 10) submissionStatus += '\n';
}
if (submissionStatus.length === 0) submissionStatus = ' ';
embed.spliceFields(3, 1, { name: '제출 현황', value: `${submissionStatus}` });
Expand All @@ -173,25 +172,32 @@ module.exports = async (interaction) => {
};

collector.on('collect', async (i) => {
if(await updateEmbed()) {
return await i.deferUpdate();
await i.deferReply({ ephemeral: true });

if (inButtonProgress.has(userId)) {
return await i.editReply({ content: '다른 요청을 처리중입니다.' });
}
inButtonProgress.add(userId);

if (i.customId === 'updateButton') {
return await i.deferUpdate();
if (await updateEmbed() || i.customId === 'updateButton') {
inButtonProgress.delete(userId);
return await i.deleteReply();
}

if (i.customId === 'giveupButton') {
if (i.user.id !== userId) {
return await i.reply({ content: '남의 디펜스를 포기할 수 없습니다.', ephemeral: true });
inButtonProgress.delete(userId);
return await i.editReply({ content: '남의 디펜스를 포기할 수 없습니다.' });
}

await failedDefense('디펜스를 포기하였습니다.');
return await i.deferUpdate();
inButtonProgress.delete(userId);
return await i.deleteReply();
}
});

collector.on('end', async (collected, reason) => {

collector.on('end', async (_, reason) => {
if (reason === 'time') {
if(await updateEmbed() === false) {
return await failedDefense('제한 시간 초과로 디펜스를 실패하였습니다.');
Expand Down

0 comments on commit 4f96535

Please sign in to comment.