Example #1
0
def main():
    with open('./config.json') as f:
        conf = json.loads(f.read())
        irc_host = conf['irc_host']
        irc_port = conf['irc_port']
        irc_chans = conf['irc_channels']
        irc_nick = conf['irc_nick']
        tee_server = conf['tee_server']
        tee_alias = conf['tee_alias']
        tee_port = conf['tee_port']

    bot = ircbot(irc_host, irc_port, irc_nick)
    srv = teeserver(tee_server, tee_port, tee_alias)

    for chan in irc_chans:
        bot.join_chan(chan)

    while (True):
        try:
            man, chan, msg = bot.recv_msg()
            if msg and msg.startswith('.tee'):
                print('[teebot]', 'recv command `.tee`')

                if not srv.update():
                    bot.send_msg(chan,
                                 man + ': ' + 'failed to update server info')
                    continue

                reply = ''
                msg = [x for x in msg.split(' ') if x]

                if msg[1:]:
                    if msg[1] == 'server':
                        reply = server_info(srv)
                    if msg[1] == 'player' and msg[2:]:
                        reply = player_info(srv, msg[2])
                    if msg[1] == 'help':
                        reply = help()
                else:
                    reply = players_list(srv)

                if reply:
                    bot.send_msg(chan, man + ': ' + reply)
        except KeyboardInterrupt:
            bot.stop()
            srv.stop()
            print('[teebot]', 'exit')
            exit(0)
Example #2
0
def main():
    with open("./config.json") as f:
        conf = json.loads(f.read())
        port = conf["port"]
        irc_host = conf["irc_host"]
        irc_port = conf["irc_port"]
        irc_chan = conf["irc_channel"]
        irc_nick = conf["irc_nick"]

    bot = ircbot(irc_host, irc_port, irc_nick)
    srv = server(port)

    bot.join_chan(irc_chan)

    bot.start(srv.get_list)
    srv.start(bot.send_msg)
Example #3
0
def main():
    with open('./config.json') as f:
        conf = json.loads(f.read())
        irc_host = conf['irc_host']
        irc_port = conf['irc_port']
        irc_chans = conf['irc_channels']
        irc_nick = conf['irc_nick']
        tee_server = conf['tee_server']
        tee_alias = conf['tee_alias']
        tee_port = conf['tee_port']

    bot = ircbot(irc_host, irc_port, irc_nick)
    srv = teeserver(tee_server, tee_port, tee_alias)

    for chan in irc_chans:
        bot.join_chan(chan)

    while (True):
        try:
            man, chan, msg = bot.recv_msg()
            if msg and msg.startswith('.tee'):
                print('[teebot]', 'recv command `.tee`')

                if not srv.update():
                    bot.send_msg(chan, man + ': ' + 'failed to update server info')
                    continue

                reply = ''
                msg = [ x for x in msg.split(' ') if x]

                if msg[1:]:
                    if msg[1] == 'server':
                        reply = server_info(srv)
                    if msg[1] == 'player' and msg[2:]:
                        reply = player_info(srv, msg[2])
                    if msg[1] == 'help':
                        reply = help()
                else:
                    reply = players_list(srv)

                if reply:
                    bot.send_msg(chan, man + ': ' + reply)
        except KeyboardInterrupt:
            bot.stop()
            srv.stop()
            print('[teebot]', 'exit')
            exit(0)
Example #4
0
def main():
    global f

    os.environ['TZ'] = 'Asia/Shanghai'
    tzset()
    print('[logbot]', 'start logging:', strftime('%Y-%m-%d %H:%M:%S'))

    cd(repo)
    f = open(strftime('%Y-%m-%d.log'), 'a')

    bot = ircbot(host, port, nick)
    bot.join_chan(chan)

    try:
        while True:
            rmsg = bot.recv_msg()
            if rmsg == (None, None, None):
                continue
            if rmsg[1] in ['PART', 'JOIN']:
                man, act, ch = rmsg
                line = '[{0}] -- {1} {2} {3}\n'.format(strftime('%H:%M:%S'), man, act, chan)
            elif rmsg[1] ==  'QUIT':
                man, act, ch = rmsg
                line = '[{0}] -- {1} {2}\n'.format(strftime('%H:%M:%S'), man, act)
            else:
                man, ch, msg = rmsg
                if ch != chan:
                    continue
                line = '[{0}] {1}: {3}\n'.format(strftime('%H:%M:%S'), man, ch, msg)
            log(line)
            
    except KeyboardInterrupt:
        bot.stop()
        f.close()
        print('[logbot]', 'exit')
        exit(0)
Example #5
0
def main():
    bot = ircbot.ircbot()
    bot.run()