Skip to content

Commit

Permalink
fix: pay regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Qwenty228 committed Oct 9, 2023
1 parent 90c6ffc commit 86d5f4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ Before you can run this bot, make sure you have the following installed:

5. In the `.env` file, define the following environment variables:
- `TOKEN`: Your API token or secret key.
- `CLIENT_ID` : Your discord client id.
- `DB_HOST`: The hostname or IP address of your database server.
- `DB_PORT` : The port of your database server.
- `DB_USER`: The username for connecting to the database.
- `DB_PASSWORD`: The password for the database user.
- `DB_PASS`: The password for the database user.
- `DB_NAME`: The name of your database.

The `.env` file should look like this:

```plaintext
TOKEN=your_api_token_here
CLIENT_ID=your_bot_client_id_here
DB_HOST=your_database_host_here
DB_PORT=your_database_port_here
DB_USER=your_database_user_here
DB_PASSWORD=your_database_password_here
DB_PASS=your_database_password_here
DB_NAME=your_database_name_here
```

Expand Down
8 changes: 5 additions & 3 deletions cogs/Citizen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from utils.embeds import user_embed, qr_confirmation_embed
from utils.views import Show_User_View, Confirmation_View
from utils.promptpay import PromptPay
from utils.pattern_check import image_path_check

class Citizen(commands.Cog):
def __init__(self, bot: 'Oppy') -> None:
Expand Down Expand Up @@ -53,6 +54,7 @@ async def __set_phone(self, interaction: discord.Interaction, phone: str, user:
async def __show_user(self, interaction: discord.Interaction, user: discord.Member, ephemeral: bool = False):
"""Shows the user's account information."""
await interaction.response.defer(ephemeral=ephemeral)
await self.__ensure_user(user)
try:
if (old := self._routine.get(interaction.user.id)):
m, v = old
Expand Down Expand Up @@ -133,9 +135,9 @@ async def set_phone(self, ctx: commands.Context, phone: str, user: typing.Union[
await self.__set_phone(ctx, phone, user, ephemeral)

@app_commands.command()
async def show_user(self, ctx: discord.Interaction, user: discord.Member, ephemeral: bool = False):
async def show_user(self, interaction: discord.Interaction, user: discord.Member, ephemeral: bool = False):
"""Shows the user's account information."""
await self.__show_user(ctx, user, ephemeral)
await self.__show_user(interaction, user, ephemeral)

@app_commands.command()
async def set_qr(self, interaction: discord.Interaction, qr: discord.Attachment, user: typing.Union[discord.User, None], ephemeral: bool = True):
Expand All @@ -151,7 +153,7 @@ async def pay(self, interaction: discord.Interaction, amount: float = 0.00, user
user = interaction.user
await self.__ensure_user(user)
content = f"```Paying {user.display_name} {amount} Baht```" if amount else f"Paying {user.display_name}"
if (qr:= await self.bot.database.get_user_qr(user)) != '0':
if (qr:= await self.bot.database.get_user_qr(user)) != '0' and image_path_check(qr):
await interaction.response.send_message(content=content, file=discord.File(fp=qr, filename="qr.png"))
elif (p := await self.bot.database.get_user_phone(user)) != '0':
await interaction.response.send_message(content=content, file=discord.File(fp=PromptPay.to_byte_QR(p, amount), filename="qr.png"))
Expand Down

0 comments on commit 86d5f4d

Please sign in to comment.