Exemplo n.º 1
0
def delete_unused_channels(echo, tl=30):
    todel = []
    for chan in bot.channels:
        l = chan.stats.lastgame()
        if l:
            lasttime = int(l[1])
        else:
            lasttime = int(chan.cfg["FIRST_INIT"])
        tl = tl * 60 * 60 * 24
        if int(time.time()) - lasttime > tl:
            if echo:
                display("{0} ({1})| {2} - Unused for {3}".format(
                    chan.name, chan.id, chan.stats.stats(),
                    datetime.timedelta(seconds=time.time() - lasttime)))
            else:
                todel.append(chan.id)
    for chanid in todel:
        config.delete_channel(chanid)
Exemplo n.º 2
0
def run():
    try:
        cmd = userinput_queue.get(False)
        display("CONSOLE| /" + cmd)
        try:
            l = cmd.split(" ", 1)
            if l[0] == "help":
                display("CONSOLE| " + help)
            elif l[0] == "notice":
                for i in bot.channels:
                    client.notice(i.channel, l[1])
            elif l[0] == "say":
                channel, text = l[1].split("#", 1)
                for i in bot.channels:
                    if i.name == channel:
                        client.notice(i.channel, text)
                        return
            elif l[0] == "disable_pickups":
                channel = rstrip("#")
                for i in bot.channels:
                    if i.name == channel:
                        config.delete_channel(i.channel)
            elif l[0] == "status":
                display(
                    "CONSOLE| Total pickup channels: {0}. {1} messages to send waiting in queue."
                    .format(len(bot.channels), len(client.send_queue)))
            elif l[0] == "pickups":
                channels = []
                for c in bot.channels:
                    pickups = []
                    for p in c.pickups:
                        if p.players != []:
                            pickups.append('[{0} ({1}/{2})]'.format(
                                p.name, len(p.players), p.cfg["maxplayers"]))
                    if pickups != []:
                        channels.append("{0} {1}".format(
                            c.name, " ".join(pickups)))
                display("All pickups: {0}".format(" | ".join(channels)))
            elif l[0] == "stats":
                for c in bot.channels:
                    display("STATS| {0}: {1}".format(c.name,
                                                     stats3.stats(c.id)))
            elif l[0] == "channels":
                display("CONSOLE| Pickup channels: {0}".format(" | ".join(
                    [i.name for i in bot.channels])))
            elif l[0] == "exec":
                exec(l[1])
            elif l[0] == "reset_players":
                comment = False
                if len(l) > 1:
                    comment = l[1]
                for i in bot.channels:
                    i.reset_players(comment=comment)
            elif l[0] == "delete_unused_channels":
                if len(l) > 1:
                    delete_unused_channels(False, int(l[1]))
                else:
                    delete_unused_channels(False)
            elif l[0] == "echo_unused_channels":
                if len(l) > 1:
                    delete_unused_channels(True, int(l[1]))
                else:
                    delete_unused_channels(True)
            elif l[0] == "echo_empty_servers":
                client.get_empty_servers()
            elif l[0] == "leave_server":
                client.send_queue.append(['leave_server', l[1]])
            elif l[0] == "quit":
                terminate()
        except Exception as e:
            display("CONSOLE| ERROR: " + str(e))
    except:
        pass