Merge pull request #8 from jesopo/master

Regex is dumb.
This commit is contained in:
Dan 2018-09-09 17:36:47 +01:00 committed by GitHub
commit 5cb70f7a7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 11 deletions

View file

@ -4,8 +4,9 @@ PRIORITY_URGENT = 0
PRIORITY_HIGH = 1 PRIORITY_HIGH = 1
PRIORITY_MEDIUM = 2 PRIORITY_MEDIUM = 2
PRIORITY_LOW = 3 PRIORITY_LOW = 3
PRIORITY_MONITOR = 4
DEFAULT_PRIORITY = PRIORITY_LOW DEFAULT_PRIORITY = PRIORITY_MEDIUM
DEFAULT_DELIMITER = "." DEFAULT_DELIMITER = "."
class Event(object): class Event(object):

View file

@ -1,5 +1,5 @@
import re import re
import Utils import EventManager, Utils
STR_MORE = "%s (more...)" % Utils.FONT_RESET STR_MORE = "%s (more...)" % Utils.FONT_RESET
STR_CONTINUED = "(...continued) " STR_CONTINUED = "(...continued) "
@ -48,8 +48,10 @@ class Module(object):
def __init__(self, bot, events, exports): def __init__(self, bot, events, exports):
self.bot = bot self.bot = bot
self.events = events self.events = events
events.on("received.message.channel").hook(self.channel_message) events.on("received.message.channel").hook(self.channel_message,
events.on("received.message.private").hook(self.private_message) priority=EventManager.PRIORITY_LOW)
events.on("received.message.private").hook(self.private_message,
priority=EventManager.PRIORITY_LOW)
events.on("received.command.help").hook(self.help, events.on("received.command.help").hook(self.help,
help="Show help for commands", usage="<command>") help="Show help for commands", usage="<command>")
@ -153,7 +155,7 @@ class Module(object):
target.last_stdout = stdout target.last_stdout = stdout
target.last_stderr = stderr target.last_stderr = stderr
buffer.skip_next() buffer.skip_next()
event.eat()
def channel_message(self, event): def channel_message(self, event):
command_prefix = event["channel"].get_setting("command-prefix", command_prefix = event["channel"].get_setting("command-prefix",

View file

@ -1,5 +1,5 @@
import re, time import re, time
import Utils import EventManager, Utils
REGEX_KARMA = re.compile("(.*)(\+{2,}|\-{2,})$") REGEX_KARMA = re.compile("(.*)(\+{2,}|\-{2,})$")
KARMA_DELAY_SECONDS = 3 KARMA_DELAY_SECONDS = 3
@ -10,7 +10,7 @@ class Module(object):
self.events = events self.events = events
events.on("new").on("user").hook(self.new_user) events.on("new").on("user").hook(self.new_user)
events.on("received").on("message").on("channel").hook( events.on("received").on("message").on("channel").hook(
self.channel_message) self.channel_message, priority=EventManager.PRIORITY_MONITOR)
events.on("received").on("command").on("karma").hook( events.on("received").on("command").on("karma").hook(
self.karma, help="Get your or someone else's karma", self.karma, help="Get your or someone else's karma",
usage="[target]") usage="[target]")
@ -52,10 +52,14 @@ class Module(object):
event["user"].last_karma = time.time() event["user"].last_karma = time.time()
elif verbose: elif verbose:
if target: if target:
self.events.on("send").on("stderr").call(module_name="Karma", self.events.on("send.stderr").call(
target=event["channel"], message="You cannot change your own karma") module_name="Karma", target=event["channel"],
message="You cannot change your own karma")
elif verbose: elif verbose:
event["stderr"].write("Try again in a couple of seconds") self.events.on("send.stderr").call(module_name="Karma",
target=event["channel"],
message="Try again in a couple of seconds")
def karma(self, event): def karma(self, event):
if event["args"]: if event["args"]:
target = event["args"] target = event["args"]

View file

@ -4,7 +4,7 @@ class Module(object):
def __init__(self, bot, events, exports): def __init__(self, bot, events, exports):
events.on("received").on("message").on("channel" events.on("received").on("message").on("channel"
).hook(self.channel_message, ).hook(self.channel_message,
priority=EventManager.PRIORITY_MEDIUM) priority=EventManager.PRIORITY_HIGH)
events.on("received").on("command").on("to").hook( events.on("received").on("command").on("to").hook(
self.to, min_args=2, help=("Relay a message to a " self.to, min_args=2, help=("Relay a message to a "
"user the next time they talk in a channel"), "user the next time they talk in a channel"),