Commit Graph

109 Commits

Author SHA1 Message Date
d3de274e48 Rearrange lib/core.ex code
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-18 16:41:27 -07:00
a73d94376f Add top-level channels to example config
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-18 16:34:28 -07:00
09cb4ac752 Update config with some docs
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-18 16:33:43 -07:00
8789f8b097 Add top-level channels to configuration
If you want all modules to act on all channels, you can simply set
`channels: :all` on all modules, and add `channels: ["#channel",
"#channel", ...]` to the same configuration level as `plugins`. These
are added to the "all channels" list and joined automatically.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-18 16:28:45 -07:00
e288ee1e27 Ignore build data with docker-compose
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-18 15:44:13 -07:00
feda81f205 Remove some stray comments from docker-compose.yml
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-18 15:20:14 -07:00
88bd7a6231 Add Dockerfile, docker-compose.yml, and docker.env
Omnibot can be run using Docker and docker-compose using the provided
files.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-18 15:17:53 -07:00
5742bf52e2 Rename OMNIBOT_CFG env variable to OMNIBOT_CONFIG
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-18 15:17:12 -07:00
fe0fb59977 Fix up logic for Omnibot.Core pinging and auto-reconnect
The core module keeps track of the last message received. If the last
message received was more than X seconds ago (configurable), it will
send a ping. If the last message was received more than Y seconds ago
(again, configurable) then reset the connection.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-12 18:25:24 -07:00
8d42e6ecb3 Add ping watcher to Omnibot.Core
Core module now pings the server and attempts to reconnect if a
respective pong has not been received in a certain amount of time.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-12 15:33:04 -07:00
a3e4a088b3 Add Omnibot.Plugin.Base.on_connect/1 callback
This new callback gets called immediately upon connecting to the server.
It is automatically implemented as a no-op by default.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-12 15:31:40 -07:00
0f3edb52bc Add cfg/1 to Omnibot.Plugin macro
This allows getting a specific key from the configuration instead of
getting the full array. Allows for using this:

    cfg(:some_config)

instead of this:

    cfg()[:some_config]

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-12 15:27:07 -07:00
c1602065ae Update Omnibot.Core state to use a map for flexibility
More things need to be added to Omnibot.Core's state, so it's been
expanded to a map to allow for that.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 16:17:42 -07:00
aa6a4bf5fa Move lib/core/core.ex -> lib/core.ex
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 16:14:08 -07:00
906a20bda1 Update calls of Enum.member?/1 to be 'x in y' instead
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 16:00:09 -07:00
1f574dd0eb Remove lib/state.ex
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 15:58:42 -07:00
3b7562a1d2 Add base moduledoc to Plugin.Supervisor
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 15:55:36 -07:00
accfc2a7fe Remove old TODO
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 15:43:43 -07:00
66b20c976f Remove Omnibot.State from process tree
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 15:37:02 -07:00
2f378dd438 Finish removing Omnibot.State functions
Omnibot.State shouldn't be used anywhere anymore except as a GenServer
being started up in the supervisor.

Also, configuration must be loaded through Config.load/1 rather than
being constructed, because everything expects a tuple of {plugin,
config} now.

Finally, Omnibot.Core must be added to the configuration in order for
basic functionality.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 15:23:53 -07:00
2165167954 Remove usage of State.all_channels/0
Deprecating Omnibot.State:

Config.all_channels/1 has the same logic as this, and is better
documented anyway.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 13:30:32 -07:00
2dc7bbd94d Replace all other State.cfg/0 in favor of Irc.cfg/1
State.cfg/0 should be removed from the codebase by this point. Should be
safe to remove.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 12:52:37 -07:00
6110420015 Comment out !markov status command, since it's quite expensive
There's probably a better way to make this less expensive, but I'm not
sure what it is. Until then, we'll leave this feature out.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 12:50:33 -07:00
715480230a Remove Omnibot.State.cfg/0 from Omnibot.Irc module
Deprecating Omnibot.State: IRC module holds its own configuration now.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 12:48:28 -07:00
b423507796 Add deprecations for Omnibot.State functions
We're getting rid of the State hack module, because each IRC connection
should hold onto its own config.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 12:46:54 -07:00
f89b31520b Add some more fortunes for fortune module
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-08-11 12:45:29 -07:00
192e1b2b08 Add Omnibot.Config documentation
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-21 18:09:15 -07:00
0960d8f541 Fix test/util_test.exs formatting to move alias into defmodule body
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-21 17:47:24 -07:00
6de47a2fec Update example config 'modules' and 'module_paths' to use 'plugin(s)' instead
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-21 17:45:03 -07:00
d91493fd46 Reformat markov bot's @default_config array
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-21 17:11:05 -07:00
dac2c7438a Minor change of 'if not' -> 'unless'
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-21 14:59:55 -07:00
b1461e24db Fix bug in Markov.Chain where reply_chance would get reset, add regression tests for this
* Markov.Chain.add_weight/4 would return a fresh new markov chain,
  instead of using all of the previous values of the chain that was
  being modified. This would result in resetting the reply_chance value
  to the default of 0.01.
