2019-02-22 11:23:36 +00:00
|
|
|
from src import utils
|
|
|
|
|
|
|
|
def handle_311(event):
|
|
|
|
nickname = event["args"][1]
|
2019-03-05 11:20:32 +00:00
|
|
|
username = event["args"][2]
|
|
|
|
hostname = event["args"][3]
|
|
|
|
realname = event["args"][4]
|
|
|
|
|
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-02-22 11:23:36 +00:00
|
|
|
nickname = event["prefix"].nickname
|
|
|
|
reason = event["args"].get(0)
|
|
|
|
|
2019-03-10 13:14:15 +00:00
|
|
|
if event["direction"] == utils.Direction.Recv:
|
2019-02-22 11:23:36 +00:00
|
|
|
nickname = event["prefix"].nickname
|
|
|
|
if (not event["server"].is_own_nickname(nickname) and
|
|
|
|
not event["prefix"].hostmask == "*"):
|
|
|
|
user = event["server"].get_user(nickname)
|
|
|
|
event["server"].remove_user(user)
|
|
|
|
events.on("received.quit").call(reason=reason, user=user,
|
|
|
|
server=event["server"])
|
|
|
|
else:
|
|
|
|
event["server"].disconnect()
|
|
|
|
else:
|
|
|
|
events.on("send.quit").call(reason=reason, server=event["server"])
|
|
|
|
|
|
|
|
def nick(events, event):
|
|
|
|
new_nickname = event["args"].get(0)
|
2019-03-05 11:20:32 +00:00
|
|
|
user = event["server"].get_user(event["prefix"].nickname)
|
|
|
|
old_nickname = user.nickname
|
2019-02-22 11:23:36 +00:00
|
|
|
|
2019-03-05 11:20:32 +00:00
|
|
|
if not event["server"].is_own_nickname(event["prefix"].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:
|
|
|
|
event["server"].set_own_nickname(new_nickname)
|
|
|
|
events.on("self.nick").call(server=event["server"],
|
|
|
|
new_nickname=new_nickname, old_nickname=old_nickname)
|
|
|
|
|
2019-03-05 11:20:32 +00:00
|
|
|
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):
|
|
|
|
user = event["server"].get_user(event["prefix"].nickname)
|
|
|
|
message = event["args"].get(0)
|
|
|
|
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):
|
|
|
|
nickname = event["prefix"].nickname
|
|
|
|
username = event["args"][0]
|
|
|
|
hostname = event["args"][1]
|
|
|
|
|
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):
|
|
|
|
user = event["server"].get_user(event["prefix"].nickname)
|
|
|
|
user.realname = event["args"][0]
|
|
|
|
|
|
|
|
def account(events, event):
|
|
|
|
user = event["server"].get_user(event["prefix"].nickname)
|
|
|
|
|
|
|
|
if not event["args"][0] == "*":
|
|
|
|
user.identified_account = event["args"][0]
|
|
|
|
user.identified_account_id = event["server"].get_user(
|
|
|
|
event["args"][0]).get_id()
|
|
|
|
events.on("received.account.login").call(user=user,
|
|
|
|
server=event["server"], account=event["args"][0])
|
|
|
|
else:
|
|
|
|
user.identified_account = None
|
|
|
|
user.identified_account_id = None
|
|
|
|
events.on("received.account.logout").call(user=user,
|
|
|
|
server=event["server"])
|