60 lines
1.7 KiB
Python
60 lines
1.7 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.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]
|
|
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
|
|
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
|