Skip to content

Commit

Permalink
Improved disabling logic for custom commands on premium cancellation (#…
Browse files Browse the repository at this point in the history
…1825)

* improve CC disabling logic on premium cancellation

* fix typo

---------

Co-authored-by: Ashish <[email protected]>
  • Loading branch information
ashishjh-bst and ashishjh-bst authored Jan 19, 2025
1 parent 0a30f61 commit 50b3d40
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
5 changes: 3 additions & 2 deletions common/patreon/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func (p *Poller) Poll() {
for {
logger.Infof("Fetching Patrons, page: %d ", page)
membersResponse, err := p.client.FetchMembers(campaignId, 200, cursor)

if err != nil {
logger.WithError(err).Error("Failed fetching pledges")
p.isLastFetchSuccess = false
Expand All @@ -172,7 +171,9 @@ func (p *Poller) Poll() {
// Loop over the pledges to get e.g. their amount and user name
for _, memberData := range membersResponse.Data {
attributes := memberData.Attributes

if memberData.ID == "7997692f-610e-446f-b9c7-ffe198cb7808" {
logger.Printf("%#v", memberData)
}
user, ok := users[memberData.Relationships.User.Data.ID]
tierCents := 0
if len(memberData.Relationships.Tiers.Data) > 0 {
Expand Down
11 changes: 6 additions & 5 deletions customcommands/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,12 @@ func CCActionExecLimit(guildID int64) int {
}

func (p *Plugin) OnRemovedPremiumGuild(GuildID int64) error {
commands, err := models.CustomCommands(qm.Where("guild_id = ?", GuildID), qm.Offset(MaxCommands)).AllG(context.Background())
_, err := models.CustomCommands(qm.Where("guild_id = ? AND length(regexp_replace(array_to_string(responses, ''), E'\\r', '', 'g')) > ?", GuildID, MaxCCResponsesLength)).UpdateAllG(context.Background(), models.M{"disabled": true})
if err != nil {
return errors.WrapIf(err, "Failed disabling long custom commands on premium removal")
}

commands, err := models.CustomCommands(qm.Where("guild_id = ? AND disabled = false", GuildID), qm.OrderBy("local_id ASC"), qm.Offset(MaxCommands)).AllG(context.Background())
if err != nil {
return errors.WrapIf(err, "failed getting custom commands")
}
Expand All @@ -700,10 +705,6 @@ func (p *Plugin) OnRemovedPremiumGuild(GuildID int64) error {
return errors.WrapIf(err, "Failed disabling trigger on edits on premium removal")
}

_, err = models.CustomCommands(qm.Where("guild_id = ? AND length(regexp_replace(array_to_string(responses, ''), E'\\r', '', 'g')) > ?", GuildID, MaxCCResponsesLength)).UpdateAllG(context.Background(), models.M{"disabled": true})
if err != nil {
return errors.WrapIf(err, "Failed disabling long customs commands on premium removal")
}
return nil
}

Expand Down
2 changes: 0 additions & 2 deletions yagpdb_docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ services:
restart: unless-stopped
volumes:
- db:/var/lib/postgresql/data
ports:
- 5432:5432
networks:
- default
env_file:
Expand Down

0 comments on commit 50b3d40

Please sign in to comment.