Skip to content

Commit

Permalink
fix ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobbyperson committed Sep 6, 2024
1 parent 9705709 commit 14b50db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
3 changes: 1 addition & 2 deletions cogs/utils/econfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down Expand Up @@ -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()]
Expand Down
23 changes: 14 additions & 9 deletions cogs/utils/miscfuncs.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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()
await db.close()

0 comments on commit 14b50db

Please sign in to comment.