2019-10-27 10:19:00 +00:00
|
|
|
from src import IRCLine, utils
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
def handle_332(events, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
channel = event["server"].channels.get(event["line"].args[1])
|
|
|
|
topic = event["line"].args.get(2)
|
2019-02-22 11:23:36 +00:00
|
|
|
channel.set_topic(topic)
|
|
|
|
events.on("received.332").call(channel=channel, server=event["server"],
|
|
|
|
topic=topic)
|
|
|
|
|
|
|
|
def topic(events, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
user = event["server"].get_user(event["line"].source.nickname)
|
|
|
|
channel = event["server"].channels.get(event["line"].args[0])
|
|
|
|
topic = event["line"].args.get(1)
|
2019-02-22 11:23:36 +00:00
|
|
|
channel.set_topic(topic)
|
2019-02-22 11:26:48 +00:00
|
|
|
events.on("received.topic").call(channel=channel, server=event["server"],
|
2019-02-22 11:23:36 +00:00
|
|
|
topic=topic, user=user)
|
|
|
|
|
|
|
|
def handle_333(events, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
channel = event["server"].channels.get(event["line"].args[1])
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-10-27 10:19:00 +00:00
|
|
|
topic_setter = IRCLine.parse_hostmask(event["line"].args[2])
|
2019-06-22 11:17:45 +00:00
|
|
|
topic_time = int(event["line"].args[3])
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-09-16 17:38:46 +00:00
|
|
|
channel.set_topic_setter(topic_setter)
|
2019-02-22 11:23:36 +00:00
|
|
|
channel.set_topic_time(topic_time)
|
2019-02-22 11:26:48 +00:00
|
|
|
events.on("received.333").call(channel=channel,
|
2019-09-16 17:41:47 +00:00
|
|
|
setter=topic_setter, set_at=topic_time, server=event["server"])
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
def handle_353(event):
|
2019-06-22 11:17:45 +00:00
|
|
|
channel = event["server"].channels.get(event["line"].args[2])
|
|
|
|
nicknames = event["line"].args.get(3).split(" ")
|
2019-05-09 10:55:35 +00:00
|
|
|
|
|
|
|
# there can sometimes be a dangling space at the end of a 353
|
|
|
|
if nicknames and not nicknames[-1]:
|
|
|
|
nicknames.pop(-1)
|
|
|
|
|
2019-02-22 11:23:36 +00:00
|
|
|
for nickname in nicknames:
|
|
|
|
modes = set([])
|
|
|
|
|
|
|
|
while nickname[0] in event["server"].prefix_symbols:
|
|
|
|
modes.add(event["server"].prefix_symbols[nickname[0]])
|
|
|
|
nickname = nickname[1:]
|
|
|
|
|
2019-05-20 15:33:32 +00:00
|
|
|
if event["server"].has_capability_str("userhost-in-names"):
|
2019-10-27 10:19:00 +00:00
|
|
|
hostmask = IRCLine.parse_hostmask(nickname)
|
2019-02-22 11:23:36 +00:00
|
|
|
nickname = hostmask.nickname
|
2019-09-27 11:54:20 +00:00
|
|
|
user = event["server"].get_user(hostmask.nickname,
|
|
|
|
username=hostmask.username, hostname=hostmask.hostname)
|
2019-02-22 11:23:36 +00:00
|
|
|
else:
|
|
|
|
user = event["server"].get_user(nickname)
|
|
|
|
user.join_channel(channel)
|
|
|
|
channel.add_user(user)
|
|
|
|
|
|
|
|
for mode in modes:
|
|
|
|
channel.add_mode(mode, nickname)
|
|
|
|
|
|
|
|
def handle_366(event):
|
2019-06-22 11:17:45 +00:00
|
|
|
event["server"].send_whox(event["line"].args[1], "n", "ahnrtu", "111")
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
def join(events, event):
|
|
|
|
account = None
|
|
|
|
realname = None
|
2019-06-22 11:17:45 +00:00
|
|
|
channel_name = event["line"].args[0]
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-06-22 11:17:45 +00:00
|
|
|
if len(event["line"].args) == 3:
|
|
|
|
if not event["line"].args[1] == "*":
|
|
|
|
account = event["line"].args[1]
|
|
|
|
realname = event["line"].args[2]
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-09-27 11:54:20 +00:00
|
|
|
user = event["server"].get_user(event["line"].source.nickname,
|
|
|
|
username=event["line"].source.username,
|
|
|
|
hostname=event["line"].source.hostname)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-03-06 15:51:10 +00:00
|
|
|
if account:
|
2019-11-21 15:49:08 +00:00
|
|
|
user.account = account
|
2019-03-06 15:51:10 +00:00
|
|
|
if realname:
|
|
|
|
user.realname = realname
|
|
|
|
|
2019-06-22 11:17:45 +00:00
|
|
|
is_self = event["server"].is_own_nickname(event["line"].source.nickname)
|
2019-04-15 13:41:09 +00:00
|
|
|
if is_self:
|
2019-02-22 11:23:36 +00:00
|
|
|
channel = event["server"].channels.add(channel_name)
|
2019-04-15 13:41:09 +00:00
|
|
|
else:
|
|
|
|
channel = event["server"].channels.get(channel_name)
|
|
|
|
|
|
|
|
|
|
|
|
channel.add_user(user)
|
|
|
|
user.join_channel(channel)
|
|
|
|
|
|
|
|
if is_self:
|
2019-02-22 11:23:36 +00:00
|
|
|
events.on("self.join").call(channel=channel, server=event["server"],
|
|
|
|
account=account, realname=realname)
|
|
|
|
channel.send_mode()
|
2019-03-05 11:20:32 +00:00
|
|
|
else:
|
|
|
|
events.on("received.join").call(channel=channel, user=user,
|
|
|
|
server=event["server"], account=account, realname=realname)
|
|
|
|
|
2019-02-22 11:23:36 +00:00
|
|
|
def part(events, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
channel = event["server"].channels.get(event["line"].args[0])
|
|
|
|
user = event["server"].get_user(event["line"].source.nickname)
|
|
|
|
reason = event["line"].args.get(1)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-04-15 13:41:09 +00:00
|
|
|
channel.remove_user(user)
|
|
|
|
user.part_channel(channel)
|
|
|
|
if not len(user.channels):
|
|
|
|
event["server"].remove_user(user)
|
|
|
|
|
2019-06-22 11:17:45 +00:00
|
|
|
if not event["server"].is_own_nickname(event["line"].source.nickname):
|
2019-02-22 11:26:48 +00:00
|
|
|
events.on("received.part").call(channel=channel, reason=reason,
|
|
|
|
user=user, server=event["server"])
|
2019-02-22 11:23:36 +00:00
|
|
|
else:
|
2019-04-15 13:41:09 +00:00
|
|
|
event["server"].channels.remove(channel)
|
2019-02-22 11:23:36 +00:00
|
|
|
events.on("self.part").call(channel=channel, reason=reason,
|
|
|
|
server=event["server"])
|
2019-03-05 11:20:32 +00:00
|
|
|
|
2019-07-03 07:13:28 +00:00
|
|
|
def handle_324(events, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
if event["line"].args[1] in event["server"].channels:
|
|
|
|
channel = event["server"].channels.get(event["line"].args[1])
|
|
|
|
modes = event["line"].args[2]
|
|
|
|
args = event["line"].args[3:]
|
2019-07-03 07:13:28 +00:00
|
|
|
new_modes = channel.parse_modes(modes, args[:])
|
|
|
|
events.on("received.324").call(modes=new_modes,
|
|
|
|
channel=channel, server=event["server"], mode_str=modes,
|
|
|
|
args_str=args)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
def handle_329(event):
|
2019-06-22 11:17:45 +00:00
|
|
|
channel = event["server"].channels.get(event["line"].args[1])
|
|
|
|
channel.creation_timestamp = int(event["line"].args[2])
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
def handle_477(timers, event):
|
2019-09-07 14:21:35 +00:00
|
|
|
pass
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
def kick(events, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
user = event["server"].get_user(event["line"].source.nickname)
|
|
|
|
target = event["line"].args[1]
|
|
|
|
channel = event["server"].channels.get(event["line"].args[0])
|
|
|
|
reason = event["line"].args.get(2)
|
2019-03-05 11:20:32 +00:00
|
|
|
target_user = event["server"].get_user(target)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
if not event["server"].is_own_nickname(target):
|
|
|
|
events.on("received.kick").call(channel=channel, reason=reason,
|
|
|
|
target_user=target_user, user=user, server=event["server"])
|
|
|
|
else:
|
|
|
|
event["server"].channels.remove(channel)
|
|
|
|
events.on("self.kick").call(channel=channel, reason=reason, user=user,
|
|
|
|
server=event["server"])
|
|
|
|
|
2019-03-05 11:20:32 +00:00
|
|
|
channel.remove_user(target_user)
|
|
|
|
target_user.part_channel(channel)
|
|
|
|
if not len(target_user.channels):
|
|
|
|
event["server"].remove_user(target_user)
|
|
|
|
|
2019-02-22 11:23:36 +00:00
|
|
|
def rename(events, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
old_name = event["line"].args[0]
|
2019-06-22 21:08:39 +00:00
|
|
|
new_name = event["line"].args[1]
|
2019-02-22 11:23:36 +00:00
|
|
|
channel = event["server"].channels.get(old_name)
|
|
|
|
|
|
|
|
event["server"].channels.rename(old_name, new_name)
|
|
|
|
events.on("received.rename").call(channel=channel, old_name=old_name,
|
2019-06-22 11:17:45 +00:00
|
|
|
new_name=new_name, reason=event["line"].args.get(2),
|
|
|
|
server=event["server"])
|