diff --git a/bot/bot.go b/bot/bot.go index 1859f32..c5b237d 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -112,7 +112,8 @@ func (b *bot) migrateDB() { } // Adds a constructed handler to the bots handlers list -func (b *bot) AddPlugin(name string, h Plugin) { +func (b *bot) AddPlugin(h Plugin) { + name := reflect.TypeOf(h).String() b.plugins[name] = h b.pluginOrdering = append(b.pluginOrdering, name) if entry := h.RegisterWeb(); entry != nil { diff --git a/bot/interfaces.go b/bot/interfaces.go index e4ec4d8..74eed27 100644 --- a/bot/interfaces.go +++ b/bot/interfaces.go @@ -45,7 +45,7 @@ type Bot interface { // Who lists users in a particular channel Who(string) []user.User // AddPlugin registers a new plugin handler - AddPlugin(string, Plugin) + AddPlugin(Plugin) // First arg should be one of bot.Message/Reply/Action/etc Send(Kind, ...interface{}) (string, error) // First arg should be one of bot.Message/Reply/Action/etc diff --git a/bot/mock.go b/bot/mock.go index 70dd1df..ea8986e 100644 --- a/bot/mock.go +++ b/bot/mock.go @@ -46,7 +46,7 @@ func (mb *MockBot) Send(kind Kind, args ...interface{}) (string, error) { } return "ERR", fmt.Errorf("Mesasge type unhandled") } -func (mb *MockBot) AddPlugin(name string, f Plugin) {} +func (mb *MockBot) AddPlugin(f Plugin) {} func (mb *MockBot) Register(p Plugin, kind Kind, cb Callback) {} func (mb *MockBot) Receive(kind Kind, msg msg.Message, args ...interface{}) {} func (mb *MockBot) Filter(msg msg.Message, s string) string { return s } diff --git a/main.go b/main.go index eb07687..6ab529d 100644 --- a/main.go +++ b/main.go @@ -78,32 +78,32 @@ func main() { b := bot.New(c, client) - b.AddPlugin("admin", admin.New(b)) - b.AddPlugin("emojifyme", emojifyme.New(b)) - b.AddPlugin("first", first.New(b)) - b.AddPlugin("leftpad", leftpad.New(b)) - b.AddPlugin("talker", talker.New(b)) - b.AddPlugin("dice", dice.New(b)) - b.AddPlugin("picker", picker.New(b)) - b.AddPlugin("beers", beers.New(b)) - b.AddPlugin("remember", fact.NewRemember(b)) - b.AddPlugin("your", your.New(b)) - b.AddPlugin("counter", counter.New(b)) - b.AddPlugin("reminder", reminder.New(b)) - b.AddPlugin("babbler", babbler.New(b)) - b.AddPlugin("zork", zork.New(b)) - b.AddPlugin("rss", rss.New(b)) - b.AddPlugin("reaction", reaction.New(b)) - b.AddPlugin("twitch", twitch.New(b)) - b.AddPlugin("inventory", inventory.New(b)) - b.AddPlugin("rpgORdie", rpgORdie.New(b)) - b.AddPlugin("sisyphus", sisyphus.New(b)) - b.AddPlugin("tell", tell.New(b)) - b.AddPlugin("couldashouldawoulda", couldashouldawoulda.New(b)) - b.AddPlugin("nedepedia", nerdepedia.New(b)) + b.AddPlugin(admin.New(b)) + b.AddPlugin(emojifyme.New(b)) + b.AddPlugin(first.New(b)) + b.AddPlugin(leftpad.New(b)) + b.AddPlugin(talker.New(b)) + b.AddPlugin(dice.New(b)) + b.AddPlugin(picker.New(b)) + b.AddPlugin(beers.New(b)) + b.AddPlugin(fact.NewRemember(b)) + b.AddPlugin(your.New(b)) + b.AddPlugin(counter.New(b)) + b.AddPlugin(reminder.New(b)) + b.AddPlugin(babbler.New(b)) + b.AddPlugin(zork.New(b)) + b.AddPlugin(rss.New(b)) + b.AddPlugin(reaction.New(b)) + b.AddPlugin(twitch.New(b)) + b.AddPlugin(inventory.New(b)) + b.AddPlugin(rpgORdie.New(b)) + b.AddPlugin(sisyphus.New(b)) + b.AddPlugin(tell.New(b)) + b.AddPlugin(couldashouldawoulda.New(b)) + b.AddPlugin(nerdepedia.New(b)) // catches anything left, will always return true - b.AddPlugin("factoid", fact.New(b)) - b.AddPlugin("db", db.New(b)) + b.AddPlugin(fact.New(b)) + b.AddPlugin(db.New(b)) for { err := client.Serve()