undo
This commit is contained in:
26
Program.cs
26
Program.cs
@@ -67,32 +67,6 @@ client.MessageService.MessageReceived += async (message) =>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (Utils.ContainsAny(content, $"{prefix}react"))
|
|
||||||
{
|
|
||||||
if (message.AuthorUserId != ownerId) return;
|
|
||||||
|
|
||||||
string[] args = content.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
if (args.Length < 2) return;
|
|
||||||
string emoji = args[1];
|
|
||||||
|
|
||||||
var interceptor = new Utils.ReactionInterceptor(Console.Out);
|
|
||||||
Console.SetOut(interceptor);
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
interceptor.Reset();
|
|
||||||
await message.AddReactionAsync(emoji);
|
|
||||||
if (interceptor.DetectedAlreadyExists)
|
|
||||||
{
|
|
||||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
|
||||||
Console.WriteLine("Reaction already exists, stopping.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
|
||||||
}
|
|
||||||
|
|
||||||
var echoprefixes = new[] { $"{prefix}echo"};
|
var echoprefixes = new[] { $"{prefix}echo"};
|
||||||
if (Utils.ContainsAny(content, echoprefixes))
|
if (Utils.ContainsAny(content, echoprefixes))
|
||||||
{
|
{
|
||||||
|
|||||||
28
utils.cs
28
utils.cs
@@ -106,33 +106,5 @@ namespace SkyBot
|
|||||||
initializedPlanets.Add(planet.Id);
|
initializedPlanets.Add(planet.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReactionInterceptor : TextWriter
|
|
||||||
{
|
|
||||||
private readonly TextWriter _original;
|
|
||||||
public bool DetectedAlreadyExists { get; private set; }
|
|
||||||
public override Encoding Encoding => _original.Encoding;
|
|
||||||
|
|
||||||
public ReactionInterceptor(TextWriter original)
|
|
||||||
{
|
|
||||||
_original = original;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset() => DetectedAlreadyExists = false;
|
|
||||||
|
|
||||||
public override void WriteLine(string value)
|
|
||||||
{
|
|
||||||
if (value?.Contains("Reaction already exists") == true)
|
|
||||||
DetectedAlreadyExists = true;
|
|
||||||
_original.WriteLine(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Write(string value)
|
|
||||||
{
|
|
||||||
if (value?.Contains("Reaction already exists") == true)
|
|
||||||
DetectedAlreadyExists = true;
|
|
||||||
_original.Write(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user