push broken mod

This commit is contained in:
NotAKidoS 2023-04-26 11:18:40 -05:00
parent 742f816d3d
commit 344e3bb6d6
12 changed files with 500 additions and 0 deletions

View file

@ -0,0 +1,43 @@
using Kafe.ChatBox;
namespace NAK.Melons.ChatBoxExtensions.Integrations;
internal class ChatBoxCommands : CommandBase
{
public static void RegisterCommands()
{
bool awaitingPing = false;
DateTime pingTime = DateTime.MinValue; // store the time when "ping" command was sent
Commands.RegisterCommand("ping",
onCommandSent: (message, sound) =>
{
pingTime = DateTime.Now;
awaitingPing = true;
},
onCommandReceived: (sender, message, sound) =>
{
RemoteCommandListenForSelf(message, args =>
{
ChatBox.SendMessage("/pong " + GetPlayerUsername(sender), false);
});
});
Commands.RegisterCommand("pong",
onCommandSent: null,
onCommandReceived: (sender, message, sound) =>
{
RemoteCommandListenForSelf(message, args =>
{
if (awaitingPing)
{
awaitingPing = false;
TimeSpan timeSincePing = DateTime.Now - pingTime; // calculate the time difference
ChatBox.SendMessage($"Time since ping: {timeSincePing.TotalMilliseconds}ms", false);
return;
}
ChatBox.SendMessage($"You have to ping first, {GetPlayerUsername(sender)}!", false);
});
});
}
}