diff --git a/discordbot.py b/discordbot.py index 1194e3df..dfbc8bd7 100644 --- a/discordbot.py +++ b/discordbot.py @@ -15,11 +15,12 @@ import configparser import async_timeout import raven import logging -import errors import datetime import sqlalchemy.exc import coloredlogs import errors +import math +import enum logging.getLogger().disabled = True logger = logging.getLogger(__name__) @@ -38,19 +39,10 @@ queue_emojis = [":one:", ":nine:", ":keycap_ten:"] -# Zalgo text -zalgo_up = ['̍', '̎', '̄', '̅', '̿', '̑', '̆', '̐', '͒', '͗', '͑', '̇', '̈', '̊', '͂', '̓', '̈́', '͊', - '͋', '͌', '̃', '̂', '̌', '͐', '́', '̋', '̏', '̽', '̉', 'ͣ', 'ͤ', 'ͥ', 'ͦ', 'ͧ', 'ͨ', 'ͩ', - 'ͪ', 'ͫ', 'ͬ', 'ͭ', 'ͮ', 'ͯ', '̾', '͛', '͆', '̚', ] -zalgo_down = ['̖', '̗', '̘', '̙', '̜', '̝', '̞', '̟', '̠', '̤', '̥', '̦', '̩', '̪', '̫', '̬', '̭', '̮', - '̯', '̰', '̱', '̲', '̳', '̹', '̺', '̻', '̼', 'ͅ', '͇', '͈', '͉', '͍', '͎', '͓', '͔', '͕', - '͖', '͙', '͚', '', ] -zalgo_middle = ['̕', '̛', '̀', '́', '͘', '̡', '̢', '̧', '̨', '̴', '̵', '̶', '͜', '͝', '͞', '͟', '͠', '͢', - '̸', '̷', '͡', ] - # Init the event loop loop = asyncio.get_event_loop() +# TODO: remove me # Init the config reader config = configparser.ConfigParser() config.read("config.ini") @@ -117,8 +109,8 @@ class Succ: def __bool__(self): return False - - def __getattr__(self): + + def __getattr__(self, attr): return Succ() def __call__(self, *args, **kwargs): @@ -131,102 +123,223 @@ class Succ: return "" +# TODO # Init the Sentry client -if config.get("Sentry") and config["Sentry"].get("token"): - sentry = raven.Client(config["Sentry"]["token"], - release=raven.fetch_git_sha(os.path.dirname(__file__)), - install_logging_hook=False, - hook_libraries=[]) -else: - logger.warning("Sentry not set, ignoring all calls to it.") - sentry = Succ() +# if config.get("Sentry") and config["Sentry"].get("token"): +# sentry = raven.Client(config["Sentry"]["token"], +# release=raven.fetch_git_sha(os.path.dirname(__file__)), +# install_logging_hook=False, +# hook_libraries=[]) +# else: +logger.warning("Sentry not set, ignoring all calls to it.") +sentry = Succ() class Video: - def __init__(self, url: str = None, file: str = None, info: dict = None, enqueuer: discord.Member = None): - self.url = url - if file is None and info is None: - self.file = str(hash(url)) + ".opus" - elif info is not None: - self.file = "./opusfiles/" + re.sub(r'[/\\?*"<>|!:]', "_", info["title"]) + ".opus" - else: - self.file = file - self.downloaded = False if file is None else True - self.info = info + def __init__(self, enqueuer: typing.Optional[discord.Member] = None): + self.is_ready = False + self.name = None self.enqueuer = enqueuer - self.duration = None + self.audio_source = None def __str__(self): - if self.info is None or "title" not in self.info: - return f"`{self.file}`" - return f"_{self.info['title']}_" - - def __repr__(self): - return f"" + if self.name is None: + return "_Untitled_" + return self.name def plain_text(self): - if self.info is None or "title" not in self.info: - return self.file - return self.info['title'] + """Title without formatting to be printed on terminals.""" + if self.name is None: + return "Untitled" + return self.name - async def download(self, progress_hooks: typing.List["function"] = None): - # File already downloaded - if self.downloaded: - raise errors.AlreadyDownloadedError() - # No progress hooks - if progress_hooks is None: - progress_hooks = [] - # Check if under max duration - self.duration = datetime.timedelta(seconds=self.info.get("duration", 0)) - if self.info is not None and self.duration.total_seconds() > int(config["YouTube"]["max_duration"]): - raise errors.DurationError() + def database_text(self): + """The text to be stored in the database for the stats. Usually the same as plain_text().""" + if self.name is None: + raise errors.VideoHasNoName() + return self.name + + def __repr__(self): + return f"