Ejemplo n.º 1
0
def on_privmsg(cli, rawnick, chan, msg, notice = False):
    try:
        prefixes = getattr(var, "STATUSMSG_PREFIXES")
    except AttributeError:
        pass
    else:
        if botconfig.IGNORE_HIDDEN_COMMANDS and chan[0] in prefixes:
            return

    try:
        getattr(var, "CASEMAPPING")
    except AttributeError:
        # some kind of hack for strange networks which don't put server name in some of the NOTICEs on startup
        if not rawnick:
            return
        if notice and "!" not in rawnick and chan in ("*", "AUTH"):
            # On-connect message before RPL_ISUPPORT is sent.
            return

        log("Server did not send a case mapping; falling back to rfc1459.")
        var.CASEMAPPING = "rfc1459"

    if (notice and ((not var.irc_equals(chan, botconfig.NICK) and not botconfig.ALLOW_NOTICE_COMMANDS) or
                    (var.irc_equals(chan, botconfig.NICK) and not botconfig.ALLOW_PRIVATE_NOTICE_COMMANDS))):
        return  # not allowed in settings

    if var.irc_equals(chan, botconfig.NICK):
        chan = parse_nick(rawnick)[0]

    for fn in decorators.COMMANDS[""]:
        try:
            fn.caller(cli, rawnick, chan, msg)
        except Exception:
            sys.stderr.write(traceback.format_exc())
            if botconfig.DEBUG_MODE:
                raise


    for x in decorators.COMMANDS:
        if chan != parse_nick(rawnick)[0] and not msg.lower().startswith(botconfig.CMD_CHAR):
            break # channel message but no prefix; ignore
        if msg.lower().startswith(botconfig.CMD_CHAR+x):
            h = msg[len(x)+len(botconfig.CMD_CHAR):]
        elif not x or msg.lower().startswith(x):
            h = msg[len(x):]
        else:
            continue
        if not h or h[0] == " ":
            for fn in decorators.COMMANDS.get(x, []):
                try:
                    fn.caller(cli, rawnick, chan, h.lstrip())
                except Exception:
                    sys.stderr.write(traceback.format_exc())
                    if botconfig.DEBUG_MODE:
                        raise
Ejemplo n.º 2
0
def on_privmsg(cli, rawnick, chan, msg, notice=False):
    currmod = ld.MODULES[ld.CURRENT_MODULE]

    if botconfig.IGNORE_HIDDEN_COMMANDS and (chan.startswith("@#")
                                             or chan.startswith("+#")):
        return

    if (notice and
        ((chan != botconfig.NICK and not botconfig.ALLOW_NOTICE_COMMANDS) or
         (chan == botconfig.NICK
          and not botconfig.ALLOW_PRIVATE_NOTICE_COMMANDS))):
        return  # not allowed in settings

    if chan == botconfig.NICK:
        chan = parse_nick(rawnick)[0]

    if currmod and "" in currmod.COMMANDS.keys():
        for fn in currmod.COMMANDS[""]:
            try:
                fn(cli, rawnick, chan, msg)
            except:
                if botconfig.DEBUG_MODE:
                    raise
                else:
                    log(traceback.format_exc())
                    cli.msg(chan, "An error has occurred and has been logged.")

    for x in set(
            list(COMMANDS.keys()) +
        (list(currmod.COMMANDS.keys()) if currmod else list())):
        if chan != parse_nick(rawnick)[0] and not msg.lower().startswith(
                botconfig.CMD_CHAR):
            break  # channel message but no prefix; ignore
        if msg.lower().startswith(botconfig.CMD_CHAR + x):
            h = msg[len(x) + len(botconfig.CMD_CHAR):]
        elif not x or msg.lower().startswith(x):
            h = msg[len(x):]
        else:
            continue
        if not h or h[0] == " ":
            for fn in COMMANDS.get(
                    x, []) + (currmod.COMMANDS.get(x, []) if currmod else []):
                try:
                    fn(cli, rawnick, chan, h.lstrip())
                except:
                    if botconfig.DEBUG_MODE:
                        raise
                    else:
                        log(traceback.format_exc())
                        cli.msg(chan,
                                "An error has occurred and has been logged.")
Ejemplo n.º 3
0
    def tryBotCommand(self, prefix, dest, msg):
        """ tests a command to see if its a command for the bot, returns True
        and calls self.processBotCommand(cmd, sender) if its is.
        """
    
        logging.debug("tryBotCommand('%s' '%s' '%s')" % (prefix, dest, msg))

        if dest == self.client.nick:
            dest = parse_nick(prefix)[0]
        elif msg.startswith(self.client.nick):
            msg = msg[len(self.client.nick)+1:]
        else: 
            return False

        msg = msg.strip()

        parts = msg.split(' ', 1)
        command = parts[0]
        arg = parts[1:]

        try:
            self.command_handler.run(command, prefix, dest, *arg)
        except CommandError as e:
            helpers.msg(self.client, dest, str(e))
        return True
Ejemplo n.º 4
0
    def tryBotCommand(self, prefix, dest, msg):
        """ tests a command to see if its a command for the bot, returns True
        and calls self.processBotCommand(cmd, sender) if its is.
        """

        logging.debug("tryBotCommand('%s' '%s' '%s')" % (prefix, dest, msg))

        if dest == self.client.nick:
            dest = parse_nick(prefix)[0]
        elif msg.startswith(self.client.nick):
            msg = msg[len(self.client.nick) + 1:]
        else:
            return False

        msg = msg.strip()

        parts = msg.split(' ', 1)
        command = parts[0]
        arg = parts[1:]

        try:
            self.command_handler.run(command, prefix, dest, *arg)
        except CommandError as e:
            helpers.msg(self.client, dest, str(e))
        return True
