예제 #1
0
        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);
        }
예제 #2
0
        public async Task SyncFromServer()
        {
            var allResponse = await _conversationService.AllAsync();

            _contacts = allResponse.Items;
            foreach (var contact in _contacts)
            {
                if (contact.LatestMessage != null)
                {
                    contact.Messages.Add(contact.LatestMessage);
                }
            }

            var requestsResponse = await _friendshipService.MyRequestsAsync();

            _requests = requestsResponse.Items;
        }
예제 #3
0
파일: BotBase.cs 프로젝트: LXKing/Kahla
        public async Task Command()
        {
            while (true)
            {
                Console.Write($"Bot:\\System\\{Profile.NickName}>");
                var command = Console.ReadLine();
                if (command.Length < 1)
                {
                    continue;
                }
                switch (command.ToLower().Trim()[0])
                {
                case 'e':
                    Environment.Exit(0);
                    return;

                case 'a':
                    var conversations = await ConversationService.AllAsync();

                    BotLogger.LogSuccess($"Successfully get all your conversations.");
                    foreach (var conversation in conversations.Items)
                    {
                        BotLogger.LogInfo($"ID:\t{conversation.ConversationId}");
                        BotLogger.LogInfo($"Name:\t{conversation.DisplayName}");
                        BotLogger.LogInfo($"Online:\t{conversation.Online}");
                        BotLogger.LogInfo($"Type:\t{conversation.Discriminator}");
                        BotLogger.LogInfo($"Last:\t{conversation.LatestMessage}");
                        BotLogger.LogInfo($"Time:\t{conversation.LatestMessageTime}");
                        BotLogger.LogInfo($"Unread:\t{conversation.UnReadAmount}\n");
                    }
                    break;

                case 'c':
                    Console.Clear();
                    break;

                case 'l':
                    await LogOff();

                    BotLogger.LogWarning($"Successfully log off. Use command:`r` to reconnect.");
                    break;

                case 'h':
                    BotLogger.LogInfo($"Kahla bot commands:");

                    BotLogger.LogInfo($"\r\nConversation");
                    BotLogger.LogInfo($"\ta\tShow all conversations.");
                    BotLogger.LogInfo($"\ts\tSay something to someone.");
                    BotLogger.LogInfo($"\tb\tBroadcast to all conversations.");
                    BotLogger.LogInfo($"\tc\tClear console.");

                    BotLogger.LogInfo($"\r\nGroup");
                    BotLogger.LogInfo($"\tm\tMute all groups.");
                    BotLogger.LogInfo($"\tu\tUnmute all groups.");

                    BotLogger.LogInfo($"\r\nNetwork");
                    BotLogger.LogInfo($"\tr\tReconnect to Stargate.");
                    BotLogger.LogInfo($"\tl\tLogout.");

                    BotLogger.LogInfo($"\r\nProgram");
                    BotLogger.LogInfo($"\th\tShow help.");
                    BotLogger.LogInfo($"\te\tQuit bot.");
                    break;

                default:
                    BotLogger.LogDanger($"Unknown command: {command}. Please try command: 'h' for help.");
                    break;
                }
            }
        }