public bool AddAddress(long userId, string address) { try { bool isSuccess = false; if (AddressUtil.IsChecksumAddress(address) || AddressUtil.IsValidEthereumAddressHexFormat(address)) { lock (dbLocker) { using (var db = new AddressesCheckerContext()) { if (db.Addresses.Any(c => c.UserId == userId)) { ExecuteSql($"DELETE FROM Addresses WHERE UserId='{userId}'"); } var balance = CheckBalance(address).Result; db.Addresses.Add(new Address(address, userId) { Balance = balance }); db.SaveChanges(); isSuccess = true; } } } else { Send(new MessageSentEventArgs() { Target = userId.ToString(), Response = new CommandResponse($"Looks like `{address}` is not valid eth address, you have to check it`", parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown) }); return(false); } return(isSuccess); } catch (Exception ex) { Send(new MessageSentEventArgs() { Target = userId.ToString(), Response = new CommandResponse($"Exception `{ex.Message}` happened at your request, try again.", parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown) }); return(false); } }
public EtherBalanceBot(string key, int adminId, List <string> questions) : base(key, adminId, null, "BalanceChecker", true, questions) { _db = new AddressesCheckerContext(); Task.Run(Schedule); }