Compare commits

..

No commits in common. "223b915d2d48f66e863cc1c6d9ac4193794e8add" and "ce3da3c91bf517e7c49cdcca6a19da9525e376b2" have entirely different histories.

5 changed files with 55 additions and 45 deletions

View file

@ -13,7 +13,6 @@ class ExportChannels(commands.Cog):
self.config.register_global(
bot_token = None
)
self.data_path = data_manager.cog_data_path(self)
class ConfigException(Exception):
pass
@ -21,7 +20,7 @@ class ExportChannels(commands.Cog):
async def export(self, channels: list):
token = await self.config.bot_token()
if token is None:
raise(self.ConfigException("Bot token not set!"))
raise(self.ConfigException, "Bot token not set!")
data_path = data_manager.cog_data_path(self)
bundled_data_path = data_manager.bundled_data_path(self)
out = f'{data_path}{os.sep}Exported Channels'
@ -72,12 +71,12 @@ class ExportChannels(commands.Cog):
@commands.group()
@checks.is_owner()
async def exportset(self, ctx: commands.Context):
async def exportset(self, ctx):
"""Configuration options for the ExportChannels cog."""
@exportset.command()
@checks.is_owner()
async def token(self, ctx: commands.Context, token: str):
async def token(self, ctx, token: str):
"""Sets the bot token used for Discord Chat Exporter."""
await self.config.bot_token.set({token})
await ctx.send(content="Token set!")
@ -85,18 +84,21 @@ class ExportChannels(commands.Cog):
@exportset.command()
@checks.is_owner()
async def checkoutputpath(self, ctx: commands.Context):
async def checkoutputpath(self, ctx):
"""Checks what file path DCE is outputting to."""
self.data_path = data_manager.cog_data_path(self)
await ctx.send(content=f"{self.data_path}")
@commands.command()
@commands.admin()
async def exportchannel(self, ctx: commands.Context, channel: discord.TextChannel):
async def exportchannel(self, ctx, channel: discord.TextChannel):
"""Exports a channel using Discord Chat Exporter."""
token = await self.config.bot_token()
dce_install = data_manager.bundled_data_path(self)
if token is None:
await ctx.send(content=f"Please set your token with the ``{ctx.prefix}exportset token`` command!")
return
id_list = [thread.id for thread in channel.threads]
id_list.insert(0, channel.id)
await self.export(id_list)
else:
id_list = [thread.id for thread in channel.threads]
id_list.insert(0, channel.id)
await self.export(id_list)

View file

@ -275,16 +275,16 @@ class IssueResponseModal(discord.ui.Modal, title="Sending response message..."):
if embed.author.name == "Bot Bug Report":
issue_title = f"[BOT BUG] {_issue_title}"
# desired_labels = ["bot", "bug"]
desired_labels = ["bot", "bug"]
elif embed.author.name == "Bot Suggestion":
issue_title = f"[BOT SUGGESTION] {_issue_title}"
# desired_labels = ["bot", "enhancement"]
desired_labels = ["bot", "enhancement"]
elif embed.author.name == "Cog Bug Report":
issue_title = f"[{field_values[0]}] {_issue_title}"
# desired_labels = ["cog", "bug"]
desired_labels = ["cog", "bug"]
elif embed.author.name == "Cog Suggestion":
issue_title = f"[{field_values[0]}] {_issue_title}"
# desired_labels = ["cog", "enhancement"]
desired_labels = ["cog", "enhancement"]
headers = {
"Authorization": f"Bearer {await self.config.gitea_token()}",

View file

@ -1,11 +1,10 @@
import asyncio
import os
import re
import sqlite3
import discord
from redbot.core import Config, checks, commands, data_manager
import os
import sqlite3
from yt_dlp import YoutubeDL, utils
from redbot.core import commands, checks, Config, data_manager
class MusicDownloader(commands.Cog):
def __init__(self, bot):
@ -40,7 +39,7 @@ class MusicDownloader(commands.Cog):
db_path = os.path.join(data_path, "database.db")
con = sqlite3.connect(db_path)
cur = con.cursor()
cur.execute("SELECT user_id, reason FROM blacklist_log WHERE user_id = ?;", (user_id,))
cur.execute(f"SELECT user_id, reason FROM blacklist_log WHERE user_id = ?;", (user_id,))
result = cur.fetchone()
con.close()
if result:
@ -85,7 +84,7 @@ class MusicDownloader(commands.Cog):
except self.UserBlacklisted as e:
await ctx.send(f"You are blacklisted from running this command!\nReason: `{e}`")
return
def youtube_download(self, url: str, path: str):
def youtube_download(self, url: str, path: str, message: discord.Message):
"""This function does the actual downloading of the YouTube Video."""
class Logger:
def debug(self, msg):
@ -109,14 +108,14 @@ class MusicDownloader(commands.Cog):
with YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url=url, download=False)
title = info['title']
Yid = info['id']
filename = title + f' [{Yid}].m4a'
id = info['id']
filename = title + f' [{id}].m4a'
full_filename = os.path.join(data_path, filename)
if os.path.isfile(full_filename):
previously_existed = True
else:
with YoutubeDL(ydl_opts) as ydl:
ydl.download(url)
error_code = ydl.download(url)
previously_existed = False
return filename, previously_existed
data_path = await self.config.save_directory()
@ -127,8 +126,10 @@ class MusicDownloader(commands.Cog):
pattern = "[" + re.escape(illegal_chars) + "]"
modified_subfolder = re.sub(pattern, r'__**\g<0>**__', subfolder)
await ctx.send(f"Your subfolder contains illegal characters: `{modified_subfolder}`")
return
elif os.path.isfile(data_path):
await ctx.send("Your 'subfolder' is a file, not a directory!")
return
elif os.path.exists(data_path) is False:
message = await ctx.send("Your subfolder does not exist yet, would you like to continue? It will be automatically created.")
def check(message):
@ -149,7 +150,7 @@ class MusicDownloader(commands.Cog):
message = await msg("YouTube Downloader started!")
try:
ytdlp_output = youtube_download(self, url, data_path, message)
except (utils.DownloadError, utils.ExtractorError):
except utils.DownloadError or utils.ExtractorError:
await message.edit(content="Please provide a link to YouTube and not another site.\nThe site you've linked to is known for using DRM protection, so MusicDownloader cannot download from it.")
return
full_filename = os.path.join(data_path, ytdlp_output[0])
@ -184,7 +185,7 @@ class MusicDownloader(commands.Cog):
cur.execute("SELECT user_id, reason FROM blacklist_log WHERE user_id = ?;", (user.id,))
result = cur.fetchone()
if result:
reason = result
user_id, reason = result
await ctx.send(f"{user.mention} is in the blacklist for the following reason: `{reason}`", allowed_mentions = discord.AllowedMentions(users=False))
else:
await ctx.send(f"{user.mention} is not in the blacklist.", allowed_mentions = discord.AllowedMentions(users=False))

