DeavmiComedy

- Fixed funny text generation
This commit is contained in:
Tristan B. Velloza Kildaire 2023-06-17 15:40:17 +02:00
parent a6589c7174
commit edaca4849a
1 changed files with 15 additions and 8 deletions

View File

@ -32,21 +32,28 @@ public class DeavmiComedy : Mod
public override void react(Message fullMessage, string channel, string messageBody)
{
import std.string : indexOf;
import std.string : indexOf, strip;
// Guaranteed to not be -1 as `accepts()` wouldn't have passed then
long funnyIdx = indexOf(messageBody, commandStr);
string toBeFunnied = messageBody[funnyIdx+commandStr.length..$];
// Apply the comedy (courtesy of @rany2's original Botty code)
import std.regex : regex, replaceAll;
string ranyRegex = `\x1f|\x01|\x02|\x12|\x0f|\x1d|\x16|\x0f(?:\d{1,2}(?:,\d{1,2})?)?|\x03(?:\d{1,2}(?:,\d{1,2})?)?`;
auto replacementRegex = regex(ranyRegex);
// // Apply the comedy (courtesy of @rany2's original Botty code)
// import std.regex : regex, replaceAll;
// string ranyRegex = `\x1f|\x01|\x02|\x12|\x0f|\x1d|\x16|\x0f(?:\d{1,2}(?:,\d{1,2})?)?|\x03(?:\d{1,2}(?:,\d{1,2})?)?`;
// auto replacementRegex = regex(ranyRegex);
import std.stdio;
writeln(replacementRegex);
// import std.stdio;
// writeln(replacementRegex);
string funniedText = replaceAll(toBeFunnied, replacementRegex, "$&");
// string funniedText = replaceAll(toBeFunnied, replacementRegex, "$&");
string funniedText;
foreach(char fChar; toBeFunnied)
{
funniedText = funniedText ~ fChar ~ ' ';
}
funniedText = funniedText.strip();
getBot().channelMessage(funniedText, channel);
}