yandex check
This commit is contained in:
parent
79695fe142
commit
93ff1dc2af
@ -2,6 +2,7 @@ import string
|
|||||||
from typing import Any, AsyncIterable
|
from typing import Any, AsyncIterable
|
||||||
|
|
||||||
from v6d2ctx.context import Context, Explicit, escape
|
from v6d2ctx.context import Context, Explicit, escape
|
||||||
|
from v6d3music.config import prefix
|
||||||
from v6d3music.utils.assert_admin import assert_admin
|
from v6d3music.utils.assert_admin import assert_admin
|
||||||
from v6d3music.utils.effects_for_preset import effects_for_preset
|
from v6d3music.utils.effects_for_preset import effects_for_preset
|
||||||
from v6d3music.utils.entries_for_url import entries_for_url
|
from v6d3music.utils.entries_for_url import entries_for_url
|
||||||
@ -43,7 +44,17 @@ class BoundCtx:
|
|||||||
self.member = ctx.member
|
self.member = ctx.member
|
||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
self.url = it.info["url"]
|
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.effects = it.effects
|
||||||
self.already_read = it.already_read
|
self.already_read = it.already_read
|
||||||
self.options = self._options()
|
self.options = self._options()
|
||||||
@ -53,7 +64,9 @@ class BoundCtx:
|
|||||||
if self.effects:
|
if self.effects:
|
||||||
if self.effects not in allowed_effects:
|
if self.effects not in allowed_effects:
|
||||||
assert_admin(self.ctx.member)
|
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")
|
raise Explicit("malformed effects")
|
||||||
return options_for_effects(self.effects)
|
return options_for_effects(self.effects)
|
||||||
else:
|
else:
|
||||||
@ -98,9 +111,13 @@ class ArgCtx:
|
|||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
for url in urls:
|
for url in urls:
|
||||||
if url in presets:
|
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 {"+", "-"}:
|
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("-'"):
|
if url.startswith("+") or url.startswith('-"') or url.startswith("-'"):
|
||||||
raise Explicit(
|
raise Explicit(
|
||||||
"expected url, got `+` or `-\"` or `-'`. maybe you forgot to separate control symbol from the effects?"
|
"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"
|
"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."
|
"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:
|
match args:
|
||||||
case ["-", effects, *args]:
|
case ["-", effects, *args]:
|
||||||
pass
|
pass
|
||||||
@ -121,7 +140,12 @@ class ArgCtx:
|
|||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
post = PostCtx(effects)
|
post = PostCtx(effects)
|
||||||
match args:
|
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)
|
seconds = 3600 * int(h) + 60 * int(m) + int(s)
|
||||||
case [m, s, *args] if m.isdecimal() and s.isdecimal():
|
case [m, s, *args] if m.isdecimal() and s.isdecimal():
|
||||||
seconds = 60 * int(m) + int(s)
|
seconds = 60 * int(m) + int(s)
|
||||||
@ -141,4 +165,6 @@ class ArgCtx:
|
|||||||
case [*args]:
|
case [*args]:
|
||||||
break
|
break
|
||||||
for url in urls:
|
for url in urls:
|
||||||
|
if url.startswith("<") and url.endswith(">"):
|
||||||
|
url = url[1:-1]
|
||||||
self.sources.append(UrlCtx(url, post))
|
self.sources.append(UrlCtx(url, post))
|
||||||
|
Loading…
Reference in New Issue
Block a user