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) |         Module.__init__(self, irc, config, server) | ||||||
| 
 | 
 | ||||||
|         rootcommand = '^!storycraft' |         rootcommand = '^!storycraft' | ||||||
|         statuspattern = rootcommand + '\s+status(\s+(\d+)$|$)' |         statuspattern = rootcommand + '\s+status$' | ||||||
|         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 progress|completed|my games|waiting for me)$' |         listgamespattern = rootcommand + '\s+list\s+games\s+(open|in progress|completed|my games|waiting for me)$' | ||||||
|         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+(.*)$' | ||||||
|  |         gamestatuspattern = rootcommand + '\s+game\s+(\d+)\s+status$' | ||||||
|         exportpattern = rootcommand + '\s+export\s+(\d+)$' |         exportpattern = rootcommand + '\s+export\s+(\d+)$' | ||||||
| 
 | 
 | ||||||
|         self.statusre = re.compile(statuspattern) |         self.statusre = re.compile(statuspattern) | ||||||
| @ -89,6 +90,7 @@ class Storycraft(Module): | |||||||
|         self.startgamere = re.compile(startgamepattern) |         self.startgamere = re.compile(startgamepattern) | ||||||
|         self.showlinere = re.compile(showlinepattern) |         self.showlinere = re.compile(showlinepattern) | ||||||
|         self.addlinere = re.compile(addlinepattern) |         self.addlinere = re.compile(addlinepattern) | ||||||
|  |         self.gamestatusre = re.compile(gamestatuspattern) | ||||||
|         self.exportre = re.compile(exportpattern) |         self.exportre = re.compile(exportpattern) | ||||||
| 
 | 
 | ||||||
|     def db_init(self): |     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)) |             return self.reply(connection, event, self.storycraft_showline(connection, event, nick, userhost, what, admin_unlocked)) | ||||||
|         elif self.addlinere.search(what): |         elif self.addlinere.search(what): | ||||||
|             return self.reply(connection, event, self.storycraft_addline(connection, event, nick, userhost, what, admin_unlocked)) |             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): |         elif self.exportre.search(what): | ||||||
|             return self.reply(connection, event, self.storycraft_export(connection, event, nick, userhost, what, admin_unlocked)) |             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) |         match = self.statusre.search(what) | ||||||
|         if match: |         if match: | ||||||
|             if match.group(2): |             # do the general status of all games | ||||||
|                 game_id = int(match.group(2)) |             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 |                 # do the status of one game | ||||||
|                 game = self._get_game_details(game_id) |                 game = self._get_game_details(game_id) | ||||||
| @ -195,14 +212,6 @@ class Storycraft(Module): | |||||||
|                     return status_str |                     return status_str | ||||||
|                 else: |                 else: | ||||||
|                     return 'Game #{0:d} does not exist.'.format(game_id) |                     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): |     def storycraft_newgame(self, connection, event, nick, userhost, what, admin_unlocked): | ||||||
|         """Add a game to the system, which users can join.""" |         """Add a game to the system, which users can join.""" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user