You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB

"""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 = ""
self.current_thing = None
def on_pubmsg(self, event):
if not self.respects_handling_conditions():
return False
if self.current_thing is not None:
message = event.arguments[0]
capture_sentence = self.config["capture_sentence"]
if message == capture_sentence:
self.capture(event.source.nick, event.target)
return True
else:
self.bot.log_d(f"Capture: “{message}” != “{capture_sentence}")
return False
if proc(self.config["rate"]):
self.release_in_channel = event.target
return False
def on_ping(self, event):
if self.release_in_channel:
self.release_thing(self.release_in_channel)
self.release_in_channel = ""
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