Compare commits
No commits in common. "5ee4117f4ee6795784d55a17385298f803a5c6d8" and "39341178ffa957bea219bbf61a32ffd9b7faff3c" have entirely different histories.
5ee4117f4e
...
39341178ff
|
|
@ -20,13 +20,10 @@ module.exports = {
|
||||||
color: 'var(--message-56)',
|
color: 'var(--message-56)',
|
||||||
},
|
},
|
||||||
channels: ['GamesNight'],
|
channels: ['GamesNight'],
|
||||||
games: ['mash', 'trivia', 'ping', 'duck'],
|
games: ['mash', 'trivia'],
|
||||||
trivia: {
|
trivia: {
|
||||||
mode: 'first', // first or timeout
|
mode: 'first', // first or timeout
|
||||||
rounds: 10,
|
rounds: 10,
|
||||||
timeout: 30,
|
timeout: 30,
|
||||||
},
|
},
|
||||||
duck: {
|
|
||||||
interval: [10, 3600], // seconds
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.5.0",
|
"version": "1.4.9",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.5.0",
|
"version": "1.4.9",
|
||||||
"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.5.0",
|
"version": "1.4.9",
|
||||||
"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": {
|
||||||
|
|
|
||||||
46
src/app.js
46
src/app.js
|
|
@ -47,9 +47,7 @@ async function getWsId(httpSession) {
|
||||||
return res.body;
|
return res.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setPoints(defaultKey, user, value, { mode = 'add', key }) {
|
async function setPoints(gameKey, user, value, mode = 'add') {
|
||||||
const gameKey = key || defaultKey;
|
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
logger.warn(`Failed to set ${gameKey} points for missing user`);
|
logger.warn(`Failed to set ${gameKey} points for missing user`);
|
||||||
return;
|
return;
|
||||||
|
|
@ -72,14 +70,14 @@ 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, { user, room, command }) {
|
function getPoints(game, { user, room }) {
|
||||||
const userPoints = (points[command] || points[game.key])?.[`${user.id}:${user.username}`];
|
const userPoints = points[game.key]?.[`${user.id}:${user.username}`];
|
||||||
|
|
||||||
game.sendMessage(`You have scored **${userPoints || 0}** points in ${game.name}, @${user.username}`, room.id);
|
game.sendMessage(`You have scored **${userPoints || 0}** points in ${game.name}, @${user.username}`, room.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLeaderboard(game, { user, room, command }) {
|
function getLeaderboard(game, { user, room }) {
|
||||||
const leaderboard = points[command] || points[game.key];
|
const leaderboard = points[game.key];
|
||||||
|
|
||||||
if (!leaderboard || Object.keys(leaderboard).length === 0) {
|
if (!leaderboard || Object.keys(leaderboard).length === 0) {
|
||||||
game.sendMessage(`No points scored in ${game.name} yet!`, room.id);
|
game.sendMessage(`No points scored in ${game.name} yet!`, room.id);
|
||||||
|
|
@ -140,12 +138,12 @@ function onMessage(message, bot, games) {
|
||||||
const room = bot.rooms[message.roomId];
|
const room = bot.rooms[message.roomId];
|
||||||
|
|
||||||
if (['leaderboard', 'lead', 'leader', 'leaders', 'scoreboard', 'best'].includes(subcommand) && games[command]) {
|
if (['leaderboard', 'lead', 'leader', 'leaders', 'scoreboard', 'best'].includes(subcommand) && games[command]) {
|
||||||
getLeaderboard(games[command], { user, room, command });
|
getLeaderboard(games[command], { user, room });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (['points', 'score'].includes(subcommand) && games[command]) {
|
if (['points', 'score'].includes(subcommand) && games[command]) {
|
||||||
getPoints(games[command], { user, room, command });
|
getPoints(games[command], { user, room });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,14 +151,13 @@ function onMessage(message, bot, games) {
|
||||||
const args = message.body.split(/\s+/).slice(1);
|
const args = message.body.split(/\s+/).slice(1);
|
||||||
const game = games[command];
|
const game = games[command];
|
||||||
|
|
||||||
if (game && game.onCommand) {
|
if (game) {
|
||||||
if (user) {
|
if (user) {
|
||||||
user.points = points[game.key]?.[`${user.id}:${user.username}`] || 0;
|
user.points = points[game.key]?.[`${user.id}:${user.username}`] || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
game.onCommand(args, {
|
games[command].onCommand(args, {
|
||||||
...game,
|
...game,
|
||||||
command,
|
|
||||||
subcommand,
|
subcommand,
|
||||||
bot,
|
bot,
|
||||||
message,
|
message,
|
||||||
|
|
@ -217,25 +214,18 @@ function getGames(bot) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const setGamePoints = (userId, score, options) => setPoints(key, userId, score, options);
|
const setGamePoints = (userId, score, mode) => setPoints(key, userId, score, mode);
|
||||||
|
|
||||||
const curatedGame = {
|
|
||||||
...game,
|
|
||||||
...(key.game && key),
|
|
||||||
name: game.name || key,
|
|
||||||
key,
|
|
||||||
sendMessage,
|
|
||||||
setPoints: setGamePoints,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (game.onStart) {
|
|
||||||
game.onStart({ ...curatedGame, bot });
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...acc,
|
...acc,
|
||||||
[key]: curatedGame,
|
[key]: {
|
||||||
...game.commands?.reduce((commandAcc, command) => ({ ...commandAcc, [command]: curatedGame }), {}),
|
...game,
|
||||||
|
...(key.game && key),
|
||||||
|
name: game.name || key,
|
||||||
|
key,
|
||||||
|
sendMessage,
|
||||||
|
setPoints: setGamePoints,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const config = require('config');
|
|
||||||
|
|
||||||
const ducks = new Map();
|
|
||||||
let shots = new Map();
|
|
||||||
|
|
||||||
function launchDuck(context) {
|
|
||||||
ducks.delete(context.room?.id);
|
|
||||||
shots = new Map();
|
|
||||||
|
|
||||||
const interval = Array.isArray(config.duck.interval)
|
|
||||||
? ((Math.random() * (config.duck.interval[1] - config.duck.interval[0])) + config.duck.interval[0]) * 1000
|
|
||||||
: config.duck.interval * 1000;
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
if (context.bot.rooms.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const rooms = Object.values(context.bot.rooms);
|
|
||||||
const room = rooms[Math.floor(Math.random() * rooms.length)];
|
|
||||||
|
|
||||||
ducks.set(room.id, new Date());
|
|
||||||
context.sendMessage('Quack! :duck:', room.id);
|
|
||||||
}, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onCommand(args, context) {
|
|
||||||
const duck = ducks.get(context.room.id);
|
|
||||||
|
|
||||||
if (!duck) {
|
|
||||||
context.sendMessage(`There is no duck, what are you shooting at, @${context.user.username}?!`, context.room.id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const hit = Math.random() > 0.3;
|
|
||||||
const time = ((new Date().getTime() - duck.getTime()) / 1000).toFixed(3);
|
|
||||||
|
|
||||||
if (context.command === 'bang') {
|
|
||||||
if (hit) {
|
|
||||||
context.sendMessage(`You shot a duck in **${time} seconds**, @${context.user.username}`, context.room.id);
|
|
||||||
launchDuck(context);
|
|
||||||
|
|
||||||
context.setPoints(context.user, 1, { key: 'bang' });
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const messages = [
|
|
||||||
`How could you miss *that*, @${context.user.username}...?!`,
|
|
||||||
`Better luck next time, @${context.user.username}.`,
|
|
||||||
`The duck got away, @${context.user.username}`,
|
|
||||||
`Channeling Gareth Southgate, @${context.user.username}? You missed!`,
|
|
||||||
];
|
|
||||||
|
|
||||||
shots.set(context.user.id, new Date());
|
|
||||||
context.sendMessage(messages[Math.floor(Math.random() * messages.length)], context.room.id);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (['bef', 'befriend'].includes(context.command)) {
|
|
||||||
if (hit) {
|
|
||||||
context.sendMessage(`You befriended a duck in **${time} seconds**, @${context.user.username}`, context.room.id);
|
|
||||||
launchDuck(context);
|
|
||||||
|
|
||||||
context.setPoints(context.user, 1, { key: 'befriend' });
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const messages = [
|
|
||||||
`The duck does not want to be your friend right now, @${context.user.username}`,
|
|
||||||
`The duck would like some time for itself, @${context.user.username}`,
|
|
||||||
`The duck isn't in the mood right now, @${context.user.username}`,
|
|
||||||
];
|
|
||||||
|
|
||||||
shots.set(context.user.id, new Date());
|
|
||||||
context.sendMessage(messages[Math.floor(Math.random() * messages.length)], context.room.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: 'Duck',
|
|
||||||
commands: ['bang', 'bef', 'befriend'],
|
|
||||||
onStart: launchDuck,
|
|
||||||
onCommand,
|
|
||||||
};
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
'use strict';
|
|
||||||
|
|
||||||
function onCommand(args, context) {
|
|
||||||
context.sendMessage(`Pong, @${context.user.username}!`, context.room.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: 'Ping',
|
|
||||||
onCommand,
|
|
||||||
};
|
|
||||||
|
|
@ -50,7 +50,7 @@ async function playRound(context, round = 0) {
|
||||||
|
|
||||||
const question = game.questions[round];
|
const question = game.questions[round];
|
||||||
|
|
||||||
context.sendMessage(`**Question ${round + 1}/${game.questions.length}** (${question.category}): ${question.question}`, context.room.id);
|
context.sendMessage(`**Question ${round + 1}/${game.questions.length}**: ${question.question}`, context.room.id);
|
||||||
context.logger.info(`Trivia asked "${question.question}" with answer: ${question.answer}`);
|
context.logger.info(`Trivia asked "${question.question}" with answer: ${question.answer}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -163,7 +163,7 @@ function onCommand(args, context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onMessage(message, context) {
|
async function onMessage(message, context) {
|
||||||
if (!game || context.user.id === config.user.id) {
|
if (!game) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue