2019-02-22 11:23:36 +00:00
|
|
|
from src import utils
|
|
|
|
|
2019-06-21 09:47:21 +00:00
|
|
|
def _from_self(server, source):
|
|
|
|
if source:
|
|
|
|
return server.is_own_nickname(source.nickname)
|
2019-02-22 11:23:36 +00:00
|
|
|
else:
|
2019-06-21 09:47:21 +00:00
|
|
|
return False
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-06-03 10:03:12 +00:00
|
|
|
def message(events, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
from_self = _from_self(event["server"], event["line"].source)
|
2019-02-22 11:23:36 +00:00
|
|
|
if from_self == None:
|
|
|
|
return
|
|
|
|
|
2019-06-03 13:22:19 +00:00
|
|
|
direction = "send" if from_self else "received"
|
|
|
|
|
2019-06-22 11:17:45 +00:00
|
|
|
target_str = event["line"].args[0]
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-06-03 10:03:12 +00:00
|
|
|
message = None
|
2019-06-22 11:17:45 +00:00
|
|
|
if len(event["line"].args) > 1:
|
|
|
|
message = event["line"].args[1]
|
2019-06-03 10:03:12 +00:00
|
|
|
|
|
|
|
if not from_self and (
|
2019-06-22 11:17:45 +00:00
|
|
|
not event["line"].source or
|
2019-06-03 10:03:12 +00:00
|
|
|
not event["server"].name or
|
2019-06-22 11:17:45 +00:00
|
|
|
event["line"].source.hostmask == event["server"].name or
|
2019-06-03 10:03:12 +00:00
|
|
|
target_str == "*"):
|
2019-06-22 11:17:45 +00:00
|
|
|
if event["line"].source:
|
|
|
|
event["server"].name = event["line"].source.hostmask
|
2019-06-03 10:03:12 +00:00
|
|
|
|
|
|
|
events.on("received.server-notice").call(message=message,
|
|
|
|
message_split=message.split(" "), server=event["server"])
|
|
|
|
return
|
|
|
|
|
|
|
|
if from_self:
|
|
|
|
user = event["server"].get_user(event["server"].nickname)
|
|
|
|
else:
|
2019-06-22 11:17:45 +00:00
|
|
|
user = event["server"].get_user(event["line"].source.nickname)
|
2019-09-26 16:47:45 +00:00
|
|
|
user.username = event["line"].source.username
|
|
|
|
user.hostname = event["line"].source.hostname
|
2019-06-03 10:03:12 +00:00
|
|
|
|
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-06-08 09:59:14 +00:00
|
|
|
target = target_str.lstrip("".join(event["server"].statusmsg))
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-09-20 13:52:41 +00:00
|
|
|
is_channel = event["server"].is_channel(target)
|
2019-06-03 10:03:12 +00:00
|
|
|
|
2019-09-20 13:52:41 +00:00
|
|
|
if is_channel:
|
2019-02-22 11:23:36 +00:00
|
|
|
if not target in event["server"].channels:
|
|
|
|
return
|
2019-06-03 10:03:12 +00:00
|
|
|
target_obj = event["server"].channels.get(target)
|
|
|
|
else:
|
|
|
|
target_obj = event["server"].get_user(target)
|
|
|
|
|
|
|
|
kwargs = {"server": event["server"], "target": target_obj,
|
2019-06-22 11:17:45 +00:00
|
|
|
"target_str": target_str, "user": user, "tags": event["line"].tags,
|
2019-06-21 19:20:28 +00:00
|
|
|
"is_channel": is_channel, "from_self": from_self, "line": event["line"]}
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
action = False
|
2019-06-03 10:03:12 +00:00
|
|
|
|
2019-06-03 10:10:01 +00:00
|
|
|
if message:
|
|
|
|
ctcp_message = utils.irc.parse_ctcp(message)
|
|
|
|
|
|
|
|
if ctcp_message:
|
2019-06-22 11:17:45 +00:00
|
|
|
if (not ctcp_message.command == "ACTION" or not
|
|
|
|
event["line"].command == "PRIVMSG"):
|
|
|
|
if event["line"].command == "PRIVMSG":
|
2019-06-03 13:22:19 +00:00
|
|
|
ctcp_action = "request"
|
2019-06-03 10:10:01 +00:00
|
|
|
else:
|
2019-06-03 13:22:19 +00:00
|
|
|
ctcp_action = "response"
|
|
|
|
events.on(direction).on("ctcp").on(ctcp_action).call(
|
2019-06-03 12:51:30 +00:00
|
|
|
message=ctcp_message.message, **kwargs)
|
2019-06-03 13:22:19 +00:00
|
|
|
events.on(direction).on("ctcp").on(ctcp_action).on(
|
|
|
|
ctcp_message.command).call(message=ctcp_message.message,
|
|
|
|
**kwargs)
|
2019-06-03 10:10:01 +00:00
|
|
|
return
|
2019-06-03 10:03:12 +00:00
|
|
|
else:
|
2019-06-03 10:10:01 +00:00
|
|
|
message = ctcp_message.message
|
|
|
|
action = True
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-06-03 10:03:12 +00:00
|
|
|
if not message == None:
|
|
|
|
kwargs["message"] = message
|
|
|
|
kwargs["message_split"] = message.split(" ")
|
|
|
|
kwargs["action"] = action
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-06-22 11:17:45 +00:00
|
|
|
event_type = event["line"].command.lower()
|
|
|
|
if event_type == "privmsg":
|
2019-06-03 10:03:12 +00:00
|
|
|
event_type = "message"
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-06-03 10:03:12 +00:00
|
|
|
context = "channel" if is_channel else "private"
|
2019-02-22 11:23:36 +00:00
|
|
|
hook = events.on(direction).on(event_type).on(context)
|
|
|
|
|
2019-06-03 10:03:12 +00:00
|
|
|
if is_channel:
|
|
|
|
hook.call(channel=target_obj, **kwargs)
|
2019-06-08 17:48:42 +00:00
|
|
|
if message:
|
|
|
|
target_obj.buffer.add_message(user.nickname, message, action,
|
2019-06-22 11:17:45 +00:00
|
|
|
event["line"].tags, from_self)
|
2019-02-22 11:23:36 +00:00
|
|
|
else:
|
2019-06-03 10:03:12 +00:00
|
|
|
hook.call(**kwargs)
|
2019-06-03 10:35:31 +00:00
|
|
|
|
|
|
|
buffer_obj = target_obj
|
2019-06-03 10:37:23 +00:00
|
|
|
if not from_self:
|
2019-06-03 10:35:31 +00:00
|
|
|
buffer_obj = user
|
|
|
|
|
2019-06-08 17:48:42 +00:00
|
|
|
if message:
|
|
|
|
buffer_obj.buffer.add_message(user.nickname, message, action,
|
2019-06-22 11:17:45 +00:00
|
|
|
event["line"].tags, from_self)
|