diff --git a/.gitignore b/.gitignore index 8af5c69..3abe6ab 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ config.json storage.json resources/* !resources/.gitkeep +venv/ +.vim/ diff --git a/config.json.example b/config.json.example index 7025175..b3b17eb 100644 --- a/config.json.example +++ b/config.json.example @@ -22,6 +22,12 @@ "welcome_rate": 10, "farewell_rate": 10 }, + "capture": { + "rate": 0.1, + "things": "🍇🍈🍉🍊🍋🍌🍍🥭🍎🍏🍐🍑🍒🍓", + "capture_sentence": "Catch!", + "captured_sentence": "Well done {winner}, you got that {thing}!" + }, "common": { "command_suffix": "please", "handling_conditions": { diff --git a/edmond/plugin.py b/edmond/plugin.py index ec7668e..835b4fd 100644 --- a/edmond/plugin.py +++ b/edmond/plugin.py @@ -32,8 +32,9 @@ class Plugin: For now these levels are used: - 0: default - -3: low, misc parsing of messages, answer to various messages - - -8: handling of unknown commands - - -9: handling of unknown questions + - -6: handling of unknown commands + - -7: handling of unknown questions + - -8: handling any message that might match something - -10: lowest, e.g. for random reactions usually with a very low rate """ diff --git a/edmond/plugins/capture.py b/edmond/plugins/capture.py new file mode 100644 index 0000000..87fe484 --- /dev/null +++ b/edmond/plugins/capture.py @@ -0,0 +1,50 @@ +"""A little capture game!""" + +import random + +from edmond.plugin import Plugin +from edmond.utils import proc + + +class CapturePlugin(Plugin): + + REQUIRED_CONFIGS = [ + "rate", "things", "capture_sentence", "captured_sentence" + ] + + def __init__(self, bot): + super().__init__(bot) + self.priority = -8 + self.current_thing = None + + def on_pubmsg(self, event): + if self.current_thing is not None: + message = event.arguments[0] + if message == self.config["capture_sentence"]: + self.capture(event.source.nick, event.target) + return True + return False + + if proc(self.config["rate"]): + self.release_thing(event.target) + return True + return False + + def release_thing(self, target): + self.current_thing = random.choice(self.config["things"]) + self.bot.say(target, f"(>O_O)> ~~{self.current_thing}") + + def capture(self, winner, target): + congratz = self.config["captured_sentence"].format( + winner=winner, + thing=self.current_thing + ) + self.bot.say(target, congratz) + + collections = self.get_storage_value("collections", default={}) + if winner not in collections: + collections[winner] = [] + collections[winner].append(self.current_thing) + self.set_storage_value("collections", collections) + + self.current_thing = None diff --git a/edmond/plugins/unknown_command.py b/edmond/plugins/unknown_command.py index b6647ee..44bc5b9 100644 --- a/edmond/plugins/unknown_command.py +++ b/edmond/plugins/unknown_command.py @@ -16,7 +16,7 @@ class UnknownCommandPlugin(Plugin): def __init__(self, bot): super().__init__(bot) - self.priority = -8 + self.priority = -6 self._client = None @property diff --git a/edmond/plugins/unknown_question.py b/edmond/plugins/unknown_question.py index 61aff05..f4581a6 100644 --- a/edmond/plugins/unknown_question.py +++ b/edmond/plugins/unknown_question.py @@ -15,7 +15,7 @@ class UnknownQuestionPlugin(Plugin): def __init__(self, bot): super().__init__(bot) - self.priority = -9 + self.priority = -7 self.misc_plugin = None def on_welcome(self, event):