feat: add self-mention filtering with regex in MentionBot and update default model in README

Adds a `filterSelfMentions` method to `MentionBot.swift` that uses `NSRegularExpression` to strip case-insensitive bot username mentions from AI responses before posting, preventing infinite reply loops. Updates the default OpenRouter model from `x-ai/grok-3-fast-beta` to `x-ai/grok-code-fast-1` in README.md, along with revised example model identifiers for Claude, Gemini, and other providers.
This commit is contained in:
2025-12-20 20:36:15 +00:00
parent 3bd2edba80
commit 4d3a29a435
3 changed files with 33 additions and 5 deletions
+20 -1
View File
@@ -201,8 +201,27 @@ actor MentionBot {
return context
}
private func filterSelfMentions(from text: String) -> String {
guard let pattern = try? NSRegularExpression(
pattern: "@\(NSRegularExpression.escapedPattern(for: botUsername))",
options: [.caseInsensitive]
) else {
return text
}
let range = NSRange(text.startIndex..., in: text)
return pattern.stringByReplacingMatches(
in: text,
options: [],
range: range,
withTemplate: ""
).replacingOccurrences(of: " ", with: " ")
.trimmingCharacters(in: .whitespaces)
}
private func postReply(rantId: Int, replyTo: String, response: String) async {
let reply = "@\(replyTo) \(response)"
let filteredResponse = filterSelfMentions(from: response)
let reply = "@\(replyTo) \(filteredResponse)"
guard !dryRun else {
await logger.info("DRY RUN: Would post reply to rant \(rantId):\n\(reply)")