private async void Transport_TextMessageReceived(object sender, EventArgs <BotTextMessage> e) { try { if (e?.Item1?.Text?.IsNullOrEmpty() != false) { return; } Core.Log.LibVerbose("Message received, looking for command..."); _counterMessagesReceived.Increment(); var message = e.Item1; var sCommands = Commands.Where((cmd, sMessage) => cmd.Condition(sMessage.Text), message).ToArray(); if (sCommands.Any()) { #region Get Chat if (Chats.TryGet(message.Chat.Id, out var storedChat)) { storedChat.ChatType = message.Chat.ChatType; storedChat.Name = message.Chat.Name; // message.Chat.State = storedChat.State; } else { Chats.Add(message.Chat); } #endregion #region Get User if (!Users.Contains(message.User.Id)) { Users.Add(message.User); } #endregion foreach (var sCommand in sCommands) { Core.Log.LibVerbose("Executing command for: {0}", message.Text); var res = await sCommand.Handler(this, message).ConfigureAwait(false); Core.Log.LibVerbose("Command executed."); if (res) { break; } } } else { Core.Log.LibVerbose("Command not found for the message: {0}", message.Text); } } catch (Exception ex) { Core.Log.Write(ex); } }
public async Task SendTextMessageAsync(BotChat chat, string message, MessageParseMode parseMode = MessageParseMode.Default) { if (!IsConnected) { return; } Core.Log.LibVerbose("Sending text message. ChatId = {0}, Message = {1}", chat?.Id, message); await Transport.SendTextMessageAsync(chat, message, parseMode).ConfigureAwait(false); Core.Log.LibVerbose("Message sent."); _counterMessagesSent.Increment(); }
public bool TrackChat(BotChat chat) { if (chat is null) { return(false); } lock (TrackedChats) { if (TrackedChats.Contains(chat.Id)) { return(false); } TrackedChats.Add(chat); Core.Log.LibVerbose("Chat Tracked"); _counterTrackedChat.Increment(); OnTrackedChatsChanged?.Invoke(this, EventArgs.Empty); return(true); } }
public void IncrementMessagesReceived() { _messagesReceivedCount?.Increment(); }
public void IncrementMessagesSent() { _messagesSentCount?.Increment(); }
public void IncrementTotalExceptions() { _totalExceptions?.Increment(); }
public int IncrementMessages() { _totalMessagesReceived?.Increment(); _currentMessages?.Increment(); return(Interlocked.Increment(ref CurrentMessages)); }
public void IncrementTotalMessagesProccesed() { _totalMessagesProcessed?.Increment(); }