Storycraft: add command to show the assignee the line to reply to.

apparently at 3 AM i forgot to implement important features, because
this is pretty critical to the game actually being playable. let
the assignee, if the game is still open, get the text of the line
they are to reply to.

also display it, rather than the add line command, where appropriate.
This commit is contained in:
Brian S. Stephan 2011-01-09 10:41:57 -06:00
parent 8c1d98cb74
commit fd22cb64d4
1 changed files with 47 additions and 1 deletions

View File

@ -77,6 +77,7 @@ class Storycraft(Module):
joingamepattern = rootcommand + '\s+join\s+game\s+(\d+)$'
listgamespattern = rootcommand + '\s+list\s+games\s+(open|in\s+progress)$'
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+(.*)$'
self.statusre = re.compile(statuspattern)
@ -84,6 +85,7 @@ class Storycraft(Module):
self.joingamere = re.compile(joingamepattern)
self.listgamesre = re.compile(listgamespattern)
self.startgamere = re.compile(startgamepattern)
self.showlinere = re.compile(showlinepattern)
self.addlinere = re.compile(addlinepattern)
def db_init(self):
@ -166,6 +168,8 @@ class Storycraft(Module):
return self.storycraft_listgames(connection, event, nick, userhost, what, admin_unlocked)
elif self.startgamere.search(what):
return self.storycraft_startgame(connection, event, nick, userhost, what, admin_unlocked)
elif self.showlinere.search(what):
return self.storycraft_showline(connection, event, nick, userhost, what, admin_unlocked)
elif self.addlinere.search(what):
return self.storycraft_addline(connection, event, nick, userhost, what, admin_unlocked)
@ -327,7 +331,7 @@ class Storycraft(Module):
master_channel = settings.master_channel
# tell the control channel
self.irc.reply(connection, master_channel, '{0:s} started storycraft #{1:d}! - first player is {2:s}, do \'!storycraft game {1:d} add line YOURTEXT\' when it\'s your turn to reply!'.format(nick, game_id, player.nick))
self.irc.reply(connection, master_channel, '{0:s} started storycraft #{1:d}! - first player is {2:s}, do \'!storycraft game {1:d} show line\' when the game is assigned to you.'.format(nick, game_id, player.nick))
return 'Game #{0:d} started.'.format(game_id)
else:
@ -341,6 +345,48 @@ class Storycraft(Module):
else:
return 'Game #{0:d} does not exist.'.format(game_id)
def storycraft_showline(self, connection, event, nick, userhost, what, admin_unlocked):
"""List the line to continue with, if queryer is the assignee."""
match = self.showlinere.search(what)
if match:
game_id = int(match.group(1))
# retrieve the game
game = self._get_game_details(game_id)
if game:
# check that the game is in progress
if 'IN PROGRESS' == game.status:
# get the most recent line
lines = self._get_lines_for_game(game_id)
if lines:
line = lines[0]
# check that the line is a prompt for input
if line.line == '':
player = self._get_player_by_id(line.player_id)
# check that the caller is the person the line is assigned to
if player.userhost == userhost:
# check previous line
if len(lines) > 1:
# get previous line and display it
repline = lines[1]
return 'The current line is \'{0:s}\'. Continue the story with \'!storycraft game {1:d} add line YOUR TEXT\'.'.format(repline.line, game_id)
else:
# player is starting the story
return 'You are starting the story! Add the first line with \'!storycraft game {0:d} add line YOUR TEXT\'.'.format(game_id)
else:
return 'You are not the assignee of the current game.'
else:
return 'Game is in progress but the most recent line is not available - internal consistency error.'
else:
return 'Game #{0:d} has no lines - internal consistency error.'.format(game_id)
else:
return 'Game #{0:d} has not been started.'.format(game_id)
else:
return 'Game #{0:d} does not exist.'.format(game_id)
def storycraft_addline(self, connection, event, nick, userhost, what, admin_unlocked):
"""Add a line to an in progress game."""