Skip to content

first gambling commit #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

first gambling commit #86

wants to merge 9 commits into from

Conversation

bu420
Copy link

@bu420 bu420 commented Dec 18, 2023

No description provided.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@@ -2,3 +2,4 @@ fuzzywuzzy==0.18.0
discord.py==2.1.0
aiohttp==3.8.5
python-Levenshtein==0.12.2
datetime==5.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a package for that? Isn't python standard library datetime utils sufficient?

from src.util.user_database import *


daily_amount = 10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put configuration options in config.py

"""
Place a bet (50/50). Enter the amount to bet.
"""
user_database_check_if_user_exists_otherwise_add(ctx.author.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's one long af identifier

Copy link

@YuhanunCitgez YuhanunCitgez Mar 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

user_database_upsert is better

@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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ssecond typo

# 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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have extracted all database queries except for this one, why?

@@ -0,0 +1,31 @@
import sqlite3

user_database_connection = sqlite3.connect('users.db')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

database path should be configurable (in config.py)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is non-persistent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

count = query.fetchone()[0]

# If no user ID was found in database, add user.
if count == 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be if not count

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.
@YuhanunCitgez
Copy link

@Tsche we still wanna move ahead?

@Tsche
Copy link
Member

Tsche commented Feb 13, 2024

@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.

@makian123
Copy link
Contributor

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 ;drop table users)

@bu420
Copy link
Author

bu420 commented Mar 9, 2024

@makian123 SQL injections won't be a problem as long as we use parameterized queries with question marks instead of raw string operations

@makian123
Copy link
Contributor

Alright, that is pretty cool

@makian123
Copy link
Contributor

you need to modify the docker run args so it takes in a volume, that way sqlite database will be persistent

@makian123
Copy link
Contributor

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.
Requesting this because i have some moderation feature plans in future and it'd make it easier to have one sqlite database with different tables

@bu420
Copy link
Author

bu420 commented May 19, 2024

@makian123 moved gambling specific functions from db.py into gamble.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants