Implement IRCv3's draft/rename

This commit is contained in:
jesopo 2018-11-04 14:48:55 +00:00
parent 9fe7815c17
commit 6d742f6a74
2 changed files with 18 additions and 1 deletions

View file

@ -11,7 +11,7 @@ RE_MODES = re.compile(r"[-+]\w+")
CAPABILITIES = {"multi-prefix", "chghost", "invite-notify", "account-tag", CAPABILITIES = {"multi-prefix", "chghost", "invite-notify", "account-tag",
"account-notify", "extended-join", "away-notify", "userhost-in-names", "account-notify", "extended-join", "away-notify", "userhost-in-names",
"draft/message-tags-0.2", "server-time", "cap-notify", "draft/message-tags-0.2", "server-time", "cap-notify",
"batch", "draft/labeled-response"} "batch", "draft/labeled-response", "draft/rename"}
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
def _handle(self, server, line): def _handle(self, server, line):
@ -566,3 +566,15 @@ class Module(ModuleManager.BaseModule):
else: else:
self.events.on("self.kick").call(channel=channel, self.events.on("self.kick").call(channel=channel,
reason=reason, user=user, server=event["server"]) reason=reason, user=user, server=event["server"])
# a channel has been renamed
@utils.hook("raw.rename")
def rename(self, event):
old_name = event["args"][0]
new_name = event["args"][1]
channel = event["server"].get_channel(old_name)
event["server"].rename_channel(old_name, new_name)
self.events.on("received.rename").call(channel=channel,
old_name=old_name, new_name=new_name,
reason=event["arbitrary"] or events["args"][2]))

View file

@ -214,6 +214,11 @@ class Server(IRCObject.Object):
for user in channel.users: for user in channel.users:
user.part_channel(channel) user.part_channel(channel)
del self.channels[channel.name] del self.channels[channel.name]
def rename_channel(self, old_name, new_name):
channel = self.channels.pop(old_name.lower())
channel.name = new_name.lower()
self.channels[channel.name] = channel
def parse_data(self, line: str): def parse_data(self, line: str):
if not line: if not line:
return return