* Add tests to make sure this doesn't happen to add_weights in the
  future.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-21 14:58:10 -07:00
ec1dd42ca1 Fix routing bug in IRC and base plugin
Previously, messages were only routed from IRC if they were *not* for
the current user. This should only be happening for privmsg messages,
since a plugin is generally aware of what it's sending out.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-18 14:09:17 -07:00
d2a1cb541d Change message routing logic to be an implication instead of AND
Previously, a message wouldn't be admitted if it didn't have a prefix,
(logical) AND if the message was equal to the bot's nickname.

Now, a message with a blank prefix passes through, but if the prefix is
the bot's nickname, it does not.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 22:14:40 -07:00
b72071793b Remove unnecessary kruft
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 22:14:33 -07:00
9fac85cc9a Remove extraneous IO.inspect calls
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 21:43:48 -07:00
109cd67b37 Add reply_chance to markov chains and markov commands
Every time a user sends a message, there is now a chance that markov
will reply with a random message based on what they said. !markov chance
allows lookups and setting of the chance that a user may receive a
message.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 21:39:39 -07:00
e375f1604a Finish up markov with implementation of !markov status
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 20:51:01 -07:00
04a4c740bd Add allchain and implement "all", "emulate" commands for markov plugin
* Markov allchain is generated from all markov chains in the save
  directory for the given channel. This omits starting processes for
  known markov chains.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 20:08:18 -07:00
9dc1033cd2 Add merge/1 and merge/2 to Markov.Chain
merge/1 takes a nonempty list of markov chains to merge

merge/2 takes two markov chains of the same order and sums their weights

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 20:07:02 -07:00
6f625c21ca Add Markov.ChainServer for Markov plugin
* Markov chains each have their own process keeping it updated and
  synchronized. The markov plugin has been upgraded to account for this.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 17:40:22 -07:00
9cfc77d1a4 Squash warning in wordbot re: function parens
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 17:40:14 -07:00
880f363792 Remove (supervisor) opts from Omnibot.Plugin opts, update Plugin.Supervisor to use :one_for_all strategy by default
Plugin opts no longer contains options for the supervisors that watch
plugins, and said supervisors now adopt the one_for_all strategy. This
is because these servers *generally* need one another to stay alive.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 17:37:55 -07:00
e88bd58229 Update markov chains to be backed by maps instead of lists
This should hopefully speed up lookups and stuff like that.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 17:33:52 -07:00
296f061a70 Bump us back up to Elixir 1.10
We aren't compatible with 1.7. Oops.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-17 17:15:27 -07:00
bb8ebca0b8 IRC messages are not routed if they are sent by the bot
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-16 18:00:43 -07:00
02470bcf1d Add "ignore" list to wordbot plugin
Wordbot can now ignore users who send messages to the channel.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-16 17:54:34 -07:00
4c93b42fdc Finish markov chain generation impl
* Markov chains will train and generate chains correctly now
* Implement Markov.save_chains/0
* Add a couple more utils that help accomplish the above

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-15 16:25:25 -07:00
c43c075588 Minor changes all around
* Wordbot does not IO.inspect() the winners of the round
* Split Omnibot.Plugin.base_children/1 into base_children_before/1 and
  base_children_after/1 for plugins that come before and after the
  children in the module
* Other minor changes

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-14 19:13:43 -07:00
522c62a55c Finish plugin and routing overhaul, there's a new model in town:
* Plugins all derive from Omnibot.Plugin. There still is a base plugin,
  in case we want to have another plugin backend instead of a GenServer
* All plugins are monitored by a unique Plugin.Supervisor, which is in
  turn started by the PluginSupervisor (yes this is confusing, yes it
  needs to be renamed)
* Any other auxiliary child processes may be started through the
  Plugin.children/1 function.
* By default, plugins have a CfgState process which is an Agent that
  keeps track of the plugin's configuration and state
* Plugin API is now called through the GenServer backend for better
  synchronicity.
* Very few changes to the front-facing Plugin API, which is nice

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-07-14 15:05:00 -07:00