Compare commits
No commits in common. "0d49fb145715c429bd6155037a55ca181a04908c" and "edbc35aa190015843ddb158ce59f578e37340549" have entirely different histories.
0d49fb1457
...
edbc35aa19
|
@ -25,8 +25,7 @@
|
||||||
"beers": {
|
"beers": {
|
||||||
"commands": ["beer"],
|
"commands": ["beer"],
|
||||||
"beers": ["Paix-Dieu"],
|
"beers": ["Paix-Dieu"],
|
||||||
"opening_text": "/me cracks open a {beer} for {target}",
|
"opening_text": "/me cracks open a {beer} for {target}"
|
||||||
"target_word": "for"
|
|
||||||
},
|
},
|
||||||
"caretaker": {
|
"caretaker": {
|
||||||
"warm_welcome": ["Hi {target}!"],
|
"warm_welcome": ["Hi {target}!"],
|
||||||
|
|
|
@ -183,8 +183,8 @@ class Plugin:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def __save_question(self, question, matched, preamble):
|
def __save_question(self, question, match, preamble):
|
||||||
content = question[len(matched):].strip()
|
content = question[len(match):].strip()
|
||||||
content = content.rstrip("?").rstrip()
|
content = content.rstrip("?").rstrip()
|
||||||
question = Question(preamble, content)
|
question = Question(preamble, content)
|
||||||
self.question = question
|
self.question = question
|
||||||
|
@ -228,23 +228,23 @@ class Plugin:
|
||||||
# If no_content is False (default), simply compare the parsed
|
# If no_content is False (default), simply compare the parsed
|
||||||
# identifier with available identifiers.
|
# identifier with available identifiers.
|
||||||
if no_content:
|
if no_content:
|
||||||
matches = lambda pc, ai: (
|
match = lambda pc, ai: (
|
||||||
pc.raw == ai or pc.raw.startswith(ai + " ")
|
pc.raw == ai or pc.raw.startswith(ai + " ")
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
matches = lambda pc, ai: pc.ident == ai
|
match = lambda pc, ai: pc.ident == ai
|
||||||
# First case: the command identifier has been used.
|
# First case: the command identifier has been used.
|
||||||
if matches(parsed_command, ident):
|
if match(parsed_command, ident):
|
||||||
parsed_command.ident = ident
|
parsed_command.ident = ident
|
||||||
parsed_command.matched = ident
|
parsed_command.match = ident
|
||||||
self.__save_command(parsed_command)
|
self.__save_command(parsed_command)
|
||||||
return True
|
return True
|
||||||
# Second case: an alias of the identifier has been used.
|
# Second case: an alias of the identifier has been used.
|
||||||
ident_aliases = aliases.get(ident, [])
|
ident_aliases = aliases.get(ident, [])
|
||||||
for alias in ident_aliases:
|
for alias in ident_aliases:
|
||||||
if matches(parsed_command, alias):
|
if match(parsed_command, alias):
|
||||||
parsed_command.ident = ident
|
parsed_command.ident = ident
|
||||||
parsed_command.matched = alias
|
parsed_command.match = alias
|
||||||
self.__save_command(parsed_command)
|
self.__save_command(parsed_command)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -313,4 +313,4 @@ class Command:
|
||||||
# Raw command content (minus name and suffix), always set.
|
# Raw command content (minus name and suffix), always set.
|
||||||
raw: str
|
raw: str
|
||||||
# Identifier matched, possibly an alias. Set only when matched.
|
# Identifier matched, possibly an alias. Set only when matched.
|
||||||
matched: str = ""
|
match: str = ""
|
||||||
|
|
|
@ -5,7 +5,7 @@ from edmond.plugin import Plugin
|
||||||
|
|
||||||
class BeersPlugin(Plugin):
|
class BeersPlugin(Plugin):
|
||||||
|
|
||||||
REQUIRED_CONFIGS = ["commands", "beers", "opening_text", "target_word"]
|
REQUIRED_CONFIGS = ["commands", "beers", "opening_text"]
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
super().__init__(bot)
|
super().__init__(bot)
|
||||||
|
@ -13,17 +13,10 @@ class BeersPlugin(Plugin):
|
||||||
def on_pubmsg(self, event):
|
def on_pubmsg(self, event):
|
||||||
if not self.should_handle_command(event.arguments[0]):
|
if not self.should_handle_command(event.arguments[0]):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
target = event.source.nick
|
|
||||||
if self.command.content:
|
|
||||||
words = self.command.content.split(maxsplit=1)
|
|
||||||
if len(words) == 2 and words[0] == self.config["target_word"]:
|
|
||||||
target = words[1]
|
|
||||||
|
|
||||||
beer = random.choice(self.config["beers"])
|
beer = random.choice(self.config["beers"])
|
||||||
opening_text = self.config["opening_text"].format(
|
opening_text = self.config["opening_text"].format(
|
||||||
beer=beer,
|
beer=beer,
|
||||||
target=target
|
target=event.source.nick
|
||||||
)
|
)
|
||||||
self.bot.say(event.target, opening_text)
|
self.bot.say(event.target, opening_text)
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -29,11 +29,11 @@ class CaptureGivePlugin(Plugin):
|
||||||
|
|
||||||
# "give" command.
|
# "give" command.
|
||||||
if self.command.ident == self.config["commands"][0]:
|
if self.command.ident == self.config["commands"][0]:
|
||||||
content = self.command.raw[len(self.command.matched):].strip()
|
content = self.command.raw[len(self.command.match):].strip()
|
||||||
matched = self.content_re.matched(content)
|
match = self.content_re.match(content)
|
||||||
if not matched:
|
if not match:
|
||||||
return False
|
return False
|
||||||
groups = matched.groupdict()
|
groups = match.groupdict()
|
||||||
if any(k not in groups for k in ("thing", "person")):
|
if any(k not in groups for k in ("thing", "person")):
|
||||||
return False
|
return False
|
||||||
thing = groups["thing"]
|
thing = groups["thing"]
|
||||||
|
|
|
@ -32,11 +32,11 @@ class NotesPlugin(Plugin):
|
||||||
|
|
||||||
# "note down" command.
|
# "note down" command.
|
||||||
if self.command.ident == self.config["commands"][0]:
|
if self.command.ident == self.config["commands"][0]:
|
||||||
content = self.command.raw[len(self.command.matched):].strip()
|
content = self.command.raw[len(self.command.match):].strip()
|
||||||
matched = self.content_re.match(content)
|
match = self.content_re.match(content)
|
||||||
if not matched:
|
if not match:
|
||||||
return False
|
return False
|
||||||
groups = matched.groupdict()
|
groups = match.groupdict()
|
||||||
if any(k not in groups for k in ("target", "note")):
|
if any(k not in groups for k in ("target", "note")):
|
||||||
return False
|
return False
|
||||||
target = groups["target"]
|
target = groups["target"]
|
||||||
|
|
|
@ -37,13 +37,13 @@ class YoutubeParserPlugin(Plugin):
|
||||||
return False
|
return False
|
||||||
words = event.arguments[0].split()
|
words = event.arguments[0].split()
|
||||||
for word in words:
|
for word in words:
|
||||||
matched = self.VIDEO_URL_RE.match(word)
|
match = self.VIDEO_URL_RE.match(word)
|
||||||
if matched:
|
if match:
|
||||||
return self.handle_match(matched, event.target)
|
return self.handle_match(match, event.target)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def handle_match(self, matched, target):
|
def handle_match(self, match, target):
|
||||||
groupdict = matched.groupdict()
|
groupdict = match.groupdict()
|
||||||
code = groupdict.get("code1") or groupdict.get("code2")
|
code = groupdict.get("code1") or groupdict.get("code2")
|
||||||
if not code:
|
if not code:
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in a new issue