View file

@ -1,4 +1,7 @@
from redbot.core import commands, checks, Config
import discord
from datetime import datetime
from redbot.core.bot import Red
from redbot.core import commands, checks, Config, bot
class Podcast(commands.Cog):
"""Provides a questions submission system for podcasts.
@ -18,19 +21,20 @@ class Podcast(commands.Cog):
)
@commands.command()
async def podcast(self, ctx: commands.Context, question: str):
async def podcast(self, ctx, question: str):
"""Submits a question to the Podcast."""
prefix = await self.bot.get_valid_prefixes()
if await self.config.guild(ctx.guild).global_mode(True):
submission_channel = ctx.bot.get_channel(await self.config.global_submission_channel())
submission_channel = bot.get_channel(await self.config.global_submission_channel())
blacklisted_users = await self.config.global_blacklisted_users()
elif await self.config.guild(ctx.guild).global_mode(False):
submission_channel = ctx.bot.get_channel(await self.config.guild(ctx.guild).submission_channel())
submission_channel = bot.get_channel(await self.config.guild(ctx.guild).submission_channel())
blacklisted_users = await self.config.guild(ctx.guild).blacklisted_users()
else:
return
if ctx.author.id in blacklisted_users:
await ctx.author.send(content=f"You are blacklisted from ``{prefix}podcast``!")
return
else:
await submission_channel.send(content=f"{question}")
await ctx.send(content="Question submitted!")
@ -44,11 +48,11 @@ class Podcast(commands.Cog):
@podcastset.command(name="global")
async def set_global_mode(self, ctx, enabled: bool):
"""Enables or disables global mode."""
if enabled is True:
if enabled == True:
await self.config.guild(ctx.guild).global_mode.set(True)
await ctx.send(content="``global_mode`` has been enabled.")
elif enabled is False:
elif enabled == False:
await self.config.guild(ctx.guild).global_mode.set(False)
await ctx.send(content="``global_mode`` has been disabled.")
else:
await ctx.send(content="Please specify an argument!")
await ctx.send(content="Please specify an argument!")

View file

@ -1,8 +1,8 @@
import discord
from pytimeparse2 import disable_dateutil, parse
from discord import ui
from discord.ext.commands import Bot
from pytimeparse2 import disable_dateutil, parse
from redbot.core import Config, app_commands, commands
from redbot.core import Config, commands, app_commands
class Shortmute(commands.Cog):
"""Allows staff members to shortmute individuals for up to 30 minutes, using Discord's Timeouts feature."""
@ -43,7 +43,7 @@ class Shortmute(commands.Cog):
if evidence_image and evidence_link:
await interaction.response.send_message(content="You've provided both the `evidence_image` and the `evidence_link` arguments! Please only use one or the other.", ephemeral=True)
return
if evidence_link:
elif evidence_link:
evidence = evidence_link
elif evidence_image:
evidence = str(evidence_image)
@ -70,7 +70,7 @@ class Shortmute(commands.Cog):
if role in target.roles:
await interaction.response.send_message(content="You're trying to shortmute someone who is immune from shortmuting.", ephemeral=True)
return
if duration in (1, -1):
if duration == 1 or duration == -1:
readable_duration = f"{duration} minute"
else:
readable_duration = f"{duration} minutes"
@ -80,7 +80,7 @@ class Shortmute(commands.Cog):
if duration > 30:
await interaction.response.send_message(content=f"{readable_duration} is longer than the 30 minutes you are allowed to shortmute users for.", ephemeral=True)
return
if duration < 1:
elif duration < 1:
await interaction.response.send_message(content=f"Please shortmute the user for longer than {readable_duration}! The maximum duration is 30 minutes.", ephemeral=True)
return
if skip_confirmation is False:
@ -104,7 +104,7 @@ class Shortmute(commands.Cog):
dm_embed.set_image(url=evidence)
try:
await target.send(embed=dm_embed)
except discord.HTTPException:
except discord.HTTPException as error:
await message.edit(content="Could not message the target, user most likely has Direct Messages disabled.")
logging_channels_list = await self.config.guild(interaction.guild).logging_channels()
if logging_channels_list:
@ -124,12 +124,12 @@ class Shortmute(commands.Cog):
self.config = Config.get_conf(None, cog_name='Shortmute', identifier=25781647388294)
@ui.button(label="Yes", style=discord.ButtonStyle.success)
async def shortmute_button_yes(self, button: ui.Button, interaction: discord.Interaction): # pylint: disable=arguments-differ
async def shortmute_button_yes(self, button: ui.Button, interaction: discord.Interaction):
disable_dateutil()
target: discord.Member = self.passed_info['target']
target = self.passed_info['target']
readable_duration = self.passed_info['readable_duration']
reason: str = self.passed_info['reason']
old_interaction: discord.Interaction = self.passed_info['interaction']
reason = self.passed_info['reason']
old_interaction = self.passed_info['interaction']
color = self.passed_info['color']
timedelta = self.passed_info['timedelta']
evidence = self.passed_info['evidence']
@ -146,7 +146,7 @@ class Shortmute(commands.Cog):
dm_embed.set_image(url=evidence)
try:
await target.send(embed=dm_embed)
except discord.HTTPException:
except discord.HTTPException as error:
await old_message.edit(content="Could not message the target, user most likely has Direct Messages disabled.")
logging_channels_list = await self.config.guild(old_interaction.guild).logging_channels()
if logging_channels_list:
@ -159,8 +159,8 @@ class Shortmute(commands.Cog):
await channel_obj.send(embed=logging_embed)
@ui.button(label="No", style=discord.ButtonStyle.danger)
async def shortmute_button_no(self, button: ui.Button, interaction: discord.Interaction): # pylint: disable=arguments-differ
message: discord.Message = await self.passed_info['interaction'].edit_original_response(content="Command cancelled.", view=None, embed=None)
async def shortmute_button_no(self, button: ui.Button, interaction: discord.Interaction):
message = await self.passed_info['interaction'].edit_original_response(content="Command cancelled.", view=None, embed=None)
await message.delete(delay=3)
@commands.group(name='shortmuteset', autohelp=True)
@ -190,10 +190,11 @@ class Shortmute(commands.Cog):
@commands.admin()
async def shortmute_config_channel_add(self, ctx: commands.Context, channel: discord.TextChannel = None):
"""Adds a channel to the logging channels list."""
current_list: list = await self.config.guild(ctx.guild).logging_channels()
current_list = await self.config.guild(ctx.guild).logging_channels()
if channel:
if channel.id in current_list:
await ctx.send("This channel is already in the logging channel list!")
return
else:
current_list.append(channel.id)
await self.config.guild(ctx.guild).logging_channels.set(current_list)
@ -239,6 +240,7 @@ class Shortmute(commands.Cog):
if role:
if role.id in current_list:
await ctx.send("This role is already in the immune roles list!")
return
else:
current_list.append(role.id)
await self.config.guild(ctx.guild).immune_roles.set(current_list)
@ -284,6 +286,7 @@ class Shortmute(commands.Cog):
if user:
if user.id in current_list:
await ctx.send("That user is already in the blacklisted users list!")
return
else:
current_list.append(user.id)
await self.config.guild(ctx.guild).blacklisted_users.set(current_list)