Storycraft: list games waiting for me.
shows games in progress where the current line is assigned to the queryer, and games open (waiting for registrations) that the queryer started
This commit is contained in:
parent
26a510ff40
commit
b133b37d61
@ -75,7 +75,7 @@ class Storycraft(Module):
|
||||
statuspattern = rootcommand + '\s+status(\s+(\d+)$|$)'
|
||||
newgamepattern = rootcommand + '\s+new\s+game(\s+with\s+config\s+(.*)$|$)'
|
||||
joingamepattern = rootcommand + '\s+join\s+game\s+(\d+)$'
|
||||
listgamespattern = rootcommand + '\s+list\s+games\s+(open|in progress|completed|my games)$'
|
||||
listgamespattern = rootcommand + '\s+list\s+games\s+(open|in progress|completed|my games|waiting for me)$'
|
||||
startgamepattern = rootcommand + '\s+start\s+game\s+(\d+)$'
|
||||
showlinepattern = rootcommand + '\s+game\s+(\d+)\s+show\s+line$'
|
||||
addlinepattern = rootcommand + '\s+game\s+(\d+)\s+add\s+line\s+(.*)$'
|
||||
@ -301,6 +301,8 @@ class Storycraft(Module):
|
||||
games = self._get_completed_games()
|
||||
elif category == 'my games':
|
||||
games = self._get_active_games_with_player(nick)
|
||||
elif category == 'waiting for me':
|
||||
games = self._get_games_waiting_on_player(nick)
|
||||
|
||||
if len(games) > 5:
|
||||
# just list the game ids
|
||||
@ -757,6 +759,56 @@ class Storycraft(Module):
|
||||
print('sqlite error: ' + str(e))
|
||||
raise
|
||||
|
||||
def _get_games_waiting_on_player(self, player_nick):
|
||||
"""Return the games where the player nick is the owner of a pending line.
|
||||
|
||||
Include the games that the player started and are open, since they're waiting
|
||||
on the person too.
|
||||
"""
|
||||
|
||||
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
|
||||
INNER JOIN storycraft_line line ON line.player_id = player.id
|
||||
WHERE player.nick = ? AND game.status = 'IN PROGRESS' AND line.line = ''
|
||||
UNION
|
||||
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
|
||||
WHERE game.owner_nick = ? AND game.status = 'OPEN'
|
||||
'''
|
||||
cursor = db.execute(query, (player_nick, player_nick))
|
||||
results = cursor.fetchall()
|
||||
for result in results:
|
||||
game = self.StorycraftGame()
|
||||
|
||||
game.id = int(result['game.id'])
|
||||
game.round_mode = int(result['game.round_mode'])
|
||||
game.game_length = int(result['game.game_length'])
|
||||
game.line_length = int(result['game.line_length'])
|
||||
game.random_method = int(result['game.random_method'])
|
||||
game.lines_per_turn = int(result['game.lines_per_turn'])
|
||||
game.status = result['game.status']
|
||||
game.owner_nick = result['game.owner_nick']
|
||||
game.owner_userhost = result['game.owner_userhost']
|
||||
game.start_time = result['game.start_time']
|
||||
game.end_time = result['game.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):
|
||||
"""Return the games of the specified type."""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user