예제 #1
0
        public static string VariablesParser(
            string text,
            string languageId = "en")
        {
            string parsedText = text;

            parsedText = parsedText.Replace("{{command_check_first_row}}",
                                            CacheData.GetTranslation(languageId, "command_check_first_row"));
            parsedText = parsedText.Replace("{{privilege_delete_messages}}",
                                            CacheData.GetTranslation(languageId, "privilege_delete_messages"));
            parsedText = parsedText.Replace("{{privilege_ban_users}}",
                                            CacheData.GetTranslation(languageId, "privilege_ban_users"));
            parsedText = parsedText.Replace("{{privilege_pin_messages}}",
                                            CacheData.GetTranslation(languageId, "privilege_pin_messages"));
            parsedText = parsedText.Replace("{{optional}}",
                                            CacheData.GetTranslation(languageId, "optional"));
            parsedText = parsedText.Replace("{{result}}",
                                            CacheData.GetTranslation(languageId, "result"));
            parsedText = parsedText.Replace("{{privilege_check_ok}}",
                                            CacheData.GetTranslation(languageId, "privilege_check_ok"));
            parsedText = parsedText.Replace("{{privilege_check_ko}}",
                                            CacheData.GetTranslation(languageId, "privilege_check_ko"));
            parsedText = parsedText.Replace("{{true}}",
                                            CacheData.GetTranslation(languageId, "true"));
            parsedText = parsedText.Replace("{{false}}",
                                            CacheData.GetTranslation(languageId, "false"));
            parsedText = parsedText.Replace("{{version}}",
                                            BotTools.CurrentVersion());

            return(parsedText);
        }
예제 #2
0
        public static bool CanHandleGroup(string dashboardUserId, string groupId)
        {
            DashboardUser du = dul.GetById(dashboardUserId);

            if (du == null)
            {
                return(false);
            }

            if (BotTools.IsUserOperator(du.TelegramUserId))
            {
                return(true);
            }

            return(dpl.GetGroups(dashboardUserId)
                   .SingleOrDefault(x => x.GroupId == groupId) != null);
        }
예제 #3
0
        private static void RecordSupportSessionMessage(Message message)
        {
            Models.SupportSessionLog.SenderType senderType = Models.SupportSessionLog.SenderType.User;
            if (BotTools.IsUserOperator(message.From.Id))
            {
                senderType = Models.SupportSessionLog.SenderType.Operator;
            }
            else if (CacheData.CurrentChatAdmins[message.Chat.Id]
                     .Contains(message.From.Id))
            {
                senderType = Models.SupportSessionLog.SenderType.Admin;
            }

            LogTools.AddSupportSessionLog(new Models.SupportSessionLog()
            {
                GroupId   = CacheData.Groups[message.Chat.Id].GroupId,
                SenderId  = message.From.Id,
                Text      = message.Text,
                Timestamp = DateTime.UtcNow,
                Type      = senderType
            });
        }
예제 #4
0
        public static bool HandleSupportSessionMsg(Message message)
        {
            if (!CacheData.ActiveSupport
                .Contains(message.Chat.Id))
            {
                return(false);
            }

            if (!lastOperatorSupportMsg.ContainsKey(message.Chat.Id))
            {
                lastOperatorSupportMsg[message.Chat.Id] = DateTime.UtcNow;
            }

            bool isFromOperator = false;

            if (BotTools.IsUserOperator(message.From.Id))
            {
                isFromOperator = true;
                Manager.BotClient.DeleteMessageAsync(message.Chat.Id, message.MessageId);
                ChatMessage newMsg = new ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    ParseMode = ParseMode.Html,
                    Text      = message.Text +
                                "\n\nMessage from operator: <b>" + message.From.Username + "</b>"
                };
                if (message.ReplyToMessage != null)
                {
                    newMsg.ReplyToMessageId = message.ReplyToMessage.MessageId;
                }
                MessageQueueManager.EnqueueMessage(newMsg);
                lastOperatorSupportMsg[message.Chat.Id] = DateTime.UtcNow;
            }

            var timeDifference = DateTime.UtcNow - lastOperatorSupportMsg[message.Chat.Id];

            if (timeDifference.Minutes >= 3 && timeDifference.Minutes < 5)
            {
                ChatMessage newMsg = new ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    ParseMode = ParseMode.Markdown,
                    Text      = "*[Alert]*" +
                                "\n\nSupport session is going to be automatically closed in 2 minutes " +
                                "due to operator's inactivity"
                };
                MessageQueueManager.EnqueueMessage(newMsg);
            }
            if (timeDifference.Minutes >= 5)
            {
                ChatMessage newMsg = new ChatMessage()
                {
                    Timestamp = DateTime.UtcNow,
                    Chat      = message.Chat,
                    ParseMode = ParseMode.Markdown,
                    Text      = "*[Alert]*" +
                                "\n\nSupport session is closed due to operator's inactivity"
                };
                MessageQueueManager.EnqueueMessage(newMsg);
                CacheData.ActiveSupport.Remove(message.Chat.Id);
                CacheData.CurrentChatAdmins.Remove(message.Chat.Id);

                MessageQueueManager.EnqueueLog(new ChatMessage()
                {
                    ParseMode = ParseMode.Markdown,
                    Text      = String.Format(
                        "*[Log]*" +
                        "\n\nSupport session ended due to operator's inactivity" +
                        "\nChatId: `{0}`" +
                        "\nChat: `{1}`" +
                        "\n\n*hash_code:* #UB{2}-{3}",
                        message.Chat.Id,
                        message.Chat.Title,
                        message.Chat.Id.ToString().Replace("-", ""),
                        Guid.NewGuid())
                });
            }

            Task.Run(() => RecordSupportSessionMessage(message));

            return(isFromOperator);
        }