示例#1
0
def cmd_sysrefresh(bot, trigger, db=None):
    """
    Refreshes the starsystem database if you have halfop or better.  Reports the last refresh time otherwise.

    -f: Force refresh even if data is stale.  Requires op.
    """
    access = ratlib.sopel.best_channel_mode(bot, trigger.nick)
    privileged = access & (HALFOP | OP)
    msg = ""

    if privileged:
        try:
            refreshed = refresh_database(
                bot,
                force=access & OP and trigger.group(2) and trigger.group(2) == '-f',
                callback=lambda: bot.say("Starting starsystem refresh...")
            )
            if refreshed:
                bot.say(refresh_time_stats(bot))
                return
            msg = "Not yet.  "
        except ConcurrentOperationError:
            bot.say("A starsystem refresh operation is already in progress.")
            return

    when = get_status(db).starsystem_refreshed
    if not when:
        msg += "The starsystem database appears to have never been initialized."
    else:
        when = when.astimezone(datetime.timezone.utc)
        msg += "The starsystem database was refreshed at {} ({}) or an update is still in progress. It is only allowed every {} seconds.".format(
            ratlib.format_timestamp(when), ratlib.format_timedelta(when), bot.config.ratbot.edsm_maxage or '<unknown>'
        )
    bot.say(msg)
示例#2
0
def cmd_version(bot, trigger):
    from ratlib import format_timedelta, format_timestamp
    started = bot.memory['ratbot']['stats']['started']
    bot.say(
        "Version {version}, up {delta} since {time}"
        .format(
            version=bot.memory['ratbot']['version'],
            delta=format_timedelta(datetime.datetime.now(tz=started.tzinfo) - started),
            time=format_timestamp(started)
        )
    )
示例#3
0
        def task():
            with timed() as t:
                db = ratlib.db.get_session(bot)
                stmt = sql.select([
                    sql.column('eddb_id'),
                    sql.column('distance'),
                    sql.column('remaining'),
                    sql.column('final'),
                ]).select_from(sql.func.find_route(source.eddb_id, target.eddb_id, maxdistance)).alias()
                query = (
                    db.query(Starsystem, stmt.c.distance, stmt.c.remaining, stmt.c.final)
                    .join(stmt, Starsystem.eddb_id == stmt.c.eddb_id)
                    .order_by(stmt.c.remaining.desc())
                )
                result = query.all()
                text = [banner, '']

                sysline_fmt = "{jump:5}: {sys.name:30}  ({sys.x:.2f}, {sys.y:.2f}, {sys.z:.2f})"
                travel_fmt = "       -> (jump {distance:.2f} LY; {remaining:.2f} LY remaining)"

                for jump, row in enumerate(result):
                    if not jump:
                        jump = "START"
                    else:
                        text.append(travel_fmt.format(distance=row.distance, remaining=row.remaining))
                        if row.final:
                            jump = "  END"
                    text.append(sysline_fmt.format(jump=jump, sys=row.Starsystem))
            success = result[-1].final
            elapsed = ratlib.format_timedelta(t.delta)
            text.append('')
            if success:
                text.append("Plot completed in {}.".format(elapsed))
            else:
                text.append("Could not complete plot.  Went {} jumps in {}.".format(len(result) - 1, elapsed))
            text = "\n".join(text) + "\n"
            url = post_to_hastebin(text, bot.config.ratbot.hastebin_url or "http://hastebin.com/") + ".txt"

            if success:
                return (
                    "Plot from {source.name} to {target.name} completed: {url}"
                    .format(source=source, target=target, url=url)
                )
            else:
                return (
                    "Plot from {source.name} to {target.name} failed, partial results at: {url}"
                    .format(source=source, target=target, url=url)
                )