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 = [
|
2022-08-09 23:47:28 +02:00
|
|
|
"rate",
|
|
|
|
"things",
|
|
|
|
"capture_sentence",
|
|
|
|
"captured_sentence",
|
2021-06-06 18:28:43 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
super().__init__(bot)
|
|
|
|
self.priority = -8
|
2021-06-29 17:09:53 +02:00
|
|
|
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]
|
2022-08-30 18:50:28 +02:00
|
|
|
capture_sentence = self.config["capture_sentence"]
|
|
|
|
if message == capture_sentence:
|
2021-06-06 18:28:43 +02:00
|
|
|
self.capture(event.source.nick, event.target)
|
|
|
|
return True
|
2022-08-30 18:50:28 +02:00
|
|
|
else:
|
|
|
|
self.bot.log_d(f"Capture: “{message}” != “{capture_sentence}”")
|
2021-06-06 18:28:43 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
if proc(self.config["rate"]):
|
2021-06-29 17:09:53 +02:00
|
|
|
self.release_in_channel = event.target
|
2021-06-06 18:28:43 +02:00
|
|
|
return False
|
|
|
|
|
2021-06-29 17:09:53 +02:00
|
|
|
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(
|
2022-08-09 23:47:28 +02:00
|
|
|
winner=winner, thing=self.current_thing
|
2021-06-06 18:28:43 +02:00
|
|
|
)
|
|
|
|
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
|