public async Task <bool> Execute(string command) { var conversations = await _conversationService.AllAsync(); _botLogger.LogInfo(""); foreach (var conversation in conversations.Items) { _botLogger.LogInfo($"ID: {conversation.ConversationId}\tName:\t{conversation.DisplayName}"); } _botLogger.LogInfo(""); var convId = _botLogger.ReadLine("Enter conversation ID you want to say:"); var target = conversations.Items.FirstOrDefault(t => t.ConversationId.ToString() == convId); if (target == null) { _botLogger.LogDanger($"Can't find conversation with ID: {convId}"); return(true); } var toSay = _botLogger.ReadLine($"Enter the message you want to send to '{target.DisplayName}':"); if (string.IsNullOrWhiteSpace(toSay)) { _botLogger.LogDanger("Can't send empty content."); return(true); } var encrypted = _aes.OpenSSLEncrypt(toSay, _eventSyncer.Contacts.FirstOrDefault(t => t.ConversationId == target.ConversationId)?.AesKey); await _conversationService.SendMessageAsync(encrypted, target.ConversationId); _botLogger.LogSuccess("Sent."); return(true); }
public async Task Start() { var listenTask = await _botListener .WithBot(_translateBot) .Start(); _botLogger.LogSuccess("Bot started! Waitting for commands. Enter 'help' to view available commands."); await Task.WhenAll(listenTask, _botCommander.Command()); }
public async Task Start() { var listenTask = await Connect(); BotLogger.LogSuccess("Bot started! Waitting for commands. Enter 'help' to view available commands."); await Task.WhenAll(listenTask, Command()); }
public async Task Run(bool enableCommander = true, int autoReconnectMax = int.MaxValue) { int reconnectAttempts = 0; await BuildBot.OnBotStarting(); ConnectTask = Connect((websocketAddress) => { MonitorTask = MonitorEvents(websocketAddress); if (enableCommander) { CommandTask = _botCommander.Command(); } }); while ( !CommandTask.IsCompleted || !MonitorTask.IsCompleted || !ConnectTask.IsCompleted) { if (reconnectAttempts < autoReconnectMax && MonitorTask.IsCompleted && ConnectTask.IsCompleted) { if (await SignedIn()) { reconnectAttempts++; _botLogger.LogSuccess($"\nTrying to auto reconect! Attempts: {reconnectAttempts}"); ConnectTask = Connect((websocketAddress) => { MonitorTask = MonitorEvents(websocketAddress); }); } else { _botLogger.LogDanger("Cannot start reconnecting. Because checking sign in status failed."); } } await Task.Delay(5000); } }
private async Task <bool> TestKahlaLive() { try { _botLogger.LogInfo($"Using Kahla Server: {_kahlaLocation}"); await Task.Delay(200); _botLogger.LogInfo("Testing Kahla server connection..."); await Task.Delay(1000); var index = await _homeService.IndexAsync(); _botLogger.LogSuccess("Success! Your bot is successfully connected with Kahla!\r\n"); await Task.Delay(200); _botLogger.LogInfo($"Server time: {index.Value}\tLocal time: {DateTime.UtcNow}"); return(true); } catch (Exception e) { _botLogger.LogDanger(e.Message); return(false); } }
public async Task <bool> Execute(string command) { await Task.Delay(0); foreach (var request in _eventSyncer.Requests) { _botLogger.LogInfo($"Name:\t{request.Creator.NickName}"); _botLogger.LogInfo($"Time:\t{request.CreateTime}"); if (request.Completed) { _botLogger.LogSuccess("\tCompleted."); } else { _botLogger.LogWarning("\tPending."); } } return(true); }