Ejemplo n.º 5
0
def on_privmsg(cli, rawnick, chan, msg, notice = False):

    try:
        prefixes = getattr(var, "STATUSMSG_PREFIXES")
    except AttributeError:
        pass
    else:
        if botconfig.IGNORE_HIDDEN_COMMANDS and chan[0] in prefixes:
            return

    if (notice and ((chan != botconfig.NICK and not botconfig.ALLOW_NOTICE_COMMANDS) or
                    (chan == botconfig.NICK and not botconfig.ALLOW_PRIVATE_NOTICE_COMMANDS))):
        return  # not allowed in settings

    if chan == botconfig.NICK:
        chan = parse_nick(rawnick)[0]

    if "" in wolfgame.COMMANDS.keys():
        for fn in wolfgame.COMMANDS[""]:
            try:
                fn(cli, rawnick, chan, msg)
            except Exception:
                if botconfig.DEBUG_MODE:
                    raise
                else:
                    notify_error(cli, chan, log)


    for x in set(list(COMMANDS.keys()) + list(wolfgame.COMMANDS.keys())):
        if chan != parse_nick(rawnick)[0] and not msg.lower().startswith(botconfig.CMD_CHAR):
            break # channel message but no prefix; ignore
        if msg.lower().startswith(botconfig.CMD_CHAR+x):
            h = msg[len(x)+len(botconfig.CMD_CHAR):]
        elif not x or msg.lower().startswith(x):
            h = msg[len(x):]
        else:
            continue
        if not h or h[0] == " ":
            for fn in COMMANDS.get(x, []) + (wolfgame.COMMANDS.get(x, [])):
                try:
                    fn(cli, rawnick, chan, h.lstrip())
                except Exception:
                    if botconfig.DEBUG_MODE:
                        raise
                    else:
                        notify_error(cli, chan, log)
Ejemplo n.º 6
0
 def add(self, sender, dest, arg):
     user, commands = arg.split(' ', 1)
     commands = commands.split(' ')
     for command in commands:
         ae = AuthEntry(user, command)
         db.session.save_or_update(ae)
     db.session.commit()
     helpers.msgOK(self.client, dest, parse_nick(sender)[0])
Ejemplo n.º 7
0
    def privmsg(self, nick, chan, msg):
        print 'msg from: %s' % nick
        # print msg
        # print len(nick)
        # print len(chan)
        # print len(msg)
        # print 'only listening to: %s' % tgt_nick
        
        nick_seg = None

        if nick:
            nick_segs = parse_nick(nick)
            nick_seg = nick_segs[0]

        if self.tgt_nick and nick_seg == self.tgt_nick:
            if self.session_role == Role.HOST:
                ## HOST behavior
                # print 'imahost'
                buffer_match = share_view_reply_pattern.match(msg)
                cmd_match = view_sel_cmd_pattern.match(msg)
                if buffer_match:
                    print 'sharing buffer'
                    # bad hack for base64 encoding/decoding support
                    self.max_buf_size = int(float(buffer_match.group(1))/2)
                    self.share_entire_view()
                elif cmd_match:
                    self.session_selection = None
                    self.session_selection = sublime.Region(int(cmd_match.group(1)), int(cmd_match.group(2)))
                    sublime.set_timeout(lambda: self.show_shared_selection(), 100)
                ## more msg handling here ##
            else:
                cmd_match = view_sel_cmd_pattern.match(msg)
                syntax_match = view_set_syntax_pattern.match(msg)
                if msg == CollabMessages.END_SHARE_PUBLISH:
                    self.am_recving_buffer = False
                elif cmd_match:
                    self.session_selection = None
                    self.session_selection = sublime.Region(int(cmd_match.group(1)), int(cmd_match.group(2)))
                    sublime.set_timeout(lambda: self.show_shared_selection(), 100)
                elif syntax_match:
                    self.session_syntax = syntax_match.group(1)
                    sublime.set_timeout(lambda: self.set_syntax(), 100)
                elif self.am_recving_buffer:
                    print 'recvd msg of len %d' % len(msg)
                    self.in_queue_lock.acquire()
                    self.in_queue.insert(0, msg)
                    self.in_queue_lock.release()
                    sublime.set_timeout(lambda: self.publish_partner_chunk(), 100)
                ## PARTNER behavior
                # print "%s said to %s: %s" % (nick_seg, chan, msg)
        elif msg == CollabMessages.START_SHARE:
            # request from a potential host to start a session
            self.tgt_nick = nick_seg
            print 'show start session dialog'
            self.max_buf_size = 498 - (len(nick) + len(chan))
            sublime.set_timeout(lambda: self.partner_accept_session_dialog(), 0)
        else:
            print "%s from %s IS NOT WELCOMEin " % (nick_seg, chan)
Ejemplo n.º 8
0
 def remove(self, sender, dest, arg):
     user, commands = arg.split(' ', 1)
     commands = commands.split(' ')
     for command in commands:
         ae = AuthEntry.getForUser(user, command)
         if len(ae):
             db.session.delete(ae)
     db.session.commit()
     helpers.msgOK(self.client, dest, parse_nick(sender)[0])
