fix ruff linting errors

This commit is contained in:
LBlend committed 2023-04-28 21:49:59 +09:00
1 parent aade6689b6
commit f0d8a73706
5 files changed
+23 -20

No files matched your search

+6 -6
View File
@@ -115,7 +115,7 @@ class Birthday(commands.Cog):
self.cursor.execute(
"""
SELECT *, CAST(birthday + ((EXTRACT(YEAR FROM AGE(birthday)) + 1) * interval '1' YEAR) AS DATE) AS next_fbirthday
SELECT *, CAST(birthday + ((EXTRACT(YEAR FROM AGE(birthday)) + 1) * interval '1' YEAR) AS DATE) AS next_bday
FROM birthdays
WHERE discord_id = %s
""",
@@ -135,15 +135,15 @@ class Birthday(commands.Cog):
Returns
----------
(list[tuple[int, datetime, datetime]]): A list of tuples containing the user ID, the date of birth and the next birthday
(list[tuple[int, datetime, datetime]]): List of tuples containing the user ID, date of birth and next birthday
"""
self.cursor.execute(
"""
SELECT *, CAST(birthday + ((EXTRACT(YEAR FROM AGE(birthday)) + 1) * interval '1' YEAR) AS DATE) AS next_birthday
FROM birthdays
ORDER BY next_birthday ASC
LIMIT 5
SELECT *, CAST(birthday + ((EXTRACT(YEAR FROM AGE(birthday)) + 1) * interval '1' YEAR) AS DATE) AS next_bday
FROM birthdays
ORDER BY next_birthday ASC
LIMIT 5
"""
)
results = self.cursor.fetchall()
+4 -1
View File
@@ -175,8 +175,11 @@ class Gullkorn(commands.Cog):
most_cited_string = self.__construct_data_string(most_cited)
citations_posted_string = self.__construct_data_string(citations_posted)
gullkorn_first_msg = "https://canary.discord.com/channels/" + \
"747542543750660178/865970753748074576/1034587913285025912"
embed = discord.Embed(title="Gullkornstatistikk for serveren")
embed.description = f"Antall gullkorn siden [denne meldingen](https://canary.discord.com/channels/747542543750660178/865970753748074576/1034587913285025912): *{summary[0]}*"
embed.description = f"Antall gullkorn siden [denne meldingen]({gullkorn_first_msg}): *{summary[0]}*"
embed.add_field(name="Mest sitert", value=most_cited_string, inline=False)
embed.add_field(name="Postet mest", value=citations_posted_string, inline=False)
await interaction.response.send_message(embed=embed, ephemeral=False)
+5 -5
View File
@@ -66,7 +66,7 @@ class Info(commands.Cog):
# Use map instead of list comprehension because I can divide the code into 2 lines
boosters = list(
map(
lambda booster: f"{booster.name}#{booster.discriminator} - {discord.utils.format_dt(booster.premium_since)}",
lambda b: f"{b.name}#{b.discriminator} - {discord.utils.format_dt(b.premium_since)}",
sorted(interaction.guild.premium_subscribers, key=lambda m: m.premium_since),
)
)
@@ -158,7 +158,7 @@ class Info(commands.Cog):
roles = (
roles
if len(roles) < 1024
else f'Bruk `/{self.bot.tree.get_command("guild").get_command("roller").qualified_name}` for å se rollene'
else f"Bruk `/{self.bot.tree.get_command('guild').get_command('roller').qualified_name}` for å se rollene"
)
# Boosts
@@ -166,7 +166,7 @@ class Info(commands.Cog):
boosters = (
boosters
if len(boosters) < 1024
else f'Bruk `/{self.bot.tree.get_command("guild").get_command("boosters").qualified_name}` for å se boostere'
else f"Bruk `/{self.bot.tree.get_command('guild').get_command('boosters').qualified_name}` for å se boostere" # noqa: E501
)
# Channels counts
@@ -564,7 +564,7 @@ class Info(commands.Cog):
# Create list of members with index, name#discriminator and creation date
members_formatted = list(
map(
lambda m: f'**#{(m[0] + 1)}** {m[1].name}#{m[1].discriminator} - {discord.utils.format_dt(m[1].created_at, style="F")}',
lambda m: f'**#{(m[0] + 1)}** {m[1].name}#{m[1].discriminator} - {discord.utils.format_dt(m[1].created_at, style="F")}', # noqa: E501
enumerate(members),
)
)
@@ -600,7 +600,7 @@ class Info(commands.Cog):
# Create list of members with index, name#discriminator and creation date
members_formatted = list(
map(
lambda m: f'**#{(m[0] + 1)}** {m[1].name}#{m[1].discriminator} - {discord.utils.format_dt(m[1].joined_at, style="F")}',
lambda m: f'**#{(m[0] + 1)}** {m[1].name}#{m[1].discriminator} - {discord.utils.format_dt(m[1].joined_at, style="F")}', # noqa: E501
enumerate(members),
)
)
-1
View File
@@ -1,4 +1,3 @@
import asyncio
import random
import aiocron
+8 -7
View File
@@ -9,6 +9,7 @@ from io import StringIO
import discord
import nltk
import numpy as np
import psycopg2
from discord import app_commands
from discord.ext import commands
from discord.ext import tasks
@@ -115,9 +116,9 @@ class WordCloud(commands.Cog):
""",
word_freqs,
)
except:
except psycopg2.Error as err:
self.bot.db_connection.rollback()
self.bot.logger.exception("Failed to insert wordcloud cache into database")
self.bot.logger.error(f"Failed to insert wordcloud cache into database - {err}")
self.word_freq_cache.clear()
@@ -231,14 +232,14 @@ class WordCloud(commands.Cog):
try:
self.cursor.execute(
"""
INSERT INTO wordcloud_metadata (discord_user_id, tracked_since_message_channel_id, tracked_since_message_id)
INSERT INTO wordcloud_metadata
VALUES (%s, %s, %s)
""",
(interaction.user.id, interaction.channel_id, interaction.id),
)
except:
except psycopg2.Error as err:
self.bot.db_connection.rollback()
self.bot.logger.exception("Failed to insert wordcloud metadata into database")
self.bot.logger.error(f"Failed to insert wordcloud metadata into database - {err}")
return await interaction.response.send_message(
embed=embed_templates.error_warning(interaction, text="Klarte ikke å skrive til database"),
ephemeral=False,
@@ -277,9 +278,9 @@ class WordCloud(commands.Cog):
""",
(interaction.user.id, interaction.user.id),
)
except:
except psycopg2.Error as err:
self.bot.db_connection.rollback()
self.bot.logger.exception("Failed to delete wordcloud metadata from database")
self.bot.logger.error(f"Failed to delete wordcloud metadata from database - {err}")
return await interaction.response.send_message(
embed=embed_templates.error_warning(interaction, text="Klarte ikke å slette fra database"),
ephemeral=False,