2019-02-22 11:23:36 +00:00
|
|
|
from src import utils
|
|
|
|
|
|
|
|
def _from_self(server, direction, prefix):
|
2019-03-10 13:14:15 +00:00
|
|
|
if direction == utils.Direction.Send:
|
2019-05-20 15:33:32 +00:00
|
|
|
if server.has_capability_str("echo-message"):
|
2019-02-22 11:23:36 +00:00
|
|
|
return None
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
if prefix:
|
|
|
|
return server.is_own_nickname(prefix.nickname)
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def privmsg(events, event):
|
|
|
|
from_self = _from_self(event["server"], event["direction"],
|
|
|
|
event.get("prefix", None))
|
|
|
|
if from_self == None:
|
|
|
|
return
|
|
|
|
|
|
|
|
user = None
|
|
|
|
if "prefix" in event and not from_self:
|
|
|
|
user = event["server"].get_user(event["prefix"].nickname)
|
|
|
|
|
|
|
|
message = event["args"][1]
|
2019-05-21 22:09:32 +00:00
|
|
|
target_str = event["args"][0]
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
# strip prefix_symbols from the start of target, for when people use
|
|
|
|
# e.g. 'PRIVMSG +#channel :hi' which would send a message to only
|
|
|
|
# voiced-or-above users
|
2019-05-21 22:09:32 +00:00
|
|
|
target = target_str.lstrip("".join(event["server"].prefix_symbols.keys()))
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
channel = None
|
|
|
|
if target[0] in event["server"].channel_types:
|
|
|
|
if not target in event["server"].channels:
|
|
|
|
return
|
|
|
|
channel = event["server"].channels.get(target)
|
|
|
|
|
|
|
|
action = False
|
|
|
|
event_type = "message"
|
|
|
|
ctcp_message = utils.irc.parse_ctcp(message)
|
|
|
|
if ctcp_message:
|
|
|
|
message = ctcp_message.message
|
|
|
|
if ctcp_message.command == "ACTION":
|
|
|
|
action = True
|
|
|
|
message = ctcp_message.message
|
2019-03-06 13:51:38 +00:00
|
|
|
else:
|
|
|
|
event_type = "ctcp.%s" % ctcp_message.command
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
if user and "account" in event["tags"]:
|
|
|
|
user.identified_account = event["tags"]["account"]
|
|
|
|
user.identified_account_id = event["server"].get_user(
|
|
|
|
event["tags"]["account"]).get_id()
|
|
|
|
|
2019-02-23 10:53:55 +00:00
|
|
|
kwargs = {"message": message, "message_split": message.split(" "),
|
2019-02-22 11:23:36 +00:00
|
|
|
"server": event["server"], "tags": event["tags"],
|
2019-05-21 22:09:32 +00:00
|
|
|
"action": action, "target_str": target_str}
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
direction = "send" if from_self else "received"
|
|
|
|
context = "channel" if channel else "private"
|
|
|
|
hook = events.on(direction).on(event_type).on(context)
|
|
|
|
|
|
|
|
user_nickname = None
|
|
|
|
if user:
|
|
|
|
user_nickname = None if from_self else user.nickname
|
|
|
|
|
|
|
|
if channel:
|
2019-05-21 22:09:32 +00:00
|
|
|
hook.call(user=user, channel=channel, **kwargs)
|
2019-02-22 11:23:36 +00:00
|
|
|
channel.buffer.add_message(user_nickname, message, action,
|
|
|
|
event["tags"], user==None)
|
|
|
|
elif event["server"].is_own_nickname(target):
|
|
|
|
hook.call(user=user, **kwargs)
|
|
|
|
user.buffer.add_message(user_nickname, message, action,
|
|
|
|
event["tags"], False)
|
|
|
|
elif from_self:
|
|
|
|
# a message we've sent to a user
|
|
|
|
user = event["server"].get_user(target)
|
|
|
|
hook.call(user=user, **kwargs)
|
|
|
|
user.buffer.add_message(user_nickname, message, action,
|
|
|
|
event["tags"], True)
|
|
|
|
|
|
|
|
def notice(events, event):
|
|
|
|
from_self = _from_self(event["server"], event["direction"],
|
|
|
|
event.get("prefix", None))
|
|
|
|
if from_self == None:
|
|
|
|
return
|
|
|
|
|
|
|
|
message = event["args"][1]
|
|
|
|
target = event["args"][0]
|
|
|
|
|
|
|
|
if "prefix" in event and (
|
|
|
|
not event["prefix"] or
|
|
|
|
not event["server"].name or
|
|
|
|
event["prefix"].hostmask == event["server"].name or
|
|
|
|
target == "*"):
|
|
|
|
if event["prefix"]:
|
|
|
|
event["server"].name = event["prefix"].hostmask
|
|
|
|
|
|
|
|
events.on("received.server-notice").call(message=message,
|
2019-02-23 10:53:55 +00:00
|
|
|
message_split=message.split(" "), server=event["server"])
|
2019-02-22 11:23:36 +00:00
|
|
|
else:
|
|
|
|
user = None
|
|
|
|
if "prefix" in event and not from_self:
|
|
|
|
user = event["server"].get_user(event["prefix"].nickname)
|
|
|
|
|
|
|
|
channel = None
|
|
|
|
if target[0] in event["server"].channel_types:
|
|
|
|
channel = event["server"].channels.get(target)
|
|
|
|
|
|
|
|
direction = "send" if from_self else "received"
|
|
|
|
context = "channel" if channel else "private"
|
|
|
|
hook = events.on(direction).on("notice").on(context)
|
|
|
|
|
|
|
|
user_nickname = None
|
|
|
|
if user:
|
|
|
|
user_nickname = None if from_self else user.nickname
|
|
|
|
|
2019-02-23 10:53:55 +00:00
|
|
|
kwargs = {"message": message, "message_split": message.split(" "),
|
2019-02-22 11:23:36 +00:00
|
|
|
"server": event["server"], "tags": event["tags"]}
|
|
|
|
|
|
|
|
if channel:
|
|
|
|
hook.call(user=user, channel=channel, **kwargs)
|
|
|
|
channel.buffer.add_notice(user_nickname, message, event["tags"],
|
|
|
|
user==None)
|
|
|
|
elif event["server"].is_own_nickname(target):
|
|
|
|
hook.call(user=user, **kwargs)
|
|
|
|
user.buffer.add_notice(user_nickname, message, event["tags"],
|
|
|
|
False)
|
|
|
|
elif from_self:
|
|
|
|
# a notice we've sent to a user
|
|
|
|
user = event["server"].get_user(target)
|
|
|
|
hook.call(user=user, **kwargs)
|
|
|
|
user.buffer.add_notice(user_nickname, message, event["tags"],
|
|
|
|
True)
|
|
|
|
|
|
|
|
def tagmsg(events, event):
|
|
|
|
from_self = _from_self(event["server"], event["direction"],
|
|
|
|
event.get("prefix", None))
|
|
|
|
if from_self == None:
|
|
|
|
return
|
|
|
|
|
|
|
|
user = None
|
|
|
|
if "prefix" in event and not from_self:
|
|
|
|
user = event["server"].get_user(event["prefix"].nickname)
|
|
|
|
|
|
|
|
target = event["args"][0]
|
|
|
|
channel = None
|
|
|
|
if target[0] in event["server"].channel_types:
|
|
|
|
channel = event["server"].channels.get(target)
|
|
|
|
|
|
|
|
direction = "send" if from_self else "received"
|
|
|
|
context = "channel" if channel else "private"
|
|
|
|
hook = events.on(direction).on("tagmsg").on(context)
|
|
|
|
|
|
|
|
kwargs = {"server": event["server"], "tags": event["tags"]}
|
|
|
|
|
|
|
|
if channel:
|
|
|
|
hook.call(user=user, channel=channel, **kwargs)
|
2019-02-22 16:31:17 +00:00
|
|
|
elif event["server"].is_own_nickname(target):
|
2019-02-22 11:23:36 +00:00
|
|
|
hook.call(user=user, **kwargs)
|
|
|
|
elif from_self:
|
|
|
|
user = event["server"].get_user(target)
|
|
|
|
hook.call(user=user, **kwargs)
|