Compare commits

..

No commits in common. "8960a23448f1335607455c4d0e5276be942d3498" and "4b8077f7e71b77748278fe9e4f55e66ab14c8b9c" have entirely different histories.

3 changed files with 10 additions and 13 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "schat2-clive",
"version": "1.24.6",
"version": "1.24.5",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "schat2-clive",
"version": "1.24.6",
"version": "1.24.5",
"license": "ISC",
"dependencies": {
"better-sqlite3": "^8.3.0",

View File

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

View File

@ -123,10 +123,10 @@ function setRule(rule, context) {
context.sendMessage(`Chat rule must be at least 3 characters long, ${context.user.prefixedUsername}`, context.room.id, { label: false });
}
async function getTokens(username) {
async function getTokens(context) {
const { used_tokens: usedTokens } = await knex('chat_tokens')
.sum('tokens as used_tokens')
.where('user_id', username)
.where('user_id', context.user.id)
.where('created', '>', knex.raw(`datetime('now', '-${config.chat.userTokenPeriod} hour')`)) // 1 day ago
.first();
@ -154,11 +154,9 @@ async function onCommand(args, context) {
return;
}
if (['tokens', 'credit'].includes(context.subcommand || context.command)) {
const username = args[0] ? args[0].replace(new RegExp(`^${config.usernamePrefix}`), '') : context.user.username;
const tokens = await getTokens(username);
context.sendMessage(`${args[0] ? `${style.bold(username)} has` : 'You have'} ${style.bold(config.chat.userTokenLimit - tokens)} chat tokens remaining. They will be returned gradually over ${config.chat.userTokenPeriod} hours.`, context.room.id, { label: false });
if (['tokens', 'credit'].includes(context.subcommand)) {
const tokens = await getTokens(context);
context.sendMessage(`You have ${config.chat.userTokenLimit - tokens} chat tokens remaining. They will be returned gradually over ${config.chat.userTokenPeriod} hours.`, context.room.id, { label: false });
return;
}
@ -166,7 +164,7 @@ async function onCommand(args, context) {
const prompt = args.join(' ');
try {
const usedTokens = await getTokens(context.user.username);
const usedTokens = await getTokens(context);
if (usedTokens >= config.chat.userTokenLimit) {
context.logger.info(`${context.user.username} was rate limited at ${usedTokens}: ${prompt}`);
@ -202,7 +200,7 @@ async function onCommand(args, context) {
context.sendMessage(`${context.user.prefixedUsername}: ${curatedContent}`, context.room.id, { label: false });
await knex('chat_tokens').insert({
user_id: context.user.username,
user_id: context.user.id,
tokens: res.body.usage.total_tokens,
created: knex.raw("datetime('now')"),
});
@ -226,5 +224,4 @@ module.exports = {
onCommand,
onMessage,
onStart,
commands: ['tokens'],
};