예제 #1
0
파일: opts.py 프로젝트: Lujeni/old-projects
def makesxmppconfig(opts=None, botname=None, type="sxmpp"):
    """ make config file based on options. """
    if not opts: botname = botname or "default-%s" % type
    else:
        if not botname: botname = opts.name or "default-%s" % type
    botname = stripname(botname)
    from jsb.lib.config import Config, makedefaultconfig
    cfg = Config('fleet' + os.sep + botname + os.sep + 'config')
    cfg.type = type
    cfg.name = botname
    if not opts:
        cfg.user = cfg.user or ""
        cfg.host = cfg.host or ""
        cfg.password =  cfg.password or ""
        cfg.server = cfg.server or ""
        cfg.owner = cfg.owner or []
        cfg.loglevel = cfg.lowlevel or "warn" 
        cfg.nick = cfg.nick or "jsb"
        cfg.channels = []
        cfg.openfire = False
        return cfg        
    if opts.openfire: cfg.openfire = True ; logging.warn("openfire mode is enabled")
    else: cfg.openfire = False ; logging.warn("openfire mode is disabled")
    if opts.doregister: cfg.doregister = True ; logging.warn("register mode is enabled")
    else: cfg.doregister = False ; logging.warn("register mode is disabled")
    if not cfg.disable: cfg.disable = False
    if not cfg.channels: cfg.channels = []
    if opts.user: cfg.user = opts.user
    if not cfg.user: raise NoUserProvided("user is not provided .. try giving the -u option to the bot (and maybe -p as well) or run jsb-init and edit %s" % cfg.cfile)
    if opts.user:
        try: cfg.host = opts.user.split('@')[1]
        except (IndexError, ValueError): print "user is not in the nick@server format"
    if not cfg.host:
        try: cfg.host = cfg.user.split('@')[1]
        except (IndexError, ValueError): print "user is not in the nick@server format"
    if opts.password: cfg.password = opts.password
    if opts.server: cfg.server = opts.server
    else: cfg.server = cfg.server or ""
    if opts.name: cfg.jid = opts.name
    if not cfg.owner: cfg.owner = []
    if opts.owner and opts.owner not in cfg.owner: cfg.owner.append(opts.owner)
    if not cfg.owner: raise NoOwnerSet("try using the -o option or run jsb-init and edit %s" % cfg.cfile)
    if opts.nick: cfg.nick = opts.nick
    else: cfg.nick = cfg.nick or "jsb"
    if opts.channel:
        if not opts.channel in cfg.channels: cfg.channels.append(opts.channel)
    else: cfg.channels = cfg.channels or []
    return cfg
예제 #2
0
파일: opts.py 프로젝트: code2u/jsb
def makesxmppconfig(opts=None, botname=None):
    """ make config file based on options. """
    if not opts: botname = botname or "default-sxmpp"
    else:
        if not botname: botname = opts.name or "default-sxmpp"
    botname = stripname(botname)
    cfg = Config('fleet' + os.sep + botname + os.sep + 'config')
    cfg.type = "sxmpp"
    cfg.name = botname
    if not opts:
        cfg.user = cfg.user or ""
        cfg.host = cfg.host or ""
        cfg.password =  cfg.passord or ""
        cfg.server = cfg.server or ""
        cfg.owner = cfg.owner or []
        cfg.loglevel = cfg.lowlevel or "warn" 
        cfg.nick = cfg.nick or "jsb"
        cfg.channels = []
        return cfg        
    if not cfg.disable: cfg.disable = False
    if not cfg.channels: cfg.channels = []
    if opts.user: cfg.user = opts.user
    else: cfg.user = cfg.user or "*****@*****.**" % cfg.uuid
    if opts.user:
        try: cfg.host = opts.user.split('@')[1]
        except (IndexError, ValueError): print "user is not in the nick@server format"
    if not cfg.host:
        try: cfg.host = cfg.user.split('@')[1]
        except (IndexError, ValueError): print "user is not in the nick@server format"
    if opts.password: cfg.password = opts.password
    if opts.server: cfg.server = opts.server
    else: cfg.server = cfg.server or ""
    if opts.name: cfg.jid = opts.name
    if not cfg.owner: cfg.owner = []
    if opts.owner and opts.owner not in cfg.owner: cfg.owner.append(opts.owner)
    if opts.nick: cfg.nick = opts.nick
    else: cfg.nick = cfg.nick or "jsb"
    if opts.channel:
        if not opts.channel in cfg.channels: cfg.channels.append(opts.channel)
    else: cfg.channels = cfg.channels or []
    return cfg
