Skip to content

Commit

Permalink
supporter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed Oct 3, 2024
1 parent a17f6a2 commit 5c5f15b
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
87 changes: 87 additions & 0 deletions src/FMBot.Bot/TextCommands/AdminCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,49 @@ public async Task UpdateSingleDiscordSupporters([Remainder] string user)
this.Context.LogCommandUsed(CommandResponse.NoPermission);
}
}
[Command("updatemultidiscordsupporters")]
[Summary("Updates multiple discord supporter")]
public async Task UpdateMultipleDiscordSupporters([Remainder] string user)
{
if (await this._adminService.HasCommandAccessAsync(this.Context.User, UserType.Admin))
{
try
{
var idsToUpdate = user.Split(",");
var updated = new StringBuilder();
var skipped = new StringBuilder();

foreach (var id in idsToUpdate)
{
var userToUpdate = await this._settingService.GetDifferentUser(user);

if (userToUpdate == null)
{
skipped.AppendLine($"{id} - <@{id}>");
continue;
}

await this._supporterService.UpdateSingleDiscordSupporter(userToUpdate.DiscordUserId);
updated.AppendLine($"{id} - <@{id}>");
}

await ReplyAsync("Updated:\n" +
$"{updated}\n" +
$"Skipped:\n" +
$"{skipped}",
allowedMentions: AllowedMentions.None);
}
catch (Exception e)
{
await this.Context.HandleCommandException(e);
}
}
else
{
await ReplyAsync("Error: Insufficient rights. Only FMBot owners can stop timer.");
this.Context.LogCommandUsed(CommandResponse.NoPermission);
}
}

[Command("refreshpremiumservers")]
[Summary("Refreshes cached premium servers")]
Expand Down Expand Up @@ -1958,6 +2001,50 @@ public async Task RunTimerAsync([Remainder] string job = null)
}
}

[Command("removetimer")]
[Summary("Remove a timer manually (only works if it exists)")]
[Alias("removejob", "deletejob")]
public async Task RemoveJobAsync([Remainder] string job = null)
{
if (await this._adminService.HasCommandAccessAsync(this.Context.User, UserType.Admin))
{
try
{
if (job == null)
{
await ReplyAsync("Pick a job to remove. Check `.timerstatus` for available jobs.");
this.Context.LogCommandUsed(CommandResponse.WrongInput);
return;
}

var recurringJobs = JobStorage.Current.GetConnection().GetRecurringJobs();

var jobToRemove = recurringJobs.FirstOrDefault(f => f.Id.ToLower() == job.ToLower());

if (jobToRemove == null)
{
await ReplyAsync("Could not find job you're looking for. Check `.timerstatus` for available jobs.");
this.Context.LogCommandUsed(CommandResponse.WrongInput);
return;
}

RecurringJob.RemoveIfExists(jobToRemove.Id);
await ReplyAsync($"Removed job {jobToRemove.Id}", allowedMentions: AllowedMentions.None);

this.Context.LogCommandUsed();
}
catch (Exception e)
{
await this.Context.HandleCommandException(e);
}
}
else
{
await ReplyAsync("Error: Insufficient rights. Only FMBot owners can remove jobs.");
this.Context.LogCommandUsed(CommandResponse.NoPermission);
}
}

[Command("timerstatus")]
[Summary("Checks the status of the timer.")]
public async Task TimerStatusAsync()
Expand Down
2 changes: 1 addition & 1 deletion src/FMBot.Subscriptions/Services/DiscordSkuService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static List<DiscordEntitlement> DiscordEntitlementsToGrouped(IEnumerable<

private static DiscordEntitlement DiscordEntitlement(IGrouping<ulong, DiscordEntitlementResponseModel> s)
{
var noEndDate = s.OrderByDescending(o => o.StartsAt).First().EndsAt == null;
var noEndDate = s.Any(a => !a.EndsAt.HasValue);

return new DiscordEntitlement
{
Expand Down

0 comments on commit 5c5f15b

Please sign in to comment.