Commit Graph

85 Commits

Author SHA1 Message Date
d73dabef43 Rename lib/contrib/wordbot.ex -> lib/contrib/wordbot/wordbot.ex
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 18:50:34 -07:00
96c5ed78cf Rename lib/irc.ex -> lib/irc/irc.ex
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 18:49:48 -07:00
8f112487c1 Update the instance of "module" with "plugin" and "mod" with "plug" where appropriate
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 18:30:46 -07:00
62a1064e87 Remove a couple of files that were accidentally introduced in the last commit
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 18:30:34 -07:00
f004b0ed01 Add lib/plugin that was removed in the last commit, whoops
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 18:23:55 -07:00
4d7073cfcd Rename Module -> Plugin with basic find/replace
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 18:23:24 -07:00
fcfdb17daa Format and add some comments to the linkbot module
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 18:14:38 -07:00
e3f30d30c1 Make linkbot title parsing more robust
Linkbot titles now check the "meta" tags for either "og:title" or
"title" attributes. This is usually a more accurate/correct title than
using the "title" tag, but this is checked as a last resort.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 18:09:09 -07:00
67192f2c5e Fix small bug with wordbot word score choice
The game ID was accidentally being added as a word to the wordlist. This
is no longer the case.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 18:04:13 -07:00
d56c0bf75c Update wordbot leaderboard and scoreboard to use "denotified" nicks
Nicknames that are sent by wordbot for the leaderboard command and the
end-of-game scoreboard are split up by zero-width space characters, to
avoid pinging the users at random times.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 17:23:29 -07:00
9b11c1c44d Remove old TODO
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 16:35:52 -07:00
0c15496579 Implement wordbot leaderboard command
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 16:35:19 -07:00
7f8a886550 Polish off wordbot implementation, add Omnibot.Module.GenServer
Wordbot implementation now uses the new Omnibot.Module.GenServer module,
which uses a GenServer instead of an Agent. This way, the module can
receive messages and makes storage a little easier.

Beyond that, minor changes all around.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-02 16:23:38 -07:00
67ba7a5847 WIP: Wordbot
Wordbot is a little more complex of a bot module and I've been working
on it here.

Other than wordbot module, a few minor tweaks have been added all around
that don't really affect anything.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-01 12:04:51 -07:00
871b7771fe Further separate module agents and module impl
Add Omnibot.Module.Agent which implements the basic agent cfg + state
persistence functionality, which is then included in the Omnibot.Module.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-14 18:46:19 -04:00
7f6a5e8a90 Fix small bug with linkbot where Regex.scan() would return a list of lists, instead of a list of strings
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-14 18:10:10 -04:00
4b269675d5 Clean up tasks being started by Omnibot.Irc.route_msg/2
Previously, tasks would be started with an auxiliary task that would
time out based on the module's timeout value - i.e. two tasks per module
per message. This was a little silly, so I've migrated to using
Task.Supervisor.async_stream_nolink/4. The only downside is that
module-defined timeout is not available for config, because all function
calls need to have the same timeout. This can probably be fixed by
breaking down the async_stream_nolink() function, but for now setting a
hard 30 second timeout works well enough.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-14 18:00:31 -04:00
76d96c2fe2 Rename Omnibot.Module -> Omnibot.Module.Base, add Omnibot.Module with agent
Previously, all modules were Agents. This renames the Omnibot.Module to
be the base module, and the new Omnibot.Module uses an Agent by default.

This opens the doors to possibly allowing metamodule supervisors for
modules that may be more complex.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-14 17:34:06 -04:00
95fc775349 Update main supervisor to only start the IRC connection if IEx is *not* running
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-14 16:47:44 -04:00
f12bc13e13 Remove test code and add hostname blacklist to Linkbot
Linkbot will now block addresses that attempt to use localhost, *.local,
*.home, *.localdomain, hosts that don't have a dot in them, and IP
addresses. This is to avoid exposing the bot to local addresses on the
host computer.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-14 16:41:40 -04:00
4083b5b858 Add default_config, and cfg[:timeout] for tasks
- Using the @default_config attribute in a module will fill out a default
value.
- cfg[:timeout] sets the timeout for the task for this module to finish.
- Update Omnibot.Irc.route_msg/2 to have each task spawn a second task,
  while the first task waits for its child to finish, otherwise killing
  it.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 21:47:46 -04:00
9dc00562fd Add linkbot contrib module
Linkbot listens for http:// and https:// links, and attempts to get
their titles.

This also adds the "tesla" dependency to mix.exs

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 20:59:58 -04:00
8c8f3c928d Add commands() for modules, which scoops up all commands defined.
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-06-13 20:59:09 -04:00
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