Skip to content

Commit 9262a03

Browse files
committed
feat: Fix UGO command, add ugoexternal
1 parent 93b09f3 commit 9262a03

4 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/cache/ugo.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export function addUGOPoints(this: Client, pointsData: Record<string, number>, g
5959
});
6060
UGO_POINTS.set(current);
6161

62-
// TODO: Test this
63-
uploadToPastie(JSON.stringify(commit, null, 2)).then(url => this.addUser('ugo').send(`;setpointsbyjson boardgames, ${url}`));
62+
uploadToPastie(JSON.stringify(commit, null, 2)).then(url => {
63+
this.addUser('ugo').send(`;setpointsfromjson boardgames, ${url}`);
64+
});
6465
}

src/ps/commands/alts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export const command: PSCommand = {
2727
}
2828
const altsList = await getAlts(lookup);
2929
// TODO: Handle no-alts case
30-
message.privateReply($T('COMMANDS.ALTS', { alts: altsList.join(', ') }));
30+
message.privateReply($T('COMMANDS.ALTS', { alts: altsList?.join(', ') ?? 'None' }));
3131
},
3232
};

src/ps/commands/games/other.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { addUGOPoints, getUGOPlayed, setUGOPlayed } from '@/cache/ugo';
12
import { getScrabbleDex } from '@/database/games';
23
import { Board } from '@/ps/commands/points';
34
import { parseMod } from '@/ps/games/mods';
45
import { checkWord } from '@/ps/games/scrabble/checker';
56
import { ScrabbleMods } from '@/ps/games/scrabble/constants';
67
import { ScrabbleModData } from '@/ps/games/scrabble/mods';
8+
import { CHAIN_REACTION_META } from '@/ps/ugo/constants';
79
import { toId } from '@/tools';
810
import { ChatError } from '@/utils/chatError';
911
import { mapValues } from '@/utils/map';
@@ -106,12 +108,27 @@ export const command: PSCommand[] = [
106108
name: 'ugoexternal',
107109
help: 'Adds points for external UGO games.',
108110
syntax: 'CMD [winner], [...others]',
111+
flags: { allowPMs: true },
109112
perms: message => message.author.id === 'partprofessor',
110113
categories: ['game'],
111-
async run({ arg }) {
114+
async run({ arg, message }) {
112115
const players = arg.split(',');
113-
const winner = toId(players[0]);
114-
// TODO
116+
const winner = players[0];
117+
118+
const pointsData = Object.fromEntries(
119+
players
120+
.filter(player => {
121+
const prevCount = getUGOPlayed(CHAIN_REACTION_META.id, player);
122+
setUGOPlayed(CHAIN_REACTION_META.id, player, prevCount + 1);
123+
return prevCount <= CHAIN_REACTION_META.ugo.cap;
124+
})
125+
.map(player => [
126+
player.trim(),
127+
player === winner ? CHAIN_REACTION_META.ugo.points.win(players.length) : CHAIN_REACTION_META.ugo.points.loss,
128+
])
129+
);
130+
131+
addUGOPoints.call(message.parent, pointsData, CHAIN_REACTION_META.id);
115132
},
116133
},
117134
];

src/ps/games/game.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ export class BaseGame<State extends BaseState> {
281281
if (staffHTML) this.room.sendHTML(staffHTML, { name: this.id, rank: '+', change: true });
282282
}
283283
}
284-
// TODO: Handle max players state
285284
renderCloseSignups?(): ReactElement;
286285
closeSignups(change = true): void {
287286
const closeSignupsHTML = (this.renderCloseSignups ?? renderCloseSignups).bind(this)();

0 commit comments

Comments
 (0)