public static InlineKeyboardMarkup AddressMenu(ResourceManager resMgr, User u, string id, UserAddress ua, TelegramOptions options) { var buttons = new List <InlineKeyboardButton[]>(); if (ua == null) { buttons.Add3(u, resMgr.Get(Res.AddressInfoButton, u), "address-links " + id, resMgr.Get(Res.Delete, u), "deleteaddress " + id, resMgr.Get(Res.ManageAddress, u), "manageaddress " + id); } else { if (u.Type == 0) { buttons.Add2(u, resMgr.Get(Res.TransactionNotify, ua), (ua.NotifyTransactions ? "tranoff" : "tranon") + " " + id, resMgr.Get(Res.SetThreshold, ua), "setthreshold " + id); buttons.Add2(u, resMgr.Get(Res.DelegationNotify, ua), (ua.NotifyDelegations ? "dlgoff" : "dlgon") + " " + id, resMgr.Get(Res.SetDlgThreshold, ua), "setdlgthreshold " + id); buttons.Add2(u, resMgr.Get(Res.DelegatorsBalanceNotifyToggle, ua), $"toggle_delegators_balance {id}", resMgr.Get(Res.DelegatorsBalanceThresholdButton, ua), "change_delegators_balance_threshold " + id); buttons.Add2(u, resMgr.Get(Res.RewardNotify, ua), (ua.NotifyBakingRewards ? "bakingoff" : "bakingon") + " " + id, resMgr.Get(Res.CycleNotify, ua), (ua.NotifyCycleCompletion ? "cycleoff" : "cycleon") + " " + id); buttons.Add2(u, resMgr.Get(Res.NotifyRightsAssigned, ua), (ua.NotifyRightsAssigned ? "rightsoff" : "rightson") + " " + id, resMgr.Get(Res.MissesNotify, ua), (ua.NotifyMisses ? "missesoff" : "misseson") + " " + id); buttons.Add(u, resMgr.Get(Res.NotifyOutOfFreeSpace, ua), (ua.NotifyOutOfFreeSpace ? "outoffreespaceoff" : "outoffreespaceon") + " " + id); buttons.Add2(u, resMgr.Get(Res.RenameAddress, ua), "setname " + id, resMgr.Get(Res.Delete, ua), "deleteaddress " + id); if (u.IsAdmin(options) || ua.IsOwner) { buttons.Add(u, resMgr.Get(Res.NotifyFollowers, ua), "notifyfollowers " + id); } } else { buttons.Add2(u, resMgr.Get(Res.TransactionNotify, ua), (ua.NotifyTransactions ? "tranoff" : "tranon") + " " + id, resMgr.Get(Res.DelegationNotify, ua), (ua.NotifyDelegations ? "dlgoff" : "dlgon") + " " + id); buttons.Add2(u, resMgr.Get(Res.RewardNotify, ua), (ua.NotifyBakingRewards ? "bakingoff" : "bakingon") + " " + id, resMgr.Get(Res.CycleNotify, ua), (ua.NotifyCycleCompletion ? "cycleoff" : "cycleon") + " " + id); buttons.Add2(u, resMgr.Get(Res.NotifyRightsAssigned, ua), (ua.NotifyRightsAssigned ? "rightsoff" : "rightson") + " " + id, resMgr.Get(Res.MissesNotify, ua), (ua.NotifyMisses ? "missesoff" : "misseson") + " " + id); buttons.Add2(u, resMgr.Get(Res.NotifyOutOfFreeSpace, ua), (ua.NotifyOutOfFreeSpace ? "outoffreespaceoff" : "outoffreespaceon") + " " + id, resMgr.Get(Res.Delete, ua), "deleteaddress " + id); } } return(new InlineKeyboardMarkup(buttons)); }
public TelegramEffect(IOptions <TelegramOptions> options, TelegramBotClient botClient, ILogger <TelegramEffect> logger) { _botClient = botClient; _logger = logger; _telegramOptions = options.Value; }
public TelegramService(IOptions <TelegramOptions> options) { _telegramOptions = options.Value; _httpClient = new HttpClient { BaseAddress = new Uri($"https://api.telegram.org/bot{_telegramOptions.BotToken}/") }; }
public async Task <AboutTelegramBot> UpdateTelegramOptions(TelegramOptions options) { //TODO: Don't check unchanged settings //TODO: Answer more descriptive messages //TODO: Use Uri instead of string concatenation _updater.Save(options); _bot.Initialize(); await _bot.SendMessage(options.AdminChat, "Hello Francis administrator, if you received this message, this means your configuration is valid."); if (!Directory.Exists(options.MediaLocation)) { throw new ArgumentException("Invalid media location"); } return(await _bot.Client.GetMeAsync()); }
public IpWhitelist(IOptions <TelegramOptions> config) { _config = config.Value; _allowedIps = config.Value.TelegramIpWhitelist.Select(IPAddressRange.Parse); }
public ValidateTelegramTokenAttribute(IOptions <TelegramOptions> options) { _telegramOptions = options.Value; }
public CommandsService(IOptions <TelegramOptions> telegramOptions) { _telegramOptions = telegramOptions.Value; }
public InMemoryAuthenticationService(IOptions <TelegramOptions> options, ILogger <InMemoryAuthenticationService> logger) { _logger = logger; _options = options.Value; }
/// <summary> /// Temporary added as extension method /// </summary> /// <param name="user"></param> /// <returns></returns> public static bool IsAdmin(this User user, TelegramOptions config) => config.DevUsers.Contains(user.Username);
public static InlineKeyboardMarkup Settings(ResourceManager resMgr, User user, TelegramOptions options) { var buttons = new List <InlineKeyboardButton[]>(); Action <string, string> add = (text, data) => buttons.Add(new[] { new InlineKeyboardButton { Text = text, CallbackData = data } }); Action <string, string, string, string> add2 = (text1, data1, text2, data2) => buttons.Add(new[] { new InlineKeyboardButton { Text = text1, CallbackData = data1 }, new InlineKeyboardButton { Text = text2, CallbackData = data2 } }); add2("🇺🇸 English", "set_en", "🇷🇺 Русский", "set_ru"); add(resMgr.Get(Res.Explorer, user), "set_explorer"); if (user.HideHashTags) { add(resMgr.Get(Res.HashTags, user), "showhashtags"); } else { add(resMgr.Get(Res.HashTags, user), "hidehashtags"); } add(resMgr.Get(Res.WhaleAlerts, user), "set_whalealert"); add(resMgr.Get(Res.NetworkIssueAlerts, user), "set_nialert"); if (user.VotingNotify) { add(resMgr.Get(Res.VotingNotify, user), "hidevotingnotify"); } else { add(resMgr.Get(Res.VotingNotify, user), "showvotingnotify"); } if (user.ReleaseNotify) { add(resMgr.Get(Res.ReleaseNotify, user), "tezos_release_off"); } else { add(resMgr.Get(Res.ReleaseNotify, user), "tezos_release_on"); } if (user.IsAdmin(options)) { add("🖋 Broadcast message", "broadcast"); add("👫 Get user list", "getuserlist"); foreach (var cmd in TezosBot.Commands.Where(o => o.username == user.Username || o.username == user.Id.ToString())) { add(cmd.commandname, "cmd" + TezosBot.Commands.IndexOf(cmd)); } } add(resMgr.Get(Res.Donate, user), "donate"); return(new InlineKeyboardMarkup(buttons.ToArray())); }
public static InlineKeyboardMarkup AddressMenu(ResourceManager resMgr, User u, string id, UserAddress ua, TelegramOptions options) { var buttons = new List <InlineKeyboardButton[]>(); if (ua == null) { buttons.Add(new[] { new InlineKeyboardButton { Text = resMgr.Get(Res.Delete, u), CallbackData = "deleteaddress " + id }, new InlineKeyboardButton { Text = resMgr.Get(Res.ManageAddress, u), CallbackData = "manageaddress " + id } }); } else { buttons.Add(new[] { new InlineKeyboardButton { Text = resMgr.Get(Res.TransactionNotify, ua), CallbackData = (ua.NotifyTransactions ? "tranoff" : "tranon") + " " + id }, new InlineKeyboardButton { Text = resMgr.Get(Res.SetThreshold, u), CallbackData = "setthreshold " + id } }); buttons.Add(new[] { new InlineKeyboardButton { Text = resMgr.Get(Res.DelegationNotify, ua), CallbackData = (ua.NotifyDelegations ? "dlgoff" : "dlgon") + " " + id }, new InlineKeyboardButton { Text = resMgr.Get(Res.SetDlgThreshold, u), CallbackData = "setdlgthreshold " + id } }); buttons.Add(new[] { InlineKeyboardButton.WithCallbackData( text: resMgr.Get(Res.DelegatorsBalanceNotifyToggle, ua), callbackData: $"toggle_delegators_balance {id}" ), InlineKeyboardButton.WithCallbackData( text: resMgr.Get(Res.DelegatorsBalanceThresholdButton, ua), callbackData: $"change_delegators_balance_threshold {id}" ), }); buttons.Add(new[] { new InlineKeyboardButton { Text = resMgr.Get(Res.RewardNotify, ua), CallbackData = (ua.NotifyBakingRewards ? "bakingoff" : "bakingon") + " " + id }, new InlineKeyboardButton { Text = resMgr.Get(Res.CycleNotify, ua), CallbackData = (ua.NotifyCycleCompletion ? "cycleoff" : "cycleon") + " " + id } }); buttons.Add(new[] { new InlineKeyboardButton { Text = resMgr.Get(Res.RenameAddress, u), CallbackData = "setname " + id }, new InlineKeyboardButton { Text = resMgr.Get(Res.MissesNotify, ua), CallbackData = (ua.NotifyMisses ? "missesoff" : "misseson") + " " + id } }); buttons.Add(new[] { new InlineKeyboardButton { Text = resMgr.Get(Res.Delete, u), CallbackData = "deleteaddress " + id } }); if (u.IsAdmin(options)) { buttons.Add(new[] { new InlineKeyboardButton { Text = resMgr.Get(Res.NotifyFollowers, u), CallbackData = "notifyfollowers " + id } }); } } return(new InlineKeyboardMarkup(buttons)); }
public Telegram(IOptions <TelegramOptions> options, TelegramCallbackHandler handler) { _handler = handler; _options = options.Value; _logger = Log.ForContext <Telegram>(); }
private static bool IsValid(TelegramOptions options) { return(!string.IsNullOrEmpty(options.Token) && !string.IsNullOrEmpty(options.ChatId)); }
public static InlineKeyboardMarkup Settings(ResourceManager resMgr, User user, TelegramOptions options) { var buttons = new List <InlineKeyboardButton[]>(); Action <string, string> add = (text, data) => buttons.Add(new[] { new InlineKeyboardButton { Text = text, CallbackData = (user.Type != 0 ? $"_{user.Id}_" : "") + data } }); Action <string, string, string, string> add2 = (text1, data1, text2, data2) => buttons.Add(new[] { new InlineKeyboardButton { Text = text1, CallbackData = (user.Type != 0 ? $"_{user.Id}_" : "") + data1 }, new InlineKeyboardButton { Text = text2, CallbackData = (user.Type != 0 ? $"_{user.Id}_" : "") + data2 } }); add(resMgr.Get(Res.Language, user.Language, new { flag = Languages.Get(user.Language).Icon, name = Languages.Get(user.Language).Name }), "set_" + Languages.Next(user.Language).Code); add(resMgr.Get(Res.UserCurrency, user), "change_currency"); add(resMgr.Get(Res.Explorer, user), "set_explorer"); if (user.HideHashTags) { add(resMgr.Get(Res.HashTags, user), "showhashtags"); } else { add(resMgr.Get(Res.HashTags, user), "hidehashtags"); } add(resMgr.Get(Res.WhaleAlerts, user), "set_whalealert"); //add(resMgr.Get(Res.NetworkIssueAlerts, user), "set_nialert"); if (user.VotingNotify) { add(resMgr.Get(Res.VotingNotify, user), "hidevotingnotify"); } else { add(resMgr.Get(Res.VotingNotify, user), "showvotingnotify"); } if (user.ReleaseNotify) { add(resMgr.Get(Res.ReleaseNotify, user), "tezos_release_off"); } else { add(resMgr.Get(Res.ReleaseNotify, user), "tezos_release_on"); } if (user.IsAdmin(options)) { add("🖋 Broadcast message", "broadcast"); foreach (var cmd in TezosBot.Commands.Where(o => o.username == user.Username || o.username == user.Id.ToString())) { add(cmd.commandname, "cmd" + TezosBot.Commands.IndexOf(cmd)); } } add(resMgr.Get(Res.Donate, user), "donate"); return(new InlineKeyboardMarkup(buttons.ToArray())); }