def generate_markdown_report(self, loop_start): """ Separate from the others as this logs to a sidebar rather than a file """ s = self.session land_report = StatusCommand.lands_status_for(s, self.config) hq = self.reddit.get_subreddit(self.config.headquarters) cur = now() elapsed = (cur - loop_start) + self.config["bot"]["sleep"] version_str = version(self.config) bot_report = ("Bot Status:\n\n" "* Last run at %s\n\n" "* Seconds per Frame: %d\n\n" "* Version: %s") % ( timestr(cur), elapsed, version_str, ) report = "%s\n\n%s" % (land_report, bot_report) # This is apparently not immediately done, or there's some caching. # Keep an eye on it. hq.update_settings(description=report)
def execute(self, context): dest = Region.get_region(self.where, context) if dest: now = time.mktime(time.localtime()) begins = now + context.config["game"]["battle_delay"] battle = None if dest.capital is not None: invade = context.config['game']['capital_invasion'] if invade == 'none': context.reply("You cannot invade the enemy capital") return try: battle = dest.invade(context.player, begins) if "battle_lockout" in context.config["game"]: battle.lockout = context.config["game"]["battle_lockout"] context.session.commit() except db.RankException: context.reply("You don't have the authority " "to invade a region!") except db.TeamException: context.reply("You can't invade %s, you already own it!" % dest.markdown()) except db.NonAdjacentException: context.reply("%s is not next to any territory you control" % dest.markdown()) except db.InProgressException as ipe: context.reply("%s is %s being invaded!" % (dest.markdown(), ipe.other.markdown("already"))) except db.TimingException as te: context.reply(("%s is too fortified to be attacked. " "These fortifications will break down by %s") % (dest.markdown(), timestr(te.expected))) if battle: context.reply("**Confirmed** Battle will begin at %s" % battle.begins_str()) title = ("[Invasion] The %s armies march!" % context.team_name()) submitted = InvadeCommand.post_invasion(title, battle, context.reddit) if submitted: battle.submission_id = submitted.name context.session.commit() else: logging.warn("Couldn't submit invasion thread") context.session.rollback()
def execute(self, context): dest = Region.get_region(self.where, context) if dest: now = time.mktime(time.localtime()) begins = now + context.config["game"]["battle_delay"] battle = None if dest.capital is not None: invade = context.config['game']['capital_invasion'] if invade == 'none': context.reply("You cannot invade the enemy capital") return try: battle = dest.invade(context.player, begins) if "battle_lockout" in context.config["game"]: battle.lockout = context.config["game"]["battle_lockout"] context.session.commit() except db.RankException: context.reply("You don't have the authority " "to invade a region!") except db.TeamException: context.reply("You can't invade %s, you already own it!" % dest.markdown()) except db.NonAdjacentException: context.reply("%s is not next to any territory you control" % dest.markdown()) except db.InProgressException as ipe: context.reply("%s is %s being invaded!" % (dest.markdown(), ipe.other.markdown("already"))) except db.TimingException as te: context.reply(("%s is too fortified to be attacked. " "These fortifications will break down by %s") % (dest.markdown(), timestr(te.expected))) if battle: context.reply("**Confirmed** Battle will begin at %s" % battle.begins_str()) title = ("[Invasion] The %s armies march on %s!" % (context.team_name(), dest.name)) submitted = InvadeCommand.post_invasion(title, battle, context.reddit) if submitted: battle.submission_id = submitted.name context.session.commit() else: logging.warn("Couldn't submit invasion thread") context.session.rollback()
def generate_markdown_report(self, loop_start): """ Separate from the others as this logs to a sidebar rather than a file """ s = self.session land_report = StatusCommand.lands_status_for(s, self.config) hq = self.reddit.get_subreddit(self.config.headquarters) cur = now() elapsed = (cur - loop_start) + self.config["bot"]["sleep"] version_str = version(self.config) bot_report = ("Bot Status:\n\n" "* Last run at %s\n\n" "* Seconds per Frame: %d\n\n" "* Version: %s") % (timestr(cur), elapsed, version_str) report = "%s\n\n%s" % (land_report, bot_report) # This is apparently not immediately done, or there's some caching. # Keep an eye on it. hq.update_settings(description=report)
def timestr(self, secs=None): return utils.timestr(secs)
def execute(self, context): context.reply("The current time is: %s" % timestr())