Ejemplo n.º 9
0
def on_privmsg(cli, rawnick, chan, msg, notice = False):
    currmod = ld.MODULES[ld.CURRENT_MODULE]
    
    if botconfig.IGNORE_HIDDEN_COMMANDS and (chan.startswith("@#") or chan.startswith("+#")):
        return
    
    if (notice and ((chan != botconfig.NICK and not botconfig.ALLOW_NOTICE_COMMANDS) or
                    (chan == botconfig.NICK and not botconfig.ALLOW_PRIVATE_NOTICE_COMMANDS))):
        return  # not allowed in settings

    if chan == botconfig.NICK:
        chan = parse_nick(rawnick)[0]

    if currmod and "" in currmod.COMMANDS.keys():
        for fn in currmod.COMMANDS[""]:
            try:
                fn(cli, rawnick, chan, msg)
            except:
                if botconfig.DEBUG_MODE:
                    raise
                else:
                    log(traceback.format_exc())
                    cli.msg(chan, "An error has occurred and has been logged.")

    for x in set(list(COMMANDS.keys()) + (list(currmod.COMMANDS.keys()) if currmod else list())):
        if chan != parse_nick(rawnick)[0] and not msg.lower().startswith(botconfig.CMD_CHAR):
            break # channel message but no prefix; ignore
        if msg.lower().startswith(botconfig.CMD_CHAR+x):
            h = msg[len(x)+len(botconfig.CMD_CHAR):]
        elif not x or msg.lower().startswith(x):
            h = msg[len(x):]
        else:
            continue
        if not h or h[0] == " ":
            for fn in COMMANDS.get(x, []) + (currmod.COMMANDS.get(x, []) if currmod else []):
                try:
                    fn(cli, rawnick, chan, h.lstrip())
                except:
                    if botconfig.DEBUG_MODE:
                        raise
                    else:
                        log(traceback.format_exc())
                        cli.msg(chan, "An error has occurred and has been logged.")
Ejemplo n.º 10
0
def on_privmsg(cli, rawnick, chan, msg, notice = False):

    try:
        prefixes = getattr(var, "STATUSMSG_PREFIXES")
    except AttributeError:
        pass
    else:
        if botconfig.IGNORE_HIDDEN_COMMANDS and chan[0] in prefixes:
            return

    if (notice and ((chan != botconfig.NICK and not botconfig.ALLOW_NOTICE_COMMANDS) or
                    (chan == botconfig.NICK and not botconfig.ALLOW_PRIVATE_NOTICE_COMMANDS))):
        return  # not allowed in settings

    if chan == botconfig.NICK:
        chan = parse_nick(rawnick)[0]

    for fn in decorators.COMMANDS[""]:
        try:
            fn.caller(cli, rawnick, chan, msg)
        except Exception:
            sys.stderr.write(traceback.format_exc())
            if botconfig.DEBUG_MODE:
                raise


    for x in decorators.COMMANDS:
        if chan != parse_nick(rawnick)[0] and not msg.lower().startswith(botconfig.CMD_CHAR):
            break # channel message but no prefix; ignore
        if msg.lower().startswith(botconfig.CMD_CHAR+x):
            h = msg[len(x)+len(botconfig.CMD_CHAR):]
        elif not x or msg.lower().startswith(x):
            h = msg[len(x):]
        else:
            continue
        if not h or h[0] == " ":
            for fn in decorators.COMMANDS.get(x, []):
                try:
                    fn.caller(cli, rawnick, chan, h.lstrip())
                except Exception:
                    sys.stderr.write(traceback.format_exc())
                    if botconfig.DEBUG_MODE:
                        raise
Ejemplo n.º 11
0
            def innerf(*args):
                largs = list(args)
                if len(largs) > 1 and largs[1]:
                    nick, _, _, cloak = parse_nick(largs[1])

                    if cloak is None:
                        cloak = ""
                else:
                    nick = ""
                    cloak = ""

                if not raw_nick and len(largs) > 1 and largs[1]:
                    largs[1] = nick
                    #if largs[1].startswith("#"):
                if not permissions or "" in s:
                    return f(*largs)
                if cloak:
                    for pattern in botconfig.DENY.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in botconfig.DENY[pattern]:
                                    largs[0].notice(
                                        nick,
                                        "You do not have permission to use that command."
                                    )
                                    return
                    for pattern in botconfig.ALLOW.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in botconfig.ALLOW[pattern]:
                                    return f(*largs)  # no questions
                if owner_only:
                    if cloak and [
                            ptn for ptn in botconfig.OWNERS
                            if fnmatch.fnmatch(cloak.lower(), ptn.lower())
                    ]:
                        return f(*largs)
                    elif cloak:
                        largs[0].notice(
                            nick, "You are not a developer or Coordinator."
                        )  #Changed bot owner to Developer / Coordinator
                        return
                if admin_only:
                    if cloak and [
                            ptn for ptn in botconfig.ADMINS + botconfig.OWNERS
                            if fnmatch.fnmatch(cloak.lower(), ptn.lower())
                    ]:
                        return f(*largs)
                    elif cloak:
                        largs[0].notice(nick,
                                        "You are not a Youth! Teammember."
                                        )  # Changed Admin to teammember
                        return
                return f(*largs)
Ejemplo n.º 12
0
 def __init__(self, client, nick_string, source, content, is_private_message):
     self.client = client
     self.nickstring = nick_string
     parsed_nick_string = parse.parse_nick(nick_string) 
     self.sender = parsed_nick_string[0]
     self.sender_mode = parsed_nick_string[1]
     self.sender_user = parsed_nick_string[2]
     self.sender_host = parsed_nick_string[3]
     self.source = source
     self.content = content
     self.is_private_message = is_private_message
