Made Pylint happy

This commit is contained in:
Vegard Berg 2022-10-15 03:35:42 +02:00
parent 8aec106671
commit 2c93e81be0
Signed by: myrkvi
GPG Key ID: BFE35EA1A44D5E40
7 changed files with 53 additions and 66 deletions

View File

@ -4,12 +4,9 @@ from os import getenv
from naff import (
Client,
Intents,
OptionTypes,
Permissions,
listen,
slash_command,
InteractionContext,
slash_option,
)
from naff.api import events
from naff.models.discord.embed import (
@ -19,10 +16,8 @@ from naff.models.discord.embed import (
EmbedFooter,
)
from database import GuildSettings as GuildSettingsModel, JoinLeave
from dotenv import load_dotenv
from database import GuildSettings as GuildSettingsModel, JoinLeave
bot = Client(intents=Intents.ALL, debug_scope=387153131378835456)
@ -37,7 +32,7 @@ async def on_ready():
if guild_q is None:
guild_q = GuildSettingsModel(guild_id=guild.id)
guild_q.save()
# @listen()
@ -84,7 +79,6 @@ async def on_member_leave(event: events.MemberRemove):
await channel.send(str(joinleave_q.leave_message).format(member=event.member, guild=event.guild))
@slash_command(name="ping", description="Ping the bot")
@ -158,7 +152,7 @@ def main():
# Load extensions
bot.load_extension("heimdallr.commands.admin")
bot.load_extension("heimdallr.commands.gatekeep")
bot.load_extension("heimdallr.commands.gatekeep")
bot.load_extension("heimdallr.commands.quote")
bot.load_extension("heimdallr.commands.infractions")
bot.load_extension("heimdallr.commands.self_roles")
@ -167,4 +161,4 @@ def main():
bot.start(getenv("DISCORD_TOKEN"))
if __name__ == "__main__":
main()
main()

View File

@ -1,3 +1,4 @@
# pylint: disable=consider-using-f-string
import logging
from typing import Optional
from naff import (

View File

@ -6,7 +6,6 @@ from naff import (
Client,
Extension,
slash_command,
slash_option,
InteractionContext,
Modal,
ParagraphText,
@ -22,7 +21,7 @@ from database import BotMessages as BotMessagesModel
# Template modal for creating/editing bot messages.
message_creation_modal = Modal(
custom_id="bot-message-create",
title=f"Create a message as the bot",
title="Create a message as the bot",
components=[
ParagraphText(
custom_id="embeds",
@ -52,17 +51,16 @@ class BotMessages(Extension):
default_member_permissions=Permissions.MANAGE_GUILD,
)
async def bot_message_create_command(self, ctx: InteractionContext):
# Respond with the template modal. No values have been set in the modal, as it is
# a new message.
await ctx.send_modal(message_creation_modal)
# Wait for the user to submit the modal, and ensure that we are receiving the
# correct modal.
modal_ctx: ModalContext = await self.client.wait_for_modal(message_creation_modal, author=ctx.author)
if modal_ctx.custom_id != "bot-message-create":
return
# Retrieve the values from the modal.
# Ensure that at least one of the fields is filled in, as a message cannot be
# empty.
@ -84,7 +82,7 @@ class BotMessages(Extension):
# If the JSON is invalid, return an error.
embed: dict | None = None
embeds: list | None = None
try:
if embeds_string:
embeds_temp = json.loads(embeds_string)
@ -98,7 +96,7 @@ class BotMessages(Extension):
ephemeral=True,
)
return
# Send the bot message in the channel.
msg = await ctx.channel.send(
content=content_string if content_string else None,
@ -165,13 +163,13 @@ class BotMessages(Extension):
# Send the modal to the user
await ctx.send_modal(modal)
# Wait for the user to submit the modal, and ensure that we are receiving the
# correct modal.
modal_ctx: ModalContext = await self.client.wait_for_modal(modal, author=ctx.author)
if modal_ctx.custom_id != "bot-message-edit":
return
embeds_string: str = modal_ctx.responses["embeds"]
content_string: str = modal_ctx.responses["content"]
if (
@ -186,7 +184,7 @@ class BotMessages(Extension):
embed: dict | None = None
embeds: list | None = None
try:
if embeds_string:
embeds_temp = json.loads(embeds_string)
@ -200,7 +198,7 @@ class BotMessages(Extension):
ephemeral=True,
)
return
await message.edit(
content=content_string if content_string else None,
embed=embed,

View File

@ -1,5 +1,6 @@
import logging
import random, string
import random
import string
from io import BytesIO
from naff import (
Extension,
@ -17,7 +18,6 @@ from naff import (
SlashCommandChoice,
Button,
ButtonStyles,
Embed,
)
from naff.api import events
from naff.models.discord.enums import Permissions
@ -60,12 +60,12 @@ class Gatekeep(Extension):
),
],
)
async def set_type_command(self, ctx: InteractionContext, type: str):
async def set_type_command(self, ctx: InteractionContext, type_: str):
gk: GatekeepModel
gk, _ = GatekeepModel.get_or_create(guild_id=ctx.guild.id)
gk.gatekeep_method = type
gk.gatekeep_method = type_
gk.save()
await ctx.send(f"Gatekeep type set to {type}", ephemeral=True)
await ctx.send(f"Gatekeep type set to {type_}", ephemeral=True)
@slash_command(
name="gatekeep",
@ -193,7 +193,8 @@ class Gatekeep(Extension):
if not welcome_channel:
await ctx.send(
f"{user.mention} has been approved.\nNB: No welcome channel has been set attempting to DM {user.mention}",
(f"{user.mention} has been approved.\n"
f"NB: No welcome channel has been set attempting to DM {user.mention}"),
ephemeral=True,
)
await user.send(
@ -204,7 +205,8 @@ class Gatekeep(Extension):
channel = await ctx.guild.fetch_channel(jl.message_channel)
if not channel:
await ctx.send(
f"{user.mention} has been approved.\nNB: No welcome channel has been set attempting to DM {user.mention}",
(f"{user.mention} has been approved.\n"
f"NB: No welcome channel has been set attempting to DM {user.mention}"),
ephemeral=True,
)
await user.send(
@ -406,10 +408,6 @@ class Gatekeep(Extension):
await ctx.message.delete()
def setup(client: Client):
GatekeepModel.create_table()
GatekeepCaptchasModel.create_table()

View File

@ -1,3 +1,4 @@
# pylint: disable=unsubscriptable-object
import logging
from typing import List, Optional
from naff import (
@ -63,7 +64,6 @@ class Infractions(Extension):
# await ctx.send(embed=embeds, ephemeral=True)
paginator = Paginator.create_from_embeds(self.client, *embeds)
await paginator.send(ctx)
paginator.send
@slash_command(
name="user-infractions",
@ -226,16 +226,16 @@ class Infractions(Extension):
guild_settings: Optional[GuildSettings] = GuildSettings.get_or_none(GuildSettings.guild_id == int(ctx.guild_id))
if guild_settings is not None:
if guild_settings.admin_channel is not None:
admin_channel = await self.client.fetch_channel(int(guild_settings.admin_channel))
if admin_channel is not None:
await admin_channel.send(embed=Embed(
title=f"Warned {user.display_name} ({user.username}#{user.discriminator}, {user.id})",
description=f"{reason}",
color=infraction_colour(0x0000FF),
fields=[
],
))
if guild_settings.admin_channel is not None:
admin_channel = await self.client.fetch_channel(int(guild_settings.admin_channel))
if admin_channel is not None:
await admin_channel.send(embed=Embed(
title=f"Warned {user.display_name} ({user.username}#{user.discriminator}, {user.id})",
description=f"{reason}",
color=infraction_colour(0x0000FF),
fields=[
],
))
if not silent and warning_msg is None:
await ctx.send(

View File

@ -1,8 +1,10 @@
# pylint: disable=not-an-iterable
# pylint: disable=unsubscriptable-object
# pylint: disable=logging-fstring-interpolation
from datetime import datetime, timedelta
import logging
import json
from time import sleep
from typing import Dict, List, Tuple
from typing import List, Tuple
from naff import (
Client,
Extension,
@ -29,8 +31,8 @@ from naff import (
from naff.api import events
from naff.client.errors import HTTPException
from database import Polls as PollsModel, PollVotes as PollVotesModel
from peewee import fn
from database import Polls as PollsModel, PollVotes as PollVotesModel
PollOptions = List[Tuple[str | None, str]]
@ -43,7 +45,7 @@ def datetime_to_discord_relative_time(dt: datetime) -> str:
def generate_bar(num: int, total: int, length: int = 10) -> str:
"""Create a bar graph from a number and a total.
Parameters
----------
num : int
@ -77,7 +79,7 @@ def generate_poll_embed(
expires: datetime = None,
) -> Embed:
"""Create a poll embed from a title, options and votes.
Parameters
----------
title : str
@ -114,7 +116,7 @@ def generate_poll_embed(
return embed
def num_to_emoji(num: int) -> str:
def num_to_emoji(num: int) -> str: # pylint: disable=too-many-return-statements
match num:
case 0:
return "0"
@ -140,7 +142,7 @@ def num_to_emoji(num: int) -> str:
return "🔟"
case _:
raise ValueError(f"Invalid number: `num` must be 0 <= num <= 10.")
raise ValueError("Invalid number: `num` must be 0 <= num <= 10.")
class Polls(Extension):
@ -150,7 +152,7 @@ class Polls(Extension):
@listen(events.Ready)
async def on_ready(self):
await self.poll_expiry_check()
self.poll_expiry_check.start()
self.poll_expiry_check.start() # pylint: disable=no-member
@slash_command(
name="polls",
@ -178,7 +180,7 @@ class Polls(Extension):
required=False,
opt_type=OptionTypes.BOOLEAN,
)
async def create_poll(
async def create_poll( # pylint: disable=too-many-locals
self,
ctx: InteractionContext,
*,
@ -307,7 +309,7 @@ class Polls(Extension):
poll_entry.save()
@listen(events.Button)
async def on_button(self, button: events.Button):
async def on_button(self, button: events.Button): #pylint: disable=too-many-branches,too-many-statements
ctx = button.context
# Ensure that the pressed button is a vote button.
@ -404,7 +406,7 @@ class Polls(Extension):
options: PollOptions = json.loads(poll_entry.options)
votes = len(options) * [0]
for i, vote in enumerate(votes_q):
for vote in votes_q:
votes[int(vote.option)] = vote.count
embed = generate_poll_embed(
@ -466,7 +468,7 @@ class Polls(Extension):
# Delete associated database entries, as they will no longer be updated.
PollVotesModel.delete().where(PollVotesModel.poll_id == poll_entry.id).execute()
poll_entry.delete_instance()
def setup(client: Client):

View File

@ -1,4 +1,4 @@
from re import S
# pylint: disable=not-an-iterable
from typing import Dict, List, Optional, Tuple
import logging
from naff import (
@ -11,7 +11,6 @@ from naff import (
InteractionContext,
Role,
Embed,
EmbedField,
AutocompleteContext,
Select,
SelectOption,
@ -21,7 +20,6 @@ from naff import (
Message,
)
from naff.api import events
from naff import components
from database import (
SelfRoles as SelfRolesModel,
SelfRoleGroups as SelfRoleGroupsModel,
@ -544,11 +542,11 @@ class SelfRoles(Extension):
async def role_group_regenerate(self, ctx: InteractionContext):
await ctx.defer(ephemeral=True)
msg: Message = ctx.target
if msg.author.id != self.client.user.id:
await ctx.send("This message is not from the bot!", ephemeral=True)
return
if (
len(msg.embeds) < 1
or msg.embeds[0].title is None
@ -621,10 +619,6 @@ class SelfRoles(Extension):
await ctx.send("Role group message regenerated!", ephemeral=True)
@slash_command(
name="role",
description="Manage your roles",
@ -648,7 +642,7 @@ class SelfRoles(Extension):
)
if role_q is None:
await ctx.send(f"Failed to retrieve self-role.", ephemeral=True)
await ctx.send("Failed to retrieve self-role.", ephemeral=True)
return
role = await ctx.guild.fetch_role(role)
@ -732,7 +726,7 @@ class SelfRoles(Extension):
await ctx.defer(ephemeral=True)
role = await ctx.guild.fetch_role(role)
if role is None:
await ctx.send(f"Failed to retrieve role.", ephemeral=True)
await ctx.send("Failed to retrieve role.", ephemeral=True)
return
if role not in ctx.author.roles: