Storycraft: add 'list games my games', which is the open/in progress games the queryer is in
This commit is contained in:
parent
ce7d9e8010
commit
26a510ff40
@ -75,7 +75,7 @@ class Storycraft(Module):
|
|||||||
statuspattern = rootcommand + '\s+status(\s+(\d+)$|$)'
|
statuspattern = rootcommand + '\s+status(\s+(\d+)$|$)'
|
||||||
newgamepattern = rootcommand + '\s+new\s+game(\s+with\s+config\s+(.*)$|$)'
|
newgamepattern = rootcommand + '\s+new\s+game(\s+with\s+config\s+(.*)$|$)'
|
||||||
joingamepattern = rootcommand + '\s+join\s+game\s+(\d+)$'
|
joingamepattern = rootcommand + '\s+join\s+game\s+(\d+)$'
|
||||||
listgamespattern = rootcommand + '\s+list\s+games\s+(open|in\s+progress|completed)$'
|
listgamespattern = rootcommand + '\s+list\s+games\s+(open|in progress|completed|my games)$'
|
||||||
startgamepattern = rootcommand + '\s+start\s+game\s+(\d+)$'
|
startgamepattern = rootcommand + '\s+start\s+game\s+(\d+)$'
|
||||||
showlinepattern = rootcommand + '\s+game\s+(\d+)\s+show\s+line$'
|
showlinepattern = rootcommand + '\s+game\s+(\d+)\s+show\s+line$'
|
||||||
addlinepattern = rootcommand + '\s+game\s+(\d+)\s+add\s+line\s+(.*)$'
|
addlinepattern = rootcommand + '\s+game\s+(\d+)\s+add\s+line\s+(.*)$'
|
||||||
@ -299,6 +299,8 @@ class Storycraft(Module):
|
|||||||
games = self._get_in_progress_games()
|
games = self._get_in_progress_games()
|
||||||
elif category == 'completed':
|
elif category == 'completed':
|
||||||
games = self._get_completed_games()
|
games = self._get_completed_games()
|
||||||
|
elif category == 'my games':
|
||||||
|
games = self._get_active_games_with_player(nick)
|
||||||
|
|
||||||
if len(games) > 5:
|
if len(games) > 5:
|
||||||
# just list the game ids
|
# just list the game ids
|
||||||
@ -716,6 +718,45 @@ class Storycraft(Module):
|
|||||||
|
|
||||||
return self._get_games_of_type('OPEN')
|
return self._get_games_of_type('OPEN')
|
||||||
|
|
||||||
|
def _get_active_games_with_player(self, player_nick):
|
||||||
|
"""Return the in progress/open games that include the player nick."""
|
||||||
|
|
||||||
|
games = []
|
||||||
|
try:
|
||||||
|
# get the games of specified type and populate a list
|
||||||
|
db = self.get_db()
|
||||||
|
query = '''
|
||||||
|
SELECT game.id, game.round_mode, game.game_length, game.line_length,
|
||||||
|
game.random_method, game.lines_per_turn, game.status, game.owner_nick,
|
||||||
|
game.owner_userhost, game.start_time, game.end_time
|
||||||
|
FROM storycraft_game game
|
||||||
|
INNER JOIN storycraft_player player ON player.game_id = game.id
|
||||||
|
WHERE player.nick = ? AND (game.status = 'OPEN' OR game.status = 'IN PROGRESS')
|
||||||
|
'''
|
||||||
|
cursor = db.execute(query, (player_nick,))
|
||||||
|
results = cursor.fetchall()
|
||||||
|
for result in results:
|
||||||
|
game = self.StorycraftGame()
|
||||||
|
|
||||||
|
game.id = int(result['id'])
|
||||||
|
game.round_mode = int(result['round_mode'])
|
||||||
|
game.game_length = int(result['game_length'])
|
||||||
|
game.line_length = int(result['line_length'])
|
||||||
|
game.random_method = int(result['random_method'])
|
||||||
|
game.lines_per_turn = int(result['lines_per_turn'])
|
||||||
|
game.status = result['status']
|
||||||
|
game.owner_nick = result['owner_nick']
|
||||||
|
game.owner_userhost = result['owner_userhost']
|
||||||
|
game.start_time = result['start_time']
|
||||||
|
game.end_time = result['end_time']
|
||||||
|
|
||||||
|
games.append(game)
|
||||||
|
|
||||||
|
return games
|
||||||
|
except sqlite3.Error as e:
|
||||||
|
print('sqlite error: ' + str(e))
|
||||||
|
raise
|
||||||
|
|
||||||
def _get_games_of_type(self, game_type):
|
def _get_games_of_type(self, game_type):
|
||||||
"""Return the games of the specified type."""
|
"""Return the games of the specified type."""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user