Commit Graph

62 Commits

Author SHA1 Message Date
a627842717 Update/fix Omnibot.Irc.route_msg/2 to spawn a new task for each module, instead of a single task for all modules
Previously, if a message was supposed to be handled by 3 modules, they
would all be handled, synchronously, in the same process. If any of them
crashed, it would affect any other modules that needed to be processed
ahead of it.

Now, a new task is spun up for each module, so module handlers are now
indpendent.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 20:56:02 -04:00
5719e9e279 Remove TODO from supervisor.ex
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 20:53:53 -04:00
4000528d81 Move more stuff from other places into Omnibot.Core
* Present rooms are tracked by Omnibot.Core now, instead of
  Omnibot.State
* Channel synchronization is done through Omnibot.Core instead of
  Omnibot.Irc
* Add Omnibot.Module.on_init/1 callback, which returns a "state" value
  for the module to keep track of. By default, the state is nil.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 18:45:02 -04:00
91cdd9cae8 Remove router.ex and move behavior to Omnibot.Irc
Omnibot.Router was useful when it was used for actually routing
messages. However, its responsibilities have spread such that it's just
a single function at this point. So this single function has been moved
to Omnibot.Irc as a private function instead.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 18:11:18 -04:00
b1640a8c44 Remove IO.inspect from module_supervisor init
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 18:11:03 -04:00
4d27e30b88 Finish migration to using a module to control core behavior
Previously, core behavior was handled in the Omnibot.Router module.
However, since the module system is robust enough, this work has been
delegated to the Omnibot.Core module.

Additionally, the Omnibot.State module has been augmented to keep track
of the modules that have been currently loaded, and methods that are
used to get the list of loaded modules and routing information for those
modules are coming from Omnibot.State as well (as opposed to
Omnibot.Config). This is to avoid requiring the Omnibot.Core module be
included in the config, plus avoiding modification of the runtime config
after it has already been loaded.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 18:01:40 -04:00
304a8d4164 WIP: Move Config.all_channels/0 and Config.channel_modules/1 logic into State; add State.add_loaded_module/2
The problem:

When we're going through the list of modules to send messages to based
on the channels they're a part of, it was being done so through the
config. Since the config doesn't (and shouldn't) list all of the core
modules that get included, any core modules that were loaded and running
under the ModuleSupervisor would not get included in the router's
attempt to send messages to a module.

Now, the Config.all_channels and Config.channel_modules functions live
in State, and State has a new "add_loaded_module" function where loaded
modules are registered. The aforementioned moved functions will use this
as the "source of truth" when deciding where to send messages for
modules to handle.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 17:13:05 -04:00
73c5f58243 WIP: Move to using modules for implementing core behavior
Since modules can now intercept all messages in the channels they're
listening for, it'd be cool to have modules handling things like making
sure the Omnibot.State stays updated as appropriate, and that pings are
ponged, etc.

This will probably deprecate the router, since it's been reduced to a
single function call, but we'll see about that.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 16:04:19 -04:00
5f251d22ce Remove IO.inspect that was included in the last commit
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 15:22:12 -04:00
ed22d1bf0f Update modules to be more egonomic, add command macro
Modules are now defined using on_{msg,channel_msg,join,part,kick}.
Additionally, commands can be defined using a convenient macro.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 15:20:00 -04:00
e2e7ae22b8 Add Omnibot.Module
Modules can easily be defined with `use Omnibot.Module`.
Omnibot.Contrib.Fortune has been updated to use this.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-12 18:24:11 -04:00
6340936895 Initial commit with IRC and bot example.
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-12 17:29:35 -04:00