Compare commits
No commits in common. "e0aab6acf36d69a2199293bc74208415b85e57bc" and "a47b8adf9971668e6204a0a3cba3fe482f98653c" have entirely different histories.
e0aab6acf3
...
a47b8adf99
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.21.1",
|
"version": "1.21.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.21.1",
|
"version": "1.21.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bhttp": "^1.2.8",
|
"bhttp": "^1.2.8",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.21.1",
|
"version": "1.21.0",
|
||||||
"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": {
|
||||||
|
|
|
@ -6,10 +6,8 @@ const crypto = require('crypto');
|
||||||
const style = require('../utils/style');
|
const style = require('../utils/style');
|
||||||
|
|
||||||
const dieFaces = ['⚀', '⚁', '⚂', '⚃', '⚄', '⚅'];
|
const dieFaces = ['⚀', '⚁', '⚂', '⚃', '⚄', '⚅'];
|
||||||
const coinFaces = ['🗿', '🏛️'];
|
|
||||||
|
|
||||||
function onCommand(args, context) {
|
function onCommand(args, context) {
|
||||||
const type = ['coin', 'flip'].includes(context.command) ? 'coin' : 'dice';
|
|
||||||
const pattern = args[0]?.match(/(\d+)?d(\d+)?/i);
|
const pattern = args[0]?.match(/(\d+)?d(\d+)?/i);
|
||||||
|
|
||||||
if (pattern) {
|
if (pattern) {
|
||||||
|
@ -18,33 +16,30 @@ function onCommand(args, context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const rolls = Math.max(Number(args[0]) || 1, 1);
|
const rolls = Math.max(Number(args[0]) || 1, 1);
|
||||||
const faces = type === 'coin' ? 2 : Math.max(Number(args[1]) || 6, 1);
|
const faces = Math.max(Number(args[1]) || 6, 1);
|
||||||
|
|
||||||
if (rolls > config.dice.maxRolls) {
|
if (rolls > config.dice.maxRolls) {
|
||||||
context.sendMessage(`You can only roll ${config.dice.maxRolls} dice at one time`, context.room.id, { label: type });
|
context.sendMessage(`You can only roll ${config.dice.maxRolls} dice at one time`, context.room.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (faces > config.dice.maxFaces) {
|
if (faces > config.dice.maxFaces) {
|
||||||
context.sendMessage(`Your dice can have at most ${config.dice.maxFaces} faces`, context.room.id, { label: type });
|
context.sendMessage(`Your dice can have at most ${config.dice.maxFaces} faces`, context.room.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const results = Array.from({ length: rolls }, () => {
|
const results = Array.from({ length: rolls }, () => {
|
||||||
const result = crypto.randomInt(1, faces + 1);
|
const result = crypto.randomInt(1, faces + 1);
|
||||||
|
|
||||||
if (type === 'coin') {
|
// using U+2003 Em Space after dice to create double space that doesn't get filtered in SChat
|
||||||
return `${style.yellow(`(${coinFaces[result - 1]})`)} ${style.bold(result === 1 ? 'heads' : 'tails')}`; // eslint-disable-line no-irregular-whitespace
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${style.grey(dieFaces[result - 1] || '☐')} ${style.bold(result)}`; // eslint-disable-line no-irregular-whitespace
|
return `${style.grey(dieFaces[result - 1] || '☐')} ${style.bold(result)}`; // eslint-disable-line no-irregular-whitespace
|
||||||
});
|
});
|
||||||
|
|
||||||
context.sendMessage(results.join(style.grey(' | ')), context.room.id, { label: type });
|
context.sendMessage(results.join(style.grey(' | ')), context.room.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
onCommand,
|
onCommand,
|
||||||
commands: ['dice', 'die', 'roll', 'coin', 'coins', 'flip'],
|
commands: ['dice', 'die', 'roll'],
|
||||||
help: 'What\'s your next move? Try ~dice [rolls] [faces], ~die, ~roll, ~coin or ~flip',
|
help: 'What\'s your next move? Try ~dice [rolls] [faces], ~die or ~roll',
|
||||||
};
|
};
|
||||||
|
|
12
src/play.js
12
src/play.js
|
@ -90,10 +90,6 @@ function styleCommands(rawBody) {
|
||||||
}
|
}
|
||||||
/* eslint-enable no-irregular-whitespace */
|
/* eslint-enable no-irregular-whitespace */
|
||||||
|
|
||||||
function capitalize(string) {
|
|
||||||
return `${string.slice(0, 1).toUpperCase()}${string.slice(1)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function curateMessageBody(rawBody, game, key, options) {
|
function curateMessageBody(rawBody, game, key, options) {
|
||||||
const body = options?.styleCommands ? styleCommands(rawBody) : rawBody;
|
const body = options?.styleCommands ? styleCommands(rawBody) : rawBody;
|
||||||
|
|
||||||
|
@ -101,11 +97,7 @@ function curateMessageBody(rawBody, game, key, options) {
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
const label = typeof options.label === 'string'
|
return `${style.grey(`[${game.name || `${key.slice(0, 1).toUpperCase()}${key.slice(1)}`}]`)} ${body}`;
|
||||||
? capitalize(options.label)
|
|
||||||
: game.name || capitalize(key);
|
|
||||||
|
|
||||||
return `${style.grey(`[${label}]`)} ${body}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getGames(bot, identifier) {
|
async function getGames(bot, identifier) {
|
||||||
|
@ -132,7 +124,7 @@ async function getGames(bot, identifier) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const setGamePoints = (user, score = 1, options) => setPoints(identifier, key, user, score, options);
|
const setGamePoints = (userId, score = 1, options) => setPoints(identifier, key, userId, score, options);
|
||||||
|
|
||||||
const curatedGame = {
|
const curatedGame = {
|
||||||
...game,
|
...game,
|
||||||
|
|
Loading…
Reference in New Issue