Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e949a980fb | ||
|
|
9a0292c2fa |
Generated
+1
-1
@@ -10,7 +10,7 @@
|
|||||||
"isupport",
|
"isupport",
|
||||||
"list"
|
"list"
|
||||||
]
|
]
|
||||||
revision = "15a51e0151ea95fccb9c72f45061f1b292e6195b"
|
revision = "2dd72f9838d99e084c85de0d8fce290bcc547cbe"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/dgrijalva/jwt-go"
|
name = "github.com/dgrijalva/jwt-go"
|
||||||
|
|||||||
+21
-10
@@ -4,6 +4,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.aiterp.net/rpdata/logbot3/internal/util"
|
||||||
|
|
||||||
"git.aiterp.net/gisle/irc"
|
"git.aiterp.net/gisle/irc"
|
||||||
"git.aiterp.net/rpdata/logbot3/internal/config"
|
"git.aiterp.net/rpdata/logbot3/internal/config"
|
||||||
)
|
)
|
||||||
@@ -50,10 +52,12 @@ func handler(event *irc.Event, client *irc.Client) {
|
|||||||
|
|
||||||
case "ctcp.action", "packet.privmsg":
|
case "ctcp.action", "packet.privmsg":
|
||||||
{
|
{
|
||||||
|
// The echo-message polyfill will return to sender.
|
||||||
if event.Nick == bot.client.Nick() {
|
if event.Nick == bot.client.Nick() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only continue with channel messages, but log the others.
|
||||||
channel := event.ChannelTarget()
|
channel := event.ChannelTarget()
|
||||||
if channel == nil {
|
if channel == nil {
|
||||||
if event.Verb() == "action" {
|
if event.Verb() == "action" {
|
||||||
@@ -65,31 +69,38 @@ func handler(event *irc.Event, client *irc.Client) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse account, just in case it'll be useful one day.
|
||||||
account := ""
|
account := ""
|
||||||
if user, ok := bot.client.FindUser(event.Nick); ok {
|
if user, ok := bot.client.FindUser(event.Nick); ok {
|
||||||
account = user.Account
|
account = user.Account
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the kind of psot this is.
|
||||||
kind := ""
|
kind := ""
|
||||||
if event.Verb() == "action" {
|
if strings.HasPrefix(event.Nick, "=") || strings.HasPrefix(event.Nick, "\x1F=") {
|
||||||
kind = "action"
|
|
||||||
} else {
|
|
||||||
if strings.HasPrefix(event.Nick, "=") {
|
|
||||||
kind = "scene"
|
kind = "scene"
|
||||||
|
} else if strings.ToLower(event.Verb()) == "action" {
|
||||||
|
kind = "action"
|
||||||
} else {
|
} else {
|
||||||
kind = "text"
|
kind = "text"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Format NPC posts' nick and text.
|
||||||
|
nick := event.Nick
|
||||||
|
text := event.Text
|
||||||
|
if strings.HasPrefix(event.Nick, "\x1F") || kind == "scene" {
|
||||||
|
nick = strings.Replace(event.Nick, "\x1F", "", 2)
|
||||||
|
text = util.RemoveNPCAttribution(event.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
post := ChannelPost{
|
// Dispatch it.
|
||||||
|
bot.handlePost(channel.Name(), ChannelPost{
|
||||||
Account: account,
|
Account: account,
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
Nick: event.Nick,
|
Nick: nick,
|
||||||
Time: event.Time,
|
Time: event.Time,
|
||||||
Text: event.Text,
|
Text: text,
|
||||||
}
|
})
|
||||||
|
|
||||||
bot.handlePost(channel.Name(), post)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log notices
|
// Log notices
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RemoveNPCAttribution removes NPC attribution.
|
||||||
|
func RemoveNPCAttribution(str string) string {
|
||||||
|
lastOpen := strings.LastIndex(str, "(")
|
||||||
|
lastClose := strings.LastIndex(str, ")")
|
||||||
|
ending := len(str) - 1
|
||||||
|
|
||||||
|
if lastOpen > 0 && str[lastOpen-1] != '(' && (lastClose == -1 || lastClose == ending) {
|
||||||
|
cutoff := lastOpen
|
||||||
|
for cutoff > 1 && str[cutoff-1] == ' ' {
|
||||||
|
cutoff--
|
||||||
|
}
|
||||||
|
|
||||||
|
return str[:cutoff]
|
||||||
|
}
|
||||||
|
|
||||||
|
return str
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package util_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.aiterp.net/rpdata/logbot3/internal/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRemoveNPCAttribution(t *testing.T) {
|
||||||
|
table := []struct {
|
||||||
|
Input string
|
||||||
|
Output string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
Input: "Character does stuff. (Player_Name)",
|
||||||
|
Output: "Character does stuff.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "Text (with some clarification) about stuff.",
|
||||||
|
Output: "Text (with some clarification) about stuff.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "Text without anything.",
|
||||||
|
Output: "Text without anything.",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "((*Correction))",
|
||||||
|
Output: "((*Correction))",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, row := range table {
|
||||||
|
t.Run(fmt.Sprintf("Row_%d", i), func(t *testing.T) {
|
||||||
|
result := util.RemoveNPCAttribution(row.Input)
|
||||||
|
|
||||||
|
if result != row.Output {
|
||||||
|
t.Errorf("Row %d failed", i)
|
||||||
|
t.Errorf("Expected: %#+v", row.Output)
|
||||||
|
t.Errorf("Result: %#+v", result)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user