Skip to content

Commit fa8d78b

Browse files
committed
make user filter a little more fault tolerant
1 parent af60340 commit fa8d78b

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/Bot/Systems/Commands/Text/Modules/UserFilterModule.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,10 @@ private async Task<bool> HandleUserAsync(
226226
{
227227
if (VolteStarscript.Hypervisor.Run(script, StarscriptHelper.Wrap(user)).GetBooleanValue())
228228
{
229+
Debug(LogSource.Service, $"{user} matched filter {entry.Id} in guild {Context.Guild.Id}");
230+
229231
if (await entry.ExecuteAsync(Context.Guild, user))
230-
{
231-
Debug(LogSource.Service, $"{user} matched filter {entry.Id} in guild {Context.Guild.Id}");
232232
return true;
233-
}
234233
}
235234
}
236235
catch (FormatException)

src/Bot/Systems/UserFilter/UserFilterTable.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ public class UserFilterEntry
5151
public async Task<bool> HandleAsync(IGuild guild, IGuildUser user)
5252
{
5353
StringSegment returnVal = null;
54-
54+
5555
try
5656
{
57-
var script = Starscript.Compile();
58-
59-
returnVal = VolteStarscript.Hypervisor.Run(script, StarscriptHelper.Wrap(user));
57+
using (var script = Starscript.Compile())
58+
{
59+
returnVal = VolteStarscript.Hypervisor.Run(script, StarscriptHelper.Wrap(user));
60+
}
6061

6162
if (returnVal.GetBooleanValue())
6263
{
63-
if (await ExecuteAsync(guild, user))
64-
{
65-
Debug(LogSource.Service, $"{user} matched filter {Id} in guild {user.Guild.Id}");
66-
}
64+
Debug(LogSource.Service, $"{user} matched filter {Id} in guild {user.Guild.Id}");
65+
66+
_ = await ExecuteAsync(guild, user);
6767
}
6868

6969
return true;
@@ -108,6 +108,7 @@ public async Task<bool> ExecuteAsync(IGuild guild, IGuildUser user)
108108
try
109109
{
110110
await user.WarnAsync(VolteBot.Client.CurrentUser, VolteBot.Services, Reason);
111+
Debug(LogSource.Service, $"Warned {user} in guild {user.Guild.Id} because they matched filter {Id}");
111112
return true;
112113
}
113114
catch (HttpException)
@@ -119,6 +120,7 @@ public async Task<bool> ExecuteAsync(IGuild guild, IGuildUser user)
119120
{
120121
await user.KickAsync(Reason,
121122
DiscordHelper.RequestOptions(x => x.AuditLogReason = $"Triggered user filter {Id}"));
123+
Debug(LogSource.Service, $"Kicked {user} in guild {user.Guild.Id} because they matched filter {Id}");
122124
return true;
123125
}
124126
catch (HttpException)
@@ -130,6 +132,7 @@ await user.KickAsync(Reason,
130132
{
131133
await guild.AddBanAsync(user.Id, 7, Reason,
132134
DiscordHelper.RequestOptions(x => x.AuditLogReason = $"Triggered user filter {Id}"));
135+
Debug(LogSource.Service, $"Banned {user} in guild {user.Guild.Id} because they matched filter {Id}");
133136
return true;
134137
}
135138
catch (HttpException)
@@ -142,14 +145,16 @@ await guild.AddBanAsync(user.Id, 7, Reason,
142145
await guild.AddBanAsync(user.Id, 7, Reason,
143146
DiscordHelper.RequestOptions(x => x.AuditLogReason = $"Triggered user filter {Id}"));
144147
await guild.RemoveBanAsync(user.Id);
148+
Debug(LogSource.Service, $"Softbanned {user} in guild {user.Guild.Id} because they matched filter {Id}");
145149
return true;
146150
}
147151
catch (HttpException)
148152
{
149153
return false;
150154
}
151155
default:
152-
throw new ArgumentOutOfRangeException(nameof(Action));
156+
Debug(LogSource.Service, $"Unknown action type {Enum.GetName(Action)} for filter {Id}");
157+
return false;
153158
}
154159
}
155160
}

0 commit comments

Comments
 (0)