From 93ff1dc2afdb8161bb64d9bac5dbb9c5858355fd Mon Sep 17 00:00:00 2001 From: timofey Date: Wed, 27 Dec 2023 04:34:30 +0000 Subject: [PATCH] yandex check --- v6d3music/utils/argctx.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/v6d3music/utils/argctx.py b/v6d3music/utils/argctx.py index d82d45f..171d66c 100644 --- a/v6d3music/utils/argctx.py +++ b/v6d3music/utils/argctx.py @@ -2,6 +2,7 @@ import string from typing import Any, AsyncIterable from v6d2ctx.context import Context, Explicit, escape +from v6d3music.config import prefix from v6d3music.utils.assert_admin import assert_admin from v6d3music.utils.effects_for_preset import effects_for_preset from v6d3music.utils.entries_for_url import entries_for_url @@ -43,7 +44,17 @@ class BoundCtx: self.member = ctx.member self.ctx = ctx self.url = it.info["url"] - self.description = f'{escape(it.info.get("title", "unknown"))} `Rby` {ctx.member}' + if "yandex" in self.url and ( + not ctx.guild + or ( + ctx.guild.id != 541241763042689025 + and ctx.author.id != 264054779888533515 + ) + ): + raise Explicit("yandex is not allowed") + self.description = ( + f'{escape(it.info.get("title", "unknown"))} `Rby` {ctx.member}' + ) self.effects = it.effects self.already_read = it.already_read self.options = self._options() @@ -53,7 +64,9 @@ class BoundCtx: if self.effects: if self.effects not in allowed_effects: assert_admin(self.ctx.member) - if not set(self.effects) <= set(string.ascii_letters + string.digits + "*,=+-/()|.^:_"): + if not set(self.effects) <= set( + string.ascii_letters + string.digits + "*,=+-/()|.^:_" + ): raise Explicit("malformed effects") return options_for_effects(self.effects) else: @@ -98,9 +111,13 @@ class ArgCtx: raise RuntimeError for url in urls: if url in presets: - raise Explicit("expected url, got preset. maybe you are missing `+`?") + raise Explicit( + "expected url, got preset. maybe you are missing `+`?" + ) if url in {"+", "-"}: - raise Explicit("expected url, got `+` or `-`. maybe you tried to use multiple effects?") + raise Explicit( + "expected url, got `+` or `-`. maybe you tried to use multiple effects?" + ) if url.startswith("+") or url.startswith('-"') or url.startswith("-'"): raise Explicit( "expected url, got `+` or `-\"` or `-'`. maybe you forgot to separate control symbol from the effects?" @@ -110,6 +127,8 @@ class ArgCtx: "bot cannot decide how to handle an URL with both `watch` and `list` in it.\n" "instead, use either `youtube.com/watch` URL without `&list=` part or `youtube.com/playlist` URL." ) + if url == "skip": + raise Explicit(f"to skip, use `{prefix}skip`") match args: case ["-", effects, *args]: pass @@ -121,7 +140,12 @@ class ArgCtx: raise RuntimeError post = PostCtx(effects) match args: - case [h, m, s, *args] if h.isdecimal() and m.isdecimal() and s.isdecimal(): + case [ + h, + m, + s, + *args, + ] if h.isdecimal() and m.isdecimal() and s.isdecimal(): seconds = 3600 * int(h) + 60 * int(m) + int(s) case [m, s, *args] if m.isdecimal() and s.isdecimal(): seconds = 60 * int(m) + int(s) @@ -141,4 +165,6 @@ class ArgCtx: case [*args]: break for url in urls: + if url.startswith("<") and url.endswith(">"): + url = url[1:-1] self.sources.append(UrlCtx(url, post))