Skip to content

Commit

Permalink
Fixed error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
PoIarStar committed Apr 22, 2023
1 parent 054244c commit 8c814c8
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions cogs/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ async def create_work(self, inter, name, wages: int, requirement_level: int = 1,
await inter.response.send_message('Валюта по-умолчанию настроена неправильно')
return
currency = currency[0]
cur.execute(f"SELECT id FROM currencies WHERE name = '{currency}' and system = {system}")
currency = cur.fetchone()
if not currency:
await inter.response.send_message('Название валюты указано неверно')
return
currency = currency[0]
cur.execute(f"INSERT INTO works(name, currency, wages, req_lvl, system) VALUES"
f" ('{name}', '{currency}', {wages}, {requirement_level}, {system})")
conn.commit()
Expand All @@ -176,8 +182,12 @@ async def add_money(self, inter, user: disnake.User, value, currency: str = None
return
currency = currency[0]
cur.execute(f"SELECT id FROM currencies WHERE name = '{currency}' and system = {system}")
num = cur.fetchone()[0]
cur.execute(f"UPDATE users set currency_{num} = currency_{num} + {int(value)} WHERE uid = {user.id} "
currency = cur.fetchone()
if not currency:
await inter.response.send_message('Название валюты указано неверно')
return
currency = currency[0]
cur.execute(f"UPDATE users set currency_{currency} = currency_{currency} + {int(value)} WHERE uid = {user.id} "
f"AND system = {system}")
conn.commit()
await inter.response.send_message(f'{user} получает {value} единиц валюты {currency}.'
Expand Down Expand Up @@ -270,7 +280,11 @@ async def create_item(self, inter, name, description, price: int, currency: str
return
currency = currency[0]
cur.execute(f"SELECT id FROM currencies WHERE system = {system} AND name = '{currency}'")
currency = cur.fetchone()[0]
currency = cur.fetchone()
if not currency:
await inter.response.send_message('Название валюты указано неверно')
return
currency = currency[0]
cur.execute("INSERT INTO SHOP(name, description, currency, price, add_role, remove_role, guild)"
f" VALUES('{name}', '{description}', '{currency}', {price}, "
f"{add_role.id if add_role else 'NULL'}, {remove_role.id if remove_role else 'NULL'},"
Expand Down Expand Up @@ -381,7 +395,11 @@ async def roulette(self, inter, currency: str = None, bullets: int = 1):
return
if randint(1, 6) > bullets:
cur.execute(f"SELECT great_unit, emoji, id FROM currencies WHERE name = '{currency}'")
unit, emoji, id = cur.fetchone()
currency = cur.fetchone()
if not currency:
await inter.response.send_message('Название валюты указано неверно')
return
unit, emoji, id = currency
cur.execute(f'SELECT roulette_cnt FROM users WHERE uid = {inter.author.id} AND system = {system}')
cnt = cur.fetchone()[0]
prize = round(bullets * unit * cnt)
Expand Down

0 comments on commit 8c814c8

Please sign in to comment.