Skip to content

Commit

Permalink
Merge pull request #31 from hirusha-adi/use-database
Browse files Browse the repository at this point in the history
Use database
  • Loading branch information
hirusha-adi authored Nov 22, 2024
2 parents 7bc0f89 + 044f8fd commit 1ad2f19
Show file tree
Hide file tree
Showing 24 changed files with 597 additions and 271 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ __pycache__/
instance/
.webassets-cache
test.py

# Database stuff
*dev*.db*
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Near - Discord bot of TeamSDS
# Near - A discord bot for Team SDS

<p align="center">
<img src="https://user-images.githubusercontent.com/36286877/208341567-6706e40f-03b5-4e29-836c-760708f2e619.png" alt="Lisence">
<img src="https://raw.githubusercontent.com/hirusha-adi/Near-Data/refs/heads/main/images/github/github-banner.png" alt="Lisence">
<br>
<img src="https://img.shields.io/github/license/hirusha-adi/Near?style=for-the-badge" alt="Lisence">
<img src="https://img.shields.io/github/last-commit/hirusha-adi/Near?style=for-the-badge" alt="Last Commit">
Expand Down
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# NearBot v0.8

1. Use a database with an asyncio supported ORM (`tortoise-orm`)
2. Optmized code in `nearbot.py`
3. Document the code (with the help of Codeium)
4. Fixed broken `loadex` and `unloadex` commands
5. Fixed the issue with embed thumbnails, by storing images in [this](https://github.com/hirusha-adi/Near-Data) repository

# NearBot v0.7.3

1. Update dependencies:
Expand Down
4 changes: 2 additions & 2 deletions near/cogs/administration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def move(self,interaction: discord.Interaction,channel_to: discord.VoiceCh
# https://discordpy.readthedocs.io/en/stable/api.html#discord.Member.move_to
await member.move_to(channel_to)

embed = embeds.Common(
embed = await embeds.Common(
client=self.client,
interaction=interaction,
title="Moved members!",
Expand All @@ -60,7 +60,7 @@ async def move(self,interaction: discord.Interaction,channel_to: discord.VoiceCh
await interaction.response.send_message(embed=embed)

except Exception as e:
await interaction.response.send_message(embed=embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"),ephemeral=False)
await interaction.response.send_message(embed=await embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"),ephemeral=False)


async def setup(client: commands.Bot):
Expand Down
48 changes: 24 additions & 24 deletions near/cogs/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class Crypto(commands.Cog):
def __init__(self, client: commands.Bot):
self.client = client

@app_commands.command(name="btc", description="Get the current Bitcoin Rates")
async def btc(self, interaction: discord.Interaction):
logger.info(f"Command invoked by {interaction.user.name} ({interaction.user.id}) in {interaction.guild} ({interaction.guild_id})")
Expand All @@ -21,19 +21,19 @@ async def btc(self, interaction: discord.Interaction):
async with session.get('https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,EUR') as response:
r = await response.json()

embed = embeds.Common(
embed = await embeds.Common(
client=self.client,
interaction=interaction,
title="Bitcoin",
thumbnail="https://cdn.pixabay.com/photo/2013/12/08/12/12/bitcoin-225079_960_720.png",
thumbnail="crypto_btc",
)
embed.add_field(name="USD", value=f"{r['USD']}$", inline=False)
embed.add_field(name="EUR", value=f"{r['EUR']}€", inline=False)
await interaction.response.send_message(embed=embed)

except Exception as e:
await interaction.response.send_message(embed=embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)
await interaction.response.send_message(embed=await embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)

@app_commands.command(name="eth", description="Get the current Etherium Rates")
async def eth(self, interaction: discord.Interaction):
logger.info(f"Command invoked by {interaction.user.name} ({interaction.user.id}) in {interaction.guild} ({interaction.guild_id})")
Expand All @@ -42,18 +42,18 @@ async def eth(self, interaction: discord.Interaction):
async with session.get('https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD,EUR') as response:
r = await response.json()

embed = embeds.Common(
embed = await embeds.Common(
client=self.client,
interaction=interaction,
title="Ethereum",
thumbnail="https://cdn.discordapp.com/attachments/271256875205525504/374282740218200064/2000px-Ethereum_logo.png",
thumbnail="crypto_eth",
)
embed.add_field(name="USD", value=f"{r['USD']}$", inline=False)
embed.add_field(name="EUR", value=f"{r['EUR']}€", inline=False)
await interaction.response.send_message(embed=embed)

except Exception as e:
await interaction.response.send_message(embed=embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)
await interaction.response.send_message(embed=await embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)

@app_commands.command(name="xmr", description="Get the current Monero Rates")
async def xmr(self, interaction: discord.Interaction):
Expand All @@ -62,19 +62,19 @@ async def xmr(self, interaction: discord.Interaction):
async with aiohttp.ClientSession() as session:
async with session.get('https://min-api.cryptocompare.com/data/price?fsym=XMR&tsyms=USD,EUR') as response:
r = await response.json()
embed = embeds.Common(

embed = await embeds.Common(
client=self.client,
interaction=interaction,
title="Monero",
thumbnail="https://cdn.discordapp.com/attachments/940889393974104084/1073564308979597312/monero-xmr-logo.png",
thumbnail="crypto_xmr",
)
embed.add_field(name="USD", value=f"{r['USD']}$", inline=False)
embed.add_field(name="EUR", value=f"{r['EUR']}€", inline=False)
await interaction.response.send_message(embed=embed)

except Exception as e:
await interaction.response.send_message(embed=embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)
await interaction.response.send_message(embed=await embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)

@app_commands.command(name="doge", description="Get the current Doge Coin Rates")
async def doge(self, interaction: discord.Interaction):
Expand All @@ -83,19 +83,19 @@ async def doge(self, interaction: discord.Interaction):
async with aiohttp.ClientSession() as session:
async with session.get('https://min-api.cryptocompare.com/data/price?fsym=DOGE&tsyms=USD,EUR') as response:
r = await response.json()
embed = embeds.Common(

embed = await embeds.Common(
client=self.client,
interaction=interaction,
title="Doge Coin",
thumbnail="https://cdn.discordapp.com/attachments/940889393974104084/1073564685061861388/Dogecoin_Logo.png",
thumbnail="crypto_doge",
)
embed.add_field(name="USD", value=f"{r['USD']}$", inline=False)
embed.add_field(name="EUR", value=f"{r['EUR']}€", inline=False)
await interaction.response.send_message(embed=embed)

except Exception as e:
await interaction.response.send_message(embed=embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)
await interaction.response.send_message(embed=await embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)

@app_commands.command(name="xrp", description="Get the current XRP Rates")
async def xrp(self, interaction: discord.Interaction):
Expand All @@ -104,19 +104,19 @@ async def xrp(self, interaction: discord.Interaction):
async with aiohttp.ClientSession() as session:
async with session.get('https://min-api.cryptocompare.com/data/price?fsym=XRP&tsyms=USD,EUR') as response:
r = await response.json()
embed = embeds.Common(

embed = await embeds.Common(
client=self.client,
interaction=interaction,
title="Ripple",
thumbnail="https://cdn.discordapp.com/attachments/940889393974104084/1073565079410319430/free-ripple-coin-icon-2208-thumb.png",
thumbnail="crypto_xrp",
)
embed.add_field(name="USD", value=f"{r['USD']}$", inline=False)
embed.add_field(name="EUR", value=f"{r['EUR']}€", inline=False)
await interaction.response.send_message(embed=embed)

except Exception as e:
await interaction.response.send_message(embed=embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)
await interaction.response.send_message(embed=await embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)

@app_commands.command(name="rvn", description="Get the current Raven Coin Rates")
async def rvn(self, interaction: discord.Interaction):
Expand All @@ -127,19 +127,19 @@ async def rvn(self, interaction: discord.Interaction):
soup = BeautifulSoup(response.content, "html.parser")
raven_coin_value = soup.find_all("span", {"class": "currency-pricestyles__Price-sc-1rux8hj-0 jxzQXk"})[0].text
change_percentage = soup.find_all("h6", {"class": "typography__StyledTypography-owin6q-0 hZxwDe"})[0].text
embed = embeds.Common(

embed = await embeds.Common(
client=self.client,
interaction=interaction,
title="Ravencoin",
thumbnail="https://cdn.discordapp.com/attachments/940889393974104084/1073566855593197600/ravencoin-rvn-logo.png",
thumbnail="crypto_rvn",
)
embed.add_field(name="USD", value=f"{raven_coin_value}", inline=False)
embed.add_field(name="24 Hour Change %", value=f"{change_percentage}", inline=False)
await interaction.response.send_message(embed=embed)

except Exception as e:
await interaction.response.send_message(embed=embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)
await interaction.response.send_message(embed=await embeds.Error(interaction=interaction, client=self.client, error_message=f"{e}"), ephemeral=False)


async def setup(client: commands.Bot):
Expand Down
Loading

0 comments on commit 1ad2f19

Please sign in to comment.