2019-02-22 11:23:36 +00:00
|
|
|
from src import utils
|
|
|
|
|
|
|
|
def handle_311(event):
|
2019-06-22 11:17:45 +00:00
|
|
|
nickname = event["line"].args[1]
|
|
|
|
username = event["line"].args[2]
|
|
|
|
hostname = event["line"].args[3]
|
|
|
|
realname = event["line"].args[4]
|
2019-03-05 11:20:32 +00:00
|
|
|
|
2019-02-22 11:23:36 +00:00
|
|
|
if event["server"].is_own_nickname(nickname):
|
2019-03-05 11:20:32 +00:00
|
|
|
event["server"].username = username
|
|
|
|
event["server"].hostname = hostname
|
|
|
|
event["server"].realname = realname
|
|
|
|
|
|
|
|
target = event["server"].get_user(nickname)
|
|
|
|
target.username = username
|
|
|
|
target.hostname = hostname
|
|
|
|
target.realname = realname
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
def quit(events, event):
|
|
|
|
nickname = None
|
2019-03-10 13:14:15 +00:00
|
|
|
if event["direction"] == utils.Direction.Recv:
|
2019-06-22 11:17:45 +00:00
|
|
|
nickname = event["line"].source.nickname
|
|
|
|
reason = event["line"].args.get(0)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-03-10 13:14:15 +00:00
|
|
|
if event["direction"] == utils.Direction.Recv:
|
2019-06-22 11:17:45 +00:00
|
|
|
nickname = event["line"].source.nickname
|
2019-02-22 11:23:36 +00:00
|
|
|
if (not event["server"].is_own_nickname(nickname) and
|
2019-06-22 11:17:45 +00:00
|
|
|
not event["line"].source.hostmask == "*"):
|
2019-02-22 11:23:36 +00:00
|
|
|
user = event["server"].get_user(nickname)
|
|
|
|
events.on("received.quit").call(reason=reason, user=user,
|
|
|
|
server=event["server"])
|
2019-06-05 12:18:29 +00:00
|
|
|
event["server"].remove_user(user)
|
2019-02-22 11:23:36 +00:00
|
|
|
else:
|
|
|
|
event["server"].disconnect()
|
|
|
|
else:
|
|
|
|
events.on("send.quit").call(reason=reason, server=event["server"])
|
|
|
|
|
|
|
|
def nick(events, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
new_nickname = event["line"].args.get(0)
|
|
|
|
user = event["server"].get_user(event["line"].source.nickname)
|
2019-03-05 11:20:32 +00:00
|
|
|
old_nickname = user.nickname
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-06-22 11:17:45 +00:00
|
|
|
if not event["server"].is_own_nickname(event["line"].source.nickname):
|
2019-02-22 11:23:36 +00:00
|
|
|
events.on("received.nick").call(new_nickname=new_nickname,
|
|
|
|
old_nickname=old_nickname, user=user, server=event["server"])
|
|
|
|
else:
|
|
|
|
events.on("self.nick").call(server=event["server"],
|
|
|
|
new_nickname=new_nickname, old_nickname=old_nickname)
|
2019-05-12 21:20:42 +00:00
|
|
|
event["server"].set_own_nickname(new_nickname)
|
|
|
|
|
|
|
|
user.set_nickname(new_nickname)
|
|
|
|
event["server"].change_user_nickname(old_nickname, new_nickname)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
def away(events, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
user = event["server"].get_user(event["line"].source.nickname)
|
|
|
|
message = event["line"].args.get(0)
|
2019-02-22 11:23:36 +00:00
|
|
|
if message:
|
|
|
|
user.away = True
|
2019-02-22 22:26:50 +00:00
|
|
|
user.away_message = message
|
2019-02-22 11:23:36 +00:00
|
|
|
events.on("received.away.on").call(user=user, server=event["server"],
|
|
|
|
message=message)
|
|
|
|
else:
|
|
|
|
user.away = False
|
2019-02-22 22:26:50 +00:00
|
|
|
user.away_message = None
|
2019-02-22 11:23:36 +00:00
|
|
|
events.on("received.away.off").call(user=user, server=event["server"])
|
|
|
|
|
|
|
|
def chghost(event):
|
2019-06-22 11:17:45 +00:00
|
|
|
nickname = event["line"].source.nickname
|
|
|
|
username = event["line"].args[0]
|
|
|
|
hostname = event["line"].args[1]
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-03-05 11:20:32 +00:00
|
|
|
if event["server"].is_own_nickname(nickname):
|
|
|
|
event["server"].username = username
|
|
|
|
event["server"].hostname = hostname
|
|
|
|
|
|
|
|
target = event["server"].get_user(nickname)
|
2019-02-22 11:23:36 +00:00
|
|
|
target.username = username
|
|
|
|
target.hostname = hostname
|
|
|
|
|
|
|
|
def setname(event):
|
2019-06-22 11:17:45 +00:00
|
|
|
nickname = event["line"].source.nickname
|
|
|
|
realname = event["line"].args[0]
|
2019-04-02 13:21:16 +00:00
|
|
|
|
|
|
|
user = event["server"].get_user(nickname)
|
|
|
|
user.realname = realname
|
|
|
|
|
|
|
|
if event["server"].is_own_nickname(nickname):
|
|
|
|
event["server"].realname = realname
|
2019-02-22 11:23:36 +00:00
|
|
|
|
|
|
|
def account(events, event):
|
2019-06-22 11:17:45 +00:00
|
|
|
user = event["server"].get_user(event["line"].source.nickname)
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-06-22 11:17:45 +00:00
|
|
|
if not event["line"].args[0] == "*":
|
|
|
|
user.identified_account = event["line"].args[0]
|
2019-02-22 11:23:36 +00:00
|
|
|
user.identified_account_id = event["server"].get_user(
|
2019-06-22 11:17:45 +00:00
|
|
|
event["line"].args[0]).get_id()
|
2019-02-22 11:23:36 +00:00
|
|
|
events.on("received.account.login").call(user=user,
|
2019-06-22 11:17:45 +00:00
|
|
|
server=event["server"], account=event["line"].args[0])
|
2019-02-22 11:23:36 +00:00
|
|
|
else:
|
|
|
|
user.identified_account = None
|
|
|
|
user.identified_account_id = None
|
|
|
|
events.on("received.account.logout").call(user=user,
|
|
|
|
server=event["server"])
|