Exemplo n.º 1
0
 def start_game(self, chat_id, source_type, name, id=None):
     if chat_id in self.sessions:
         raise GameException(lang.msg('game_already_started'))
     song_names = self._get_song_names(source_type, name, id)
     if len(song_names) == 0:
         raise GameException(lang.msg('404_tracks', name))
     self.sessions[chat_id] = GameSession(chat_id, song_names)
Exemplo n.º 2
0
    def present(self, resource, command, bot):
        offset = int(command.get_var("offset", 0))
        kb_items = [self.build_button(item) for item in resource[1]]

        # TODO inefficient af
        next_cmd = utils.build_cmd(
            self.get_command(), {
                'p': command.get_var("p"),
                'offset': int(command.get_var("offset", 0)) + ITEMS_PER_PAGE,
                'rep': 1
            })
        prev_cmd = utils.build_cmd(
            self.get_command(), {
                'p': command.get_var("p"),
                'offset': int(command.get_var("offset", 0)) - ITEMS_PER_PAGE,
                'rep': 1
            })
        if offset >= ITEMS_PER_PAGE:
            kb_items = [[{
                "text": lang.msg('previous_page'),
                "callback_data": prev_cmd
            }]] + kb_items
        if offset + ITEMS_PER_PAGE < resource[0]:
            kb_items.append([{
                "text": lang.msg('next_page'),
                "callback_data": next_cmd
            }])

        command.msg(lang.msg('list_items',
                             floor(offset / ITEMS_PER_PAGE) + 1,
                             ceil(resource[0] / ITEMS_PER_PAGE)),
                    reply_markup=utils.build_keyboard(kb_items))
Exemplo n.º 3
0
 def _keyboard_buttons(self, data):
     return [{
         "text": lang.msg('view_tracks'),
         "callback_data": utils.build_cmd('track', {'p': data['id']})
     }, {
         "text":
         lang.msg('start_game_with'),
         "callback_data":
         utils.build_cmd('game', {'i': data['id']}, ['album'])
     }] + super()._keyboard_buttons(data)
Exemplo n.º 4
0
    def do_logic(self):
        if self.session is None: return self.msg(lang.msg('game_not_exists'))

        ret = [
            lang.msg(
                'game_stat',
                self.handler.bot.getChatMember(self.message.chat_id,
                                               user_id)['user']['first_name'],
                score) for user_id, score in self.session.scores.items()
        ]
        self.msg('*Stats*\n' + '\n'.join(ret))
Exemplo n.º 5
0
 def do_logic(self):
     source_type = list(
         filter(lambda x: x in ['artist', 'album', 'track'], self.args))
     if len(source_type) == 0: return self.msg(lang.msg('no_source'))
     name = ' '.join(
         list(
             filter(lambda x: x not in ['artist', 'album', 'track'],
                    self.args)))
     self.game.start_game(self.message.chat_id, source_type[0], name,
                          self.get_var('i'))
     self.msg(lang.msg('game_started'))
     (NextLineCommand(self.handler, self.message)).execute()
Exemplo n.º 6
0
 def do_logic(self):
     if self.session is None: return self.msg(lang.msg('game_not_exists'))
     line = self.session.get_current_line()
     score = self.session.add_guess(self.message.sender_id,
                                    ' '.join(self.args))
     if score > 0:
         self.msg(
             lang.msg('game_guess_right', self.message.sender_name, score,
                      line))
     else:
         self.msg(
             lang.msg('game_guess_wrong', self.message.sender_name,
                      ' '.join(self.args), line))
     (NextLineCommand(self.handler, self.message)).execute()
Exemplo n.º 7
0
 def randomize_song(self):
     if len(self.song_names) == 0:
         raise GameException(lang.msg('source_empty'))
     self.current_song = random.choice(self.song_names)
     if self.lyrics is None or len(self.lyrics) == 0:
         self.song_names.remove(self.current_song)
         self.randomize_song()
