Skip to content

Commit

Permalink
Added database + used formater
Browse files Browse the repository at this point in the history
  • Loading branch information
FanaticExplorer committed Jan 6, 2022
1 parent 2c2a521 commit aea3533
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/%SystemDrive%/ProgramData/Microsoft/Windows/Caches/cversions.2.db
/%SystemDrive%/ProgramData/Microsoft/Windows/Caches/{6AF0698E-D558-4F6E-9B3C-3716689AF493}.2.ver0x0000000000000001.db
/%SystemDrive%/ProgramData/Microsoft/Windows/Caches/{9315FC40-D984-4247-A2C7-1C70F63EF486}.2.ver0x0000000000000001.db
/%SystemDrive%/ProgramData/Microsoft/Windows/Caches/{DDF571F2-BE98-426D-8288-1A9A39C3FDA2}.2.ver0x0000000000000001.db
/%SystemDrive%/ProgramData/Microsoft/Windows/Caches/{F219A7FD-A3BE-48BD-A541-FA063C25677B}.2.ver0x0000000000000001.db
__pycache__/eolymp.cpython-39.pyc
36 changes: 16 additions & 20 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,34 @@
import eolymp as eo


description = '''I will give any information about any profile on Eolymp.
My github: https://github.com/FanaticExplorer/Eolymp_bot'''
description = """I will give any information about any profile on Eolymp.
My github: https://github.com/FanaticExplorer/Eolymp_bot"""

bot = commands.Bot(command_prefix=">", description=description)
place_of_launch = os.environ.get("place")
if place_of_launch == "heroku":
bot_token = os.environ.get("bot_token")
elif place_of_launch == "local":
bot_token = os.environ.get("test_bot_token")

bot = commands.Bot(command_prefix='>', description=description)
place_of_launch=os.environ.get('place')
if place_of_launch=='heroku':
bot_token=os.environ.get('bot_token')
elif place_of_launch=='local':
bot_token=os.environ.get('test_bot_token')

@bot.event
async def on_ready():
print('Logged in as')
print("Logged in as")
print(bot.user.name)
print(bot.user.id)
print('------')



print("------")


@bot.command()
async def get_info(ctx, username):
user = eo.parser(username)
embed = discord.Embed(color = 0xff9900,
title = username,
url = user.get_profile_url())
embed = discord.Embed(color=0xFF9900, title=username, url=user.get_profile_url())
embed.set_thumbnail(url=user.get_photo_link())
embed.add_field(name = "Ранг", value=user.get_rating(), inline = False)
embed.add_field(name = "Решенные задачи", value = user.get_solved(), inline = True)
embed.add_field(name = "Отправки", value = user.get_total_submissions(), inline = True)
embed.add_field(name = "Засчитанные решения", value = user.get_submits(), inline = True)
embed.add_field(name="Ранг", value=user.get_rating(), inline=False)
embed.add_field(name="Решенные задачи", value=user.get_solved(), inline=True)
embed.add_field(name="Отправки", value=user.get_total_submissions(), inline=True)
embed.add_field(name="Засчитанные решения", value=user.get_submits(), inline=True)
embed.add_field(name="Последняя задача", value=user.get_last(), inline=False)
embed.set_footer(text="Спросил: {}".format(ctx.author.display_name))
await ctx.send(embed=embed)
Expand Down
32 changes: 32 additions & 0 deletions db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sqlite3


class BotDB:
def __init__(self, db_file):
print("opening")
self.conn = sqlite3.connect(db_file)
self.cursor = self.conn.cursor()

def leaderboard(self, discord_group_id, out):
result = self.cursor.execute(
"SELECT `eolymp_nickname`, `discord_user_id` FROM `users` WHERE `discord_group_id` = ?",
(discord_group_id,),
)
bd_users_output = result.fetchall()
if out:
users = []
for user in bd_users_output:
users.append(user[0])
return users
else:
return bd_users_output

def close(self):
"""Закрываем соединение с БД"""
print("closing")
self.conn.close()


botDB_ = BotDB("eolymp_users.db")
print(botDB_.leaderboard(909078994568228865, True))
botDB_.close()
Binary file added eolymp_users.db
Binary file not shown.

0 comments on commit aea3533

Please sign in to comment.