diff --git a/bot/mock.go b/bot/mock.go index adfd08f..d14ab2e 100644 --- a/bot/mock.go +++ b/bot/mock.go @@ -42,7 +42,6 @@ func (mb *MockBot) CheckAdmin(nick string) bool { return false } func (mb *MockBot) React(channel, reaction string, message msg.Message) {} func (mb *MockBot) GetEmojiList() map[string]string { return make(map[string]string) } - func NewMockBot() *MockBot { db, err := sqlx.Open("sqlite3_custom", ":memory:") if err != nil { diff --git a/plugins/counter/counter.go b/plugins/counter/counter.go index cac69d0..ebe51b0 100644 --- a/plugins/counter/counter.go +++ b/plugins/counter/counter.go @@ -136,7 +136,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool { return false } - if tea, _ := regexp.MatchString("(?i)^tea\\. [0-9A-Za-z_ ]*\\. ((hot)|(iced))\\.?$", message.Body); tea { + if tea, _ := regexp.MatchString("(?i)^tea\\. [^.]*\\. ((hot)|(iced))\\.?$", message.Body); tea { item, err := GetItem(p.DB, nick, ":tea:") if err != nil { log.Printf("Error finding item %s.%s: %s.", nick, ":tea:", err) diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index b0b233a..868de7b 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -69,6 +69,15 @@ func TestTeaSkieselQuote(t *testing.T) { assert.Nil(t, err) assert.Equal(t, 0, item.Count) } +func TestTeaUnicodeJapanese(t *testing.T) { + mb := bot.NewMockBot() + c := New(mb) + assert.NotNil(t, c) + c.Message(makeMessage("Tea. ใŠใกใ‚„. Hot.")) + item, err := GetItem(mb.DB(), "tester", ":tea:") + assert.Nil(t, err) + assert.Equal(t, 1, item.Count) +} func TestResetMe(t *testing.T) { mb := bot.NewMockBot() diff --git a/plugins/fact/factoid.go b/plugins/fact/factoid.go index a33eb1f..0408be1 100644 --- a/plugins/fact/factoid.go +++ b/plugins/fact/factoid.go @@ -439,18 +439,15 @@ func (p *Factoid) forgetLastFact(message msg.Message) bool { p.Bot.SendMessage(message.Channel, "I refuse.") return true } - if message.User.Admin || message.User.Name == p.LastFact.Owner { - err := p.LastFact.delete(p.db) - if err != nil { - log.Println("Error removing fact: ", p.LastFact, err) - } - fmt.Printf("Forgot #%d: %s %s %s\n", p.LastFact.id.Int64, p.LastFact.Fact, - p.LastFact.Verb, p.LastFact.Tidbit) - p.Bot.SendAction(message.Channel, "hits himself over the head with a skillet") - p.LastFact = nil - } else { - p.Bot.SendMessage(message.Channel, "You don't own that fact.") + + err := p.LastFact.delete(p.db) + if err != nil { + log.Println("Error removing fact: ", p.LastFact, err) } + fmt.Printf("Forgot #%d: %s %s %s\n", p.LastFact.id.Int64, p.LastFact.Fact, + p.LastFact.Verb, p.LastFact.Tidbit) + p.Bot.SendAction(message.Channel, "hits himself over the head with a skillet") + p.LastFact = nil return true } @@ -479,12 +476,8 @@ func (p *Factoid) changeFact(message msg.Message) bool { if err != nil { log.Println("Error getting facts: ", trigger, err) } - if !(message.User.Admin && userexp[len(userexp)-1] == 'g') { + if userexp[len(userexp)-1] != 'g' { result = result[:1] - if result[0].Owner != message.User.Name && !message.User.Admin { - p.Bot.SendMessage(message.Channel, "That's not your fact to edit.") - return true - } } // make the changes msg := fmt.Sprintf("Changing %d facts.", len(result))