Пример #1
0
 def xur(self, extra):
   attachments = self.destiny_api.get_xur_inventory()
   if not attachments:
     return slack.response('Xûr is gone, for now...')
   return slack.response('Xûr\'s Inventory', {
     'attachments': attachments
   })
Пример #2
0
    def online_players(self, extra):
        last_played_chars = []
        threads = []

        def get_last_played(name, player_id):
            account_summary = self.destiny_api.get_account_summary(player_id)
            last_played_chars.append((name, self.destiny_api.get_last_played_character(account_summary)))

        for name, player_id in players.PLAYER_IDS.items():
            t = threading.Thread(target=get_last_played, args=(name, player_id))
            t.start()
            threads.append(t)
        for thread in threads:
            thread.join()
        online_chars = []
        for name, last_played_char in last_played_chars:
            last_played_date = datetime.datetime.strptime(last_played_char["dateLastPlayed"], "%Y-%m-%dT%H:%M:%SZ")
            now = datetime.datetime.utcnow()
            if now - last_played_date < datetime.timedelta(minutes=15):
                online_chars.append((name, last_played_char))
        # Sort by name
        online_chars.sort(key=lambda x: x[0])
        online_count = len(online_chars)
        if online_count == 0:
            return slack.response("No players online.")
        message = "Players online:\n"
        for name, character in online_chars:
            activity = self.destiny_api.get_activity_name(character["currentActivityHash"])
            message += "%s - %s\n" % (name, activity)
        return slack.response(message)
Пример #3
0
 def daily(self, extra):
     daily = self.destiny_api.get_daily_story()
     name = daily["activityName"]
     message = "Daily Heroic Story: %s" % name
     exotic = self.destiny_api.related_exotic(daily)
     if exotic:
         message += "\nExotic quest for:"
         attachments = [self.destiny_api.get_item_attachment(exotic)]
         return slack.response(message, {"attachments": attachments})
     return slack.response(message)
Пример #4
0
 def item_search(self, extra, category=None):
     query = extra
     results = []
     if category:
         results = self.destiny_api.search_item(query, category)
     else:
         results = self.destiny_api.search_item(query)
     if len(results) < 1:
         return slack.response('No results found for "%s"' % query)
     item_data = results[0]
     attachment = self.destiny_api.get_item_attachment(item_data)
     return slack.response(None, {"attachments": [attachment]})
Пример #5
0
 def render(self, extra):
     try:
         response = json.loads(extra)
         return slack.ephemeral(response)
     except ValueError:
         logging.warning("Invalid message:\n%s", extra)
         return slack.ephemeral(slack.response("Invalid message."))
Пример #6
0
 def nbascore(self, extra):
   tokens = extra.split()
   team_code = tokens[0].upper()
   scores = None
   if len(tokens) >= 2:
     date = tokens[1]
     scores = nba.get_scores_for_team(nba.get_stats(date), team_code)
   else:
     today = datetime.date.today()
     yesterday = datetime.date.today() - datetime.timedelta(days=1)
     for date in (today, yesterday):
       scores = nba.get_scores_for_team(nba.get_stats(str(date)), team_code)
       if scores:
         break
   if not scores:
     return slack.ephemeral(slack.response(
         'No games found for %s on %s.' % (team_code, date)))
   return slack.response(None, nba.format_scores(scores))
Пример #7
0
 def show_help(self, extra):
     help_messages = []
     for command in COMMAND_LIST:
         help_message = "*" + command.name + ""
         if command.extra:
             help_message += " [" + command.extra + "]"
         help_message += "*: " + command.help_text
         if command.alt_names:
             help_message += " [" + ", ".join(command.alt_names) + "]"
         help_messages.append(help_message)
     return slack.response("\n".join(help_messages), {"response_type": "ephemeral"})
Пример #8
0
 def show_help(self, extra):
   help_messages = []
   for command in COMMAND_LIST:
     help_message = '*' + command.name + ''
     if command.extra:
       help_message += ' [' + command.extra + ']'
     help_message += '*: ' + command.help_text
     if command.alt_names:
       help_message += ' [' + ', '.join(command.alt_names) + ']'
     help_messages.append(help_message)
   return slack.response('\n'.join(help_messages), {
     'response_type': 'ephemeral'
   })
Пример #9
0
 def spoiler(self, extra):
   import models
   message = extra
   username = slack.get_request_username(self.request)
   channel = slack.get_request_channel(self.request)
   spoiler_uri = models.Spoiler.save(username=username, channel=channel,
                                     message=message)
   domain = self.request.host_url
   url = urlparse.urljoin(domain, spoiler_uri)
   logging.info(domain, spoiler_uri, url)
   return slack.response('Spoiler from @%s:' % username, {'attachments': [{
     'title': 'Show spoiler...',
     'title_link': url,
   }]})
Пример #10
0
def hello():
  message = phrases.get_random_phrase()
  return flask.jsonify(slack.response(message))
Пример #11
0
 def post(self):
     logging.info("request params: %s", self.request.params)
     full_command_text = slack.get_text(self.request)
     slack_response = slack.response(commands.run(full_command_text))
     self.response.headers["Content-Type"] = "application/json"
     self.response.write(json.dumps(slack_response))
Пример #12
0
 def speak(self, extra):
     message = phrases.get_random_phrase()
     return slack.response(message)
Пример #13
0
 def xur(self, extra):
     attachments = self.destiny_api.get_xur_inventory()
     if not attachments:
         return slack.response("Xûr is gone, for now...")
     return slack.response("Xûr's Inventory", {"attachments": attachments})