Compare commits
3 commits
9ae5545516
...
93d59ff30b
Author | SHA1 | Date | |
---|---|---|---|
dece | 93d59ff30b | ||
dece | 7f5ed39722 | ||
dece | ab61d807be |
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,3 +2,5 @@ config.json
|
||||||
storage.json
|
storage.json
|
||||||
resources/*
|
resources/*
|
||||||
!resources/.gitkeep
|
!resources/.gitkeep
|
||||||
|
venv/
|
||||||
|
.vim/
|
||||||
|
|
|
@ -17,6 +17,7 @@ RUN useradd --uid ${UID} --gid edmond \
|
||||||
edmond
|
edmond
|
||||||
|
|
||||||
ENV DEBIAN_FRONTEND teletype
|
ENV DEBIAN_FRONTEND teletype
|
||||||
|
STOPSIGNAL SIGINT
|
||||||
|
|
||||||
USER edmond
|
USER edmond
|
||||||
ENTRYPOINT ["python", "-m", "edmond"]
|
ENTRYPOINT ["python", "-m", "edmond"]
|
||||||
|
|
|
@ -22,6 +22,17 @@
|
||||||
"welcome_rate": 10,
|
"welcome_rate": 10,
|
||||||
"farewell_rate": 10
|
"farewell_rate": 10
|
||||||
},
|
},
|
||||||
|
"capture": {
|
||||||
|
"rate": 0.1,
|
||||||
|
"things": "🍇🍈🍉🍊🍋🍌🍍🥭🍎🍏🍐🍑🍒🍓",
|
||||||
|
"capture_sentence": "Catch!",
|
||||||
|
"captured_sentence": "Well done {winner}, you got that {thing}!"
|
||||||
|
},
|
||||||
|
"capturelist": {
|
||||||
|
"commands": ["collection"],
|
||||||
|
"reply": "{target} captured {num} things : {things}",
|
||||||
|
"empty_reply": "{target} did not capture anything yet!"
|
||||||
|
},
|
||||||
"common": {
|
"common": {
|
||||||
"command_suffix": "please",
|
"command_suffix": "please",
|
||||||
"handling_conditions": {
|
"handling_conditions": {
|
||||||
|
|
|
@ -32,8 +32,9 @@ class Plugin:
|
||||||
For now these levels are used:
|
For now these levels are used:
|
||||||
- 0: default
|
- 0: default
|
||||||
- -3: low, misc parsing of messages, answer to various messages
|
- -3: low, misc parsing of messages, answer to various messages
|
||||||
- -8: handling of unknown commands
|
- -6: handling of unknown commands
|
||||||
- -9: handling of unknown questions
|
- -7: handling of unknown questions
|
||||||
|
- -8: handling any message that might match something
|
||||||
- -10: lowest, e.g. for random reactions usually with a very low rate
|
- -10: lowest, e.g. for random reactions usually with a very low rate
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -94,9 +95,15 @@ class Plugin:
|
||||||
"""Set a value in the plugin runtime dict."""
|
"""Set a value in the plugin runtime dict."""
|
||||||
self.bot.values[self.name][key] = value
|
self.bot.values[self.name][key] = value
|
||||||
|
|
||||||
def get_storage_value(self, key, default=None):
|
def get_storage_value(self, key, default=None, ns=None):
|
||||||
"""Get a value from the plugin persistent storage."""
|
"""Get a value from the plugin persistent storage.
|
||||||
return self.bot.storage.get(self.name, {}).get(key, default)
|
|
||||||
|
This will get the value from the plugin namespace, but it is possible to
|
||||||
|
get storage values from other plugins using their name as `ns`.
|
||||||
|
"""
|
||||||
|
if ns is None:
|
||||||
|
ns = self.name
|
||||||
|
return self.bot.storage.get(ns, {}).get(key, default)
|
||||||
|
|
||||||
def set_storage_value(self, key, value):
|
def set_storage_value(self, key, value):
|
||||||
"""Set a value in the plugin persistent storage."""
|
"""Set a value in the plugin persistent storage."""
|
||||||
|
|
50
edmond/plugins/capture.py
Normal file
50
edmond/plugins/capture.py
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
"""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
|
36
edmond/plugins/capture_list.py
Normal file
36
edmond/plugins/capture_list.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
from edmond.plugin import Plugin
|
||||||
|
|
||||||
|
|
||||||
|
class CaptureListPlugin(Plugin):
|
||||||
|
|
||||||
|
REQUIRED_CONFIGS = ["commands", "reply", "empty_reply"]
|
||||||
|
|
||||||
|
def __init__(self, bot):
|
||||||
|
super().__init__(bot)
|
||||||
|
|
||||||
|
def on_welcome(self, _):
|
||||||
|
if not self.bot.get_plugin("capture"):
|
||||||
|
self.bot.log_w("Capture plugin is not available.")
|
||||||
|
self.is_ready = False
|
||||||
|
|
||||||
|
def on_pubmsg(self, event):
|
||||||
|
if not self.should_handle_command(event.arguments[0]):
|
||||||
|
return False
|
||||||
|
|
||||||
|
collec_target = self.command.content or event.source.nick
|
||||||
|
collections = self.get_storage_value(
|
||||||
|
"collections",
|
||||||
|
default={},
|
||||||
|
ns="capture"
|
||||||
|
)
|
||||||
|
collection = collections.get(collec_target, [])
|
||||||
|
if collection:
|
||||||
|
reply = self.config["reply"].format(
|
||||||
|
target=collec_target,
|
||||||
|
num=len(collection),
|
||||||
|
things="".join(collection)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
reply = self.config["empty_reply"].format(target=collec_target)
|
||||||
|
self.bot.say(event.target, reply)
|
||||||
|
return True
|
|
@ -16,7 +16,7 @@ class UnknownCommandPlugin(Plugin):
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
super().__init__(bot)
|
super().__init__(bot)
|
||||||
self.priority = -8
|
self.priority = -6
|
||||||
self._client = None
|
self._client = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -15,7 +15,7 @@ class UnknownQuestionPlugin(Plugin):
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
super().__init__(bot)
|
super().__init__(bot)
|
||||||
self.priority = -9
|
self.priority = -7
|
||||||
self.misc_plugin = None
|
self.misc_plugin = None
|
||||||
|
|
||||||
def on_welcome(self, event):
|
def on_welcome(self, event):
|
||||||
|
|
|
@ -28,7 +28,7 @@ class YoutubeParserPlugin(Plugin):
|
||||||
|
|
||||||
def on_welcome(self, _):
|
def on_welcome(self, _):
|
||||||
if not (self.youtube_plugin and self.youtube_plugin.is_ready):
|
if not (self.youtube_plugin and self.youtube_plugin.is_ready):
|
||||||
self.log_w("Youtube plugin is not available.")
|
self.bot.log_w("Youtube plugin is not available.")
|
||||||
self.is_ready = False
|
self.is_ready = False
|
||||||
|
|
||||||
def on_pubmsg(self, event):
|
def on_pubmsg(self, event):
|
||||||
|
|
Loading…
Reference in a new issue