-
Notifications
You must be signed in to change notification settings - Fork 9
/
clear_media.py
44 lines (36 loc) · 1.16 KB
/
clear_media.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
from glob import glob
from pathlib import Path
from common import *
from utils.check_channel_access import access_check
# Path to base bot directory
base_path = Path(__file__).parent.parent
@bot.command()
@commands.check(access_check)
async def clear_media(ctx):
"""
This function is the main entrypoint of the !clear_media command
This will remove all .mp4 files from the data/clips and data/drops directories
and allow the bot to re-load them as needed. Useful for debugging.
"""
drop_files = glob(os.path.join(base_path, 'data/drops/', '*.mp4'))
clip_files = glob(os.path.join(base_path, 'data/clips/', '*.mp4'))
errors = []
for file_path in [*drop_files, *clip_files]:
try:
os.remove(file_path)
except Exception:
logger.debug(f"{Fore.RED}ERROR: Unable to remove file: {file_path}{Fore.RESET}")
errors.append(file_path)
if errors:
embed = discord.Embed(
title="Error Deleting Files!",
description="\n".join(errors),
color=discord.Color.red()
)
else:
embed = discord.Embed(
title="Files Cleared Successfully!",
color=discord.Color.green()
)
await ctx.send(embed=embed)