Compare commits

...

5 commits

Author SHA1 Message Date
223b915d2d
fix(shortmute): pylint fixes
Some checks failed
Pylint / Pylint (push) Failing after 1m7s
2023-09-24 20:43:26 -04:00
2b84f05eac
fix(podcast): pylint fixes 2023-09-24 20:36:48 -04:00
62a354b8c7
fix(musicdownloader): pylint fixes 2023-09-24 20:34:16 -04:00
dbe10c53d1
fix(exportchannels): pylint fixes 2023-09-24 20:29:46 -04:00
0c31c59017
fix(issues): pylint fixes 2023-09-24 20:27:01 -04:00
5 changed files with 45 additions and 55 deletions

View file

@ -13,6 +13,7 @@ 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
@ -20,7 +21,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'
@ -71,12 +72,12 @@ class ExportChannels(commands.Cog):
@commands.group() @commands.group()
@checks.is_owner() @checks.is_owner()
async def exportset(self, ctx): async def exportset(self, ctx: commands.Context):
"""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, token: str): async def token(self, ctx: commands.Context, 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!")
@ -84,21 +85,18 @@ class ExportChannels(commands.Cog):
@exportset.command() @exportset.command()
@checks.is_owner() @checks.is_owner()
async def checkoutputpath(self, ctx): async def checkoutputpath(self, ctx: commands.Context):
"""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, channel: discord.TextChannel): async def exportchannel(self, ctx: commands.Context, 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
else:
id_list = [thread.id for thread in channel.threads] id_list = [thread.id for thread in channel.threads]
id_list.insert(0, channel.id) id_list.insert(0, channel.id)
await self.export(id_list) 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,10 +1,11 @@
import asyncio import asyncio
import re
import discord
import os import os
import re
import sqlite3 import sqlite3
import discord
from redbot.core import Config, checks, commands, data_manager
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):
@ -39,7 +40,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(f"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()
con.close() con.close()
if result: if result:
@ -84,7 +85,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, message: discord.Message): def youtube_download(self, url: str, path: str):
"""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):
@ -108,14 +109,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']
id = info['id'] Yid = info['id']
filename = title + f' [{id}].m4a' filename = title + f' [{Yid}].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:
error_code = ydl.download(url) 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()
@ -126,10 +127,8 @@ 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):
@ -150,7 +149,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 or utils.ExtractorError: except (utils.DownloadError, 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])
@ -185,7 +184,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:
user_id, reason = result 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,7 +1,4 @@
import discord from redbot.core import commands, checks, Config
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.
@ -21,20 +18,19 @@ class Podcast(commands.Cog):
) )
@commands.command() @commands.command()
async def podcast(self, ctx, question: str): async def podcast(self, ctx: commands.Context, 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 = bot.get_channel(await self.config.global_submission_channel()) submission_channel = ctx.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 = bot.get_channel(await self.config.guild(ctx.guild).submission_channel()) submission_channel = ctx.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!")
@ -48,10 +44,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 == True: if enabled is 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 == False: elif enabled is 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 redbot.core import Config, commands, app_commands from pytimeparse2 import disable_dateutil, parse
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
elif evidence_link: if 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 == 1 or duration == -1: if duration in (1, -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
elif duration < 1: if 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 as error: except discord.HTTPException:
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): async def shortmute_button_yes(self, button: ui.Button, interaction: discord.Interaction): # pylint: disable=arguments-differ
disable_dateutil() disable_dateutil()
target = self.passed_info['target'] target: discord.Member = self.passed_info['target']
readable_duration = self.passed_info['readable_duration'] readable_duration = self.passed_info['readable_duration']
reason = self.passed_info['reason'] reason: str = self.passed_info['reason']
old_interaction = self.passed_info['interaction'] old_interaction: discord.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 as error: except discord.HTTPException:
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): async def shortmute_button_no(self, button: ui.Button, interaction: discord.Interaction): # pylint: disable=arguments-differ
message = await self.passed_info['interaction'].edit_original_response(content="Command cancelled.", view=None, embed=None) message: discord.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,11 +190,10 @@ 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 = await self.config.guild(ctx.guild).logging_channels() current_list: 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)
@ -240,7 +239,6 @@ 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)
@ -286,7 +284,6 @@ 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)