Compare commits

..

No commits in common. "d4edbfda7ab0a06ec1a60a36633644c7e6ee2175" and "6469a7b660f9db1a8395e091938a9ee50cf71837" have entirely different histories.

4 changed files with 17 additions and 32 deletions

View File

@ -3,11 +3,9 @@
module.exports = { module.exports = {
platform: 'schat', platform: 'schat',
user: { user: {
id: 'clive', id: 'aisha',
username: 'Clive', username: 'Aisha',
realName: 'Clive', realName: 'Aisha',
avatar: null,
key: null,
}, },
style: { style: {
// color: 'var(--message-56)', // color: 'var(--message-56)',
@ -20,7 +18,7 @@ module.exports = {
reconnectDelay: 10, // seconds reconnectDelay: 10, // seconds
prefix: '~', prefix: '~',
labels: true, labels: true,
greeting: 'Hi, I am Clive, your game host!', greeting: 'Hi, I am aisha, your game host!',
usernamePrefix: '@', usernamePrefix: '@',
channels: ['GamesNight'], channels: ['GamesNight'],
games: [ games: [
@ -72,7 +70,7 @@ module.exports = {
'gpt-4', 'gpt-4',
], ],
model: 'gpt-3.5-turbo', model: 'gpt-3.5-turbo',
replyTokenLimit: 1000, replyTokenLimit: 200,
userTokenLimit: 20000, // daily, roughly 100+ messages or $0.04 per user userTokenLimit: 20000, // daily, roughly 100+ messages or $0.04 per user
userTokenPeriod: 24, // hours userTokenPeriod: 24, // hours
temperature: 1, temperature: 1,

4
package-lock.json generated
View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.24.5", "version": "1.24.4",
"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

@ -35,7 +35,7 @@ async function onStart(context) {
.where('created', '<=', knex.raw(`datetime('now', '-${config.chat.userTokenPeriod} hour')`)) .where('created', '<=', knex.raw(`datetime('now', '-${config.chat.userTokenPeriod} hour')`))
.delete(); .delete();
context.logger.info(`Purged ${purgeResult} expired chat token totals from database`); context.logger.info(`Purged ${purgeResult} expired chat token totals from databae`);
} }
function setHistory(value, context) { function setHistory(value, context) {
@ -123,16 +123,6 @@ function setRule(rule, context) {
context.sendMessage(`Chat rule must be at least 3 characters long, ${context.user.prefixedUsername}`, context.room.id, { label: false }); context.sendMessage(`Chat rule must be at least 3 characters long, ${context.user.prefixedUsername}`, context.room.id, { label: false });
} }
async function getTokens(context) {
const { used_tokens: usedTokens } = await knex('chat_tokens')
.sum('tokens as used_tokens')
.where('user_id', context.user.id)
.where('created', '>', knex.raw(`datetime('now', '-${config.chat.userTokenPeriod} hour')`)) // 1 day ago
.first();
return usedTokens || 0;
}
async function onCommand(args, context) { async function onCommand(args, context) {
if (context.subcommand === 'history' && config.operators.includes(context.user.username)) { if (context.subcommand === 'history' && config.operators.includes(context.user.username)) {
setHistory(args[0], context); setHistory(args[0], context);
@ -149,26 +139,23 @@ async function onCommand(args, context) {
return; return;
} }
if (['rule', 'is', 'be', 'ur', 'reset'].includes(context.subcommand) && (config.chat.rulePublic || config.operators.includes(context.user.username))) { if (['rule', 'is', 'reset'].includes(context.subcommand) && (config.chat.rulePublic || config.operators.includes(context.user.username))) {
setRule(context.subcommand === 'reset' ? 'reset' : args.join(' '), context); setRule(context.subcommand === 'reset' ? 'reset' : args.join(' '), context);
return; return;
} }
if (['tokens', 'credit'].includes(context.subcommand)) {
const tokens = await getTokens(context);
context.sendMessage(`You have used ${config.chat.userTokenLimit - tokens} chat tokens remaining. They will be returned gradually over ${config.chat.userTokenPeriod} hours.`, context.room.id, { label: false });
return;
}
const prompt = args.join(' '); const prompt = args.join(' ');
try { try {
const usedTokens = await getTokens(context); const { used_tokens: usedTokens } = await knex('chat_tokens')
.sum('tokens as used_tokens')
.where('user_id', context.user.id)
.where('created', '>', knex.raw(`datetime('now', '-${config.chat.userTokenPeriod} hour')`)) // 1 day ago
.first();
if (usedTokens >= config.chat.userTokenLimit) { if (usedTokens >= config.chat.userTokenLimit) {
context.logger.info(`${context.user.username} was rate limited at ${usedTokens}: ${prompt}`); context.logger.info(`${context.user.username} was rate limited at usedTokens: ${prompt}`);
context.sendMessage(`Sorry, I love talking with you ${context.user.prefixedUsername}, but I need to take a break :( Check ${config.prefix}chat:tokens for more information.`, context.room.id, { label: false }); context.sendMessage(`Sorry, I love talking with you ${context.user.prefixedUsername}, but I need to take a break :(`, context.room.id, { label: false });
return; return;
} }