Skip to content

Commit

Permalink
add manual check command
Browse files Browse the repository at this point in the history
  • Loading branch information
sylveonnotdeko committed Jul 31, 2023
1 parent 149104d commit 6534d0a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Mewdeko/Modules/Permissions/BlacklistCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public class BlacklistCommands : MewdekoSubmodule<BlacklistService>
[Cmd, Aliases]
public Task ServerBlacklist(AddRemove action, IGuild guild, [Remainder] string? reason) => Blacklist(action, guild.Id, BlacklistType.Server, reason);

[Cmd, Aliases]
public async Task ManualBlacklistCheck()
{
await ctx.Channel.SendConfirmAsync("Sending manual check...");
await Service.SendManualCheck();
}

private async Task Blacklist(AddRemove action, ulong id, BlacklistType type, string? reason)
{
switch (action)
Expand Down
15 changes: 14 additions & 1 deletion src/Mewdeko/Modules/Permissions/Services/BlacklistService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ public sealed class BlacklistService : IEarlyBehavior, INService

private readonly TypedKey<BlacklistEntry[]> blPubKey = new("blacklist.reload");
public IList<BlacklistEntry> BlacklistEntries;
private readonly TypedKey<bool> blPrivKey = new("blacklist.reload.priv");

public BlacklistService(DbService db, IPubSub pubSub, EventHandler handler, DiscordSocketClient client)
{
this.db = db;
this.pubSub = pubSub;
this.client = client;

Reload(false);
this.pubSub.Sub(blPubKey, OnReload);
this.pubSub.Sub(blPrivKey, ManualCheck);
handler.JoinedGuild += CheckBlacklist;
client.Ready += CheckAllGuilds;
_ = CheckAllGuilds();
Expand All @@ -39,6 +40,12 @@ public BlacklistService(DbService db, IPubSub pubSub, EventHandler handler, Disc
});
}

private ValueTask ManualCheck(bool _)
{
CheckAllGuilds();
return default;
}

private Task CheckAllGuilds()
{
_ = Task.Run(async () =>
Expand All @@ -59,6 +66,12 @@ private Task CheckAllGuilds()
return Task.CompletedTask;
}

public Task SendManualCheck()
{
this.pubSub.Pub(blPrivKey, true);
return Task.CompletedTask;
}

private async Task CheckBlacklist(IGuild arg)
{
var channels = await arg.GetTextChannelsAsync();
Expand Down

0 comments on commit 6534d0a

Please sign in to comment.