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( self.config.register_global(
bot_token = None bot_token = None
) )
self.data_path = data_manager.cog_data_path(self)
class ConfigException(Exception): class ConfigException(Exception):
pass pass
@ -21,7 +20,7 @@ class ExportChannels(commands.Cog):
async def export(self, channels: list): async def export(self, channels: list):
token = await self.config.bot_token() token = await self.config.bot_token()
if token is None: 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) data_path = data_manager.cog_data_path(self)
bundled_data_path = data_manager.bundled_data_path(self) bundled_data_path = data_manager.bundled_data_path(self)
out = f'{data_path}{os.sep}Exported Channels' out = f'{data_path}{os.sep}Exported Channels'
@ -72,12 +71,12 @@ class ExportChannels(commands.Cog):
@commands.group() @commands.group()
@checks.is_owner() @checks.is_owner()
async def exportset(self, ctx: commands.Context): async def exportset(self, ctx):
"""Configuration options for the ExportChannels cog.""" """Configuration options for the ExportChannels cog."""
@exportset.command() @exportset.command()
@checks.is_owner() @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.""" """Sets the bot token used for Discord Chat Exporter."""
await self.config.bot_token.set({token}) await self.config.bot_token.set({token})
await ctx.send(content="Token set!") await ctx.send(content="Token set!")
@ -85,18 +84,21 @@ class ExportChannels(commands.Cog):
@exportset.command() @exportset.command()
@checks.is_owner() @checks.is_owner()
async def checkoutputpath(self, ctx: commands.Context): async def checkoutputpath(self, ctx):
"""Checks what file path DCE is outputting to.""" """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}") await ctx.send(content=f"{self.data_path}")
@commands.command() @commands.command()
@commands.admin() @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.""" """Exports a channel using Discord Chat Exporter."""
token = await self.config.bot_token() token = await self.config.bot_token()
dce_install = data_manager.bundled_data_path(self)
if token is None: if token is None:
await ctx.send(content=f"Please set your token with the ``{ctx.prefix}exportset token`` command!") await ctx.send(content=f"Please set your token with the ``{ctx.prefix}exportset token`` command!")
return return
id_list = [thread.id for thread in channel.threads] else:
id_list.insert(0, channel.id) id_list = [thread.id for thread in channel.threads]
await self.export(id_list) 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": if embed.author.name == "Bot Bug Report":
issue_title = f"[BOT BUG] {_issue_title}" issue_title = f"[BOT BUG] {_issue_title}"
# desired_labels = ["bot", "bug"] desired_labels = ["bot", "bug"]
elif embed.author.name == "Bot Suggestion": elif embed.author.name == "Bot Suggestion":
issue_title = f"[BOT SUGGESTION] {_issue_title}" issue_title = f"[BOT SUGGESTION] {_issue_title}"
# desired_labels = ["bot", "enhancement"] desired_labels = ["bot", "enhancement"]
elif embed.author.name == "Cog Bug Report": elif embed.author.name == "Cog Bug Report":
issue_title = f"[{field_values[0]}] {_issue_title}" issue_title = f"[{field_values[0]}] {_issue_title}"
# desired_labels = ["cog", "bug"] desired_labels = ["cog", "bug"]
elif embed.author.name == "Cog Suggestion": elif embed.author.name == "Cog Suggestion":
issue_title = f"[{field_values[0]}] {_issue_title}" issue_title = f"[{field_values[0]}] {_issue_title}"
# desired_labels = ["cog", "enhancement"] desired_labels = ["cog", "enhancement"]
headers = { headers = {
"Authorization": f"Bearer {await self.config.gitea_token()}", "Authorization": f"Bearer {await self.config.gitea_token()}",

View file

@ -1,11 +1,10 @@
import asyncio import asyncio
import os
import re import re
import sqlite3
import discord import discord
from redbot.core import Config, checks, commands, data_manager import os
import sqlite3
from yt_dlp import YoutubeDL, utils from yt_dlp import YoutubeDL, utils
from redbot.core import commands, checks, Config, data_manager
class MusicDownloader(commands.Cog): class MusicDownloader(commands.Cog):
def __init__(self, bot): def __init__(self, bot):
@ -40,7 +39,7 @@ class MusicDownloader(commands.Cog):
db_path = os.path.join(data_path, "database.db") db_path = os.path.join(data_path, "database.db")
con = sqlite3.connect(db_path) con = sqlite3.connect(db_path)
cur = con.cursor() 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() result = cur.fetchone()
con.close() con.close()
if result: if result:
@ -85,7 +84,7 @@ class MusicDownloader(commands.Cog):
except self.UserBlacklisted as e: except self.UserBlacklisted as e:
await ctx.send(f"You are blacklisted from running this command!\nReason: `{e}`") await ctx.send(f"You are blacklisted from running this command!\nReason: `{e}`")
return 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.""" """This function does the actual downloading of the YouTube Video."""
class Logger: class Logger:
def debug(self, msg): def debug(self, msg):
@ -109,14 +108,14 @@ class MusicDownloader(commands.Cog):
with YoutubeDL(ydl_opts) as ydl: with YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url=url, download=False) info = ydl.extract_info(url=url, download=False)
title = info['title'] title = info['title']
Yid = info['id'] id = info['id']
filename = title + f' [{Yid}].m4a' filename = title + f' [{id}].m4a'
full_filename = os.path.join(data_path, filename) full_filename = os.path.join(data_path, filename)
if os.path.isfile(full_filename): if os.path.isfile(full_filename):
previously_existed = True previously_existed = True
else: else:
with YoutubeDL(ydl_opts) as ydl: with YoutubeDL(ydl_opts) as ydl:
ydl.download(url) error_code = ydl.download(url)
previously_existed = False previously_existed = False
return filename, previously_existed return filename, previously_existed
data_path = await self.config.save_directory() data_path = await self.config.save_directory()
@ -127,8 +126,10 @@ class MusicDownloader(commands.Cog):
pattern = "[" + re.escape(illegal_chars) + "]" pattern = "[" + re.escape(illegal_chars) + "]"
modified_subfolder = re.sub(pattern, r'__**\g<0>**__', subfolder) modified_subfolder = re.sub(pattern, r'__**\g<0>**__', subfolder)
await ctx.send(f"Your subfolder contains illegal characters: `{modified_subfolder}`") await ctx.send(f"Your subfolder contains illegal characters: `{modified_subfolder}`")
return
elif os.path.isfile(data_path): elif os.path.isfile(data_path):
await ctx.send("Your 'subfolder' is a file, not a directory!") await ctx.send("Your 'subfolder' is a file, not a directory!")
return
elif os.path.exists(data_path) is False: 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.") message = await ctx.send("Your subfolder does not exist yet, would you like to continue? It will be automatically created.")
def check(message): def check(message):
@ -149,7 +150,7 @@ class MusicDownloader(commands.Cog):
message = await msg("YouTube Downloader started!") message = await msg("YouTube Downloader started!")
try: try:
ytdlp_output = youtube_download(self, url, data_path, message) 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.") 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 return
full_filename = os.path.join(data_path, ytdlp_output[0]) 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,)) cur.execute("SELECT user_id, reason FROM blacklist_log WHERE user_id = ?;", (user.id,))
result = cur.fetchone() result = cur.fetchone()
if result: 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)) await ctx.send(f"{user.mention} is in the blacklist for the following reason: `{reason}`", allowed_mentions = discord.AllowedMentions(users=False))
else: else:
await ctx.send(f"{user.mention} is not in the blacklist.", allowed_mentions = discord.AllowedMentions(users=False)) 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): class Podcast(commands.Cog):
"""Provides a questions submission system for podcasts. """Provides a questions submission system for podcasts.
@ -18,19 +21,20 @@ class Podcast(commands.Cog):
) )
@commands.command() @commands.command()
async def podcast(self, ctx: commands.Context, question: str): async def podcast(self, ctx, question: str):
"""Submits a question to the Podcast.""" """Submits a question to the Podcast."""
prefix = await self.bot.get_valid_prefixes() prefix = await self.bot.get_valid_prefixes()
if await self.config.guild(ctx.guild).global_mode(True): 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() blacklisted_users = await self.config.global_blacklisted_users()
elif await self.config.guild(ctx.guild).global_mode(False): 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() blacklisted_users = await self.config.guild(ctx.guild).blacklisted_users()
else: else:
return return
if ctx.author.id in blacklisted_users: if ctx.author.id in blacklisted_users:
await ctx.author.send(content=f"You are blacklisted from ``{prefix}podcast``!") await ctx.author.send(content=f"You are blacklisted from ``{prefix}podcast``!")
return
else: else:
await submission_channel.send(content=f"{question}") await submission_channel.send(content=f"{question}")
await ctx.send(content="Question submitted!") await ctx.send(content="Question submitted!")
@ -44,10 +48,10 @@ class Podcast(commands.Cog):
@podcastset.command(name="global") @podcastset.command(name="global")
async def set_global_mode(self, ctx, enabled: bool): async def set_global_mode(self, ctx, enabled: bool):
"""Enables or disables global mode.""" """Enables or disables global mode."""
if enabled is True: if enabled == True:
await self.config.guild(ctx.guild).global_mode.set(True) await self.config.guild(ctx.guild).global_mode.set(True)
await ctx.send(content="``global_mode`` has been enabled.") 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 self.config.guild(ctx.guild).global_mode.set(False)
await ctx.send(content="``global_mode`` has been disabled.") await ctx.send(content="``global_mode`` has been disabled.")
else: else:

View file

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