Skip to content
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

feat: Add user to database immediately when purchasing premium #158

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

dlsnyder8
Copy link
Contributor

Summary
Adds the user to the database in the same webhook when a purchase is successfully completed.
Alters bot checks to use this new column
Adds migration files to add the new column, as well as completing a first pass of populating the slots column based on # of guilds with premium

Additional context
These are written as upserts because it's possible that a person purchased premium, but never used the =premiumassign command, and therefore was never added to database.

Premium 1

=eval members = await bot.get_guild(576016832956334080).get_role(576756461267451934).members
let query = "INSERT INTO premium VALUES ($1, [], NULL, 1)  ON CONFLICT (identifier) DO UPDATE SET slots = 1"

for member in members:
    async with self.bot.pool.acquire() as conn:
        try:
            res = await conn.execute(query, member.id)

Premium 3

=eval members = await bot.get_guild(576016832956334080).get_role(576754574346551306).members
let query = "INSERT INTO premium VALUES ($1, [], NULL, 3)  ON CONFLICT (identifier) DO UPDATE SET slots = 3"

for member in members:
    async with self.bot.pool.acquire() as conn:
        try:
            res = await conn.execute(query, member.id)

Premium 5

=eval members = await bot.get_guild(576016832956334080).get_role(576754671620980740).members
let query = "INSERT INTO premium VALUES ($1, [], NULL, 5)  ON CONFLICT (identifier) DO UPDATE SET slots = 5"

for member in members:
    async with self.bot.pool.acquire() as conn:
        try:
            res = await conn.execute(query, member.id)

@dlsnyder8
Copy link
Contributor Author

I believe I caught everywhere that this needed to be updated in code, but feel free to let me know if you think of any other places.

My knowledge of rust is pretty rusty (ba-dum-tssss), so also let me know if there are any syntax issues.

@chamburr
Copy link
Owner

Thanks much, but I don't think I can merge this anytime soon... Migration is hard because cardinality of guilds won't give the correct premium level, and I'm not sure if I like this design because we can't quite assign premium roles manually anymore. Let's just keep this PR as is first until I can decide on something.

@dlsnyder8
Copy link
Contributor Author

I agree the cardinality isn't great, I just wanted to populate the database with initial data. I added =eval commands that would take the existing patron information (based on roles) and update the db. There should, in theory, be fewer issues since it no longer relies on membership, and users who aren't in the server and have guilds assigned can use the =premiumassign and remove commands, which they can't do now.

I can add helper functions in the admin.py file to give premium roles and update the database accordingly.

In webhooks.rs I also gave it a first pass at updating the slots column if people purchase multiple $30 premium instances, but if you like that idea I'd rewrite it a bit to perform an explicit check for a previous purchase and update roles based on that. I just didn't want to do too much there.

@SnowyJaguar1034
Copy link
Contributor

I can add helper functions in the admin.py file to give premium roles and update the database accordingly.

Could also do it via a on_member_join event: when a user joins check if their in the premium table and assign the role matching their number of slots. This could be not a great idea if it's going to hit the db a bunch of times because we get a fair number of users joining the server. Could maybe pull the entire table (or the required subset) during bot boot and store it in the cache for quicker checking.

But maybe that's adding unneeded complexity.

I know the users who had premium gifted are an issue but just because we implement this new system doesn't mean we need to remove the old one, just keep the old one as legacy until we're confident we have all of the users.

@chamburr chamburr force-pushed the main branch 2 times, most recently from 0e5a511 to 529ada7 Compare December 10, 2024 05:23
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.

3 participants