Skip to content

Commit

Permalink
✨ arguments for clearscores command
Browse files Browse the repository at this point in the history
  • Loading branch information
haliphax committed Nov 24, 2021
1 parent 9830572 commit 21eb36a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ connected. Some require that the user be either a moderator or the broadcaster.

| Command | Access | Description |
|---------|--------|-------------|
| `!clearscores` | Moderator | Reset the overlay's localStorage, clearing all score records. |
| `!clearscores [username] [username...]` | Moderator | Reset the overlay's localStorage, clearing score records. If no usernames are provided, all records are wiped. |
| `!drop` | Everyone | Play the game! |
| `!droplow` | Everyone | Show the lowest score from the last 24 hours. |
| `!droprecent` | Everyone | Show the most recent drop scores. |
Expand Down
15 changes: 15 additions & 0 deletions drop-game/static/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class Game extends Phaser.Scene {
emitter.on('droplow', this.onDropLow, this);
emitter.on('droprecent', this.onDropRecent, this);
emitter.on('droptop', this.onDropTop, this);
emitter.on('clearscores', this.onClearScores, this);
emitter.on('lose', this.onLose, this);
emitter.on('queuedrop', this.onQueueDrop, this);
emitter.on('resetdrop', this.onResetDrop, this);
Expand All @@ -33,6 +34,7 @@ export default class Game extends Phaser.Scene {
this.tidyScores();
}

/** @type {Score[]} */
get scores() {
return JSON.parse(localStorage.getItem('scores') || '[]');
}
Expand Down Expand Up @@ -307,6 +309,19 @@ export default class Game extends Phaser.Scene {
`Poooound Highest score in the past 24 hours: ${highest.username} ${highest.score.toFixed(2)}`);
}

onClearScores(who) {
if (!who) {
localStorage.clear();
twitch.say(qs.channel, 'Scores cleared.');
}
else {
const update = this.scores.filter(
v => !who.includes(v.username.toLowerCase()));
localStorage.setItem('scores', JSON.stringify(update));
twitch.say(qs.channel, `Scores cleared for ${who.join(', ')}.`);
}
}

onLose(avatar) {
this.resetTimer();
avatar.container.body.enable = false;
Expand Down
5 changes: 3 additions & 2 deletions drop-game/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ twitch.on('message', (channel, tags, message, self) => {
if (!isBroadcaster(tags) && !isModerator(tags))
return;

localStorage.clear();
twitch.say(qs.channel, 'Scores cleared.');
const who = args ? args.split(' ').map(v => v.toLowerCase()) : null;

emitter.emit('clearscores', who);
break;
case 'drop':
emitter.emit('drop', tags['display-name']);
Expand Down

0 comments on commit 21eb36a

Please sign in to comment.