Compare commits

..

No commits in common. "db0ce247ca5264b9da2e29341d1a0a722665a3ce" and "1843a5b5b33ed017506040274854f3459adc995a" have entirely different histories.

3 changed files with 17 additions and 21 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.5.13", "version": "1.5.12",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.5.13", "version": "1.5.12",
"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.5.13", "version": "1.5.12",
"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

@ -72,14 +72,10 @@ async function setPoints(defaultKey, user, value, { mode = 'add', key } = {}) {
await fs.writeFile(`./points-${instance}.json`, JSON.stringify(points, null, 4)); await fs.writeFile(`./points-${instance}.json`, JSON.stringify(points, null, 4));
} }
function getPoints(game, username, { user, room, command }) { function getPoints(game, { user, room, command }) {
const gamePoints = points[command] || points[game.key]; const userPoints = (points[command] || points[game.key])?.[`${user.id}:${user.username}`];
const userPoints = username game.sendMessage(`You have scored **${userPoints || 0}** points in ${game.name}, @${user.username}`, room.id);
? Object.entries(gamePoints || {}).find(([identifier]) => identifier.split(':')[1] === username)?.[1]
: gamePoints?.[`${user?.id}:${user?.username}`];
game.sendMessage(`${username ? `**${username}** has` : 'You have'} scored **${userPoints || 0}** points in ${game.name}, @${user.username}`, room.id);
} }
function getLeaderboard(game, { user, room, command }) { function getLeaderboard(game, { user, room, command }) {
@ -97,7 +93,7 @@ function getLeaderboard(game, { user, room, command }) {
const username = userKey.split(':')[1]; const username = userKey.split(':')[1];
return `**${username === user.username ? '@' : ''}${username}** at **${score}** points`; return `**${username === user.username ? '@' : ''}${username}** at **${score}** points`;
}) })
.slice(0, 10) .slice(-10)
.join(', '); .join(', ');
game.sendMessage(`The top ${Math.min(Object.keys(leaderboard).length, 10)} *${game.name}* players are: ${curatedLeaderboard}`, room.id); game.sendMessage(`The top ${Math.min(Object.keys(leaderboard).length, 10)} *${game.name}* players are: ${curatedLeaderboard}`, room.id);
@ -144,20 +140,20 @@ function onMessage(message, bot, games) {
const user = bot.users[message.userId] || message.user; const user = bot.users[message.userId] || message.user;
const room = bot.rooms[message.roomId]; const room = bot.rooms[message.roomId];
if (['leaderboard', 'lead', 'leader', 'leaders', 'scoreboard', 'best'].includes(subcommand) && games[command]) {
getLeaderboard(games[command], { user, room, command });
return;
}
if (['points', 'score'].includes(subcommand) && games[command]) {
getPoints(games[command], { user, room, command });
return;
}
if (command) { if (command) {
const args = body.split(/\s+/).slice(1); const args = body.split(/\s+/).slice(1);
const game = games[command]; const game = games[command];
if (['leaderboard', 'lead', 'leader', 'leaders', 'scoreboard', 'best'].includes(subcommand) && games[command]) {
getLeaderboard(games[command], { user, room, command });
return;
}
if (['points', 'score'].includes(subcommand) && games[command]) {
getPoints(games[command], args[0], { user, room, command });
return;
}
if (game && game.onCommand) { if (game && game.onCommand) {
if (user) { if (user) {
user.points = points[game.key]?.[`${user.id}:${user.username}`] || 0; user.points = points[game.key]?.[`${user.id}:${user.username}`] || 0;