public Core( Logger logger, List <OnboardClient> onboardClients, SecureString googleSheetsConfig, SecureString telegramToken) { this.logger = logger; this.telegramBot = new TelegramBot(this.logger, telegramToken); this.stockClients = new Dictionary <long, StockSheetsClient>(); foreach (OnboardClient onboardClient in onboardClients) { try { StockSheetsClient stockClient = new StockSheetsClient( googleSheetsConfig, onboardClient.SheetId, onboardClient.SheetPage, new Cell(onboardClient.ConfigCell)); this.stockClients.Add(onboardClient.ChatId, stockClient); this.logger.Log(109, onboardClient.ChatId, "Previous data:" + stockClient.ToLogMessage()); } catch (Exception ex) { this.logger.LogError(105, onboardClient.ChatId, $"Something wrong.", ex); this.telegramBot.SendMessage(onboardClient.ChatId, Logger.GetLogErrorMessage( "There is an error in your configuration or in your table." + " Bot will not calculate your guild stock this time.", ex)); } } }
private void ProcessMessage(Message message, StockSheetsClient stockClient) { if (message.ForwardFrom?.Id != ChatWarsChatId) { return; } Match match = regex.Match(message.Text); if (!match.Success) { string logMessage = $"Failed to parse message from {message.From}: {message.Text}."; this.logger.Log(101, message.Chat.Id, logMessage); this.messagesToSend.Add(new Tuple <long, string> (message.Chat.Id, logMessage)); return; } string resourceName = match.Groups[ResourceNameRegexGroupName].Value.Trim(); int resourceCount = int.Parse(match.Groups[ResourceCountRegexGroupName].Value); List <string> messagesToLog; stockClient.AddResource( message.From.Id, message.From.Username, resourceName, resourceCount, out messagesToLog); messagesToLog.ForEach(x => { this.logger.Log(102, message.Chat.Id, x); this.messagesToSend.Add(new Tuple <long, string> (message.Chat.Id, x)); }); this.logger.Log( 103, message.Chat.Id, $"User {message.From.Username} ({message.From.Id}) deposited {resourceName} ({resourceCount})."); }