From 02470bcf1d347a98d4dbdf96f7bcf2537aded649 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Thu, 16 Jul 2020 17:54:34 -0700 Subject: [PATCH] Add "ignore" list to wordbot plugin Wordbot can now ignore users who send messages to the channel. Signed-off-by: Alek Ratzloff --- lib/contrib/wordbot/wordbot.ex | 18 ++++++++++-------- omnibot.example.exs | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/contrib/wordbot/wordbot.ex b/lib/contrib/wordbot/wordbot.ex index 48f547f..eaca1ef 100644 --- a/lib/contrib/wordbot/wordbot.ex +++ b/lib/contrib/wordbot/wordbot.ex @@ -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 diff --git a/omnibot.example.exs b/omnibot.example.exs index 2ca6bf5..fe23f59 100644 --- a/omnibot.example.exs +++ b/omnibot.example.exs @@ -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}]