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

draft: premium: provide 3d grace period after slot removed #1804

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

jo3-l
Copy link
Contributor

@jo3-l jo3-l commented Dec 24, 2024

Here is a possible implementation of a grace period before which premium features--additional custom commands, feeds, and so on--are disabled after a guild loses its premium slot.

It is intended really only as a possible starting point and has not been tested very thoroughly (though it works in the simple cases I have tried): I'm happy to see parts of this code cherry-picked and included in the final implementation and the original PR abandoned.

One important issue to note with this and similar approaches is that, as is, users can assign a premium slot to a server, then immediately unlink it to get 3 free days of premium while keeping their premium slot available for use on other servers. In other words, this code does not distinguish between users deliberately unlinking their premium slot from a server and a premium slot expiring naturally--it probably should.

@jo3-l jo3-l force-pushed the feat/premium-grace-period branch from 4e4905f to bc99432 Compare December 24, 2024 07:53
@jo3-l jo3-l marked this pull request as draft December 24, 2024 07:55
@SoggySaussages
Copy link
Contributor

https://github.com/botlabs-gg/yagpdb/blob/master/premium/patreonpremiumsource/patreonpremiumsource.go#L137
why not just make this a scheduled event? Every time a new slot is
added, check what events are scheduled, choose the one that’s
closest to running and run the delete event immediately, and it will
automatically migrate empty slots (like the new one) to fill the gap.
Otherwise after three days it deletes and if there’s available slots they
fill in.

@jo3-l
Copy link
Contributor Author

jo3-l commented Dec 24, 2024

Sorry, I don't fully understand your suggested approach. It seems (?) like it might be an addon to the existing patch rather than a replacement--is that correct?

Edit: I think I understand what you're suggesting. I would prefer to leave the implementation of that to Des, if he likes the idea, since it's difficult for me to test such an addition, even moreso than the current code--I don't have Patreon set up :-)

@ashishjh-bst
Copy link
Contributor

In poller.go I can simply check if a payment is pending or declined and next charge date was 3 days from now, and send an alert, no need for a complicated event system or a schema change.


			if len(attributes.LastChargeStatus) > 0 && attributes.LastChargeStatus != patreonapi.ChargeStatusPaid && attributes.LastChargeStatus != patreonapi.ChargeStatusPending {
				continue
			}

			// Skip if the next charge date is in the past
			if attributes.NextChargeDate != nil && attributes.NextChargeDate.Before(time.Now()) {
				continue
			}

@ashishjh-bst
Copy link
Contributor

Or rather this is sufficient, no need for alerting as patreon will alert the user.

@@ -188,16 +188,12 @@ func (p *Poller) Poll() {
                                continue
                        }
 
-                       if attributes.PatronStatus != "active_patron" {
+                       if len(attributes.LastChargeStatus) > 0 && attributes.LastChargeStatus != patreonapi.ChargeStatusPaid && attributes.LastChargeStatus != patreonapi.
ChargeStatusPending && attributes.LastChargeStatus != patreonapi.ChargeStatusDeclined {
                                continue
                        }
 
-                       if len(attributes.LastChargeStatus) > 0 && attributes.LastChargeStatus != patreonapi.ChargeStatusPaid && attributes.LastChargeStatus != patreonapi.
ChargeStatusPending {
-                               continue
-                       }
-
-                       // Skip if the next charge date is in the past
-                       if attributes.NextChargeDate != nil && attributes.NextChargeDate.Before(time.Now()) {
+                       // Skip if the next charge date is passed by 3 days
+                       if attributes.NextChargeDate != nil && attributes.NextChargeDate.Before(time.Now().Add(-1*3*24*time.Hour)) {
                                continue
                        }

@jo3-l
Copy link
Contributor Author

jo3-l commented Jan 3, 2025

Sounds reasonable. I will close this draft then.

@jo3-l jo3-l closed this Jan 3, 2025
@ashishjh-bst
Copy link
Contributor

The above plan has an issue, the entitled cents amount is 0, and hence the user isn't assigned a slot, and there doesn't seem too be a way to figure out how much the user paid in the last charge.

I could possible get the users current set of slots and calculate it myself, or mark the slots to be removed after 3 days, and if a current entitled users slot is marked for removal after three days undo it.

@jo3-l
Copy link
Contributor Author

jo3-l commented Jan 4, 2025

The latter idea is somewhat like what I implemented here (and is, I think, the easiest way to go), so feel free to reuse code from this PR as needed or reopen and modify directly, whichever is easiest. Unfortunately, I will not have time to work on this more for the time being.

@ashishjh-bst ashishjh-bst reopened this Jan 6, 2025
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