hedwig-im / hedwig

An Adapter-based Bot Framework for Elixir Applications
MIT License
650 stars 73 forks source link

Allow modules to define collections of responders #67

Open rjanja opened 7 years ago

rjanja commented 7 years ago

In some cases it is convenient to define a collection of responders outside of the bot's configuration file, and then to reference that collection as a list of responders to load with the bot.

Ex.:

Instead of:

config :testbot, Testbot.Robot,
  responders: [
    {Hedwig.Responders.Help, []},
    {Hedwig.Responders.Ping, []},
    {HedwigGithub.Responder, []},
    {HedwigPlusPlus.Responder, []},
    {HedwigSimpleResponders.BeerMe, []},
    {HedwigSimpleResponders.Echo, []},
    {HedwigSimpleResponders.Fishpun, []},
    {HedwigSimpleResponders.Flip, []},
    {HedwigSimpleResponders.Manatee, []},
    {HedwigSimpleResponders.PugMe, []},
    {HedwigSimpleResponders.Shingy, []},
    {HedwigSimpleResponders.ShipIt, []},
    {HedwigSimpleResponders.Slime, []},
    {HedwigSimpleResponders.Slogan, []},
    {HedwigSimpleResponders.Stallman, []},
    {HedwigSimpleResponders.Time, []},
    {HedwigSimpleResponders.Toot, []},
    {HedwigSimpleResponders.TroutSlap, []},
    {HedwigWunderground.Responder, []},
    {HedwigMopidy.Responders.Mopidy, []},
    {HedwigSimpleResponders.Uptime, []}
  ]

It becomes possible to delegate selection of responders:

config :testbot, Testbot.Robot,
  responders: [
    {Hedwig.Responders.Help, []},
    {Hedwig.Responders.Ping, []},
    {HedwigSimpleResponders, :all, []}, # <--
    {HedwigPlusPlus.Responder, []},
    {HedwigWunderground.Responder, []},
    {HedwigMopidy.Responders.Mopidy, []}
  ]

Any options defined with the collection are in turn passed to the collector function.

coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 92.105% when pulling 25442dcee0c39fd699b2888f8fce6b011179ad98 on labzero:responder-collections into 4031779105c299e0f92f18d3e37e51f3abe55902 on hedwig-im:master.

doomspork commented 7 years ago

@rjanja can't you already define multiple responders inside the same module?

rjanja commented 7 years ago

@doomspork This may be an edge case, but HedwigSimpleResponders provides a number of responders that would be nice to pull into projects (at least, our project) as a whole. If a module provides multiple responders, users cannot currently include them all in a single line but must include each of them using a separate line of code.