-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57774ec
commit 860a7ea
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"author": [ | ||
"raidensakura" | ||
], | ||
"bot_version": "4.1.0", | ||
"description": "Display uploaded video attachment inside thread channel. Bounty plugin requested by neya.", | ||
"dpy_version": "2.3.2", | ||
"name": "video-preview", | ||
"requirements": [], | ||
"tags": [ | ||
"video", | ||
"embed" | ||
], | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Say by retke, aka El Laggron | ||
|
||
import re | ||
from logging import getLogger | ||
from typing import Any, Dict, List, Optional, Union, TYPE_CHECKING | ||
|
||
import discord | ||
from bot import ModmailBot | ||
from core import checks | ||
from core.thread import Thread | ||
from discord.ext import commands | ||
|
||
logger = getLogger(__name__) | ||
|
||
ROLE_MENTION_REGEX = re.compile(r"<@&(?P<id>[0-9]{17,19})>") | ||
|
||
|
||
class VideoPreview(commands.Cog): | ||
""" | ||
Embed a video sent through the Modmail thread to show its preview. | ||
""" | ||
|
||
def __init__(self, bot: ModmailBot): | ||
self.bot = bot | ||
self.interaction = [] | ||
|
||
__author__ = ["raidensakura"] | ||
__version__ = "1.0.0" | ||
|
||
async def cog_unload(self): | ||
logger.debug("Unloading cog...") | ||
for user in self.interaction: | ||
await self.stop_interaction(user) | ||
|
||
@commands.Cog.listener() | ||
async def on_thread_reply(self, thread: Thread, from_mod: bool, message: discord.Message, anon: bool, plain: bool) -> None: | ||
|
||
if not message.attachments: | ||
return | ||
|
||
msg = "" | ||
for i, attachment in enumerate(message.attachments): | ||
if attachment.filename.endswith(('.mp4', '.mov', '.avi', '.mkv', '.webm')): | ||
msg += f"Video Preview ({i+1})\n{attachment.url}\n" | ||
|
||
if from_mod: | ||
await thread.recipient.send(msg) | ||
else: | ||
await thread.channel.send(msg) | ||
|
||
|
||
async def setup(bot: ModmailBot) -> None: | ||
await bot.add_cog(VideoPreview(bot)) |