Exemplo n.º 8
0
    def present(self, resource, command, bot):
        if len(resource['images']) > 0:
            bot.sendPhoto(command.spotify.pick_photo(resource['images']))
        genres = ', '.join(resource['genres'])
        message = lang.msg('artist', resource['name'],
                           resource['followers']['total'], genres)

        command.msg(message, reply_markup=command.build_keyboard(resource))
Exemplo n.º 9
0
    def present(self, resource, command, bot):
        if len(resource['images']) > 0:
            bot.sendPhoto(command.spotify.pick_photo(resource['images']))
        genres = ', '.join(resource['genres'])
        artists = ', '.join([artist['name'] for artist in resource['artists']])
        message = lang.msg('album', resource['name'], resource['release_date'],
                           artists, genres, len(resource['tracks']))

        command.msg(message, reply_markup=command.build_keyboard(resource))
Exemplo n.º 10
0
    def present(self, resource, command, bot):
        artists = ', '.join([artist['name'] for artist in resource['artists']])
        message = lang.msg('track', resource['name'], artists,
                           resource['duration_ms'] / 60000)

        command.msg(message, reply_markup=command.build_keyboard(resource))
        if 'preview_url' in resource:
            bot.sendAudio(resource['preview_url'],
                          caption='Preview',
                          duration=30,
                          title=resource['name'],
                          performer=artists)
Exemplo n.º 11
0
 def action(self):
     self.render_resource(
         self.spotify.find_track(' '.join(self.args),
                                 self._get_id()), TrackPresenter,
         lang.msg('404_called', 'track', ' '.join(self.args)))
Exemplo n.º 12
0
 def parent_action(self, id):
     self.render_resource(
         self.spotify.album_tracks(id,
                                   limit=ITEMS_PER_PAGE,
                                   offset=self.get_var('offset', 0)),
         TracksPresenter, lang.msg('404'))
Exemplo n.º 13
0
 def do_logic(self):
     if self.session is None: return self.msg(lang.msg('game_not_exists'))
     self.session.randomize_line()
     lines = self.session.get_guess_lines()
     self.msg(lang.msg('game_quess', '\n'.join(lines)),
              reply_markup=self.build_keyboard(None))
Exemplo n.º 14
0
 def do_logic(self):
     if self.session is None: return self.msg(lang.msg('game_not_exists'))
     (StatsGameCommand(self.handler, self.message)).execute()
     self.game.stop_game(self.message.chat_id)
     self.msg(lang.msg('game_stopped'))
Exemplo n.º 15
0
 def action(self):
     self.render_resource(
         self.spotify.find_album(' '.join(self.args),
                                 self._get_id()), AlbumPresenter,
         lang.msg('404_called', 'album', ' '.join(self.args)))
Exemplo n.º 16
0
 def lmsg(self, typ, template, *params):
  self.msg(typ, lang.msg(template, params, lang.getLang(self.jid)))
Exemplo n.º 17
0
 def get_msg(self, template, params=()):
  return lang.msg(template, params, self.get_lang())
Exemplo n.º 18
0
 def msg(self, typ, body):
  if len(body)>8000: body = body[:8000]+'...'
  if (typ=='groupchat') and self.room and (len(body)>self.room.get_msglimit()):
   self.bot.muc.msg(typ, self.jid, lang.msg('see_private', l=lang.getLang(self.jid)))
   typ = 'chat'
  self.bot.muc.msg(typ, self.jid, body)
Exemplo n.º 19
0
 def lmsg(self, template, *params):
  self.msg(lang.msg(template, params, lang.getLang(self.jid)))
Exemplo n.º 20
0
 def get_msg(self, template, params=()):
     return lang.msg(template, params, self.get_lang())
Exemplo n.º 21
0
 def _keyboard_buttons(self, data):
     return [{
         "text": lang.msg('open_spotify'),
         "url": data['external_urls']['spotify']
     }]