From 14b50dbcb358fb4de0b808fad1347839de0ab7b5 Mon Sep 17 00:00:00 2001 From: Bobbyperson Date: Fri, 6 Sep 2024 11:06:26 -0400 Subject: [PATCH] fix ruff --- cogs/utils/econfuncs.py | 3 +-- cogs/utils/miscfuncs.py | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/cogs/utils/econfuncs.py b/cogs/utils/econfuncs.py index 6a285dd..0a05196 100644 --- a/cogs/utils/econfuncs.py +++ b/cogs/utils/econfuncs.py @@ -334,7 +334,6 @@ async def update_winloss(user, wl): async def formatted_winloss(user): current = await get_winloss(user) formatted = [] - funny = rd.randint(1, 100) for i in range(len(current)): if current[i] == "w": formatted.append(":green_square:") @@ -362,7 +361,7 @@ async def get_random_item(): # get specific map async def get_item(item): - file_path = f"maps/maps.txt" + file_path = "maps/maps.txt" if os.path.exists(file_path): with open(file_path, encoding="utf-8") as f: maps = [line.rstrip() for line in f.readlines()] diff --git a/cogs/utils/miscfuncs.py b/cogs/utils/miscfuncs.py index 5516154..81cda89 100644 --- a/cogs/utils/miscfuncs.py +++ b/cogs/utils/miscfuncs.py @@ -1,8 +1,7 @@ -from PIL import Image, ImageDraw, ImageFont +from PIL import Image, ImageDraw import time import math import random as rd -import discord import aiosqlite @@ -14,14 +13,14 @@ bank = "./data/database.sqlite" -def findMean(arr, l, r): +def findMean(arr, left, right): # Both sum and count are # initialize to 0 sum, count = 0, 0 # To calculate sum and number # of elements in range l to r - for i in range(l, r + 1): + for i in range(left, right + 1): sum += arr[i] count += 1 # Calculate floor value of mean @@ -80,10 +79,10 @@ async def send_webhook(ctx, name, avatar, message): name="Nocaro_NPC", reason="npc event" ) msg = await webhook.send(content=message, avatar_url=avatar, username=name) - except: + except: # noqa: E722 try: msg = await ctx.send(f"{name}: {message}") - except: + except: # noqa: E722 msg = await ctx.channel.send(f"{name}: {message}") return msg @@ -126,12 +125,15 @@ def draw_rotated_text(image, angle, xy, text, fill, *args, **kwargs): color_image = Image.new("RGBA", image.size, fill) image.paste(color_image, mask) + async def is_blacklisted(*args): db = await aiosqlite.connect(bank, timeout=10) cursor = await db.cursor() current_time = get_unix() for user_id in args: - await cursor.execute(f"SELECT * FROM blacklist WHERE user_id={user_id} AND (timestamp > {current_time} OR timestamp = 0)") + await cursor.execute( + f"SELECT * FROM blacklist WHERE user_id={user_id} AND (timestamp > {current_time} OR timestamp = 0)" + ) result = await cursor.fetchone() if result: await cursor.close() @@ -141,10 +143,13 @@ async def is_blacklisted(*args): await db.close() return False, 0 + async def blacklist_user(user_id, timestamp): db = await aiosqlite.connect(bank, timeout=10) cursor = await db.cursor() - await cursor.execute(f"INSERT INTO blacklist (user_id, timestamp) VALUES ({user_id}, {timestamp})") + await cursor.execute( + f"INSERT INTO blacklist (user_id, timestamp) VALUES ({user_id}, {timestamp})" + ) await db.commit() await cursor.close() - await db.close() \ No newline at end of file + await db.close()