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+")
|
||||
|
||||
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):
|
||||
def __init__(self, bot, events):
|
||||
|
@ -372,17 +373,30 @@ class LineHandler(object):
|
|||
action = message.startswith("\01ACTION ") and message.endswith("\01")
|
||||
if action:
|
||||
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:
|
||||
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,
|
||||
channel=channel, action=action, server=event["server"],
|
||||
tags=event["tags"])
|
||||
channel.buffer.add_line(user.nickname, message, action)
|
||||
|
||||
if not event["server"].is_own_nickname(nickname):
|
||||
self.events.on("received.message.channel").call(
|
||||
user=user, channel=channel, **kwargs)
|
||||
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):
|
||||
self.events.on("received").on("message").on("private").call(
|
||||
user=user, message=message, message_split=message_split,
|
||||
action=action, server=event["server"], tags=event["tags"])
|
||||
self.events.on("received.message.private").call(
|
||||
user=user, **kwargs)
|
||||
user.buffer.add_line(user.nickname, message, action)
|
||||
|
||||
# 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):
|
||||
full_message = message if not prefix else prefix+message
|
||||
|
||||
self.send("PRIVMSG %s :%s" % (target, full_message))
|
||||
action = full_message.startswith("\01ACTION "
|
||||
) and full_message.endswith("\01")
|
||||
|
||||
if action:
|
||||
message = full_message.split("\01ACTION ", 1)[1][:-1]
|
||||
if not "echo-message" in self.capabilities:
|
||||
action = full_message.startswith("\01ACTION "
|
||||
) and full_message.endswith("\01")
|
||||
|
||||
full_message_split = full_message.split()
|
||||
if self.has_channel(target):
|
||||
channel = self.get_channel(target)
|
||||
channel.buffer.add_line(None, message, action, True)
|
||||
self.events.on("self").on("message").on("channel").call(
|
||||
message=full_message, message_split=full_message_split,
|
||||
channel=channel, action=action, server=self)
|
||||
else:
|
||||
user = self.get_user(target)
|
||||
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)
|
||||
if action:
|
||||
message = full_message.split("\01ACTION ", 1)[1][:-1]
|
||||
|
||||
full_message_split = full_message.split()
|
||||
if self.has_channel(target):
|
||||
channel = self.get_channel(target)
|
||||
channel.buffer.add_line(None, message, action, True)
|
||||
self.events.on("self").on("message").on("channel").call(
|
||||
message=full_message, message_split=full_message_split,
|
||||
channel=channel, action=action, server=self)
|
||||
else:
|
||||
user = self.get_user(target)
|
||||
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):
|
||||
self.send("NOTICE %s :%s" % (target, message))
|
||||
|
|
Loading…
Reference in a new issue