Compare commits

..

No commits in common. "0d375cac92f92e8e013dbf04b062c66373a0ddad" and "2656c97b7d506858ae9ecdd0dccf50758db1dc9e" have entirely different histories.

4 changed files with 23 additions and 51 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.16.5", "version": "1.16.4",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.16.5", "version": "1.16.4",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"bhttp": "^1.2.8", "bhttp": "^1.2.8",

View File

@ -1,6 +1,6 @@
{ {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.16.5", "version": "1.16.4",
"description": "Game host for SChat 2-powered chat sites", "description": "Game host for SChat 2-powered chat sites",
"main": "src/app.js", "main": "src/app.js",
"scripts": { "scripts": {

View File

@ -16,24 +16,9 @@ const emojis = {
rock: '🪨', rock: '🪨',
paper: '📄', paper: '📄',
scissors: '✂️', scissors: '✂️',
scissoring: ':scissoring:',
}; };
const emojiAliases = { async function play(context, hand) {
rock: 'rock',
paper: 'paper',
page_facing_up: 'paper',
page_with_curl: 'paper',
newspaper: 'paper',
newspaper_roll: 'paper',
scroll: 'paper',
scissors: 'scissors',
scissoring: 'scissors',
};
const emojiLookup = Object.fromEntries(Object.entries(emojis).map(([key, emoji]) => [emoji, key]));
async function play(context, hand, originalHand) {
const counter = Object.keys(wins)[crypto.randomInt(0, 3)]; const counter = Object.keys(wins)[crypto.randomInt(0, 3)];
const userWins = wins[hand] === counter; const userWins = wins[hand] === counter;
@ -44,17 +29,11 @@ async function play(context, hand, originalHand) {
await timers.setTimeout(500); await timers.setTimeout(500);
context.sendMessage(`${emojis.paper} Paper!`, context.room.id); context.sendMessage(`${emojis.paper} Paper!`, context.room.id);
await timers.setTimeout(500); await timers.setTimeout(500);
context.sendMessage(`${emojis.scissors} Scissors!`, context.room.id);
if (originalHand === 'scissoring') {
context.sendMessage(`${emojis.scissoring} Scissoring!`, context.room.id);
} else {
context.sendMessage(`${emojis.scissors} Scissors!`, context.room.id);
}
await timers.setTimeout(750); await timers.setTimeout(750);
if (userWins) { if (userWins) {
context.sendMessage(`${style.bold('You win!')} ${config.user.username} played ${style.italic(counter)} ${emojis[counter]} against your ${style.italic(originalHand)} ${emojis[originalHand]}`, context.room.id); context.sendMessage(`${style.bold('You win!')} ${config.user.username} played ${style.italic(counter)} ${emojis[counter]} against your ${style.italic(hand)} ${emojis[hand]}`, context.room.id);
context.setPoints(context.user, 1); context.setPoints(context.user, 1);
context.setPoints(config.user, 1); context.setPoints(config.user, 1);
@ -63,7 +42,7 @@ async function play(context, hand, originalHand) {
} }
if (botWins) { if (botWins) {
context.sendMessage(`${style.bold('You lose...')} ${config.user.username} played ${style.italic(counter)} ${emojis[counter]} against your ${style.italic(originalHand)} ${emojis[originalHand]}`, context.room.id); context.sendMessage(`${style.bold('You lose...')} ${config.user.username} played ${style.italic(counter)} ${emojis[counter]} against your ${style.italic(hand)} ${emojis[hand]}`, context.room.id);
context.setPoints(context.user, -1); context.setPoints(context.user, -1);
context.setPoints(config.user, 1); context.setPoints(config.user, 1);
@ -71,21 +50,16 @@ async function play(context, hand, originalHand) {
return; return;
} }
context.sendMessage(`${style.bold('It\'s a draw.')} ${config.user.username} also played ${style.italic(originalHand)} ${emojis[originalHand]}`, context.room.id); context.sendMessage(`${style.bold('It\'s a draw.')} ${config.user.username} also played ${style.italic(counter)} ${emojis[counter]}`, context.room.id);
} }
async function onCommand(args, context) { async function onCommand(args, context) {
return play(context, context.command, context.command); return play(context, context.command);
} }
async function onMessage(args, context) { async function onMessage(args, context) {
const emojiHand = emojiLookup[context.message.body]; if (context.user?.username !== config.user.username && Object.values(emojis).some((emoji) => new RegExp(`^${emoji}$`, 'u').test(context.message.body))) {
const emojiAliasHand = config.platform === 'schat' && context.message.originalBody?.match(/^:((?:rock)|(?:paper)|(?:scissors)|(?:scissoring)|(?:page_facing_up)|(?:page_with_curl)):$/)?.[1]; play(context, context.command);
const hand = emojiHand || emojiAliases[emojiAliasHand];
if (hand && context.user?.username !== config.user.username) {
play(context, hand, emojiHand || emojiAliasHand);
} }
} }
@ -94,5 +68,5 @@ module.exports = {
onMessage, onMessage,
name: 'Rock, Paper, Scissors', name: 'Rock, Paper, Scissors',
commands: ['rock', 'paper', 'scissors'], commands: ['rock', 'paper', 'scissors'],
help: 'Can you read my mind? Play ~rock, ~paper, or ~scissors.', help: 'What\'s your next move? Try ~dice [rolls] [faces], ~die or ~roll',
}; };

View File

@ -235,19 +235,17 @@ function onMessage(message, bot, games) {
} }
} }
if (message.type === 'message') { Object.values(Object.fromEntries(Object.values(games).map((game) => [game.key, game]))).forEach((game) => game.onMessage?.(message, {
Object.values(Object.fromEntries(Object.values(games).map((game) => [game.key, game]))).forEach((game) => game.onMessage?.(message, { ...game,
...game, bot,
bot, message,
message, user: user && {
user: user && { ...user,
...user, points: points[game.key]?.[`${user.id}:${user.username}`] || 0,
points: points[game.key]?.[`${user.id}:${user.username}`] || 0, },
}, room,
room, logger,
logger, }));
}));
}
} }
module.exports = { module.exports = {