diff --git a/README.md b/README.md index 00722cc9..4d553abe 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ Works with [RealDeviceMap](https://github.com/123FLO321/RealDeviceMap) //Google maps key. "gmapsKey": "", + //Enable discord user subscriptions for custom notifications to Quests/Raids/Pokemon, if enabled database information is required below. + "enableSubscriptions": false, + //MySQL database connection string. "connectionString": "Uid=user;Password=password;Server=127.0.0.1;Port=3306;Database=brockdb", @@ -137,4 +140,10 @@ Works with [RealDeviceMap](https://github.com/123FLO321/RealDeviceMap) 34.01,-117.01 34.02,-117.02 34.03,-117.03 -``` \ No newline at end of file +``` + + +## TODO: +- Allow Pokemon id and name in Pokemon filter lists. +- Localization +- Wiki \ No newline at end of file diff --git a/config.example.json b/config.example.json index 995fc1c3..061668c3 100644 --- a/config.example.json +++ b/config.example.json @@ -1,6 +1,5 @@ { "token": "", - "enabled": true, "ownerId": 000000000000, "supporterRoleId": 000000000000, "moderators": [ @@ -9,6 +8,7 @@ "guildId": 000000000000, "webhookPort": 8002, "gmapsKey": "", + "enableSubscriptions": false, "connectionString": "", "cityRoles": [ "City1", diff --git a/src/Bot.cs b/src/Bot.cs index 4bf09081..cf38ad0e 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -23,9 +23,6 @@ using ServiceStack.OrmLite; - //TODO: Quest subscription notifications. - //TODO: Filter quests by rewards. - public class Bot { #region Variables @@ -56,8 +53,11 @@ public Bot(WhConfig whConfig) _whm.RaidAlarmTriggered += OnRaidAlarmTriggered; _whm.QuestAlarmTriggered += OnQuestAlarmTriggered; _whm.PokemonSubscriptionTriggered += OnPokemonSubscriptionTriggered; - _whm.RaidSubscriptionTriggered += OnRaidSubscriptionTriggered; - _whm.QuestSubscriptionTriggered += OnQuestSubscriptionTriggered; + if (_whConfig.EnableSubscriptions) + { + _whm.RaidSubscriptionTriggered += OnRaidSubscriptionTriggered; + _whm.QuestSubscriptionTriggered += OnQuestSubscriptionTriggered; + } _logger.Info("WebHookManager is running..."); @@ -81,12 +81,17 @@ public Bot(WhConfig whConfig) _client.ClientErrored += Client_ClientErrored; _client.DebugLogger.LogMessageReceived += DebugLogger_LogMessageReceived; + if (_whConfig.EnableSubscriptions) + { + _subMgr = new SubscriptionManager(); + } + DependencyCollection dep; using (var d = new DependencyCollectionBuilder()) { d.AddInstance ( - _dep = new Dependencies(_subMgr = new SubscriptionManager(), _whConfig) + _dep = new Dependencies(_subMgr, _whConfig) //LobbyManager = new RaidLobbyManager(_client, _config, _logger, notificationProcessor.GeofenceSvc), //ReminderSvc = new ReminderService(_client, _db, _logger), //PoGoVersionMonitor = new PokemonGoVersionMonitor(), @@ -367,6 +372,9 @@ private void OnQuestSubscriptionTriggered(object sender, QuestData e) private async Task ProcessPokemonSubscription(PokemonData pkmn) { + if (!_whConfig.EnableSubscriptions) + return; + var db = Database.Instance; if (!db.Pokemon.ContainsKey(pkmn.Id)) return; @@ -467,6 +475,9 @@ private async Task ProcessPokemonSubscription(PokemonData pkmn) private async Task ProcessRaidSubscription(RaidData raid) { + if (!_whConfig.EnableSubscriptions) + return; + var db = Database.Instance; if (!db.Pokemon.ContainsKey(raid.PokemonId)) return; @@ -565,6 +576,9 @@ private async Task ProcessRaidSubscription(RaidData raid) private async Task ProcessQuestSubscription(QuestData quest) { + if (!_whConfig.EnableSubscriptions) + return; + var db = Database.Instance; var reward = quest.Rewards[0].Info; var rewardKeyword = quest.GetRewardString(); diff --git a/src/Commands/Notifications.cs b/src/Commands/Notifications.cs index 31afecd0..b6d2305d 100644 --- a/src/Commands/Notifications.cs +++ b/src/Commands/Notifications.cs @@ -33,6 +33,12 @@ public Notifications(Dependencies dep) public async Task InfoAsync(CommandContext ctx, [Description("Discord user mention string.")] string mention = "") { + if (!_dep.WhConfig.EnableSubscriptions) + { + await ctx.RespondAsync($"{ctx.User.Mention} Subscriptions are not enabled in the config."); + return; + } + if (string.IsNullOrEmpty(mention)) { await SendUserSubscriptionSettings(ctx.Client, ctx.User, ctx.User.Id); @@ -63,6 +69,12 @@ public async Task InfoAsync(CommandContext ctx, ] public async Task EnableDisableAsync(CommandContext ctx) { + if (!_dep.WhConfig.EnableSubscriptions) + { + await ctx.RespondAsync($"{ctx.User.Mention} Subscriptions are not enabled in the config."); + return; + } + if (!_dep.SubscriptionManager.UserExists(ctx.User.Id)) { await ctx.TriggerTypingAsync(); @@ -89,6 +101,12 @@ public async Task PokeMeAsync(CommandContext ctx, [Description("Minimum level to receive notifications for, use 0 to disregard level.")] int lvl = 0, [Description("Specific gender the Pokemon must be, use * to disregard gender.")] string gender = "*") { + if (!_dep.WhConfig.EnableSubscriptions) + { + await ctx.RespondAsync($"{ctx.User.Mention} Subscriptions are not enabled in the config."); + return; + } + var isSupporter = ctx.Client.IsSupporterOrHigher(ctx.User.Id, _dep.WhConfig); if (!isSupporter) { @@ -304,6 +322,12 @@ await ctx.RespondAsync public async Task PokeMeNotAsync(CommandContext ctx, [Description("Pokemon name or id to unsubscribe from Pokemon spawn notifications.")] string poke) { + if (!_dep.WhConfig.EnableSubscriptions) + { + await ctx.RespondAsync($"{ctx.User.Mention} Subscriptions are not enabled in the config."); + return; + } + if (!_dep.SubscriptionManager.UserExists(ctx.User.Id)) { await ctx.TriggerTypingAsync(); @@ -389,6 +413,12 @@ public async Task RaidMeAsync(CommandContext ctx, [Description("Pokemon name or id to subscribe to raid notifications.")] string poke, [Description("City to send the notification if the raid appears in otherwise if null all will be sent.")] string city = null) { + if (!_dep.WhConfig.EnableSubscriptions) + { + await ctx.RespondAsync($"{ctx.User.Mention} Subscriptions are not enabled in the config."); + return; + } + var isSupporter = ctx.Client.IsSupporterOrHigher(ctx.User.Id, _dep.WhConfig); if (!isSupporter) { @@ -525,6 +555,12 @@ public async Task RaidMeNotAsync(CommandContext ctx, [Description("Pokemon name or id to unsubscribe from raid notifications.")] string poke, [Description("City to remove the quest notifications from otherwise if null all will be sent.")] string city = null) { + if (!_dep.WhConfig.EnableSubscriptions) + { + await ctx.RespondAsync($"{ctx.User.Mention} Subscriptions are not enabled in the config."); + return; + } + if (string.Compare(city, Strings.All, true) != 0 && !string.IsNullOrEmpty(city)) { if (_dep.WhConfig.CityRoles.Find(x => string.Compare(x.ToLower(), city.ToLower(), true) == 0) == null) @@ -622,6 +658,12 @@ public async Task QuestMeAsync(CommandContext ctx, [Description("Reward keyword to use to find field research. Example: Spinda, 1200 stardust, candy")] string rewardKeyword, [Description("City to send the notification if the quest appears in otherwise if null all will be sent.")] string city = null) { + if (!_dep.WhConfig.EnableSubscriptions) + { + await ctx.RespondAsync($"{ctx.User.Mention} Subscriptions are not enabled in the config."); + return; + } + if (string.Compare(city, Strings.All, true) != 0 && !string.IsNullOrEmpty(city)) { if (_dep.WhConfig.CityRoles.Find(x => string.Compare(x.ToLower(), city.ToLower(), true) == 0) == null) @@ -685,6 +727,12 @@ public async Task QuestMeNotAsync(CommandContext ctx, [Description("Reward keyword to remove from field research quest subscriptions. Example: Spinda, 1200 stardust, candy")] string rewardKeyword, [Description("City to remove the quest notifications from otherwise if null all will be sent.")] string city = null) { + if (!_dep.WhConfig.EnableSubscriptions) + { + await ctx.RespondAsync($"{ctx.User.Mention} Subscriptions are not enabled in the config."); + return; + } + if (string.Compare(city, Strings.All, true) != 0 && !string.IsNullOrEmpty(city)) { if (_dep.WhConfig.CityRoles.Find(x => string.Compare(x.ToLower(), city.ToLower(), true) == 0) == null) diff --git a/src/Configuration/WhConfig.cs b/src/Configuration/WhConfig.cs index 71e1c982..9e36866a 100644 --- a/src/Configuration/WhConfig.cs +++ b/src/Configuration/WhConfig.cs @@ -41,6 +41,9 @@ public class WhConfig [JsonProperty("mapProviderFork")] public MapProviderFork MapProviderFork { get; set; } + [JsonProperty("enableSubscriptions")] + public bool EnableSubscriptions { get; set; } + [JsonProperty("connectionString")] public string ConnectionString { get; set; } diff --git a/src/Data/DataAccessLayer.cs b/src/Data/DataAccessLayer.cs index cfcfc93f..317b203a 100644 --- a/src/Data/DataAccessLayer.cs +++ b/src/Data/DataAccessLayer.cs @@ -10,6 +10,9 @@ public static class DataAccessLayer public static IDbConnection CreateFactory() { + if (string.IsNullOrEmpty(ConnectionString)) + return null; + var factory = new OrmLiteConnectionFactory(ConnectionString, MySqlDialect.Provider); return factory.Open(); } diff --git a/src/Data/SubscriptionManager.cs b/src/Data/SubscriptionManager.cs index 679bbec0..650956d7 100644 --- a/src/Data/SubscriptionManager.cs +++ b/src/Data/SubscriptionManager.cs @@ -480,6 +480,9 @@ private void CreateDefaultTables() using (var db = DataAccessLayer.CreateFactory()) { + if (db == null) + return; + db.CreateTable(); db.CreateTable(); db.CreateTable(); diff --git a/src/WhMgr.csproj b/src/WhMgr.csproj index c08d2b2a..790385a6 100644 --- a/src/WhMgr.csproj +++ b/src/WhMgr.csproj @@ -67,9 +67,6 @@ - - ..\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll - @@ -82,12 +79,6 @@ ..\packages\System.Memory.4.5.1\lib\netstandard2.0\System.Memory.dll - - ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll - - - ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll - ..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll