Support IRCv3's echo-message
This commit is contained in:
parent
759cd64f33
commit
1c474771c5
2 changed files with 42 additions and 27 deletions
|
@ -8,7 +8,8 @@ RE_CHANTYPES = re.compile(r"\bCHANTYPES=(\W+)(?:\b|$)")
|
||||||
RE_MODES = re.compile(r"[-+]\w+")
|
RE_MODES = re.compile(r"[-+]\w+")
|
||||||
|
|
||||||
CAPABILITIES = {"message-tags", "multi-prefix", "chghost", "invite-notify",
|
CAPABILITIES = {"message-tags", "multi-prefix", "chghost", "invite-notify",
|
||||||
"account-tag", "account-notify", "extended-join", "away-notify"}
|
"account-tag", "account-notify", "extended-join", "away-notify",
|
||||||
|
"echo-message"}
|
||||||
|
|
||||||
class LineHandler(object):
|
class LineHandler(object):
|
||||||
def __init__(self, bot, events):
|
def __init__(self, bot, events):
|
||||||
|
@ -372,17 +373,30 @@ class LineHandler(object):
|
||||||
action = message.startswith("\01ACTION ") and message.endswith("\01")
|
action = message.startswith("\01ACTION ") and message.endswith("\01")
|
||||||
if action:
|
if action:
|
||||||
message = message.replace("\01ACTION ", "", 1)[:-1]
|
message = message.replace("\01ACTION ", "", 1)[:-1]
|
||||||
|
|
||||||
|
kwargs = {"message": message, "message_split": message_split,
|
||||||
|
"server": event["server"], "tags": event["tags"],
|
||||||
|
"action": action}
|
||||||
|
|
||||||
if target[0] in event["server"].channel_types:
|
if target[0] in event["server"].channel_types:
|
||||||
channel = event["server"].get_channel(event["args"][0])
|
channel = event["server"].get_channel(event["args"][0])
|
||||||
self.events.on("received").on("message").on("channel").call(
|
|
||||||
user=user, message=message, message_split=message_split,
|
if not event["server"].is_own_nickname(nickname):
|
||||||
channel=channel, action=action, server=event["server"],
|
self.events.on("received.message.channel").call(
|
||||||
tags=event["tags"])
|
user=user, channel=channel, **kwargs)
|
||||||
channel.buffer.add_line(user.nickname, message, action)
|
channel.buffer.add_line(user.nickname, message, action)
|
||||||
|
else:
|
||||||
|
# supporting echo-message
|
||||||
|
self.events.on("self.message.channel").call(
|
||||||
|
channel=channel, **kwargs)
|
||||||
|
channel.buffer.add_line(user.nickname, message, action, True)
|
||||||
|
elif event["server"].is_own_nickname(nickname):
|
||||||
|
# supporting echo-message
|
||||||
|
self.events.on("self.message.private").call(
|
||||||
|
user=event["server"].get_user(target), **kwargs)
|
||||||
elif event["server"].is_own_nickname(target):
|
elif event["server"].is_own_nickname(target):
|
||||||
self.events.on("received").on("message").on("private").call(
|
self.events.on("received.message.private").call(
|
||||||
user=user, message=message, message_split=message_split,
|
user=user, **kwargs)
|
||||||
action=action, server=event["server"], tags=event["tags"])
|
|
||||||
user.buffer.add_line(user.nickname, message, action)
|
user.buffer.add_line(user.nickname, message, action)
|
||||||
|
|
||||||
# we've received a notice
|
# we've received a notice
|
||||||
|
|
37
IRCServer.py
37
IRCServer.py
|
@ -329,27 +329,28 @@ class Server(object):
|
||||||
|
|
||||||
def send_message(self, target, message, prefix=None):
|
def send_message(self, target, message, prefix=None):
|
||||||
full_message = message if not prefix else prefix+message
|
full_message = message if not prefix else prefix+message
|
||||||
|
|
||||||
self.send("PRIVMSG %s :%s" % (target, full_message))
|
self.send("PRIVMSG %s :%s" % (target, full_message))
|
||||||
action = full_message.startswith("\01ACTION "
|
|
||||||
) and full_message.endswith("\01")
|
|
||||||
|
|
||||||
if action:
|
if not "echo-message" in self.capabilities:
|
||||||
message = full_message.split("\01ACTION ", 1)[1][:-1]
|
action = full_message.startswith("\01ACTION "
|
||||||
|
) and full_message.endswith("\01")
|
||||||
|
|
||||||
full_message_split = full_message.split()
|
if action:
|
||||||
if self.has_channel(target):
|
message = full_message.split("\01ACTION ", 1)[1][:-1]
|
||||||
channel = self.get_channel(target)
|
|
||||||
channel.buffer.add_line(None, message, action, True)
|
full_message_split = full_message.split()
|
||||||
self.events.on("self").on("message").on("channel").call(
|
if self.has_channel(target):
|
||||||
message=full_message, message_split=full_message_split,
|
channel = self.get_channel(target)
|
||||||
channel=channel, action=action, server=self)
|
channel.buffer.add_line(None, message, action, True)
|
||||||
else:
|
self.events.on("self").on("message").on("channel").call(
|
||||||
user = self.get_user(target)
|
message=full_message, message_split=full_message_split,
|
||||||
user.buffer.add_line(None, message, action, True)
|
channel=channel, action=action, server=self)
|
||||||
self.events.on("self").on("message").on("private").call(
|
else:
|
||||||
message=full_message, message_split=full_message_split,
|
user = self.get_user(target)
|
||||||
user=user, action=action, server=self)
|
user.buffer.add_line(None, message, action, True)
|
||||||
|
self.events.on("self").on("message").on("private").call(
|
||||||
|
message=full_message, message_split=full_message_split,
|
||||||
|
user=user, action=action, server=self)
|
||||||
|
|
||||||
def send_notice(self, target, message):
|
def send_notice(self, target, message):
|
||||||
self.send("NOTICE %s :%s" % (target, message))
|
self.send("NOTICE %s :%s" % (target, message))
|
||||||
|
|
Loading…
Reference in a new issue