Ejemplo n.º 1
0
 def __init__(self, name, id, server, bot):
     self.name = utils.irc.lower(server, name)
     self.id = id
     self.server = server
     self.bot = bot
     self.topic = ""
     self.topic_setter_nickname = None
     self.topic_setter_username = None
     self.topic_setter_hostname = None
     self.topic_time = 0
     self.users = set([])
     self.modes = {}
     self.user_modes = {}
     self.created_timestamp = None
     self.buffer = IRCBuffer.Buffer(bot, server)
Ejemplo n.º 2
0
    def __init__(self, name: str, id, server: "IRCServer.Server",
                 bot: "IRCBot.Bot"):
        self.name = server.irc_lower(name)
        self.id = id
        self.server = server
        self.bot = bot
        self.topic = ""
        self.topic_setter = None  # type: typing.Optional[IRCLine.Hostmask]
        self.topic_time = 0
        self.users = set([])  # type: typing.Set[IRCUser.User]
        self.modes = {}  # type: typing.Dict[str, typing.Set]
        self.user_modes = {}  # type: typing.Dict[IRCUser.User, typing.Set]
        self.created_timestamp = None
        self.buffer = IRCBuffer.Buffer(bot, server)

        self._setting_cache_prefix = "channelsetting%s-" % self.id
Ejemplo n.º 3
0
 def __init__(self, name: str, id, server: "IRCServer.Server",
         bot: "IRCBot.Bot"):
     self.name = server.irc_lower(name)
     self.id = id
     self.server = server
     self.bot = bot
     self.topic = ""
     self.topic_setter_nickname = None # type: typing.Optional[str]
     self.topic_setter_username = None # type: typing.Optional[str]
     self.topic_setter_hostname = None # type: typing.Optional[str]
     self.topic_time = 0
     self.users = set([]) # type: typing.Set[IRCUser.User]
     self.modes = {} # type: typing.Dict[str, typing.Set]
     self.user_modes = {} # type: typing.Dict[IRCUser.User, typing.Set]
     self.created_timestamp = None
     self.buffer = IRCBuffer.Buffer(bot, server)
Ejemplo n.º 4
0
    def __init__(self, nickname, id, server, bot):
        self.server = server
        self.set_nickname(nickname)
        self._id = id
        self.username = None
        self.hostname = None
        self.realname = None
        self.bot = bot
        self.channels = set([])

        self.identified_account = None
        self.identified_account_override = None

        self.identified_account_id = None
        self.identified_account_id_override = None
        self.away = False
        self.buffer = IRCBuffer.Buffer(bot, server)
Ejemplo n.º 5
0
    def __init__(self, nickname: str, id: int, server: "IRCServer.Server",
            bot: "IRCBot.Bot"):
        self.name = ""
        self.nickname = ""
        self.nickname_lower = ""

        self.server = server
        self.set_nickname(nickname)
        self._id = id
        self.username = None
        self.hostname = None
        self.realname = None
        self.bot = bot
        self.channels = set([]) # type: typing.Set[IRCChannel.Channel]

        self.identified_account = None
        self.identified_account_override = None

        self.identified_account_id = None
        self.identified_account_id_override = None
        self.away = False
        self.buffer = IRCBuffer.Buffer(bot, server)
Ejemplo n.º 6
0
    def __init__(self, nickname: str, id: int, server: "IRCServer.Server",
                 bot: "IRCBot.Bot"):
        self.name = ""
        self.nickname = ""
        self.nickname_lower = ""

        self.server = server
        self.set_nickname(nickname)
        self._id = id
        self._id_override: typing.Optional[int] = None
        self.username: typing.Optional[str] = None
        self.hostname: typing.Optional[str] = None
        self.realname: typing.Optional[str] = None
        self.bot = bot
        self.channels: typing.Set[IRCChannel.Channel] = set([])

        self.account = None

        self.away = False
        self.away_message: typing.Optional[str] = None

        self.buffer = IRCBuffer.Buffer(bot, server)
Ejemplo n.º 7
0
def message(events, event):
    from_self = _from_self(event["server"], event["line"].source)
    if from_self == None:
        return

    direction = "send" if from_self else "received"

    target_str = event["line"].args[0]

    message = None
    if len(event["line"].args) > 1:
        message = event["line"].args[1]

    source = event["line"].source
    if (not event["server"].nickname
            or not source
            or source.hostmask == event["server"].name):
        if source:
            event["server"].name = event["line"].source.hostmask
        else:
            source = IRCLine.parse_hostmask(event["server"].name)
        target_str = event["server"].nickname or "*"

    if from_self:
        user = event["server"].get_user(event["server"].nickname)
    else:
        user = event["server"].get_user(source.nickname,
            username=source.username,
            hostname=source.hostname)

    # strip prefix_symbols from the start of target, for when people use
    # e.g. 'PRIVMSG +#channel :hi' which would send a message to only
    # voiced-or-above users
    statusmsg = ""
    for char in target_str:
        if char in event["server"].statusmsg:
            statusmsg += char
        else:
            break
    target = target_str.replace(statusmsg, "", 1)

    is_channel = event["server"].is_channel(target)

    if is_channel:
        if not target in event["server"].channels:
            return
        target_obj = event["server"].channels.get(target)
    else:
        target_obj = event["server"].get_user(target)

    kwargs = {"server": event["server"], "target": target_obj,
        "target_str": target_str, "user": user, "tags": event["line"].tags,
        "is_channel": is_channel, "from_self": from_self, "line": event["line"],
        "statusmsg": statusmsg}

    action = False

    if message:
        ctcp_message = utils.irc.parse_ctcp(message)

        if ctcp_message:
            if (not ctcp_message.command == "ACTION" or not
                    event["line"].command == "PRIVMSG"):
                if event["line"].command == "PRIVMSG":
                    ctcp_action = "request"
                else:
                    ctcp_action = "response"
                events.on(direction).on("ctcp").on(ctcp_action).call(
                    message=ctcp_message.message, **kwargs)
                events.on(direction).on("ctcp").on(ctcp_action).on(
                    ctcp_message.command).call(message=ctcp_message.message,
                    **kwargs)
                return
            else:
                message = ctcp_message.message
                action = True

    if not message == None:
        kwargs["message"] = message
        kwargs["message_split"] = message.split(" ")
        kwargs["action"] = action

    event_type = event["line"].command.lower()
    if event_type == "privmsg":
        event_type = "message"

    context = "channel" if is_channel else "private"
    hook = events.on(direction).on(event_type).on(context)

    buffer_line = None
    if message:
        buffer_line = IRCBuffer.BufferLine(user.nickname, message, action,
            event["line"].tags, from_self, event["line"].command)

    buffer_obj = target_obj
    if is_channel:
        hook.call(channel=target_obj, buffer_line=buffer_line, **kwargs)
    else:
        buffer_obj = target_obj
        if not from_self:
            buffer_obj = user

        hook.call(buffer_line=buffer_line, **kwargs)

    if buffer_line:
        buffer_obj.buffer.add(buffer_line)