]> git.cworth.org Git - turbot/blobdiff - turbot/puzzle.py
Abbreviate round name to only 7 characters in Slack channel name
[turbot] / turbot / puzzle.py
index d24a7c9a4da955120f565a3ea43db4e8d66f61d5..316620c085da5d8936d808f06ec0e747a8c88c26 100644 (file)
@@ -223,6 +223,12 @@ def puzzle_matches_all(puzzle, patterns):
 def puzzle_id_from_name(name):
     return re.sub(r'[^a-zA-Z0-9_]', '', name).lower()
 
+def round_id_from_name(name):
+    """Normalize and abbreviate round name for use as a prefix
+       in a channel name."""
+
+    return re.sub(r'[^a-zA-Z0-9_]', '', name).lower()[:7]
+
 def puzzle_sort_key(puzzle):
     """Return an appropriate sort key for a puzzle in the database
 
@@ -308,7 +314,7 @@ def puzzle_channel_name(puzzle):
 
     round = ''
     if 'rounds' in puzzle:
-        round = '-' + puzzle_id_from_name(puzzle['rounds'][0])
+        round = '-' + round_id_from_name(puzzle['rounds'][0])
 
     meta = ''
     if puzzle.get('type', 'plain') == 'meta':