Ejemplo n.º 13
0
            def innerf(*args):
                largs = list(args)
                if len(largs) > 1 and largs[1]:
                    nick, _, _, cloak = parse_nick(largs[1])

                    if cloak is None:
                        cloak = ""
                else:
                    nick = ""
                    cloak = ""

                if not raw_nick and len(largs) > 1 and largs[1]:
                    largs[1] = nick
                    #if largs[1].startswith("#"):
                if not permissions or "" in s:
                    return f(*largs)
                if cloak:
                    for pattern in botconfig.DENY.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in botconfig.DENY[pattern]:
                                    largs[0].notice(
                                        nick,
                                        "Je hebt geen rechten voor dat commando."
                                    )
                                    return
                    for pattern in botconfig.ALLOW.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in botconfig.ALLOW[pattern]:
                                    return f(*largs)  # no questions
                if owner_only:
                    if cloak and [
                            ptn for ptn in botconfig.OWNERS
                            if fnmatch.fnmatch(cloak.lower(), ptn.lower())
                    ]:
                        return f(*largs)
                    elif cloak:
                        largs[0].notice(nick, "Je bent niet de eigenaar.")
                        return
                if admin_only:
                    if cloak and [
                            ptn for ptn in botconfig.ADMINS + botconfig.OWNERS
                            if fnmatch.fnmatch(cloak.lower(), ptn.lower())
                    ]:
                        return f(*largs)
                    elif cloak:
                        largs[0].notice(nick, "Je bent geen administrator.")
                        return
                return f(*largs)
Ejemplo n.º 14
0
            def innerf(*args):
                largs = list(args)
                if len(largs) > 1 and largs[1]:
                    nick, _, _, cloak = parse_nick(largs[1])

                    if cloak is None:
                        cloak = ""
                else:
                    nick = ""
                    cloak = ""
                    
                if not raw_nick and len(largs) > 1 and largs[1]:
                    largs[1] = nick
                    #if largs[1].startswith("#"):
                if not permissions or "" in s:
                    return f(*largs)
                if cloak:
                    for pattern in botconfig.DENY.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in botconfig.DENY[pattern]:
                                    largs[0].notice(nick, "You do not have permission to use that command.")
                                    return
                    for pattern in botconfig.ALLOW.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in botconfig.ALLOW[pattern]:
                                    return f(*largs)  # no questions
                if owner_only:
                    #for ptn in botconfig.OWNERS:
                    #    largs[0].notice(nick,ptn.lower())
                    if cloak and [ptn for ptn in botconfig.OWNERS 
                                  if fnmatch.fnmatch(cloak.lower(), ptn.lower())]:
                        return f(*largs)
                    elif cloak:
                        #largs[0].notice(nick, cloak.lower())
                        largs[0].notice(nick, "You are not the owner.")
                        return
                if admin_only:
                    if cloak and [ptn for ptn in botconfig.ADMINS+botconfig.OWNERS
                                  if fnmatch.fnmatch(cloak.lower(), ptn.lower())]:
                        return f(*largs)
                    elif cloak:
                        largs[0].notice(nick, "You are not an admin.")
                        return
                return f(*largs)
Ejemplo n.º 15
0
def test_parse_nick():
    user = "******"
    userName = parse.parse_nick(user)
    assert userName[0] == "mywolfbot" and userName[1] is None and userName[2] == "~mywolfbot" \
        and userName[3] == "pool-173-48-152-9.bstnma.fios.verizon.net"
Ejemplo n.º 16
0
    def caller(self, cli, rawnick, chan, rest):
        _ignore_locals_ = True
        if users.equals(chan, users.Bot.nick):
            chan = users.parse_rawnick_as_dict(rawnick)["nick"]

        largs = [cli, rawnick, chan, rest]

        cli, rawnick, chan, rest = largs
        nick, mode, ident, host = parse_nick(rawnick)

        if ident is None:
            ident = ""

        if host is None:
            host = ""

        if not self.raw_nick:
            largs[1] = nick

        if not self.pm and chan == nick:
            return # PM command, not allowed

        if not self.chan and chan != nick:
            return # channel command, not allowed

        if chan.startswith("#") and chan != botconfig.CHANNEL and not (self.flag or self.owner_only):
            if "" in self.cmds:
                return # don't have empty commands triggering in other channels
            for command in self.cmds:
                if command in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
                    break
            else:
                return

        if nick not in var.USERS and not is_fake_nick(nick):
            return

        if nick in var.USERS and var.USERS[nick]["account"] != "*":
            acc = irc_lower(var.USERS[nick]["account"])
        else:
            acc = None
        ident = irc_lower(ident)
        host = host.lower()
        hostmask = nick + "!" + ident + "@" + host

        if "" in self.cmds:
            self.func(*largs)
            return

        if self.phases and var.PHASE not in self.phases:
            return

        if self.playing and (nick not in list_players() or users._get(nick) in var.DISCONNECTED):
            return

        for role in self.roles:
            if users._get(nick) in var.ROLES[role]:
                break
        else:
            if (self.nicks is not None and nick not in self.nicks) or self.roles:
                return

        if self.silenced and nick in var.SILENCED:
            if chan == nick:
                pm(cli, nick, messages["silenced"])
            else:
                cli.notice(nick, messages["silenced"])
            return

        if self.roles or (self.nicks is not None and nick in self.nicks):
            self.func(*largs) # don't check restrictions for role commands
            # Role commands might end the night if it's nighttime
            if var.PHASE == "night":
                from src.wolfgame import chk_nightdone
                chk_nightdone()
            return

        forced_owner_only = False
        if hasattr(botconfig, "OWNERS_ONLY_COMMANDS"):
            for command in self.cmds:
                if command in botconfig.OWNERS_ONLY_COMMANDS:
                    forced_owner_only = True
                    break

        owner = is_owner(nick, ident, host)
        if self.owner_only or forced_owner_only:
            if owner:
                adminlog(chan, rawnick, self.name, rest)
                self.func(*largs)
                return

            if chan == nick:
                pm(cli, nick, messages["not_owner"])
            else:
                cli.notice(nick, messages["not_owner"])
            return

        flags = var.FLAGS[hostmask] + var.FLAGS_ACCS[acc]
        admin = is_admin(nick, ident, host)
        if self.flag and (admin or owner):
            adminlog(chan, rawnick, self.name, rest)
            self.func(*largs)
            return

        denied_cmds = var.DENY[hostmask] | var.DENY_ACCS[acc]
        for command in self.cmds:
            if command in denied_cmds:
                if chan == nick:
                    pm(cli, nick, messages["invalid_permissions"])
                else:
                    cli.notice(nick, messages["invalid_permissions"])
                return

        if self.flag:
            if self.flag in flags:
                adminlog(chan, rawnick, self.name, rest)
                self.func(*largs)
                return
            elif chan == nick:
                pm(cli, nick, messages["not_an_admin"])
            else:
                cli.notice(nick, messages["not_an_admin"])
            return

        self.func(*largs)
