MCPcopy Create free account
hub / github.com/DrewKestell/BloogBot / InitializeCommandHandler

Method InitializeCommandHandler

BloogBot/UI/MainViewModel.cs:1722–1842  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1720 }
1721
1722 async Task InitializeCommandHandler()
1723 {
1724 WoWEventHandler.OnChatMessage += OnChatMessageCallback;
1725
1726 while (true)
1727 {
1728 try
1729 {
1730 var player = ObjectManager.Player;
1731
1732 if (player != null)
1733 {
1734 if (!readyForCommands)
1735 {
1736 if (string.IsNullOrWhiteSpace(player.Name) || player.Level == 0)
1737 continue;
1738
1739 Repository.DeleteCommandsForPlayer(player.Name);
1740 SignLatestReport(player, false);
1741 readyForCommands = true;
1742
1743 await Task.Delay(2000); // wait for 1 second to sign the latest report, otherwise you'll randomly report on login
1744 }
1745 else
1746 {
1747 var commands = Repository.GetCommandsForPlayer(ObjectManager.Player.Name);
1748
1749 foreach (var command in commands)
1750 {
1751 switch (command.Command)
1752 {
1753 case "!start":
1754 Start();
1755 break;
1756 case "!stop":
1757 Stop();
1758 break;
1759 case "!chat":
1760 ThreadSynchronizer.RunOnMainThread(() =>
1761 {
1762 player.LuaCall($"SendChatMessage('{command.Args}')");
1763 });
1764 break;
1765 case "!whisper":
1766 ThreadSynchronizer.RunOnMainThread(() =>
1767 {
1768 var splitArgs = command.Args.Split(' ');
1769 var recipient = splitArgs[0];
1770 var message = string.Join(" ", splitArgs.Skip(1));
1771
1772 player.LuaCall($"SendChatMessage('{message}', 'WHISPER', nil, '{recipient}')");
1773 });
1774 break;
1775 case "!logout":
1776 ThreadSynchronizer.RunOnMainThread(() =>
1777 {
1778 player.LuaCall("Logout()");
1779 });

Callers

nothing calls this directly

Calls 12

RunOnMainThreadMethod · 0.80
GetAllItemsMethod · 0.80
UseMethod · 0.80
LuaCallWithResultsMethod · 0.80
GetCommandsForPlayerMethod · 0.45
LuaCallMethod · 0.45
RunningMethod · 0.45
SendMessageMethod · 0.45
ToStringMethod · 0.45
DeleteCommandMethod · 0.45
LogMethod · 0.45

Tested by

no test coverage detected