Skip to content

Commit

Permalink
Add video-preview plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
raidensakura committed Aug 27, 2024
1 parent 57774ec commit 860a7ea
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ Make sure to set `REGISTRY_PLUGINS_ONLY` in your environment variables to `False
<td>A port of <a href="https://github.com/laggron42/Laggrons-Dumb-Cogs/tree/v3/say">El Laggron's say cog</a> for Red Discord bot with some incompatible features removed.</td>
</tr>

</tr>
<tr>
<td><a href="https://github.com/raidensakura/modmail-plugins/tree/main/video-preview">Video Preview</a></td>
<td>Bounty plugin made for neya. It simply sends a link of a video attachment inside the thread channel so it can be played within the client.</td>
</tr>

</table>

Expand Down
15 changes: 15 additions & 0 deletions video-preview/info.json
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"
}
53 changes: 53 additions & 0 deletions video-preview/video-preview.py
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))

0 comments on commit 860a7ea

Please sign in to comment.