mirror of https://github.com/velour/catbase.git
bot: get rid of a string
I introduced reflection earlier. I may as well go whole hog now.
This commit is contained in:
parent
287c26440e
commit
a25d7b9eff
|
@ -112,7 +112,8 @@ func (b *bot) migrateDB() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a constructed handler to the bots handlers list
|
// 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.plugins[name] = h
|
||||||
b.pluginOrdering = append(b.pluginOrdering, name)
|
b.pluginOrdering = append(b.pluginOrdering, name)
|
||||||
if entry := h.RegisterWeb(); entry != nil {
|
if entry := h.RegisterWeb(); entry != nil {
|
||||||
|
|
|
@ -45,7 +45,7 @@ type Bot interface {
|
||||||
// Who lists users in a particular channel
|
// Who lists users in a particular channel
|
||||||
Who(string) []user.User
|
Who(string) []user.User
|
||||||
// AddPlugin registers a new plugin handler
|
// AddPlugin registers a new plugin handler
|
||||||
AddPlugin(string, Plugin)
|
AddPlugin(Plugin)
|
||||||
// First arg should be one of bot.Message/Reply/Action/etc
|
// First arg should be one of bot.Message/Reply/Action/etc
|
||||||
Send(Kind, ...interface{}) (string, error)
|
Send(Kind, ...interface{}) (string, error)
|
||||||
// First arg should be one of bot.Message/Reply/Action/etc
|
// First arg should be one of bot.Message/Reply/Action/etc
|
||||||
|
|
|
@ -46,7 +46,7 @@ func (mb *MockBot) Send(kind Kind, args ...interface{}) (string, error) {
|
||||||
}
|
}
|
||||||
return "ERR", fmt.Errorf("Mesasge type unhandled")
|
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) Register(p Plugin, kind Kind, cb Callback) {}
|
||||||
func (mb *MockBot) Receive(kind Kind, msg msg.Message, args ...interface{}) {}
|
func (mb *MockBot) Receive(kind Kind, msg msg.Message, args ...interface{}) {}
|
||||||
func (mb *MockBot) Filter(msg msg.Message, s string) string { return s }
|
func (mb *MockBot) Filter(msg msg.Message, s string) string { return s }
|
||||||
|
|
50
main.go
50
main.go
|
@ -78,32 +78,32 @@ func main() {
|
||||||
|
|
||||||
b := bot.New(c, client)
|
b := bot.New(c, client)
|
||||||
|
|
||||||
b.AddPlugin("admin", admin.New(b))
|
b.AddPlugin(admin.New(b))
|
||||||
b.AddPlugin("emojifyme", emojifyme.New(b))
|
b.AddPlugin(emojifyme.New(b))
|
||||||
b.AddPlugin("first", first.New(b))
|
b.AddPlugin(first.New(b))
|
||||||
b.AddPlugin("leftpad", leftpad.New(b))
|
b.AddPlugin(leftpad.New(b))
|
||||||
b.AddPlugin("talker", talker.New(b))
|
b.AddPlugin(talker.New(b))
|
||||||
b.AddPlugin("dice", dice.New(b))
|
b.AddPlugin(dice.New(b))
|
||||||
b.AddPlugin("picker", picker.New(b))
|
b.AddPlugin(picker.New(b))
|
||||||
b.AddPlugin("beers", beers.New(b))
|
b.AddPlugin(beers.New(b))
|
||||||
b.AddPlugin("remember", fact.NewRemember(b))
|
b.AddPlugin(fact.NewRemember(b))
|
||||||
b.AddPlugin("your", your.New(b))
|
b.AddPlugin(your.New(b))
|
||||||
b.AddPlugin("counter", counter.New(b))
|
b.AddPlugin(counter.New(b))
|
||||||
b.AddPlugin("reminder", reminder.New(b))
|
b.AddPlugin(reminder.New(b))
|
||||||
b.AddPlugin("babbler", babbler.New(b))
|
b.AddPlugin(babbler.New(b))
|
||||||
b.AddPlugin("zork", zork.New(b))
|
b.AddPlugin(zork.New(b))
|
||||||
b.AddPlugin("rss", rss.New(b))
|
b.AddPlugin(rss.New(b))
|
||||||
b.AddPlugin("reaction", reaction.New(b))
|
b.AddPlugin(reaction.New(b))
|
||||||
b.AddPlugin("twitch", twitch.New(b))
|
b.AddPlugin(twitch.New(b))
|
||||||
b.AddPlugin("inventory", inventory.New(b))
|
b.AddPlugin(inventory.New(b))
|
||||||
b.AddPlugin("rpgORdie", rpgORdie.New(b))
|
b.AddPlugin(rpgORdie.New(b))
|
||||||
b.AddPlugin("sisyphus", sisyphus.New(b))
|
b.AddPlugin(sisyphus.New(b))
|
||||||
b.AddPlugin("tell", tell.New(b))
|
b.AddPlugin(tell.New(b))
|
||||||
b.AddPlugin("couldashouldawoulda", couldashouldawoulda.New(b))
|
b.AddPlugin(couldashouldawoulda.New(b))
|
||||||
b.AddPlugin("nedepedia", nerdepedia.New(b))
|
b.AddPlugin(nerdepedia.New(b))
|
||||||
// catches anything left, will always return true
|
// catches anything left, will always return true
|
||||||
b.AddPlugin("factoid", fact.New(b))
|
b.AddPlugin(fact.New(b))
|
||||||
b.AddPlugin("db", db.New(b))
|
b.AddPlugin(db.New(b))
|
||||||
|
|
||||||
for {
|
for {
|
||||||
err := client.Serve()
|
err := client.Serve()
|
||||||
|
|
Loading…
Reference in New Issue