Storycraft: add storycraft_gamestatus in order to break out getting a game's status
this is primarily to use a consistent format - 'game X status' rather than 'status X'
This commit is contained in:
parent
de04fd0d85
commit
22b35bcb94
@ -73,13 +73,14 @@ class Storycraft(Module):
|
||||
Module.__init__(self, irc, config, server)
|
||||
|
||||
rootcommand = '^!storycraft'
|
||||
statuspattern = rootcommand + '\s+status(\s+(\d+)$|$)'
|
||||
statuspattern = rootcommand + '\s+status$'
|
||||
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|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+(.*)$'
|
||||
gamestatuspattern = rootcommand + '\s+game\s+(\d+)\s+status$'
|
||||
exportpattern = rootcommand + '\s+export\s+(\d+)$'
|
||||
|
||||
self.statusre = re.compile(statuspattern)
|
||||
@ -89,6 +90,7 @@ class Storycraft(Module):
|
||||
self.startgamere = re.compile(startgamepattern)
|
||||
self.showlinere = re.compile(showlinepattern)
|
||||
self.addlinere = re.compile(addlinepattern)
|
||||
self.gamestatusre = re.compile(gamestatuspattern)
|
||||
self.exportre = re.compile(exportpattern)
|
||||
|
||||
def db_init(self):
|
||||
@ -175,6 +177,8 @@ class Storycraft(Module):
|
||||
return self.reply(connection, event, self.storycraft_showline(connection, event, nick, userhost, what, admin_unlocked))
|
||||
elif self.addlinere.search(what):
|
||||
return self.reply(connection, event, self.storycraft_addline(connection, event, nick, userhost, what, admin_unlocked))
|
||||
elif self.gamestatusre.search(what):
|
||||
return self.reply(connection, event, self.storycraft_gamestatus(connection, event, nick, userhost, what, admin_unlocked))
|
||||
elif self.exportre.search(what):
|
||||
return self.reply(connection, event, self.storycraft_export(connection, event, nick, userhost, what, admin_unlocked))
|
||||
|
||||
@ -183,8 +187,21 @@ class Storycraft(Module):
|
||||
|
||||
match = self.statusre.search(what)
|
||||
if match:
|
||||
if match.group(2):
|
||||
game_id = int(match.group(2))
|
||||
# do the general status of all games
|
||||
count_completed = self._get_completed_game_count()
|
||||
count_in_progress = self._get_in_progress_game_count()
|
||||
count_open = self._get_open_game_count()
|
||||
count_free = self._get_free_game_count()
|
||||
|
||||
return 'Storycraft {0:s} - {1:d} games completed, {2:d} in progress, {3:d} open. {4:d} slots free.'.format(__version__, count_completed, count_in_progress, count_open, count_free)
|
||||
|
||||
def storycraft_gamestatus(self, connection, event, nick, userhost, what, admin_unlocked):
|
||||
"""Print information about one specific game."""
|
||||
|
||||
match = self.gamestatusre.search(what)
|
||||
if match:
|
||||
if match.group(1):
|
||||
game_id = int(match.group(1))
|
||||
|
||||
# do the status of one game
|
||||
game = self._get_game_details(game_id)
|
||||
@ -195,14 +212,6 @@ class Storycraft(Module):
|
||||
return status_str
|
||||
else:
|
||||
return 'Game #{0:d} does not exist.'.format(game_id)
|
||||
else:
|
||||
# do the general status of all games
|
||||
count_completed = self._get_completed_game_count()
|
||||
count_in_progress = self._get_in_progress_game_count()
|
||||
count_open = self._get_open_game_count()
|
||||
count_free = self._get_free_game_count()
|
||||
|
||||
return 'Storycraft {0:s} - {1:d} games completed, {2:d} in progress, {3:d} open. {4:d} slots free.'.format(__version__, count_completed, count_in_progress, count_open, count_free)
|
||||
|
||||
def storycraft_newgame(self, connection, event, nick, userhost, what, admin_unlocked):
|
||||
"""Add a game to the system, which users can join."""
|
||||
|
Loading…
Reference in New Issue
Block a user