Conversation
src/cogs/gamble.py
Outdated
| await ctx.send('You must enter a positive number greater than 0.', ephemeral=True) | ||
| return | ||
| if amount > user_database_get('money', ctx.author.id): | ||
| await ctx.send('You don\'t have enough money.', ephemeral=True) |
There was a problem hiding this comment.
Rather than escaping you can use "You don't have enough money.". We've done this pretty arbitrarily so far but ig for longer strings double quotes should be preferred
src/cogs/gamble.py
Outdated
| user_database_check_if_user_exists_otherwise_add(user.id) | ||
|
|
||
| embed = discord.Embed(title=f'{user.display_name}\'s wallet', color=discord.Color.blurple()) | ||
| embed.set_thumbnail(url='https://cdn.iconscout.com/icon/free/png-512/free-wallet-588-456730.png') |
There was a problem hiding this comment.
What's the license for that image? If you want we can add it as emoji or sticker so we don't have our bot link to something off-platform that's also entirely out of our control
requirements.txt
Outdated
| discord.py==2.1.0 | ||
| aiohttp==3.8.5 | ||
| python-Levenshtein==0.12.2 | ||
| datetime==5.4 |
There was a problem hiding this comment.
Why do we need a package for that? Isn't python standard library datetime utils sufficient?
src/cogs/gamble.py
Outdated
| from src.util.user_database import * | ||
|
|
||
|
|
||
| daily_amount = 10 |
There was a problem hiding this comment.
please put configuration options in config.py
src/cogs/gamble.py
Outdated
| """ | ||
| Place a bet (50/50). Enter the amount to bet. | ||
| """ | ||
| user_database_check_if_user_exists_otherwise_add(ctx.author.id) |
src/cogs/gamble.py
Outdated
| @commands.hybrid_command(with_app_command=True) | ||
| async def give(self, ctx: Context, user: Member, amount: int): | ||
| """ | ||
| Transfer money to another member. First argument is user ID. Ssecond argument is amount. |
src/cogs/gamble.py
Outdated
| # Poor man's clamp. | ||
| entries = max(1, min(entries, 50)) | ||
|
|
||
| query = user_database.execute(f'SELECT id, money FROM users ORDER BY money DESC LIMIT ?', [entries]) |
There was a problem hiding this comment.
you have extracted all database queries except for this one, why?
src/util/user_database.py
Outdated
| @@ -0,0 +1,31 @@ | |||
| import sqlite3 | |||
|
|
|||
| user_database_connection = sqlite3.connect('users.db') | |||
There was a problem hiding this comment.
database path should be configurable (in config.py)
src/util/user_database.py
Outdated
There was a problem hiding this comment.
namespacing by prefixing everything with user_database is yucky. Please wrap it in a class instead (or drop the prefix entirely and import the module instead of its contents to force usage of its name).
I don't like how it does a lot of stuff when importing the module (in Python modules are essentially singletons). That should not be required and will make testing a lot harder if we ever decide to write tests for any of this. If you want to ensure there's exactly one instance of this, you should probably open up the database connection during bot initialization instead.
src/util/user_database.py
Outdated
| count = query.fetchone()[0] | ||
|
|
||
| # If no user ID was found in database, add user. | ||
| if count == 0: |
Still need to fix /daily and turn the wallet icon into a server sticker.
Still need to update the sticker id in config.py after Che uploads the sticker.
|
@Tsche we still wanna move ahead? |
I'm currently super busy but in general yeah sure why not. Not sure what the current state of this PR is, I'll try to look into it some time this week. |
|
Is the input properly sanitized, since its interacting with database (amount to gamble cant be a string and where it accepts string it cant be like |
|
@makian123 SQL injections won't be a problem as long as we use parameterized queries with question marks instead of raw string operations |
|
Alright, that is pretty cool |
|
you need to modify the docker run args so it takes in a volume, that way sqlite database will be persistent |
Pesistent Docker Volume
|
I have one big issue with this, your database is non scalable, the class you've written in utils will only work for the gambling stuff, can you generalize the DB class so it uses tables and you could set field in a custom way? That way you can just write a wrapper for your gambling. |
|
@makian123 moved gambling specific functions from db.py into gamble.py. |
No description provided.