예제 #3
0
def makexmppconfig(type, opts=None, botname=None):
    """ make config file based on options. """
    if not opts: botname = botname or "default-sxmpp"
    else:
        if not botname: botname = opts.name or "default-sxmpp"
    botname = stripname(botname)
    cfg = Config('fleet' + os.sep + botname + os.sep + 'config')
    cfg.type = "sxmpp"
    cfg.botname = botname
    if not opts:
        cfg.user = ""
        cfg.host = ""
        cfg.password = ""
        cfg.server = ""
        cfg.jid = ""
        cfg.owner = []
        cfg.loglevel = "warn"
        return cfg
    if opts.user: cfg.user = opts.user
    else: cfg.user = cfg.user or "*****@*****.**" % cfg.uuid
    if opts.user:
        try:
            cfg.host = opts.user.split('@')[1]
        except ValueError:
            print "user is not in the nick@server format"
    if not cfg.host:
        try:
            cfg.host = cfg.user.split('@')[1]
        except ValueError:
            print "user is not in the nick@server format"
    if opts.password: cfg.password = opts.password
    if opts.server: cfg.server = opts.server
    else: cfg.server = cfg.server or "localhost"
    if opts.name: cfg.jid = opts.name
    if not cfg.owner: cfg.owner = []
    if opts.owner and opts.owner not in cfg.owner: cfg.owner.append(opts.owner)
    return cfg
예제 #4
0
def makesxmppconfig(opts=None, botname=None, type="sxmpp"):
    """ make config file based on options. """
    if not opts: botname = botname or "default-%s" % type
    else:
        if not botname: botname = opts.name or "default-%s" % type
    botname = stripname(botname)
    from jsb.lib.config import Config, makedefaultconfig
    cfg = Config('fleet' + os.sep + botname + os.sep + 'config')
    cfg.type = type
    cfg.name = botname
    if not opts:
        cfg.user = cfg.user or ""
        cfg.host = cfg.host or ""
        cfg.password = cfg.password or ""
        cfg.server = cfg.server or ""
        cfg.owner = cfg.owner or []
        cfg.loglevel = cfg.lowlevel or "warn"
        cfg.nick = cfg.nick or "jsb"
        cfg.channels = []
        cfg.openfire = False
        return cfg
    if opts.openfire:
        cfg.openfire = True
        logging.warn("openfire mode is enabled")
    else:
        cfg.openfire = False
        logging.warn("openfire mode is disabled")
    if opts.doregister:
        cfg.doregister = True
        logging.warn("register mode is enabled")
    else:
        cfg.doregister = False
        logging.warn("register mode is disabled")
    if opts.enable:
        cfg.disable = 0
        logging.warn("enabling %s bot in %s" % (botname, cfg.cfile))
    if not cfg.channels: cfg.channels = []
    if opts.user: cfg.user = opts.user
    if not cfg.user:
        raise NoUserProvided(
            "user is not provided .. try giving the -u option to the bot (and maybe -p as well) or run jsb-init and edit %s"
            % cfg.cfile)
    if opts.user:
        try:
            cfg.host = opts.user.split('@')[1]
        except (IndexError, ValueError):
            print "user is not in the nick@server format"
    if not cfg.host:
        try:
            cfg.host = cfg.user.split('@')[1]
        except (IndexError, ValueError):
            print "user is not in the nick@server format"
    if opts.password: cfg.password = opts.password
    if opts.server: cfg.server = opts.server
    else: cfg.server = cfg.server or ""
    if opts.name: cfg.jid = opts.name
    if not cfg.owner: cfg.owner = []
    if opts.owner and opts.owner not in cfg.owner: cfg.owner.append(opts.owner)
    if not cfg.owner:
        raise NoOwnerSet(
            "try using the -o option or run jsb-init and edit %s" % cfg.cfile)
    if opts.nick: cfg.nick = opts.nick
    else: cfg.nick = cfg.nick or "jsb"
    if opts.channel:
        if not opts.channel in cfg.channels: cfg.channels.append(opts.channel)
    else: cfg.channels = cfg.channels or []
    return cfg