Rudimentary text processing for kicks, etc

This commit is contained in:
Noi 2023-11-16 10:19:10 -08:00
parent 7d18e1f498
commit db0a1e391c
5 changed files with 16 additions and 12 deletions

View file

@ -86,4 +86,16 @@ public static class Utilities {
} catch (Exception) { } } catch (Exception) { }
return result ?? input; return result ?? input;
} }
/// <summary>
/// Given an input string, replaces certain special character combinations with information
/// from the specified message.
/// </summary>
public static string ProcessTextTokens(string input, SocketMessage m) {
// TODO elaborate on this
// For now, replaces all instances of @_ with the message sender.
return input
.Replace("@_", m.Author.Mention)
.Replace("@\\_", "@_");
}
} }

View file

@ -14,7 +14,7 @@ class Ban : BanKick {
// Ban: Unlike kick, the minimum required is just the target ID // Ban: Unlike kick, the minimum required is just the target ID
var result = await Module.Bot.BanAsync(g, msg.Author.ToString(), targetId, PurgeDays, reason, SendNotify); var result = await Module.Bot.BanAsync(g, msg.Author.ToString(), targetId, PurgeDays, reason, SendNotify);
if (result.OperationSuccess && SuccessMessage != null) { if (result.OperationSuccess && SuccessMessage != null) {
var success = ProcessText(SuccessMessage, msg); var success = Utilities.ProcessTextTokens(SuccessMessage, msg);
await msg.Channel.SendMessageAsync($"{success}\n{result.GetResultString(Module.Bot)}"); await msg.Channel.SendMessageAsync($"{success}\n{result.GetResultString(Module.Bot)}");
} else { } else {
await msg.Channel.SendMessageAsync(result.GetResultString(Module.Bot)); await msg.Channel.SendMessageAsync(result.GetResultString(Module.Bot));
@ -35,7 +35,7 @@ class Kick : BanKick {
var result = await Module.Bot.KickAsync(g, msg.Author.ToString(), targetId, reason, SendNotify); var result = await Module.Bot.KickAsync(g, msg.Author.ToString(), targetId, reason, SendNotify);
if (result.OperationSuccess && SuccessMessage != null) { if (result.OperationSuccess && SuccessMessage != null) {
var success = ProcessText(SuccessMessage, msg); var success = Utilities.ProcessTextTokens(SuccessMessage, msg);
await msg.Channel.SendMessageAsync($"{success}\n{result.GetResultString(Module.Bot)}"); await msg.Channel.SendMessageAsync($"{success}\n{result.GetResultString(Module.Bot)}");
} else { } else {
await msg.Channel.SendMessageAsync(result.GetResultString(Module.Bot)); await msg.Channel.SendMessageAsync(result.GetResultString(Module.Bot));

View file

@ -36,12 +36,4 @@ abstract class CommandConfig {
}; };
await target.SendMessageAsync(message ?? "", embed: usageEmbed.Build()); await target.SendMessageAsync(message ?? "", embed: usageEmbed.Build());
} }
protected static string ProcessText(string input, SocketMessage m) {
// TODO elaborate on this
// For now, replaces all instances of @_ with the message sender.
return input
.Replace("@_", m.Author.Mention)
.Replace("@\\_", "@_");
}
} }

View file

@ -64,7 +64,7 @@ class Timeout : CommandConfig {
var result = await Module.Bot.SetTimeoutAsync(g, msg.Author.AsEntityNameString(), targetUser, var result = await Module.Bot.SetTimeoutAsync(g, msg.Author.AsEntityNameString(), targetUser,
TimeSpan.FromMinutes(timeParam), reason, SendNotify); TimeSpan.FromMinutes(timeParam), reason, SendNotify);
if (result.Success && SuccessMessage != null) { if (result.Success && SuccessMessage != null) {
var success = ProcessText(SuccessMessage, msg); var success = Utilities.ProcessTextTokens(SuccessMessage, msg);
await msg.Channel.SendMessageAsync($"{success}\n{result.ToResultString()}"); await msg.Channel.SendMessageAsync($"{success}\n{result.ToResultString()}");
} else { } else {
await msg.Channel.SendMessageAsync(result.ToResultString()); await msg.Channel.SendMessageAsync(result.ToResultString());

View file

@ -229,7 +229,7 @@ class ResponseExecutor {
return FromError("Channel or user were not correctly set in configuration."); return FromError("Channel or user were not correctly set in configuration.");
} }
if (targetCh == null) return FromError("Could not acquire target channel."); if (targetCh == null) return FromError("Could not acquire target channel.");
await targetCh.SendMessageAsync(param[1]); await targetCh.SendMessageAsync(Utilities.ProcessTextTokens(param[1], _msg));
return FromSuccess($"Sent to {(isUser ? "user DM" : $"<#{targetCh.Id}>")}."); return FromSuccess($"Sent to {(isUser ? "user DM" : $"<#{targetCh.Id}>")}.");
} }