winding back changes, re-working multi-bot
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-aidolls",
|
"name": "discord-aidolls",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "discord-aidolls",
|
"name": "discord-aidolls",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"license": "---",
|
"license": "---",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.18.0",
|
"discord.js": "^14.18.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord-aidolls",
|
"name": "discord-aidolls",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"description": "Ollama Integration into discord with persistent bot memories",
|
"description": "Ollama Integration into discord with persistent bot memories",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"exports": "./build/index.js",
|
"exports": "./build/index.js",
|
||||||
|
|||||||
@@ -37,7 +37,17 @@ interface UserConfig {
|
|||||||
* @param message the message received from the channel
|
* @param message the message received from the channel
|
||||||
*/
|
*/
|
||||||
export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client, defaultModel }: { log: (msg: string) => void, msgHist: Queue<UserMessage>, ollama: Ollama, client: any, defaultModel: string }, message: Message) => {
|
export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client, defaultModel }: { log: (msg: string) => void, msgHist: Queue<UserMessage>, ollama: Ollama, client: any, defaultModel: string }, message: Message) => {
|
||||||
const clientId = client.user!.id
|
// Early check to prevent bot from replying to itself
|
||||||
|
if (!client.user) {
|
||||||
|
log('Client user is not defined. Skipping message processing.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const clientId = client.user.id
|
||||||
|
if (message.author.id === clientId) {
|
||||||
|
log(`Skipping message from self (bot ID: ${clientId}).`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let cleanedMessage = clean(message.content, clientId)
|
let cleanedMessage = clean(message.content, clientId)
|
||||||
log(`Message "${cleanedMessage}" from ${message.author.tag} in channel/thread ${message.channelId}.`)
|
log(`Message "${cleanedMessage}" from ${message.author.tag} in channel/thread ${message.channelId}.`)
|
||||||
|
|
||||||
@@ -61,6 +71,25 @@ export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check cooldown for bot-to-bot responses only if probability check passes
|
||||||
|
const botResponseCooldownKey = `bot:${clientId}:last_bot_response`
|
||||||
|
const cooldownPeriod = 60 // 60 seconds cooldown
|
||||||
|
if (isBotMessage && randomChance) {
|
||||||
|
log(`Bot message probability check passed (10% chance). Checking cooldown.`)
|
||||||
|
try {
|
||||||
|
const lastResponseTime = await redis.get(botResponseCooldownKey)
|
||||||
|
const currentTime = Math.floor(Date.now() / 1000)
|
||||||
|
if (lastResponseTime && (currentTime - parseInt(lastResponseTime)) < cooldownPeriod) {
|
||||||
|
log(`Bot ${clientId} is in cooldown for bot-to-bot response. Skipping.`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log(`Failed to check bot response cooldown: ${error}`)
|
||||||
|
}
|
||||||
|
} else if (isBotMessage) {
|
||||||
|
log(`Bot message probability check failed (10% chance). Skipping cooldown check.`)
|
||||||
|
}
|
||||||
|
|
||||||
// Check if last response was to a bot and require user message
|
// Check if last response was to a bot and require user message
|
||||||
const lastResponseToBotKey = `bot:${clientId}:last_response_to_bot`
|
const lastResponseToBotKey = `bot:${clientId}:last_response_to_bot`
|
||||||
let shouldRespond = true
|
let shouldRespond = true
|
||||||
@@ -76,25 +105,6 @@ export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check cooldown for bot-to-bot responses only if probability check passes
|
|
||||||
const botResponseCooldownKey = `bot:${clientId}:last_bot_response`
|
|
||||||
const cooldownPeriod = 60 // 60 seconds cooldown
|
|
||||||
if (isBotMessage && randomChance) {
|
|
||||||
log(`Bot message probability check passed (10% chance). Checking cooldown.`)
|
|
||||||
try {
|
|
||||||
const lastResponseTime = await redis.get(botResponseCooldownKey)
|
|
||||||
const currentTime = Math.floor(Date.now() / 1000)
|
|
||||||
if (lastResponseTime && (currentTime - parseInt(lastResponseTime)) < cooldownPeriod) {
|
|
||||||
log(`Bot ${clientId} is in cooldown for bot-to-bot response. Skipping.`)
|
|
||||||
shouldRespond = false
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
log(`Failed to check bot response cooldown: ${error}`)
|
|
||||||
}
|
|
||||||
} else if (isBotMessage) {
|
|
||||||
log(`Bot message probability check failed (10% chance). Skipping cooldown check.`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!shouldRespond) return
|
if (!shouldRespond) return
|
||||||
|
|
||||||
// Reset last_response_to_bot flag if this is a user message
|
// Reset last_response_to_bot flag if this is a user message
|
||||||
|
|||||||
Reference in New Issue
Block a user