예제 #1
0
        private Message SendMessage(long chatId, string text, long replyTo, ref EchoOptions echoOptions)
        {
            Trace.WriteLine(text);
            if (echoOptions == null)
            {
                echoOptions = EchoOptions.SimpleEcho();
            }

#if ONECHAT_DEBUG
            text   = $"message to chat {chatId}: {text}";
            chatId = RealChat;
#endif
            var originalText = text;
            text = LS.Escape(text);    //todo: çäåñü ïðîáëåìà, ïîòîìó ÷òî âåðí¸òñÿ unescaped è ïîòîì îïÿòü áóäåò escape ïðè îáíîâëåíèè

            EchoOptions options = echoOptions;
            return(_limiter.RespectLimitForChat(chatId, () =>
            {
                TelemetryStatic.TelemetryClient.TrackEvent(TelemetryStatic.SendMessageKey, new Dictionary <string, string> {
                    [TelemetryStatic.ToChatKey] = chatId.ToString()
                });
                var result = _api.SendTextMessage(chatId, text, false, false, (int)replyTo, options.ReplyMarkup,
                                                  ParseMode.Markdown).FromResult2(text);

                var textProperty = result.GetType().GetProperty("Text");
                textProperty.SetValue(result, originalText);//todo: low dirty thing because escaping occure in wrong place

                return result;
            }));
        }
예제 #2
0
 public Echo(int id, string text, ApiChat apiChat, EchoOptions echoOptions)
 {
     _apiChat     = apiChat;
     _echoOptions = echoOptions;
     _id          = id;
     Text         = text;
 }
예제 #3
0
        public Echo Echo(string str, long?replyTo = null, EchoOptions echoOptions = null)
        {
            string format;

            try
            {
                format = string.Format(str, _stack.Cast <object>().ToArray());
            }
            catch (FormatException exception)
            {
                throw new FormatException("Seems stack misses values", exception);
            }
            return(_apiChat.Echo(format, replyTo ?? 0, echoOptions));
        }
예제 #4
0
        public Echo UpdateEchoInlineButtons(int messageId, EchoOptions echoOptions)
        {
            // ReSharper disable once JoinDeclarationAndInitializer
            long chatId;

#if ONECHAT_DEBUG
            chatId = RealChat;
#else
            chatId = _chat.Id;
#endif
            TelemetryStatic.TelemetryClient.TrackEvent(TelemetryStatic.EditInlineKey, new Dictionary <string, string> {
                [TelemetryStatic.ToChatKey] = chatId.ToString()
            });
            var result = _api.EditMessageReplyMarkup(chatId, messageId, echoOptions.ReplyMarkup).FromResult2();
            return(EchoFromMessage(result, echoOptions));
        }
예제 #5
0
        public void ReplyEcho(string str, EchoOptions echoOptions = null)
        {
            switch (Update.Type)
            {
            case UpdateType.MessageUpdate:
                Echo(str, Update.Message.MessageId, echoOptions);
                break;

            case UpdateType.CallbackQueryUpdate:
                _apiChat.ReplyQuery(str, Update.CallbackQuery.Id);
                //Update.CallbackQuery.Id
                break;

            default:
                throw new InvalidOperationException("Message you are trying to reply to unsupported message");
            }
        }
예제 #6
0
        public Echo UpdateEchoText(int messageId, string newText, EchoOptions echoOptions = null)
        {
            Trace.WriteLine(newText);
            var chatId = _chat.Id;

#if ONECHAT_DEBUG
            newText = $"echo update to chat {chatId} {newText}";
            chatId  = RealChat;
#endif
            newText = LS.Escape(newText);
            return(_limiter.RespectLimitForChat(chatId, () =>
            {
                TelemetryStatic.TelemetryClient.TrackEvent(TelemetryStatic.EditMessageKey, new Dictionary <string, string> {
                    [TelemetryStatic.ToChatKey] = chatId.ToString()
                });
                Message result = _api.EditMessageText(chatId, messageId, newText, ParseMode.Markdown, false, echoOptions?.ReplyMarkup).FromResult2(newText);
                return EchoFromMessage(result, null);
            }));
        }
예제 #7
0
 public Echo Update(EchoOptions echoInlineButtons)
 {
     _echoOptions = echoInlineButtons;
     return(_apiChat.UpdateEchoInlineButtons(Id, echoInlineButtons));
 }
예제 #8
0
 private Echo EchoFromMessage(Message result, EchoOptions echoOptions)
 {
     return(new Echo(result.MessageId, result.Text, this, echoOptions));
 }
예제 #9
0
        public Echo Echo(string text, long replyTo, EchoOptions echoOptions)
        {
            var result = SendMessage(_chat.Id, text, replyTo, ref echoOptions);

            return(EchoFromMessage(result, echoOptions));
        }
예제 #10
0
        public Echo PrivateEcho(long userId, string text, EchoOptions echoOptions = null)
        {
            var message = SendMessage(userId, text, 0, ref echoOptions);

            return(EchoFromMessage(message, echoOptions));
        }