Skip to content

Commit

Permalink
Added exit command for drawing entries
Browse files Browse the repository at this point in the history
  • Loading branch information
SahilMak committed May 31, 2024
1 parent 02aee64 commit 9d3a6ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const main = async () => {
break;
case '$drawing':
case '$enter':
case '$exit':
command.entries(client, channel, commandName, context);
break;
case '$raid':
Expand Down
20 changes: 19 additions & 1 deletion commands/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const authorizedUsers = require('../constants/authorized');

let drawing;
let entriesList = [];
let isOpen = false; // drawing open for entries
let isOpen = false;
let winnersList = [];

const entries = (client, channel, command, context) => {
Expand All @@ -11,6 +11,9 @@ const entries = (client, channel, command, context) => {
case '$enter':
enterDrawing(args[1], client, channel, context);
break;
case '$exit':
exitDrawing(args[1], client, channel, context);
break;
case '$drawing':
if (context.badges.has('moderator') || context.badges.has('broadcaster') || authorizedUsers.includes(context.userName)) {
if (args[1]) {
Expand Down Expand Up @@ -60,6 +63,21 @@ const enterDrawing = (rawEntry, client, channel, context) => {
}
};

const exitDrawing = (rawEntry, client, channel, context) => {
if (isOpen) {
const entry = (rawEntry && (context.badges.has('moderator') || context.badges.has('broadcaster') || authorizedUsers.includes(context.userName))) ? formatEntry(rawEntry) : context.displayName;
const index = entriesList.indexOf(entry);
if (index !== -1) {
entriesList.splice(index, 1);
client.say(channel, (rawEntry) ? `@${entry} has been successfully removed from the drawing` : `@${entry} Your name has been successfully removed from the drawing`);
} else {
client.say(channel, (rawEntry) ? `@${entry} is not in the current drawing` : `@${entry} Your name is not in the current drawing`);
}
} else {
client.say(channel, `${context.displayName} There is no drawing currently in progress`);
}
};

const formatEntry = (entry) => {
return (entry.startsWith('@')) ? entry.substring(1) : entry;
};
Expand Down

0 comments on commit 9d3a6ab

Please sign in to comment.