Implement voiceloger
This commit is contained in:
25
plugin/discord/lib.py
Normal file
25
plugin/discord/lib.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import discord
|
||||
from urllib.parse import urlparse, parse_qs
|
||||
|
||||
|
||||
class ThreadedWebhook(discord.Webhook):
|
||||
__slots__ = ("thread_id",)
|
||||
|
||||
def __init__(self, *args, thread_id=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.thread_id = thread_id
|
||||
|
||||
@classmethod
|
||||
def from_url(cls, url: str, *args, **kwargs):
|
||||
self = super().from_url(url, *args, **kwargs)
|
||||
parse = urlparse(url)
|
||||
if parse.query:
|
||||
args = parse_qs(parse.query)
|
||||
if "thread_id" in args:
|
||||
self.thread_id = int(args["thread_id"][0])
|
||||
return self
|
||||
|
||||
async def send(self, *args, **kwargs):
|
||||
if self.thread_id is not None:
|
||||
kwargs.setdefault("thread", discord.Object(self.thread_id))
|
||||
return await super().send(*args, **kwargs)
|
||||
Reference in New Issue
Block a user