Ejemplo n.º 17
0
            def innerf(*args):
                largs = list(args)
                rawnick = largs[1]
                if not permissions:
                    return f(*largs)
                if len(largs) > 1 and largs[1]:
                    nick, _, _, cloak = parse_nick(largs[1])

                    if cloak is None:
                        cloak = ""
                else:
                    nick = ""
                    cloak = ""
                if not raw_nick and len(largs) > 1 and largs[1]:
                    largs[1] = nick
                if nick == "<console>":
                    return f(*largs)  # special case; no questions
                if not pm and largs[2] == nick:  # PM command
                    return
                if not chan and largs[2] != nick:  # channel command
                    return
                if largs[2].startswith("#") and largs[
                        2] != botconfig.CHANNEL and not admin_only and not owner_only:
                    if "" in s:
                        return  # Don't have empty commands triggering in other channels
                    allowed = False
                    for cmdname in s:
                        if cmdname in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
                            allowed = True
                            break
                    if not allowed:
                        return
                if nick in var.USERS.keys(
                ) and var.USERS[nick]["account"] != "*":
                    acc = var.USERS[nick]["account"]
                else:
                    acc = None
                if "" in s:
                    return f(*largs)
                if game and var.PHASE not in ("day", "night") + (
                    ("join", ) if join else ()):
                    largs[0].notice(nick, "No game is currently running.")
                    return
                if ((join and none and var.PHASE not in ("join", "none"))
                        or (none and not join and var.PHASE != "none")):
                    largs[0].notice(
                        nick,
                        "Sorry, but the game is already running. Try again next time."
                    )
                    return
                if join and not none:
                    if var.PHASE == "none":
                        largs[0].notice(nick, "No game is currently running.")
                        return
                    if var.PHASE != "join" and not game:
                        largs[0].notice(nick, "Werewolf is already in play.")
                        return
                if playing and nick not in var.list_players(
                ) or nick in var.DISCONNECTED.keys():
                    largs[0].notice(nick, "You're not currently playing.")
                    return
                if roles:
                    for role in roles:
                        if nick in var.ROLES[role]:
                            break
                    else:
                        return
                if acc:
                    for pattern in var.DENY_ACCOUNTS.keys():
                        if fnmatch.fnmatch(acc.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.DENY_ACCOUNTS[pattern]:
                                    largs[0].notice(
                                        nick,
                                        "You do not have permission to use that command."
                                    )
                                    return
                    for pattern in var.ALLOW_ACCOUNTS.keys():
                        if fnmatch.fnmatch(acc.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.ALLOW_ACCOUNTS[pattern]:
                                    if admin_only or owner_only:
                                        adminlog(largs[2], rawnick, s[0],
                                                 largs[3])
                                    return f(*largs)
                if not var.ACCOUNTS_ONLY and cloak:
                    for pattern in var.DENY.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.DENY[pattern]:
                                    largs[0].notice(
                                        nick,
                                        "You do not have permission to use that command."
                                    )
                                    return
                    for pattern in var.ALLOW.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.ALLOW[pattern]:
                                    if admin_only or owner_only:
                                        adminlog(largs[2], rawnick, s[0],
                                                 largs[3])
                                    return f(*largs)  # no questions
                if owner_only:
                    if var.is_owner(nick, cloak):
                        adminlog(largs[2], rawnick, s[0], largs[3])
                        return f(*largs)
                    else:
                        largs[0].notice(nick, "You are not the owner.")
                        return
                if admin_only:
                    if var.is_admin(nick, cloak):
                        adminlog(largs[2], rawnick, s[0], largs[3])
                        return f(*largs)
                    else:
                        largs[0].notice(nick, "You are not an admin.")
                        return
                return f(*largs)
Ejemplo n.º 18
0
    def caller(self, *args):
        largs = list(args)

        cli, rawnick, chan, rest = largs
        nick, mode, user, cloak = parse_nick(rawnick)

        if cloak is None:
            cloak = ""

        if not self.raw_nick:
            largs[1] = nick

        if not self.pm and chan == nick:
            return # PM command, not allowed

        if not self.chan and chan != nick:
            return # channel command, not allowed

        if chan.startswith("#") and chan != botconfig.CHANNEL and not (self.admin_only or self.owner_only):
            if "" in self.cmds:
                return # don't have empty commands triggering in other channels
            for command in self.cmds:
                if command in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
                    break
            else:
                return

        if nick in var.USERS and var.USERS[nick]["account"] != "*":
            acc = var.USERS[nick]["account"]
        else:
            acc = None

        if "" in self.cmds:
            return self.func(*largs)

        if self.phases and var.PHASE not in self.phases:
            return

        if self.playing and (nick not in var.list_players() or nick in var.DISCONNECTED):
            if chan == nick:
                pm(cli, nick, "You're not currently playing.")
            else:
                cli.notice(nick, "You're not currently playing.")
            return

        if self.silenced and nick in var.SILENCED:
            if chan == nick:
                pm(cli, nick, "You have been silenced, and are unable to use any special powers.")
            else:
                cli.notice(nick, "You have been silenced, and are unable to use any special powers.")
            return

        if self.roles:
            for role in self.roles:
                if nick in var.ROLES[role]:
                    break
            else:
                return

            return self.func(*largs) # don't check restrictions for role commands

        if self.owner_only:
            if var.is_owner(nick, cloak):
                adminlog(chan, rawnick, self.name, rest)
                return self.func(*largs)

            if chan == nick:
                pm(cli, nick, "You are not the owner.")
            else:
                cli.notice(nick, "You are not the owner.")
            return

        if var.is_admin(nick, cloak):
            if self.admin_only:
                adminlog(chan, rawnick, self.name, rest)
            return self.func(*largs)

        if not var.DISABLE_ACCOUNTS and acc:
            for pattern in var.DENY_ACCOUNTS:
                if fnmatch.fnmatch(acc.lower(), pattern.lower()):
                    for command in self.cmds:
                        if command in var.DENY_ACCOUNTS[pattern]:
                            if chan == nick:
                                pm(cli, nick, "You do not have permission to use that command.")
                            else:
                                cli.notice(nick, "You do not have permission to use that command.")
                            return

            for pattern in var.ALLOW_ACCOUNTS:
                if fnmatch.fnmatch(acc.lower(), pattern.lower()):
                    for command in self.cmds:
                        if command in var.ALLOW_ACCOUNTS[pattern]:
                            if self.admin_only:
                                adminlog(chan, rawnick, self.name, rest)
                            return self.func(*largs)

        if not var.ACCOUNTS_ONLY and cloak:
            for pattern in var.DENY:
                if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                    for command in self.cmds:
                        if command in var.DENY[pattern]:
                            if chan == nick:
                                pm(cli, nick, "You do not have permission to use that command.")
                            else:
                                cli.notice(nick, "You do not have permission to use that command.")
                            return

            for pattern in var.ALLOW:
                if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                    for command in self.cmds:
                        if command in var.ALLOW[pattern]:
                            if self.admin_only:
                                adminlog(chan, rawnick, self.name, rest)
                            return self.func(*largs)

        if self.admin_only:
            if chan == nick:
                pm(cli, nick, "You are not an admin.")
            else:
                cli.notice(nick, "You are not an admin.")
            return

        return self.func(*largs)
Ejemplo n.º 19
0
    def caller(self, *args):
        largs = list(args)

        cli, rawnick, chan, rest = largs
        nick, mode, ident, host = parse_nick(rawnick)

        if ident is None:
            ident = ""

        if host is None:
            host = ""

        if not self.raw_nick:
            largs[1] = nick

        if not self.pm and chan == nick:
            return # PM command, not allowed

        if not self.chan and chan != nick:
            return # channel command, not allowed

        if chan.startswith("#") and chan != botconfig.CHANNEL and not (self.admin_only or self.owner_only):
            if "" in self.cmds:
                return # don't have empty commands triggering in other channels
            for command in self.cmds:
                if command in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
                    break
            else:
                return

        if nick in var.USERS and var.USERS[nick]["account"] != "*":
            acc = var.USERS[nick]["account"]
        else:
            acc = None

        if "" in self.cmds:
            return self.func(*largs)

        if self.phases and var.PHASE not in self.phases:
            return

        if self.playing and (nick not in var.list_players() or nick in var.DISCONNECTED):
            if chan == nick:
                pm(cli, nick, messages["player_not_playing"])
            else:
                cli.notice(nick, messages["player_not_playing"])
            return

        if self.silenced and nick in var.SILENCED:
            if chan == nick:
                pm(cli, nick, messages["silenced"])
            else:
                cli.notice(nick, messages["silenced"])
            return

        if self.roles:
            for role in self.roles:
                if nick in var.ROLES[role]:
                    break
            else:
                return

            return self.func(*largs) # don't check restrictions for role commands

        forced_owner_only = False
        if hasattr(botconfig, "OWNERS_ONLY_COMMANDS"):
            for command in self.cmds:
                if command in botconfig.OWNERS_ONLY_COMMANDS:
                    forced_owner_only = True
                    break

        if self.owner_only or forced_owner_only:
            if var.is_owner(nick, ident, host):
                adminlog(chan, rawnick, self.name, rest)
                return self.func(*largs)

            if chan == nick:
                pm(cli, nick, messages["not_owner"])
            else:
                cli.notice(nick, messages["not_owner"])
            return

        if var.is_admin(nick, ident, host):
            if self.admin_only:
                adminlog(chan, rawnick, self.name, rest)
            return self.func(*largs)

        if not var.DISABLE_ACCOUNTS and acc:
            if acc in var.DENY_ACCOUNTS:
                for command in self.cmds:
                    if command in var.DENY_ACCOUNTS[acc]:
                        if chan == nick:
                            pm(cli, nick, messages["invalid_permissions"])
                        else:
                            cli.notice(nick, messages["invalid_permissions"])
                        return

            if acc in var.ALLOW_ACCOUNTS:
                for command in self.cmds:
                    if command in var.ALLOW_ACCOUNTS[acc]:
                        if self.admin_only:
                            adminlog(chan, rawnick, self.name, rest)
                        return self.func(*largs)

        if host:
            for pattern in var.DENY:
                if var.match_hostmask(pattern, nick, ident, host):
                    for command in self.cmds:
                        if command in var.DENY[pattern]:
                            if chan == nick:
                                pm(cli, nick, messages["invalid_permissions"])
                            else:
                                cli.notice(nick, messages["invalid_permissions"])
                            return

            for pattern in var.ALLOW:
                if var.match_hostmask(pattern, nick, ident, host):
                    for command in self.cmds:
                        if command in var.ALLOW[pattern]:
                            if self.admin_only:
                                adminlog(chan, rawnick, self.name, rest)
                            return self.func(*largs)

        if self.admin_only:
            if chan == nick:
                pm(cli, nick, messages["not_an_admin"])
            else:
                cli.notice(nick, messages["not_an_admin"])
            return

        return self.func(*largs)
Ejemplo n.º 20
0
            def innerf(*args):
                largs = list(args)
                rawnick = largs[1]
                if not permissions:
                    return f(*largs)
                if len(largs) > 1 and largs[1]:
                    nick, _, _, cloak = parse_nick(largs[1])

                    if cloak is None:
                        cloak = ""
                else:
                    nick = ""
                    cloak = ""
                if not raw_nick and len(largs) > 1 and largs[1]:
                    largs[1] = nick
                if nick == "<console>":
                    return f(*largs) # special case; no questions
                if not pm and largs[2] == nick: # PM command
                    return
                if not chan and largs[2] != nick: # channel command
                    return
                if largs[2].startswith("#") and largs[2] != botconfig.CHANNEL and not admin_only and not owner_only:
                    if "" in s:
                        return # Don't have empty commands triggering in other channels
                    allowed = False
                    for cmdname in s:
                        if cmdname in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
                            allowed = True
                            break
                    if not allowed:
                        return
                if nick in var.USERS.keys() and var.USERS[nick]["account"] != "*":
                    acc = var.USERS[nick]["account"]
                else:
                    acc = None
                if "" in s:
                    return f(*largs)
                if game and var.PHASE not in ("day", "night") + (("join",) if join else ()):
                    largs[0].notice(nick, "No game is currently running.")
                    return
                if ((join and none and var.PHASE not in ("join", "none"))
                        or (none and not join and var.PHASE != "none")):
                    largs[0].notice(nick, "Sorry, but the game is already running. Try again next time.")
                    return
                if join and not none:
                    if var.PHASE == "none":
                        largs[0].notice(nick, "No game is currently running.")
                        return
                    if var.PHASE != "join" and not game:
                        largs[0].notice(nick, "Werewolf is already in play.")
                        return
                if playing and nick not in var.list_players() or nick in var.DISCONNECTED.keys():
                    largs[0].notice(nick, "You're not currently playing.")
                    return
                if roles:
                    for role in roles:
                        if nick in var.ROLES[role]:
                            break
                    else:
                        return
                if acc:
                    for pattern in var.DENY_ACCOUNTS.keys():
                        if fnmatch.fnmatch(acc.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.DENY_ACCOUNTS[pattern]:
                                    largs[0].notice(nick, "You do not have permission to use that command.")
                                    return
                    for pattern in var.ALLOW_ACCOUNTS.keys():
                        if fnmatch.fnmatch(acc.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.ALLOW_ACCOUNTS[pattern]:
                                    if admin_only or owner_only:
                                        adminlog(largs[2], rawnick, s[0], largs[3])
                                    return f(*largs)
                if not var.ACCOUNTS_ONLY and cloak:
                    for pattern in var.DENY.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.DENY[pattern]:
                                    largs[0].notice(nick, "You do not have permission to use that command.")
                                    return
                    for pattern in var.ALLOW.keys():
                        if fnmatch.fnmatch(cloak.lower(), pattern.lower()):
                            for cmdname in s:
                                if cmdname in var.ALLOW[pattern]:
                                    if admin_only or owner_only:
                                        adminlog(largs[2], rawnick, s[0], largs[3])
                                    return f(*largs)  # no questions
                if owner_only:
                    if var.is_owner(nick, cloak):
                        adminlog(largs[2], rawnick, s[0], largs[3])
                        return f(*largs)
                    else:
                        largs[0].notice(nick, "You are not the owner.")
                        return
                if admin_only:
                    if var.is_admin(nick, cloak):
                        adminlog(largs[2], rawnick, s[0], largs[3])
                        return f(*largs)
                    else:
                        largs[0].notice(nick, "You are not an admin.")
                        return
                return f(*largs)
Ejemplo n.º 21
0
    def caller(self, *args):
        largs = list(args)

        cli, rawnick, chan, rest = largs
        nick, mode, ident, host = parse_nick(rawnick)

        if ident is None:
            ident = ""

        if host is None:
            host = ""

        if not self.raw_nick:
            largs[1] = nick

        if not self.pm and chan == nick:
            return # PM command, not allowed

        if not self.chan and chan != nick:
            return # channel command, not allowed

        if chan.startswith("#") and chan != botconfig.CHANNEL and not (self.flag or self.owner_only):
            if "" in self.cmds:
                return # don't have empty commands triggering in other channels
            for command in self.cmds:
                if command in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
                    break
            else:
                return

        if nick in var.USERS and var.USERS[nick]["account"] != "*":
            acc = irc_lower(var.USERS[nick]["account"])
        else:
            acc = None
        ident = irc_lower(ident)
        host = host.lower()
        hostmask = nick + "!" + ident + "@" + host

        if "" in self.cmds:
            return self.func(*largs)

        if self.phases and var.PHASE not in self.phases:
            return

        if self.playing and (nick not in list_players() or nick in var.DISCONNECTED):
            if chan == nick:
                pm(cli, nick, messages["player_not_playing"])
            else:
                cli.notice(nick, messages["player_not_playing"])
            return

        if self.silenced and nick in var.SILENCED:
            if chan == nick:
                pm(cli, nick, messages["silenced"])
            else:
                cli.notice(nick, messages["silenced"])
            return

        if self.roles:
            for role in self.roles:
                if nick in var.ROLES[role]:
                    break
            else:
                return

            return self.func(*largs) # don't check restrictions for role commands

        forced_owner_only = False
        if hasattr(botconfig, "OWNERS_ONLY_COMMANDS"):
            for command in self.cmds:
                if command in botconfig.OWNERS_ONLY_COMMANDS:
                    forced_owner_only = True
                    break

        owner = is_owner(nick, ident, host)
        if self.owner_only or forced_owner_only:
            if owner:
                adminlog(chan, rawnick, self.name, rest)
                return self.func(*largs)

            if chan == nick:
                pm(cli, nick, messages["not_owner"])
            else:
                cli.notice(nick, messages["not_owner"])
            return

        flags = var.FLAGS[hostmask] + var.FLAGS_ACCS[acc]
        admin = is_admin(nick, ident, host)
        if self.flag and (admin or owner):
            adminlog(chan, rawnick, self.name, rest)
            return self.func(*largs)

        denied_cmds = var.DENY[hostmask] | var.DENY_ACCS[acc]
        for command in self.cmds:
            if command in denied_cmds:
                if chan == nick:
                    pm(cli, nick, messages["invalid_permissions"])
                else:
                    cli.notice(nick, messages["invalid_permissions"])
                return

        if self.flag:
            if self.flag in flags:
                adminlog(chan, rawnick, self.name, rest)
                return self.func(*largs)
            elif chan == nick:
                pm(cli, nick, messages["not_an_admin"])
            else:
                cli.notice(nick, messages["not_an_admin"])
            return

        return self.func(*largs)
Ejemplo n.º 22
0
    def caller(self, *args):
        largs = list(args)

        cli, rawnick, chan, rest = largs
        nick, mode, ident, host = parse_nick(rawnick)

        if ident is None:
            ident = ""

        if host is None:
            host = ""

        if not self.raw_nick:
            largs[1] = nick

        if not self.pm and chan == nick:
            return  # PM command, not allowed

        if not self.chan and chan != nick:
            return  # channel command, not allowed

        if chan.startswith("#") and chan != botconfig.CHANNEL and not (
                self.admin_only or self.owner_only):
            if "" in self.cmds:
                return  # don't have empty commands triggering in other channels
            for command in self.cmds:
                if command in botconfig.ALLOWED_ALT_CHANNELS_COMMANDS:
                    break
            else:
                return

        if nick in var.USERS and var.USERS[nick]["account"] != "*":
            acc = var.USERS[nick]["account"]
        else:
            acc = None

        if "" in self.cmds:
            return self.func(*largs)

        if self.phases and var.PHASE not in self.phases:
            return

        if self.playing and (nick not in var.list_players()
                             or nick in var.DISCONNECTED):
            if chan == nick:
                pm(cli, nick, "You're not currently playing.")
            else:
                cli.notice(nick, "You're not currently playing.")
            return

        if self.silenced and nick in var.SILENCED:
            if chan == nick:
                pm(
                    cli, nick,
                    "You have been silenced, and are unable to use any special powers."
                )
            else:
                cli.notice(
                    nick,
                    "You have been silenced, and are unable to use any special powers."
                )
            return

        if self.roles:
            for role in self.roles:
                if nick in var.ROLES[role]:
                    break
            else:
                return

            return self.func(
                *largs)  # don't check restrictions for role commands

        if self.owner_only:
            if var.is_owner(nick, ident, host):
                adminlog(chan, rawnick, self.name, rest)
                return self.func(*largs)

            if chan == nick:
                pm(cli, nick, "You are not the owner.")
            else:
                cli.notice(nick, "You are not the owner.")
            return

        if var.is_admin(nick, ident, host):
            if self.admin_only:
                adminlog(chan, rawnick, self.name, rest)
            return self.func(*largs)

        if not var.DISABLE_ACCOUNTS and acc:
            if acc in var.DENY_ACCOUNTS:
                for command in self.cmds:
                    if command in var.DENY_ACCOUNTS[acc]:
                        if chan == nick:
                            pm(
                                cli, nick,
                                "You do not have permission to use that command."
                            )
                        else:
                            cli.notice(
                                nick,
                                "You do not have permission to use that command."
                            )
                        return

            if acc in var.ALLOW_ACCOUNTS:
                for command in self.cmds:
                    if command in var.ALLOW_ACCOUNTS[acc]:
                        if self.admin_only:
                            adminlog(chan, rawnick, self.name, rest)
                        return self.func(*largs)

        if not var.ACCOUNTS_ONLY and host:
            for pattern in var.DENY:
                if var.match_hostmask(pattern, nick, ident, host):
                    for command in self.cmds:
                        if command in var.DENY[pattern]:
                            if chan == nick:
                                pm(
                                    cli, nick,
                                    "You do not have permission to use that command."
                                )
                            else:
                                cli.notice(
                                    nick,
                                    "You do not have permission to use that command."
                                )
                            return

            for pattern in var.ALLOW:
                if var.match_hostmask(pattern, nick, ident, host):
                    for command in self.cmds:
                        if command in var.ALLOW[pattern]:
                            if self.admin_only:
                                adminlog(chan, rawnick, self.name, rest)
                            return self.func(*largs)

        if self.admin_only:
            if chan == nick:
                pm(cli, nick, "You are not an admin.")
            else:
                cli.notice(nick, "You are not an admin.")
            return

        return self.func(*largs)