Fix discord channel name and add verification

This commit is contained in:
BreadTube 2026-05-26 23:59:13 +09:00
commit d645fecae0
7 changed files with 23 additions and 4 deletions

View file

@ -2,6 +2,7 @@ from __future__ import annotations
from dataclasses import dataclass, field
from datetime import datetime
import re
from typing import NewType
from breadtube_bot.unidecode import unidecode
@ -68,7 +69,10 @@ class SubscriptionInfo:
@staticmethod
def discord_compatible_name(text: str) -> SubscriptionName:
assert text, 'Channel name cannot be empty'
return SubscriptionName(unidecode(text[:100].replace(' ', '-')))
name = unidecode(text[:100].replace(' ', '-'))
name = re.sub(r'-+', '-', name)
name = re.sub(r'-+$', '', name)
return SubscriptionName(name)
@staticmethod
def from_dict(info: dict) -> SubscriptionInfo: