2022-07-21 01:55:08 +00:00
|
|
|
|
using RegexBot.Common;
|
|
|
|
|
|
|
|
|
|
namespace RegexBot.Modules.ModCommands.Commands;
|
2022-07-18 23:44:31 +00:00
|
|
|
|
class Unban : CommandConfig {
|
|
|
|
|
private readonly string _usage;
|
|
|
|
|
|
|
|
|
|
protected override string DefaultUsageMsg => _usage;
|
|
|
|
|
|
|
|
|
|
// No configuration.
|
|
|
|
|
// TODO bring in some options from BanKick. Particularly custom success msg.
|
|
|
|
|
// TODO when ModLogs fully implemented, add a reason?
|
|
|
|
|
public Unban(ModCommands module, JObject config) : base(module, config) {
|
|
|
|
|
_usage = $"{Command} `user or user ID`\n"
|
|
|
|
|
+ "Unbans the given user, allowing them to rejoin the server.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Usage: (command) (user query)
|
|
|
|
|
public override async Task Invoke(SocketGuild g, SocketMessage msg) {
|
2024-06-09 04:08:03 +00:00
|
|
|
|
var line = SplitToParams(msg, 3);
|
2022-07-18 23:44:31 +00:00
|
|
|
|
string targetstr;
|
|
|
|
|
if (line.Length < 2) {
|
|
|
|
|
await SendUsageMessageAsync(msg.Channel, null);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
targetstr = line[1];
|
|
|
|
|
|
|
|
|
|
ulong targetId;
|
|
|
|
|
string targetDisplay;
|
|
|
|
|
var query = Module.Bot.EcQueryUser(targetstr);
|
|
|
|
|
if (query != null) {
|
|
|
|
|
targetId = (ulong)query.UserId;
|
2023-11-15 05:09:21 +00:00
|
|
|
|
targetDisplay = $"**{query.GetDisplayableUsername()}**";
|
2022-07-18 23:44:31 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (!ulong.TryParse(targetstr, out targetId)) {
|
|
|
|
|
await SendUsageMessageAsync(msg.Channel, TargetNotFound);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-15 05:09:21 +00:00
|
|
|
|
targetDisplay = $"with ID **{targetId}**";
|
2022-07-18 23:44:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Do the action
|
|
|
|
|
try {
|
|
|
|
|
await g.RemoveBanAsync(targetId);
|
|
|
|
|
await msg.Channel.SendMessageAsync($":white_check_mark: Unbanned user **{targetDisplay}**.");
|
|
|
|
|
} catch (Discord.Net.HttpException ex) {
|
|
|
|
|
const string FailPrefix = ":x: **Could not unban:** ";
|
|
|
|
|
if (ex.HttpCode == System.Net.HttpStatusCode.Forbidden)
|
2022-07-21 01:55:08 +00:00
|
|
|
|
await msg.Channel.SendMessageAsync(FailPrefix + Messages.ForbiddenGenericError);
|
2022-07-18 23:44:31 +00:00
|
|
|
|
else if (ex.HttpCode == System.Net.HttpStatusCode.NotFound)
|
|
|
|
|
await msg.Channel.SendMessageAsync(FailPrefix + "The specified user does not exist or is not in the ban list.");
|
|
|
|
|
else throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|