コード例 #1
0
ファイル: opts.py プロジェクト: buzzworkers/tl
def makexmppconfig(opts=None, botname=None, type="xmpp"):
    """ 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 tl.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 "tl"
        cfg.channels = []
        cfg.openfire = False
        return cfg        
    if not cfg.disable: cfg.disable = False
    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("try giving the -u option to the bot (and maybe -p as well) or run tl-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 tl-init and edit %s" % cfg.cfile)
    if opts.nick: cfg.nick = opts.nick
    else: cfg.nick = cfg.nick or "tl"
    if opts.channel:
        if not opts.channel in cfg.channels: cfg.channels.append(opts.channel) 
    else: cfg.channels = cfg.channels or []
    if not cfg.server:
        try: cfg.server = cfg.user.split("@")[1] 
        except IndexError: pass
    cfg.save()
    return cfg
コード例 #2
0
ファイル: fleet.py プロジェクト: buzzworkers/tl
def fleet_add(bot, ievent):
    """ arguments: <name> <type> <server>|<botjid> <nick>|<jabberpasswd> [<ircpass>] - add a newly created bot to the fleet. """
    try: 
        name, type, server, nick, password = ievent.rest.split()
    except ValueError:
        try:
            name, type, server, nick = ievent.rest.split()
            password = ""
        except ValueError:
            ievent.missing("<name> <type> <server>|<botjid> <nick>|<jabberpass> [<ircpasswd>]") ; return
    type = type.lower()
    fleet = getfleet() 
    bot = fleet.byname(name)
    if bot: ievent.reply("%s bot already exists" % name) ; return
    cfg = Config('fleet' + os.sep + stripname(name) + os.sep + 'config')
    cfg.disable = 0
    if type == "irc":
        cfg.port = 6667
        cfg.server = server
        cfg.nick = nick
        cfg.password = password
    elif type in ["xmpp", "sxmpp"]:
        cfg.port = 4442
        cfg.host = server
        try: n, serv = cfg.host.split("@")
        except (ValueError, TypeError): pass
        cfg.server = serv
        cfg.password = nick
    cfg.save()
    bot = fleet.makebot(type, name, cfg)
    fleet.addbot(bot)
    if bot:
        ievent.reply('enabled and started %s bot - %s' % (name, cfg.filename))
        start_new_thread(bot.start, ())
    else: ievent.reply("can't make %s bot" % cfg.name)
コード例 #3
0
ファイル: opts.py プロジェクト: buzzworkers/tl
def makeircconfig(opts=None, botname=None):
    """ make config file based on options. """
    if not opts: botname = botname or "default-irc"
    else:
        if not botname: botname = opts.name or "default-irc"
    origname = botname
    botname = stripname(botname)
    logging.warn("botname is %s (%s)" % (origname, botname)) 
    from tl.lib.config import Config
    cfg = Config('fleet' + os.sep + botname + os.sep + 'config')
    cfg.type = 'irc'
    cfg.name = botname
    if not opts:
        cfg.password = cfg.password or ""
        cfg.ssl = cfg.ssl or False
        cfg.port = cfg.port or 6667
        cfg.server = cfg.server or "localhost"
        cfg.owner = cfg.owner or []
        cfg.ipv6 = cfg.ipv6 or False
        cfg.nick = cfg.nick or "tl"
        cfg.channels = []
        return cfg          
    if not cfg.channels: cfg.channels = []
    if not cfg.disable: cfg.disable = False
    if opts.enable: cfg.disable = False ; logging.warn("enabling %s bot in %s" % (botname, cfg.cfile))
    if opts.password: cfg.password = opts.password
    if opts.ipv6: cfg.ipv6 = True
    else: cfg.ipv6 = cfg.ipv6 or False
    if opts.ssl: cfg.ssl = True
    else: cfg.ssl = cfg.ssl or False
    if opts.nossl: cfg.ssl = False
    if opts.port: cfg.port = opts.port or cfg.port or 6667
    else: cfg.port = cfg.port or 6667
    if opts.server: cfg.server = opts.server
    else: cfg.server = cfg.server or "localhost"
    if not cfg.owner: cfg.owner = []
    if opts.owner and opts.owner not in cfg.owner: cfg.owner.append(opts.owner)
    if opts.ipv6: cfg.ipv6 = opts.ipv6
    if opts.nick: cfg.nick = opts.nick
    else: cfg.nick = cfg.nick or "tl"
    if opts.username: cfg.username = opts.username
    else: cfg.username = cfg.username or "tl"
    if opts.channel:
        if not opts.channel in cfg.channels: cfg.channels.append(opts.channel)
    else: cfg.channels = cfg.channels or []
    cfg.save()
    return cfg