Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def valid_channel_name(name):
- """Channel names can only contain lowercase letters,
- numbers, hyphens, and underscores, and must be 21 characters or less.
- Some sample conversions from Slack to determine some heuristics:
- 1..................20abc def => 1_20abc-def
- 1..................20abc..def => 1_20abc_def
- Heuristics:
- 1. Encode input into ASCII
- 2. Replace non-alphanumeric groups of charaters by a single _
- 3. Replace all spaces by dashes
- 4. Truncate the resulting sring into first 21 characters
- """
- result = unicodedata.normalize('NFD', name).encode('ascii', 'ignore')
- result = re.sub("[^a-zA-Z\d\s-]+", '_', result)
- result = result.replace(' ', '-')
- result = result[:21].lower()
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement