|
|
@ -0,0 +1,48 @@ |
|
|
|
import logging |
|
|
|
from paircd.reply import RPL_ENDOFWHO, RPL_WHOREPLY |
|
|
|
|
|
|
|
from paircd.client import Client |
|
|
|
from paircd.command_handler import CommandHandler |
|
|
|
from paircd.message import Message |
|
|
|
from paircd.server import Server |
|
|
|
|
|
|
|
|
|
|
|
class WhoHandler(CommandHandler): |
|
|
|
def __init__(self) -> None: |
|
|
|
super().__init__("WHO", 1) |
|
|
|
|
|
|
|
async def handle(self, server: Server, client: Client, msg: Message) -> None: |
|
|
|
name = msg.args[0] |
|
|
|
if not name.startswith("#"): |
|
|
|
client.log("used WHO on invalid channel", level=logging.WARN) |
|
|
|
self.who_end(client, name) |
|
|
|
return |
|
|
|
|
|
|
|
if name not in client.channels: |
|
|
|
client.log("client used WHO outside of channel", level=logging.WARN) |
|
|
|
self.who_end(client, name) |
|
|
|
return |
|
|
|
|
|
|
|
channel = server.get_channel_by_name(name) |
|
|
|
for member in channel.clients_by_nick.values(): |
|
|
|
self.who_reply(client, name, member) |
|
|
|
self.who_end(client, name) |
|
|
|
|
|
|
|
def who_reply(self, client: Client, channel_name: str, member: Client) -> None: |
|
|
|
msg = RPL_WHOREPLY( |
|
|
|
client.nickname, |
|
|
|
channel_name, |
|
|
|
member.username, |
|
|
|
member.hostname, |
|
|
|
"0", # server |
|
|
|
member.nickname, |
|
|
|
# TODO: Implement |
|
|
|
"H", # H = here, G = gone |
|
|
|
"0", # hop count |
|
|
|
f":{member.realname}", |
|
|
|
) |
|
|
|
client.write_message(msg) |
|
|
|
|
|
|
|
def who_end(self, client: Client, channel_name: str) -> None: |
|
|
|
msg = RPL_ENDOFWHO(client.nickname, channel_name) |
|
|
|
client.write_message(msg) |