Added bot-to-bot replies
This commit is contained in:
@@ -33,18 +33,52 @@ export default event(Events.MessageCreate, async ({ log, msgHist, ollama, client
|
|||||||
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}.`)
|
||||||
|
|
||||||
// Ignore messages from all bots
|
|
||||||
if (message.author.bot) return
|
|
||||||
|
|
||||||
// Check if message mentions the bot or passes random chance (30%)
|
// Check if message mentions the bot or passes random chance (30%)
|
||||||
|
const isFromBot = message.author.bot && message.author.id !== clientId;
|
||||||
const isMentioned = message.mentions.has(clientId)
|
const isMentioned = message.mentions.has(clientId)
|
||||||
const isCommand = message.content.startsWith('/')
|
const isCommand = message.content.startsWith('/')
|
||||||
const randomChance = Math.random() < 0.30 // 30% chance
|
|
||||||
if (!isMentioned && (isCommand || !randomChance)) return
|
if (isFromBot) {
|
||||||
|
// Check interaction key to prevent rapid back-and-forth
|
||||||
|
const otherBotId = message.author.id
|
||||||
|
const interactionKey = `bot_interaction:${[clientId, otherBotId].sort().join(':')}`
|
||||||
|
const interactionExists = await redis.exists(interactionKey)
|
||||||
|
if (interactionExists) {
|
||||||
|
log('Interaction cooldown active, not responding')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine probability
|
||||||
|
let respondProbability = 0
|
||||||
|
if (isMentioned) {
|
||||||
|
respondProbability = 0.9 // 90% chance if mentioned
|
||||||
|
} else {
|
||||||
|
respondProbability = 0.2 // 20% chance if not mentioned
|
||||||
|
}
|
||||||
|
|
||||||
|
const shouldRespond = Math.random() < respondProbability
|
||||||
|
if (!shouldRespond) return
|
||||||
|
|
||||||
|
// Set interaction key with 60s expiration
|
||||||
|
await redis.set(interactionKey, '1', 'EX', 60)
|
||||||
|
} else if (!message.author.bot) {
|
||||||
|
// Human message
|
||||||
|
const randomChance = Math.random() < 0.30
|
||||||
|
if (!isMentioned && (isCommand || !randomChance)) return
|
||||||
|
} else {
|
||||||
|
// Message from self: ignore
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Log response trigger
|
// Log response trigger
|
||||||
log(isMentioned ? 'Responding to mention' : 'Responding due to random chance')
|
log(isMentioned ? 'Responding to mention' : 'Responding due to random chance')
|
||||||
|
|
||||||
|
// Log response trigger
|
||||||
|
log(isFromBot ? 'Responding to bot message' : (isMentioned ? 'Responding to mention' : 'Responding due to random chance'))
|
||||||
|
|
||||||
|
// Load and process bot’s own history
|
||||||
|
const historyFile = `${message.channelId}-${client.user.username}.json`
|
||||||
|
|
||||||
// Default stream to false
|
// Default stream to false
|
||||||
let shouldStream = false
|
let shouldStream = false
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user