Compare commits
1 Commits
0f7f0582d3
...
166e310f96
| Author | SHA1 | Date | |
|---|---|---|---|
| 166e310f96 |
@@ -1,11 +1,12 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
|
from urllib.parse import urlparse, parse_qs
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from weakref import WeakValueDictionary
|
from weakref import WeakValueDictionary
|
||||||
import discord
|
import discord
|
||||||
from discord.abc import GuildChannel
|
from discord.abc import GuildChannel, Snowflake
|
||||||
from discord.ext import commands as cmds
|
from discord.ext import commands as cmds
|
||||||
from discord import app_commands as appcmds
|
from discord import Object, app_commands as appcmds
|
||||||
from discord.utils import utcnow
|
from discord.utils import utcnow
|
||||||
|
|
||||||
from data.queries import JOINTYPE, ORDER
|
from data.queries import JOINTYPE, ORDER
|
||||||
@@ -20,6 +21,29 @@ from .lib import diff_file
|
|||||||
from .data import LogData, LoggingGuild, LoggedMessage, LogAttachment, MessageState
|
from .data import LogData, LoggingGuild, LoggedMessage, LogAttachment, MessageState
|
||||||
|
|
||||||
|
|
||||||
|
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', Object(self.thread_id))
|
||||||
|
return await super().send(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class LogCog(LionCog):
|
class LogCog(LionCog):
|
||||||
attachment_hook: discord.Webhook
|
attachment_hook: discord.Webhook
|
||||||
|
|
||||||
@@ -46,7 +70,7 @@ class LogCog(LionCog):
|
|||||||
)
|
)
|
||||||
guilds = {}
|
guilds = {}
|
||||||
for row in guildrows:
|
for row in guildrows:
|
||||||
hook = discord.Webhook.from_url(row.webhook_url, client=self.bot)
|
hook = ThreadedWebhook.from_url(row.webhook_url, client=self.bot)
|
||||||
guilds[row.guildid] = hook
|
guilds[row.guildid] = hook
|
||||||
self.logging_guilds = guilds
|
self.logging_guilds = guilds
|
||||||
|
|
||||||
@@ -470,7 +494,7 @@ class LogCog(LionCog):
|
|||||||
if not ctx.author.guild_permissions.manage_guild:
|
if not ctx.author.guild_permissions.manage_guild:
|
||||||
return
|
return
|
||||||
|
|
||||||
webhook = discord.Webhook.from_url(webhook_url, client=self.bot)
|
webhook = ThreadedWebhook.from_url(webhook_url, client=self.bot)
|
||||||
try:
|
try:
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Testing",
|
title="Testing",
|
||||||
|
|||||||
Reference in New Issue
Block a user