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>
This commit is contained in:
2020-07-16 17:54:34 -07:00
parent 4c93b42fdc
commit 02470bcf1d
2 changed files with 11 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ defmodule Omnibot.Contrib.Wordbot do
alias Omnibot.{Contrib.Wordbot, State, Util}
require Logger
@default_config wordbot_source: "words.txt", wordbot_db: "wordbot.db", words_per_round: 300, hours_per_round: 5
@default_config wordbot_source: "words.txt", wordbot_db: "wordbot.db", words_per_round: 300, hours_per_round: 5, ignore: []
@impl true
def children(cfg) do
@@ -148,13 +148,15 @@ defmodule Omnibot.Contrib.Wordbot do
@impl true
def on_channel_msg(irc, channel, nick, msg) do
words = Regex.split(@split_pattern, msg) |> MapSet.new()
game_words = Wordbot.Db.unmatched_words(channel) |> MapSet.new()
MapSet.intersection(words, game_words)
|> Enum.each(fn word ->
Wordbot.Db.add_score(channel, nick, word, msg)
Irc.send_to(irc, channel, "#{nick}: Congrats! '#{word}' is good for 1 point.")
end)
if nick not in cfg[:ignore] do
words = Regex.split(@split_pattern, msg) |> MapSet.new()
game_words = Wordbot.Db.unmatched_words(channel) |> MapSet.new()
MapSet.intersection(words, game_words)
|> Enum.each(fn word ->
Wordbot.Db.add_score(channel, nick, word, msg)
Irc.send_to(irc, channel, "#{nick}: Congrats! '#{word}' is good for 1 point.")
end)
end
end
@impl true

View File

@@ -13,7 +13,7 @@ config = %Config {
]},
{Omnibot.Contrib.Linkbot, channels: :all},
{Omnibot.Contrib.Fortune, channels: :all},
{Omnibot.Contrib.Wordbot, channels: ["#idleville"]},
{Omnibot.Contrib.Wordbot, channels: ["#idleville"], ignore: ["username"]},
],
#module_paths: [{"modules", recurse: true}]