<commit_before>import datetime

from merc import errors
from merc import feature
from merc import message


class WhoIsFeature(feature.Feature):
  NAME = __name__


install = WhoIsFeature


MAX_TARGETS = 1


class WhoIsUser(message.Reply):
  NAME = "311"
  FORCE_TRAILING = True

  def __init__(self, nick, user, host, realname):
    self.nick = nick
    self.user = user
    self.host = host
    self.realname = realname

  def as_reply_params(self, user):
    return [self.nick, self.user, self.host, "*", self.realname]


class WhoIsServer(message.Reply):
  NAME = "312"
  FORCE_TRAILING = True

  def __init__(self, nick, server, server_info=""):
    self.nick = nick
    self.server = server
    self.server_info = server_info

  def as_reply_params(self, user):
    return [self.nick, self.server, self.server_info]


class WhoIsOperator(message.Reply):
  NAME = "313"
  FORCE_TRAILING = True

  def __init__(self, nick):
    self.nick = nick

  def as_reply_params(self, user):
    return [self.nick, "is an IRC operator"]


class WhoIsIdle(message.Reply):
  NAME = "317"
  FORCE_TRAILING = True

  def __init__(self, nick, idle_time, signon_time):
    self.nick = nick
    self.idle_time = idle_time
    self.signon_time = signon_time

  def as_reply_params(self, user):
    return [self.nick, str(int(self.idle_time.total_seconds())),
            str(int(self.signon_time.timestamp())), "seconds idle, signon time"]


class WhoIsEnd(message.Reply):
  NAME = "318"
  FORCE_TRAILING = True

  def __init__(self, nick):
    self.nick = nick

  def as_reply_params(self, user):
    return [self.nick, "End of /WHOIS list"]

class WhoIsChannels(message.Reply):
  NAME = "319"
  FORCE_TRAILING = True

  def __init__(self, nick, channels):
    self.nick = nick
    self.channels = channels

  def as_reply_params(self, user):
    return [self.nick, " ".join(self.channels)]


@WhoIsFeature.register_command
class WhoIs(message.Command):
  NAME = "WHOIS"
  MIN_ARITY = 1

  def __init__(self, nicknames, *args):
    self.nicknames = nicknames.split(",")

  @message.Command.requires_registration
  def handle_for(self, user, prefix):
    for nickname in self.nicknames[:MAX_TARGETS]:
      try:
        target = user.server.get_user(nickname)
      except errors.NoSuchNick as e:
        user.send_reply(e)
      else:
        channels = []
        for channel in user.get_channels_visible_for(target):
          sigils = channel.get_channel_user_for(target).sigils
          name = sigils + channel.name
          channels.append(name)

        user.send_reply(WhoIsUser(target.nickname, target.username,
                                    target.host, target.realname))
        user.send_reply(WhoIsServer(target.nickname, target.server.name,
                                      target.server.network_name))
        if target.is_irc_operator:
          user.send_reply(WhoIsOperator(target.nickname))
        user.send_reply(WhoIsIdle(
            target.nickname,
            datetime.datetime.now() - target.last_activity_time,
            target.creation_time))
        if channels:
          user.send_reply(WhoIsChannels(target.nickname, channels))
        user.server.run_hooks("after_user_whois", user, target)<commit_msg>Remove multi-sigils from WHOIS output.<commit_after>import datetime

from merc import errors
from merc import feature
from merc import message


class WhoIsFeature(feature.Feature):
  NAME = __name__


install = WhoIsFeature


MAX_TARGETS = 1


class WhoIsUser(message.Reply):
  NAME = "311"
  FORCE_TRAILING = True

  def __init__(self, nick, user, host, realname):
    self.nick = nick
    self.user = user
    self.host = host
    self.realname = realname

  def as_reply_params(self, user):
    return [self.nick, self.user, self.host, "*", self.realname]


class WhoIsServer(message.Reply):
  NAME = "312"
  FORCE_TRAILING = True

  def __init__(self, nick, server, server_info=""):
    self.nick = nick
    self.server = server
    self.server_info = server_info

  def as_reply_params(self, user):
    return [self.nick, self.server, self.server_info]


class WhoIsOperator(message.Reply):
  NAME = "313"
  FORCE_TRAILING = True

  def __init__(self, nick):
    self.nick = nick

  def as_reply_params(self, user):
    return [self.nick, "is an IRC operator"]


class WhoIsIdle(message.Reply):
  NAME = "317"
  FORCE_TRAILING = True

  def __init__(self, nick, idle_time, signon_time):
    self.nick = nick
    self.idle_time = idle_time
    self.signon_time = signon_time

  def as_reply_params(self, user):
    return [self.nick, str(int(self.idle_time.total_seconds())),
            str(int(self.signon_time.timestamp())), "seconds idle, signon time"]


class WhoIsEnd(message.Reply):
  NAME = "318"
  FORCE_TRAILING = True

  def __init__(self, nick):
    self.nick = nick

  def as_reply_params(self, user):
    return [self.nick, "End of /WHOIS list"]

class WhoIsChannels(message.Reply):
  NAME = "319"
  FORCE_TRAILING = True

  def __init__(self, nick, channels):
    self.nick = nick
    self.channels = channels

  def as_reply_params(self, user):
    return [self.nick, " ".join(self.channels)]


@WhoIsFeature.register_command
class WhoIs(message.Command):
  NAME = "WHOIS"
  MIN_ARITY = 1

  def __init__(self, nicknames, *args):
    self.nicknames = nicknames.split(",")

  @message.Command.requires_registration
  def handle_for(self, user, prefix):
    for nickname in self.nicknames[:MAX_TARGETS]:
      try:
        target = user.server.get_user(nickname)
      except errors.NoSuchNick as e:
        user.send_reply(e)
      else:
        channels = []
        for channel in user.get_channels_visible_for(target):
          sigil = channel.get_channel_user_for(target).sigil
          name = sigil + channel.name
          channels.append(name)

        user.send_reply(WhoIsUser(target.nickname, target.username,
                                    target.host, target.realname))
        user.send_reply(WhoIsServer(target.nickname, target.server.name,
                                      target.server.network_name))
        if target.is_irc_operator:
          user.send_reply(WhoIsOperator(target.nickname))
        user.send_reply(WhoIsIdle(
            target.nickname,
            datetime.datetime.now() - target.last_activity_time,
            target.creation_time))
        if channels:
          user.send_reply(WhoIsChannels(target.nickname, channels))
        user.server.run_hooks("after_user_whois", user, target)
{'fraction_non_alphanumeric': 0.10594394825993224, 'fraction_numerical': 0.006159531875577456, 'mean_word_length': 3.046728971962617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7183685', 'n_tokens_mistral': 2182, 'n_tokens_neox': 2073, 'n_words': 455}