Compare commits

..

No commits in common. "be30882ed701829be63804e1adb5b3a335afe42f" and "0deea0e016be3cbaf4abeff8397f25bf65befec2" have entirely different histories.

6 changed files with 25 additions and 53 deletions

View File

@ -44,7 +44,6 @@ module.exports = {
duck: {
interval: [10, 3600], // seconds
duck: ':duck:',
missRatio: 0.25,
},
letters: {
length: 9,

4
package-lock.json generated
View File

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

View File

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

View File

@ -3,7 +3,6 @@
const config = require('config');
const style = require('../utils/style');
const pickRandom = require('../utils/pick-random');
const ducks = new Map();
let shots = new Map();
@ -32,35 +31,17 @@ function launchDuck(context) {
function onCommand(args, context) {
const duck = ducks.get(context.room.id);
if (!duck && context.command === 'bang') {
const message = pickRandom([
`There is no duck, what are you shooting at, ${context.user.prefixedUsername}?!`,
`You're wasting bullets, ${context.user.prefixedUsername}, there is no duck!`,
`The only quack is you, ${context.user.prefixedUsername}...`,
]);
context.sendMessage(message, context.room.id);
if (!duck) {
context.sendMessage(`There is no duck, what are you shooting at, ${config.usernamePrefix}${context.user.username}?!`, context.room.id);
return;
}
if (!duck && ['befriend', 'bef'].includes(context.command)) {
const message = pickRandom([
`You're trying to befriend a non-existent duck, ${context.user.prefixedUsername}...`,
`There aren't any ducks to befriend, ${context.user.prefixedUsername}...`,
`That's no duck, ${context.user.prefixedUsername} ✈️`,
]);
context.sendMessage(message, context.room.id);
return;
}
const hit = Math.random() > config.duck.missRatio;
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 ${style.bold(`${time} seconds`)}, ${context.user.prefixedUsername}`, context.room.id);
context.sendMessage(`You shot a duck in ${style.bold(`${time} seconds`)}, ${config.usernamePrefix}${context.user.username}`, context.room.id);
launchDuck(context);
context.setPoints(context.user, 1, { key: 'bang' });
@ -68,22 +49,22 @@ function onCommand(args, context) {
return;
}
const message = pickRandom([
`How could you miss ${style.italic('that')}, ${context.user.prefixedUsername}...?!`,
`That's a miss! Better luck next time, ${context.user.prefixedUsername}.`,
`The duck outsmarted you, ${context.user.prefixedUsername}`,
`Channeling Gareth Southgate, ${context.user.prefixedUsername}? You missed!`,
]);
const messages = [
`How could you miss ${style.italic('that')}, ${config.usernamePrefix}${context.user.username}...?!`,
`That's a miss! Better luck next time, ${config.usernamePrefix}${context.user.username}.`,
`The duck outsmarted you, ${config.usernamePrefix}${context.user.username}`,
`Channeling Gareth Southgate, ${config.usernamePrefix}${context.user.username}? You missed!`,
];
shots.set(context.user.id, new Date());
context.sendMessage(message, context.room.id);
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 ${style.bold(`${time} seconds`)}, ${context.user.prefixedUsername}`, context.room.id);
context.sendMessage(`You befriended a duck in ${style.bold(`${time} seconds`)}, ${config.usernamePrefix}${context.user.username}`, context.room.id);
launchDuck(context);
context.setPoints(context.user, 1, { key: 'befriend' });
@ -91,14 +72,14 @@ function onCommand(args, context) {
return;
}
const message = pickRandom([
`The duck does not want to be your friend right now, ${context.user.prefixedUsername}`,
`The duck would like some time for itself, ${context.user.prefixedUsername}`,
`The duck isn't in the mood right now, ${context.user.prefixedUsername}`,
]);
const messages = [
`The duck does not want to be your friend right now, ${config.usernamePrefix}${context.user.username}`,
`The duck would like some time for itself, ${config.usernamePrefix}${context.user.username}`,
`The duck isn't in the mood right now, ${config.usernamePrefix}${context.user.username}`,
];
shots.set(context.user.id, new Date());
context.sendMessage(message, context.room.id);
context.sendMessage(messages[Math.floor(Math.random() * messages.length)], context.room.id);
}
}

View File

@ -3,10 +3,10 @@
const config = require('config');
const timers = require('timers/promises');
const crypto = require('crypto');
const style = require('../utils/style');
const getLeaders = require('../utils/get-leaders');
const getWordKey = require('../utils/get-word-key');
const pickRandom = require('../utils/pick-random');
const words = require('../../assets/mash-words.json');
const availableLetters = {
@ -106,10 +106,10 @@ function pickLetters(type, context) {
}
if (type === 'consonant' || type === 'vowel') {
game.word = `${game.word}${pickRandom(availableLetters[type])}`;
game.word = `${game.word}${availableLetters[type][crypto.randomInt(0, availableLetters[type].length)]}`;
} else {
type.toLowerCase().slice(0, config.letters.length - game.word.length).split('').forEach((typeKey) => {
game.word = `${game.word}${pickRandom(availableLetters[types[typeKey]])}`;
game.word = `${game.word}${availableLetters[types[typeKey]][crypto.randomInt(0, availableLetters[types[typeKey]].length)]}`;
});
}

View File

@ -138,19 +138,11 @@ function getMessageUser(message, bot) {
return {
username: message.from,
id: message.from,
prefixedUsername: `${config.usernamePrefix}${message.from}`,
};
}
if (config.platform === 'schat') {
const user = bot.users[message.userId] || message.user;
if (user) {
return {
...user,
prefixedUsername: `${config.usernamePrefix}${user.username}`,
};
}
return bot.users[message.userId] || message.user;
}
return null;