Edm0nd/edmond/plugins/capture.py

58 lines
1.7 KiB
Python
Raw Normal View History

2021-06-06 18:28:43 +02:00
"""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.release_in_channel = ""
2021-06-06 18:28:43 +02:00
self.current_thing = None
def on_pubmsg(self, event):
2021-07-03 01:40:17 +02:00
if not self.respects_handling_conditions():
return False
2021-06-06 18:28:43 +02:00
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_in_channel = event.target
2021-06-06 18:28:43 +02:00
return False
def on_ping(self, event):
if self.release_in_channel:
self.release_thing(self.release_in_channel)
self.release_in_channel = ""
2021-06-06 18:28:43 +02:00
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