51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""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
|