|
| 1 | +import { addUGOPoints, getUGOPlayed, setUGOPlayed } from '@/cache/ugo'; |
1 | 2 | import { getScrabbleDex } from '@/database/games'; |
2 | 3 | import { Board } from '@/ps/commands/points'; |
3 | 4 | import { parseMod } from '@/ps/games/mods'; |
4 | 5 | import { checkWord } from '@/ps/games/scrabble/checker'; |
5 | 6 | import { ScrabbleMods } from '@/ps/games/scrabble/constants'; |
6 | 7 | import { ScrabbleModData } from '@/ps/games/scrabble/mods'; |
| 8 | +import { CHAIN_REACTION_META } from '@/ps/ugo/constants'; |
7 | 9 | import { toId } from '@/tools'; |
8 | 10 | import { ChatError } from '@/utils/chatError'; |
9 | 11 | import { mapValues } from '@/utils/map'; |
@@ -106,12 +108,27 @@ export const command: PSCommand[] = [ |
106 | 108 | name: 'ugoexternal', |
107 | 109 | help: 'Adds points for external UGO games.', |
108 | 110 | syntax: 'CMD [winner], [...others]', |
| 111 | + flags: { allowPMs: true }, |
109 | 112 | perms: message => message.author.id === 'partprofessor', |
110 | 113 | categories: ['game'], |
111 | | - async run({ arg }) { |
| 114 | + async run({ arg, message }) { |
112 | 115 | 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); |
115 | 132 | }, |
116 | 133 | }, |
117 | 134 | ]; |
0 commit comments