diff --git a/src/Bot.cs b/src/Bot.cs index b1127947..32c2ed41 100644 --- a/src/Bot.cs +++ b/src/Bot.cs @@ -27,6 +27,8 @@ using DSharpPlus.EventArgs; using DSharpPlus.CommandsNext; using DSharpPlus.Interactivity; + using DSharpPlus.Interactivity.Extensions; + using Microsoft.Extensions.DependencyInjection; // TODO: List all subscriptions with info command // TODO: IV wildcards @@ -96,38 +98,31 @@ public Bot(WhConfigHolder whConfig) serverConfig.LoadDmAlerts(); var client = new DiscordClient(new DiscordConfiguration { - AutomaticGuildSync = true, AutoReconnect = true, - EnableCompression = true, + AlwaysCacheMembers = true, + GatewayCompressionLevel = GatewayCompressionLevel.Payload, Token = serverConfig.Token, TokenType = TokenType.Bot, - UseInternalLogHandler = true + MinimumLogLevel = Microsoft.Extensions.Logging.LogLevel.Error, + Intents = DiscordIntents.DirectMessages + | DiscordIntents.DirectMessageReactions + | DiscordIntents.DirectMessageTyping + | DiscordIntents.GuildEmojis + | DiscordIntents.GuildMembers + | DiscordIntents.GuildMessages + | DiscordIntents.GuildMessageReactions + | DiscordIntents.GuildMessageTyping + | DiscordIntents.GuildPresences + | DiscordIntents.Guilds + | DiscordIntents.GuildWebhooks, + ReconnectIndefinitely = true, }); - // If you are on Windows 7 and using .NETFX, install - // DSharpPlus.WebSocket.WebSocket4Net from NuGet, - // add appropriate usings, and uncomment the following - // line - //client.SetWebSocketClient(); - - // If you are on Windows 7 and using .NET Core, install - // DSharpPlus.WebSocket.WebSocket4NetCore from NuGet, - // add appropriate usings, and uncomment the following - // line - //client.SetWebSocketClient(); - - // If you are using Mono, install - // DSharpPlus.WebSocket.WebSocketSharp from NuGet, - // add appropriate usings, and uncomment the following - // line - //client.SetWebSocketClient(); - client.Ready += Client_Ready; client.GuildAvailable += Client_GuildAvailable; client.GuildMemberUpdated += Client_GuildMemberUpdated; //_client.MessageCreated += Client_MessageCreated; client.ClientErrored += Client_ClientErrored; - client.DebugLogger.LogMessageReceived += DebugLogger_LogMessageReceived; // Configure Discord interactivity module var interactivity = client.UseInteractivity @@ -135,10 +130,10 @@ public Bot(WhConfigHolder whConfig) new InteractivityConfiguration { // default pagination behaviour to just ignore the reactions - PaginationBehaviour = TimeoutBehaviour.Ignore, + //PaginationBehaviour = TimeoutBehaviour.Ignore, - // default pagination timeout to 5 minutes - PaginationTimeout = TimeSpan.FromMinutes(5), + PollBehaviour = DSharpPlus.Interactivity.Enums.PollBehaviour.KeepEmojis, + PaginationBehaviour = DSharpPlus.Interactivity.Enums.PaginationBehaviour.WrapAround, // default timeout for other actions to 2 minutes Timeout = TimeSpan.FromMinutes(2) @@ -146,19 +141,24 @@ public Bot(WhConfigHolder whConfig) ); // Build the dependency collection which will contain our objects that can be globally used within each command module - DependencyCollection dep; - using (var d = new DependencyCollectionBuilder()) + var servicesCollection = new ServiceCollection() + .AddSingleton(interactivity) + .AddSingleton(_whConfig) + .AddSingleton(new StripeService(_whConfig.Instance.StripeApiKey)) + .AddSingleton(new Osm.OsmManager()) + .AddSingleton(_whm); + if (_subProcessor != null) { - d.AddInstance(new Dependencies(interactivity, _whm, _subProcessor, _whConfig, new StripeService(_whConfig.Instance.StripeApiKey))); - dep = d.Build(); + servicesCollection.AddSingleton(_subProcessor ?? new SubscriptionProcessor(_servers, _whConfig, _whm)); } + var services = servicesCollection.BuildServiceProvider(); // Discord commands configuration var commands = client.UseCommandsNext ( new CommandsNextConfiguration { - StringPrefix = serverConfig.CommandPrefix?.ToString(), + StringPrefixes = new[] { serverConfig.CommandPrefix?.ToString() }, EnableDms = true, // If command prefix is null, allow for mention prefix EnableMentionPrefix = string.IsNullOrEmpty(serverConfig.CommandPrefix), @@ -166,7 +166,7 @@ public Bot(WhConfigHolder whConfig) EnableDefaultHelp = true, CaseSensitive = false, IgnoreExtraArguments = true, - Dependencies = dep + Services = services, } ); commands.CommandExecuted += Commands_CommandExecuted; @@ -292,24 +292,25 @@ public async Task Stop() #region Discord Events - private Task Client_Ready(ReadyEventArgs e) + private Task Client_Ready(DiscordClient client, ReadyEventArgs e) { _logger.Info($"------------------------------------------"); _logger.Info($"[DISCORD] Connected."); _logger.Info($"[DISCORD] ----- Current Application"); - _logger.Info($"[DISCORD] Name: {e.Client.CurrentApplication.Name}"); - _logger.Info($"[DISCORD] Description: {e.Client.CurrentApplication.Description}"); - _logger.Info($"[DISCORD] Owner: {e.Client.CurrentApplication.Owner.Username}#{e.Client.CurrentApplication.Owner.Discriminator}"); + _logger.Info($"[DISCORD] Name: {client.CurrentApplication.Name}"); + _logger.Info($"[DISCORD] Description: {client.CurrentApplication.Description}"); + var owners = string.Join("\n", client.CurrentApplication.Owners.Select(x => $"{x.Username}#{x.Discriminator}")); + _logger.Info($"[DISCORD] Owner: {owners}"); _logger.Info($"[DISCORD] ----- Current User"); - _logger.Info($"[DISCORD] Id: {e.Client.CurrentUser.Id}"); - _logger.Info($"[DISCORD] Name: {e.Client.CurrentUser.Username}#{e.Client.CurrentUser.Discriminator}"); - _logger.Info($"[DISCORD] Email: {e.Client.CurrentUser.Email}"); + _logger.Info($"[DISCORD] Id: {client.CurrentUser.Id}"); + _logger.Info($"[DISCORD] Name: {client.CurrentUser.Username}#{client.CurrentUser.Discriminator}"); + _logger.Info($"[DISCORD] Email: {client.CurrentUser.Email}"); _logger.Info($"------------------------------------------"); return Task.CompletedTask; } - private async Task Client_GuildAvailable(GuildCreateEventArgs e) + private async Task Client_GuildAvailable(DiscordClient client, GuildCreateEventArgs e) { // If guild is in configured servers list then attempt to create emojis needed if (!_whConfig.Instance.Servers.ContainsKey(e.Guild.Id)) @@ -318,18 +319,12 @@ private async Task Client_GuildAvailable(GuildCreateEventArgs e) // Create default emojis await CreateEmojis(e.Guild.Id); - if (!(e.Client is DiscordClient client)) - { - _logger.Error($"DiscordClient is null, Unable to update status."); - return; - } - // Set custom bot status if guild is in config server list var status = _whConfig.Instance.Servers[e.Guild.Id].Status; - await client.UpdateStatusAsync(new DiscordGame(status ?? $"v{Strings.Version}"), UserStatus.Online); + await client.UpdateStatusAsync(new DiscordActivity(status ?? $"v{Strings.Version}"), UserStatus.Online); } - private async Task Client_GuildMemberUpdated(GuildMemberUpdateEventArgs e) + private async Task Client_GuildMemberUpdated(DiscordClient client, GuildMemberUpdateEventArgs e) { if (!_whConfig.Instance.Servers.ContainsKey(e.Guild.Id)) return; @@ -397,17 +392,17 @@ private async Task Client_GuildMemberUpdated(GuildMemberUpdateEventArgs e) // await _commands.HandleCommandsAsync(e); //} - private async Task Client_ClientErrored(ClientErrorEventArgs e) + private async Task Client_ClientErrored(DiscordClient client, ClientErrorEventArgs e) { _logger.Error(e.Exception); await Task.CompletedTask; } - private async Task Commands_CommandExecuted(CommandExecutionEventArgs e) + private async Task Commands_CommandExecuted(CommandsNextExtension commands, CommandExecutionEventArgs e) { // let's log the name of the command and user - e.Context.Client.DebugLogger.LogMessage(DSharpPlus.LogLevel.Info, Strings.BotName, $"{e.Context.User.Username} successfully executed '{e.Command.QualifiedName}'", DateTime.Now); + //e.Context.Client.DebugLogger.LogMessage(DSharpPlus.LogLevel.Info, Strings.BotName, $"{e.Context.User.Username} successfully executed '{e.Command.QualifiedName}'", DateTime.Now); // since this method is not async, let's return // a completed task, so that no additional work @@ -415,9 +410,9 @@ private async Task Commands_CommandExecuted(CommandExecutionEventArgs e) await Task.CompletedTask; } - private async Task Commands_CommandErrored(CommandErrorEventArgs e) + private async Task Commands_CommandErrored(CommandsNextExtension commands, CommandErrorEventArgs e) { - e.Context.Client.DebugLogger.LogMessage(DSharpPlus.LogLevel.Error, Strings.BotName, $"{e.Context.User.Username} tried executing '{e.Command?.QualifiedName ?? e.Context.Message.Content}' but it errored: {e.Exception.GetType()}: {e.Exception.Message ?? ""}", DateTime.Now); + //e.Context.Client.DebugLogger.LogMessage(DSharpPlus.LogLevel.Error, Strings.BotName, $"{e.Context.User.Username} tried executing '{e.Command?.QualifiedName ?? e.Context.Message.Content}' but it errored: {e.Exception.GetType()}: {e.Exception.Message ?? ""}", DateTime.Now); // let's check if the error is a result of lack of required permissions if (e.Exception is DSharpPlus.CommandsNext.Exceptions.ChecksFailedException) @@ -441,13 +436,13 @@ private async Task Commands_CommandErrored(CommandErrorEventArgs e) var guildId = e.Context.Guild?.Id ?? e.Context.Client.Guilds.FirstOrDefault(x => _whConfig.Instance.Servers.ContainsKey(x.Key)).Key; var prefix = _whConfig.Instance.Servers.ContainsKey(guildId) ? _whConfig.Instance.Servers[guildId].CommandPrefix : "!"; - var example = $"Command Example: ```{prefix}{e.Command.Name} {string.Join(" ", e.Command.Arguments.Select(x => x.IsOptional ? $"[{x.Name}]" : x.Name))}```\r\n*Parameters in brackets are optional.*"; + //var example = $"Command Example: ```{prefix}{e.Command.Name} {string.Join(" ", e.Command.Arguments.Select(x => x.IsOptional ? $"[{x.Name}]" : x.Name))}```\r\n*Parameters in brackets are optional.*"; // let's wrap the response into an embed var embed = new DiscordEmbedBuilder { Title = $"{emoji} Invalid Argument(s)", - Description = $"{string.Join(Environment.NewLine, e.Command.Arguments.Select(x => $"Parameter **{x.Name}** expects type **{x.Type.ToHumanReadableString()}.**"))}.\r\n\r\n{example}", + //Description = $"{string.Join(Environment.NewLine, e.Command.Overloads.Select(x => x.Arguments).Select(x => $"Parameter **{x.Name}** expects type **{x.Type.ToHumanReadableString()}.**"))}.\r\n\r\n{example}", Color = new DiscordColor(0xFF0000) // red }; await e.Context.RespondAsync(embed: embed); @@ -462,54 +457,6 @@ private async Task Commands_CommandErrored(CommandErrorEventArgs e) } } - private void DebugLogger_LogMessageReceived(object sender, DebugLogMessageEventArgs e) - { - //Color - ConsoleColor color; - switch (e.Level) - { - case DSharpPlus.LogLevel.Error: color = ConsoleColor.DarkRed; break; - case DSharpPlus.LogLevel.Warning: color = ConsoleColor.Yellow; break; - case DSharpPlus.LogLevel.Info: color = ConsoleColor.White; break; - case DSharpPlus.LogLevel.Critical: color = ConsoleColor.Red; break; - case DSharpPlus.LogLevel.Debug: default: color = ConsoleColor.DarkGray; break; - } - - //Source - var sourceName = e.Application; - - //Text - var text = e.Message; - - //Build message - var builder = new System.Text.StringBuilder(text.Length + (sourceName?.Length ?? 0) + 5); - if (sourceName != null) - { - builder.Append('['); - builder.Append(sourceName); - builder.Append("] "); - } - - for (var i = 0; i < text.Length; i++) - { - //Strip control chars - var c = text[i]; - if (!char.IsControl(c)) - builder.Append(c); - } - - if (text != null) - { - builder.Append(": "); - builder.Append(text); - } - - text = builder.ToString(); - Console.ForegroundColor = color; - Console.WriteLine(text); - Console.ResetColor(); - } - #endregion #region WebhookManager Events @@ -1072,7 +1019,7 @@ await statsChannel.SendMessageAsync(Translator.Instance.Translate("SHINY_STATS_M id = pokemon, shiny = pkmnStats.Shiny.ToString("N0"), total = pkmnStats.Total.ToString("N0"), - chance = chance, + chance, })); Thread.Sleep(500); @@ -1184,14 +1131,14 @@ private async void UnhandledExceptionHandler(object sender, UnhandledExceptionEv var client = _servers[guildId]; if (client != null) { - var owner = await client.GetUserAsync(serverConfig.OwnerId); + var owner = await client.GetMemberById(guildId, serverConfig.OwnerId); if (owner == null) { _logger.Warn($"Unable to get owner from id {serverConfig.OwnerId}."); return; } - await client.SendDirectMessage(owner, Translator.Instance.Translate("BOT_CRASH_MESSAGE"), null); + await owner.SendDirectMessage(Translator.Instance.Translate("BOT_CRASH_MESSAGE"), null); } } } diff --git a/src/Commands/Areas.cs b/src/Commands/Areas.cs index 2c7cd3eb..517c328b 100644 --- a/src/Commands/Areas.cs +++ b/src/Commands/Areas.cs @@ -1,32 +1,32 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -using DSharpPlus.CommandsNext; -using DSharpPlus.CommandsNext.Attributes; -using DSharpPlus.Entities; -using DSharpPlus.Interactivity; - -using WhMgr.Diagnostics; -using WhMgr.Extensions; -using WhMgr.Localization; -using WhMgr.Net.Webhooks; - -namespace WhMgr.Commands +namespace WhMgr.Commands { - public class Areas + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + + using DSharpPlus.CommandsNext; + using DSharpPlus.CommandsNext.Attributes; + using DSharpPlus.Entities; + using DSharpPlus.Interactivity; + using DSharpPlus.Interactivity.Extensions; + + using WhMgr.Configuration; + using WhMgr.Diagnostics; + using WhMgr.Extensions; + using WhMgr.Net.Webhooks; + + public class Areas : BaseCommandModule { private static readonly IEventLogger _logger = EventLogger.GetLogger("AREAS", Program.LogLevel); + private readonly WhConfigHolder _config; + private readonly WebhookController _whm; - private readonly Dependencies _dep; - - public Areas(Dependencies dep) + public Areas(WhConfigHolder config, WebhookController whm) { - _dep = dep; + _config = config; + _whm = whm; } @@ -37,26 +37,23 @@ public Areas(Dependencies dep) ] public async Task SendPaginated(CommandContext ctx) { - if (!await ctx.IsDirectMessageSupported(_dep.WhConfig)) + if (!await ctx.IsDirectMessageSupported(_config.Instance)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; - - var geofences = _dep.Whm.GetServerGeofences(guildId); + var server = _config.Instance.Servers[guildId]; + var geofences = _whm.GetServerGeofences(guildId); + var areas = geofences.Select(geofence => geofence.Name).OrderBy(Name => Name).ToList(); - List areas = geofences.Select(geofence => geofence.Name).OrderBy(Name => Name).ToList(); - - - var interactivity = ctx.Client.GetInteractivityModule(); - List pages = new List(); - int pagelength = 0; + var interactivity = ctx.Client.GetInteractivity(); + var pages = new List(); + var pagelength = 0; var psb = new StringBuilder(); - int linesThisPage = 0; - int num = 1; + var linesThisPage = 0; + var num = 1; var title = string.Format("Page {0}", (object)num); foreach (var line in areas.Select(area => $"- {area}\n")) { @@ -97,10 +94,7 @@ public async Task SendPaginated(CommandContext ctx) pages.Add(new Page { Embed = eb }); } - await interactivity.SendPaginatedMessage(ctx.Channel, ctx.User, pages, timeoutoverride: TimeSpan.FromMinutes(5)); + await interactivity.SendPaginatedMessageAsync(ctx.Channel, ctx.User, pages);//, timeoutoverride: TimeSpan.FromMinutes(5)); } - } - - -} +} \ No newline at end of file diff --git a/src/Commands/Dependencies.cs b/src/Commands/Dependencies.cs deleted file mode 100644 index 79f16601..00000000 --- a/src/Commands/Dependencies.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace WhMgr.Commands -{ - using DSharpPlus.Interactivity; - - using WhMgr.Configuration; - using WhMgr.Data.Subscriptions; - using WhMgr.Net.Webhooks; - using WhMgr.Osm; - using WhMgr.Services; - - public class Dependencies - { - private readonly WhConfigHolder _configHolder; - - public InteractivityModule Interactivity; - - public WebhookController Whm { get; } - - public SubscriptionProcessor SubscriptionProcessor { get; } - - public WhConfig WhConfig => _configHolder.Instance; - - public StripeService Stripe { get; } - - public OsmManager OsmManager { get; } - - public Dependencies(InteractivityModule interactivity, WebhookController whm, SubscriptionProcessor subProcessor, WhConfigHolder whConfig, StripeService stripe) - { - Interactivity = interactivity; - Whm = whm; - SubscriptionProcessor = subProcessor; - _configHolder = whConfig; - Stripe = stripe; - OsmManager = new OsmManager(); - } - } -} \ No newline at end of file diff --git a/src/Commands/Event.cs b/src/Commands/Event.cs index b87888ee..b73ac750 100644 --- a/src/Commands/Event.cs +++ b/src/Commands/Event.cs @@ -11,6 +11,7 @@ using DSharpPlus.Entities; using ServiceStack.OrmLite; + using WhMgr.Configuration; using WhMgr.Data; using WhMgr.Diagnostics; using WhMgr.Extensions; @@ -23,15 +24,15 @@ Hidden, RequirePermissions(Permissions.KickMembers) ] - public class Event + public class Event : BaseCommandModule { private static readonly IEventLogger _logger = EventLogger.GetLogger("COMMUNITYDAY", Program.LogLevel); - private readonly Dependencies _dep; + private readonly WhConfigHolder _config; - public Event(Dependencies dep) + public Event(WhConfigHolder config) { - _dep = dep; + _config = config; } [ @@ -53,9 +54,9 @@ public async Task ListAsync(CommandContext ctx) } }; var pkmnNames = new List(); - for (var i = 0; i < _dep.WhConfig.EventPokemonIds.Count; i++) + for (var i = 0; i < _config.Instance.EventPokemonIds.Count; i++) { - var pkmnId = _dep.WhConfig.EventPokemonIds[i]; + var pkmnId = _config.Instance.EventPokemonIds[i]; if (MasterFile.Instance.Pokedex.ContainsKey(pkmnId)) { pkmnNames.Add(pkmnId + ":" + MasterFile.Instance.Pokedex[pkmnId].Name); @@ -89,8 +90,8 @@ public async Task SetAsync(CommandContext ctx, pkmnFailed.Add(eventPokemonId); } - _dep.WhConfig.EventPokemonIds = pkmnToAdd; - _dep.WhConfig.Save(_dep.WhConfig.FileName); + _config.Instance.EventPokemonIds = pkmnToAdd; + _config.Instance.Save(_config.Instance.FileName); var pkmnNames = new List(); for (var i = 0; i < pkmnToAdd.Count; i++) @@ -141,8 +142,8 @@ public async Task AddAsync(CommandContext ctx, pkmnFailed.Add(eventPokemonId); } - _dep.WhConfig.EventPokemonIds.AddRange(pkmnToAdd); - _dep.WhConfig.Save(_dep.WhConfig.FileName); + _config.Instance.EventPokemonIds.AddRange(pkmnToAdd); + _config.Instance.Save(_config.Instance.FileName); var pkmnNames = new List(); for (var i = 0; i < pkmnToAdd.Count; i++) @@ -193,8 +194,8 @@ public async Task RemoveAsync(CommandContext ctx, pkmnFailed.Add(eventPokemonId); } - pkmnToRemove.ForEach(x => _dep.WhConfig.EventPokemonIds.Remove(x)); - _dep.WhConfig.Save(_dep.WhConfig.FileName); + pkmnToRemove.ForEach(x => _config.Instance.EventPokemonIds.Remove(x)); + _config.Instance.Save(_config.Instance.FileName); var pkmnNames = new List(); for (var i = 0; i < pkmnToRemove.Count; i++) diff --git a/src/Commands/Feeds.cs b/src/Commands/Feeds.cs index f3fab1fd..1ad1a8c1 100644 --- a/src/Commands/Feeds.cs +++ b/src/Commands/Feeds.cs @@ -11,19 +11,20 @@ using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; + using WhMgr.Configuration; using WhMgr.Diagnostics; using WhMgr.Extensions; using WhMgr.Localization; - public class Feeds + public class Feeds : BaseCommandModule { private static readonly IEventLogger _logger = EventLogger.GetLogger("FEEDS", Program.LogLevel); - private readonly Dependencies _dep; + private readonly WhConfigHolder _config; - public Feeds(Dependencies dep) + public Feeds(WhConfigHolder config) { - _dep = dep; + _config = config; } [ @@ -33,14 +34,14 @@ public Feeds(Dependencies dep) ] public async Task FeedsAsync(CommandContext ctx) { - if (!await ctx.IsDirectMessageSupported(_dep.WhConfig)) + if (!await ctx.IsDirectMessageSupported(_config.Instance)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; + var server = _config.Instance.Servers[guildId]; var cityRoles = server.Geofences.Select(x => x.Name).ToList(); cityRoles.Sort(); var sb = new StringBuilder(); @@ -73,15 +74,15 @@ public async Task FeedsAsync(CommandContext ctx) public async Task FeedMeAsync(CommandContext ctx, [Description("City name to join or all."), RemainingText] string cityName = null) { - if (!await ctx.IsDirectMessageSupported(_dep.WhConfig)) + if (!await ctx.IsDirectMessageSupported(_config.Instance)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; - var isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _dep.WhConfig); + var server = _config.Instance.Servers[guildId]; + var isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _config.Instance); var isFreeRole = string.IsNullOrEmpty(server.FreeRoleName) ? false : string.Compare(cityName, server.FreeRoleName, true) == 0; if (server.CitiesRequireSupporterRole && !isSupporter && !isFreeRole) { @@ -110,7 +111,7 @@ public async Task FeedMeAsync(CommandContext ctx, await ctx.RespondEmbed(Translator.Instance.Translate("FEEDS_INVALID_CITY_NAME_TYPE_COMMAND").FormatText(new { author = ctx.User.Username, - city = city, + city, prefix = server.CommandPrefix, }), DiscordColor.Red); continue; @@ -122,7 +123,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("FEEDS_INVALID_CITY_NAME_TY await ctx.RespondEmbed(Translator.Instance.Translate("FEEDS_INVALID_CITY_NAME").FormatText(new { author = ctx.User.Username, - city = city, + city, }), DiscordColor.Red); continue; } @@ -142,7 +143,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("FEEDS_INVALID_CITY_NAME"). if (assigned.Count == 0 && alreadyAssigned.Count == 0) { - ctx.Client.DebugLogger.LogMessage(DSharpPlus.LogLevel.Debug, "Feeds", $"No roles assigned or already assigned for user {ctx.User.Username} ({ctx.User.Id}). Value: {string.Join(", ", cityNames)}", DateTime.Now); + _logger.Error($"No roles assigned or already assigned for user {ctx.User.Username} ({ctx.User.Id}). Value: {string.Join(", ", cityNames)}"); return; } @@ -177,15 +178,15 @@ await ctx.RespondEmbed public async Task FeedMeNotAsync(CommandContext ctx, [Description("City name to leave or all."), RemainingText] string cityName) { - if (!await ctx.IsDirectMessageSupported(_dep.WhConfig)) + if (!await ctx.IsDirectMessageSupported(_config.Instance)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; - var isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _dep.WhConfig); + var server = _config.Instance.Servers[guildId]; + var isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _config.Instance); var isFreeRole = string.IsNullOrEmpty(server.FreeRoleName) ? false : string.Compare(cityName, server.FreeRoleName, true) == 0; if (server.CitiesRequireSupporterRole && !isSupporter && !isFreeRole) { @@ -214,7 +215,7 @@ public async Task FeedMeNotAsync(CommandContext ctx, await ctx.RespondEmbed(Translator.Instance.Translate("FEEDS_INVALID_CITY_NAME_TYPE_COMMAND").FormatText(new { author = ctx.User.Username, - city = city, + city, server.CommandPrefix, }), DiscordColor.Red); continue; @@ -226,7 +227,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("FEEDS_INVALID_CITY_NAME_TY await ctx.RespondEmbed(Translator.Instance.Translate("FEEDS_INVALID_CITY_NAME").FormatText(new { author = ctx.User.Username, - city = city, + city, }), DiscordColor.Red); continue; } @@ -269,9 +270,9 @@ await ctx.RespondEmbed private async Task AssignAllDefaultFeedRoles(CommandContext ctx) { - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); - if (_dep.WhConfig.Servers[guildId].Geofences == null) + if (_config.Instance.Servers[guildId].Geofences == null) { _logger.Warn($"City roles empty."); return; @@ -279,7 +280,7 @@ private async Task AssignAllDefaultFeedRoles(CommandContext ctx) try { - var server = _dep.WhConfig.Servers[guildId]; + var server = _config.Instance.Servers[guildId]; var areas = server.Geofences.Select(x => x.Name).ToList(); for (var i = 0; i < areas.Count; i++) { @@ -312,9 +313,9 @@ private async Task AssignAllDefaultFeedRoles(CommandContext ctx) private async Task RemoveAllDefaultFeedRoles(CommandContext ctx) { - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); - if (_dep.WhConfig.Servers[guildId].Geofences == null) + if (_config.Instance.Servers[guildId].Geofences == null) { _logger.Warn($"City roles empty."); return; @@ -322,7 +323,7 @@ private async Task RemoveAllDefaultFeedRoles(CommandContext ctx) try { - var server = _dep.WhConfig.Servers[guildId]; + var server = _config.Instance.Servers[guildId]; var areas = server.Geofences.Select(x => x.Name).ToList(); for (var i = 0; i < areas.Count; i++) { diff --git a/src/Commands/Gyms.cs b/src/Commands/Gyms.cs index 95d408f6..465d6b9d 100644 --- a/src/Commands/Gyms.cs +++ b/src/Commands/Gyms.cs @@ -9,9 +9,9 @@ using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; - using ServiceStack.OrmLite; + using WhMgr.Configuration; using WhMgr.Extensions; using WhMgr.Localization; @@ -22,14 +22,14 @@ Hidden, RequirePermissions(Permissions.KickMembers) ] - public class Gyms + public class Gyms : BaseCommandModule { //private static readonly IEventLogger _logger = EventLogger.GetLogger("GYMS", Program.LogLevel); - private readonly Dependencies _dep; + private readonly WhConfigHolder _config; - public Gyms(Dependencies dep) + public Gyms(WhConfigHolder config) { - _dep = dep; + _config = config; } [ @@ -39,7 +39,7 @@ public Gyms(Dependencies dep) public async Task ConvertedPokestopsToGymsAsync(CommandContext ctx, [Description("Real or dry run check (y/n)")] string yesNo = "y") { - using (var db = Data.DataAccessLayer.CreateFactory(_dep.WhConfig.Database.Scanner.ToString()).Open()) + using (var db = Data.DataAccessLayer.CreateFactory(_config.Instance.Database.Scanner.ToString()).Open()) { //Select query where ids match for pokestops and gyms var convertedGyms = db.Select(Strings.SQL_SELECT_CONVERTED_POKESTOPS); @@ -68,7 +68,7 @@ public async Task ConvertedPokestopsToGymsAsync(CommandContext ctx, var imageUrl = string.IsNullOrEmpty(gym.Url) ? Translator.Instance.Translate("GYM_UNKNOWN_IMAGE") : gym.Url; var locationUrl = string.Format(Strings.GoogleMaps, gym.Latitude, gym.Longitude); //eb.AddField($"{name} ({gym.Latitude},{gym.Longitude})", url); - sb.AppendLine(Translator.Instance.Translate("GYM_NAME").FormatText(new { name = name })); + sb.AppendLine(Translator.Instance.Translate("GYM_NAME").FormatText(new { name })); sb.AppendLine(Translator.Instance.Translate("GYM_DIRECTIONS_IMAGE_LINK").FormatText(new { location_url = locationUrl, diff --git a/src/Commands/Input/SubscriptionInput.cs b/src/Commands/Input/SubscriptionInput.cs index d29a7bb3..a5cbb773 100644 --- a/src/Commands/Input/SubscriptionInput.cs +++ b/src/Commands/Input/SubscriptionInput.cs @@ -58,8 +58,8 @@ await _context.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMO /// Returns a list of valid areas specified public async Task> GetAreasResult(ulong guildId) { - var deps = _context.Dependencies.GetDependency(); - var server = deps.WhConfig.Servers[guildId]; + var config = (WhConfigHolder)_context.Services.GetService(typeof(WhConfigHolder)); + var server = config.Instance.Servers[guildId]; var validAreas = server.Geofences.Select(g => g.Name).ToList(); var message = (await _context.RespondEmbed($"Enter the areas to get notifications from separated by a comma (i.e. `city1,city2`):\n**Available Areas:**\n{string.Join("\n- ", validAreas)}\n- All", DiscordColor.Blurple)).FirstOrDefault(); var cities = await _context.WaitForUserChoice(true); diff --git a/src/Commands/ModifyFilters.cs b/src/Commands/ModifyFilters.cs index 87297b30..d8f0c85c 100644 --- a/src/Commands/ModifyFilters.cs +++ b/src/Commands/ModifyFilters.cs @@ -7,19 +7,20 @@ using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; + using WhMgr.Configuration; using WhMgr.Diagnostics; using WhMgr.Extensions; [Group("filters")] - public class ModifyFilters + public class ModifyFilters : BaseCommandModule { private static readonly IEventLogger _logger = EventLogger.GetLogger("FILTERS", Program.LogLevel); - private readonly Dependencies _dep; + private readonly WhConfigHolder _config; - public ModifyFilters(Dependencies dep) + public ModifyFilters(WhConfigHolder config) { - _dep = dep; + _config = config; } [ @@ -29,14 +30,14 @@ public ModifyFilters(Dependencies dep) ] public async Task AddFilters(CommandContext ctx) { - if (!await ctx.IsDirectMessageSupported(_dep.WhConfig)) + if (!await ctx.IsDirectMessageSupported(_config.Instance)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; + var server = _config.Instance.Servers[guildId]; } [ @@ -46,14 +47,14 @@ public async Task AddFilters(CommandContext ctx) ] public async Task EditFilters(CommandContext ctx) { - if (!await ctx.IsDirectMessageSupported(_dep.WhConfig)) + if (!await ctx.IsDirectMessageSupported(_config.Instance)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; + var server = _config.Instance.Servers[guildId]; } } } \ No newline at end of file diff --git a/src/Commands/Nests.cs b/src/Commands/Nests.cs index 568ccda1..806b3209 100644 --- a/src/Commands/Nests.cs +++ b/src/Commands/Nests.cs @@ -15,24 +15,31 @@ using ServiceStack.OrmLite; using WhMgr.Alarms.Alerts; + using WhMgr.Configuration; using WhMgr.Data; using WhMgr.Data.Models; using WhMgr.Diagnostics; using WhMgr.Extensions; using WhMgr.Localization; using WhMgr.Geofence; + using WhMgr.Net.Webhooks; + using WhMgr.Osm; using WhMgr.Services; using WhMgr.Utilities; - public class Nests + public class Nests : BaseCommandModule { private static readonly IEventLogger _logger = EventLogger.GetLogger("NESTS", Program.LogLevel); - private readonly Dependencies _dep; + private readonly WhConfigHolder _config; + private readonly WebhookController _whm; + private readonly OsmManager _osmManager; - public Nests(Dependencies dep) + public Nests(WhConfigHolder config, WebhookController whm, OsmManager osm) { - _dep = dep; + _config = config; + _whm = whm; + _osmManager = osm; } [ @@ -43,14 +50,14 @@ public Nests(Dependencies dep) public async Task PostNestsAsync(CommandContext ctx, [Description("")] string args = null) { - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) { await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NOT_IN_DISCORD_SERVER"), DiscordColor.Red); return; } - var server = _dep.WhConfig.Servers[guildId]; + var server = _config.Instance.Servers[guildId]; var channelId = server.NestsChannelId; var channel = await ctx.Client.GetChannelAsync(channelId); if (channel == null) @@ -65,7 +72,7 @@ public async Task PostNestsAsync(CommandContext ctx, _logger.Warn($"Failed to delete messages in channel: {channelId}"); } - var nests = GetNests(_dep.WhConfig.Database.Nests.ToString()); + var nests = GetNests(_config.Instance.Database.Nests.ToString()); if (nests == null) { await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NESTS_LIST").FormatText(new { author = ctx.User.Username })); @@ -132,7 +139,7 @@ public async Task PostNestsAsync(CommandContext ctx, try { var eb = GenerateNestMessage(guildId, ctx.Client, nest); - var geofence = _dep.Whm.GetGeofence(guildId, nest.Latitude, nest.Longitude); + var geofence = _whm.GetGeofence(guildId, nest.Latitude, nest.Longitude); if (geofence == null) { //_logger.Warn($"Failed to find geofence for nest {nest.Key}."); @@ -160,7 +167,7 @@ public DiscordEmbed GenerateNestMessage(ulong guildId, DiscordClient client, Nes { var alertMessageType = AlertMessageType.Nests; var alertMessage = /*alarm?.Alerts[alertMessageType] ??*/ AlertMessage.Defaults[alertMessageType]; // TODO: Add nestAlert config option - var server = _dep.WhConfig.Servers[guildId]; + var server = _config.Instance.Servers[guildId]; var pokemonImageUrl = IconFetcher.Instance.GetPokemonIcon(server.IconStyle, nest.PokemonId); var properties = GetProperties(client.Guilds[guildId], nest, pokemonImageUrl); var eb = new DiscordEmbedBuilder @@ -168,7 +175,10 @@ public DiscordEmbed GenerateNestMessage(ulong guildId, DiscordClient client, Nes Title = DynamicReplacementEngine.ReplaceText(alertMessage.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alertMessage.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alertMessage.ImageUrl, properties), - ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alertMessage.IconUrl, properties), + Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail + { + Url = DynamicReplacementEngine.ReplaceText(alertMessage.IconUrl, properties), + }, Description = DynamicReplacementEngine.ReplaceText(alertMessage.Content, properties), Color = DiscordColor.Green, Footer = new DiscordEmbedBuilder.EmbedFooter @@ -193,11 +203,11 @@ public IReadOnlyDictionary GetProperties(DiscordGuild guild, Nes var gmapsLink = string.Format(Strings.GoogleMaps, nest.Latitude, nest.Longitude); var appleMapsLink = string.Format(Strings.AppleMaps, nest.Latitude, nest.Longitude); var wazeMapsLink = string.Format(Strings.WazeMaps, nest.Latitude, nest.Longitude); - var scannerMapsLink = string.Format(_dep.WhConfig.Urls.ScannerMap, nest.Latitude, nest.Longitude); - var staticMapLink = StaticMap.GetUrl(_dep.WhConfig.Urls.StaticMap, _dep.WhConfig.StaticMaps["nests"], nest.Latitude, nest.Longitude, pkmnImage, Net.Models.PokemonTeam.All, _dep.OsmManager.GetNest(nest.Name)?.FirstOrDefault()); - var geofence = _dep.Whm.GetGeofence(guild.Id, nest.Latitude, nest.Longitude); + var scannerMapsLink = string.Format(_config.Instance.Urls.ScannerMap, nest.Latitude, nest.Longitude); + var staticMapLink = StaticMap.GetUrl(_config.Instance.Urls.StaticMap, _config.Instance.StaticMaps["nests"], nest.Latitude, nest.Longitude, pkmnImage, Net.Models.PokemonTeam.All, _osmManager.GetNest(nest.Name)?.FirstOrDefault()); + var geofence = _whm.GetGeofence(guild.Id, nest.Latitude, nest.Longitude); var city = geofence?.Name ?? "Unknown"; - var address = new Location(null, city, nest.Latitude, nest.Longitude).GetAddress(_dep.WhConfig); + var address = new Location(null, city, nest.Latitude, nest.Longitude).GetAddress(_config.Instance); var dict = new Dictionary { @@ -248,14 +258,14 @@ private Dictionary> GroupNests(ulong guildId, IEnumerable>(); foreach (var nest in nests) { - var geofence = _dep.Whm.GetGeofence(guildId, nest.Latitude, nest.Longitude); + var geofence = _whm.GetGeofence(guildId, nest.Latitude, nest.Longitude); if (geofence == null) { _logger.Warn($"Failed to find geofence for nest {nest.Name}."); continue; } var geofenceName = geofence.Name; - var server = _dep.WhConfig.Servers[guildId]; + var server = _config.Instance.Servers[guildId]; var cities = server.Geofences.Select(x => x.Name.ToLower()).ToList(); if (!cities.Contains(geofenceName.ToLower())) continue; diff --git a/src/Commands/Notifications.cs b/src/Commands/Notifications.cs index 2113abb9..033e8bf7 100644 --- a/src/Commands/Notifications.cs +++ b/src/Commands/Notifications.cs @@ -23,17 +23,22 @@ using WhMgr.Extensions; using WhMgr.Localization; using WhMgr.Net.Models; + using WhMgr.Services; using WhMgr.Utilities; - public class Notifications + public class Notifications : BaseCommandModule { private static readonly IEventLogger _logger = EventLogger.GetLogger("NOTIFICATIONS", Program.LogLevel); - private readonly Dependencies _dep; + private readonly WhConfigHolder _config; + private readonly SubscriptionProcessor _subProcessor; + private readonly StripeService _stripe; - public Notifications(Dependencies dep) + public Notifications(WhConfigHolder config, SubscriptionProcessor subProcessor, StripeService stripe) { - _dep = dep; + _config = config; + _subProcessor = subProcessor; + _stripe = stripe; } #region General @@ -48,14 +53,14 @@ public async Task InfoAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); if (string.IsNullOrEmpty(mention)) { - await SendUserSubscriptionSettings(ctx.Client, ctx.User, ctx.User, guildId); + await SendUserSubscriptionSettings(ctx.Client, ctx.Member, ctx.User, guildId); return; } - var isModOrHigher = await ctx.Client.IsModeratorOrHigher(ctx.User.Id, guildId, _dep.WhConfig); + var isModOrHigher = await ctx.Client.IsModeratorOrHigher(ctx.User.Id, guildId, _config.Instance); if (!isModOrHigher) { await ctx.RespondEmbed(Translator.Instance.Translate("MSG_NOT_MODERATOR_OR_HIGHER").FormatText(new { author = ctx.User.Mention }), DiscordColor.Red); @@ -68,7 +73,7 @@ public async Task InfoAsync(CommandContext ctx, await ctx.RespondEmbed(Translator.Instance.Translate("MSG_INVALID_USER_MENTION").FormatText(new { author = ctx.User.Mention, - mention = mention, + mention, }), DiscordColor.Red); return; } @@ -80,9 +85,9 @@ await ctx.RespondEmbed(Translator.Instance.Translate("MSG_INVALID_USER_MENTION") return; } - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); - await SendUserSubscriptionSettings(ctx.Client, ctx.User, user, guildId); + await SendUserSubscriptionSettings(ctx.Client, ctx.Member, user, guildId); } [ @@ -96,7 +101,7 @@ public async Task EnableDisableAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); if (string.IsNullOrEmpty(mention)) { @@ -104,7 +109,7 @@ public async Task EnableDisableAsync(CommandContext ctx, return; } - var isModOrHigher = await ctx.Client.IsModeratorOrHigher(ctx.User.Id, guildId, _dep.WhConfig); + var isModOrHigher = await ctx.Client.IsModeratorOrHigher(ctx.User.Id, guildId, _config.Instance); if (!isModOrHigher) { await ctx.RespondEmbed(Translator.Instance.Translate("MSG_NOT_MODERATOR_OR_HIGHER").FormatText(new { author = ctx.User.Mention }), DiscordColor.Red); @@ -117,7 +122,7 @@ public async Task EnableDisableAsync(CommandContext ctx, await ctx.RespondEmbed(Translator.Instance.Translate("MSG_INVALID_USER_MENTION").FormatText(new { author = ctx.User.Mention, - mention = mention, + mention, }), DiscordColor.Red); return; } @@ -131,7 +136,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("MSG_INVALID_USER_MENTION") await EnableDisableUserSubscriptions(ctx, user, guildId); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } [ @@ -146,7 +151,7 @@ public async Task SetDistanceAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); var parts = coordinates.Replace(" ", null).Split(','); if (!double.TryParse(parts[0], out var lat) || !double.TryParse(parts[1], out var lng)) @@ -154,12 +159,12 @@ public async Task SetDistanceAsync(CommandContext ctx, await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_COORDINATES").FormatText(new { author = ctx.User.Username, - coordinates = coordinates, + coordinates, }), DiscordColor.Red); return; } - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (subscription == null) { await ctx.RespondEmbed(Translator.Instance.Translate("MSG_USER_NOT_SUBSCRIBED").FormatText(new { author = ctx.User.Username }), DiscordColor.Red); @@ -193,11 +198,11 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_COORDINATES await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_DISTANCE_SET").FormatText(new { author = ctx.User.Username, - distance = distance, + distance, latitude = lat, longitude = lng, })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } [ @@ -210,13 +215,13 @@ public async Task SetPhoneNumberAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); // Check if user is in list of acceptable users to receive Pokemon text message notifications - if (!_dep.WhConfig.Twilio.UserIds.Contains(ctx.User.Id)) + if (!_config.Instance.Twilio.UserIds.Contains(ctx.User.Id)) return; - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (subscription == null) { await ctx.RespondEmbed(Translator.Instance.Translate("MSG_USER_NOT_SUBSCRIBED").FormatText(ctx.User.Username), DiscordColor.Red); @@ -231,7 +236,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_PHONE_NUMBER_SET"). author = ctx.User.Username, number = phoneNumber, })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } [ @@ -244,10 +249,10 @@ public async Task GetExpireDateAsync(CommandContext ctx) if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); var message = BuildExpirationMessage(guildId, ctx.User); - await ctx.Client.SendDirectMessage(ctx.User, message); + await ctx.Member.SendDirectMessage(message); } [ @@ -272,10 +277,10 @@ await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_PARSING_USER_ID").Fo return; } - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); var user = await ctx.Client.GetUserAsync(realUserId); var message = BuildExpirationMessage(guildId, user); - await ctx.Client.SendDirectMessage(ctx.User, message); + await ctx.Member.SendDirectMessage(message); } #endregion @@ -296,11 +301,11 @@ public async Task PokeMeAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; + var server = _config.Instance.Servers[guildId]; //if (!int.TryParse(cpArg, out int cp)) //{ @@ -322,7 +327,7 @@ public async Task PokeMeAsync(CommandContext ctx, await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_IV_VALUES").FormatText(new { author = ctx.User.Username, - iv = iv, + iv, }), DiscordColor.Red); return; } @@ -363,7 +368,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_STAMINA_VAL await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_IV_RANGE").FormatText(new { author = ctx.User.Username, - iv = iv, + iv, }), DiscordColor.Red); return; } @@ -425,7 +430,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_LEVEL").For await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_GENDER").FormatText(new { author = ctx.User.Username, - gender = gender, + gender, }), DiscordColor.Red); return; } @@ -441,9 +446,9 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_GENDER").Fo } } - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); // Check subscription limits if (server.Subscriptions.MaxPokemonSubscriptions > 0 && subscription.Pokemon.Count >= server.Subscriptions.MaxPokemonSubscriptions) { @@ -458,7 +463,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_SUB var alreadySubscribed = new List(); var subscribed = new List(); - var isModOrHigher = await ctx.Client.IsModeratorOrHigher(ctx.User.Id, guildId, _dep.WhConfig); + var isModOrHigher = await ctx.Client.IsModeratorOrHigher(ctx.User.Id, guildId, _config.Instance); var areas = SubscriptionAreas.GetAreas(server, city); if (areas.Count == 0 && string.IsNullOrEmpty(subscription.Location)) @@ -474,9 +479,9 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_SUB var isAll = string.Compare(Strings.All, poke, true) == 0; if (isAll) { - poke = string.Join(",", PokemonValidation.GetListFromRange(1, _dep.WhConfig.MaxPokemonId)); + poke = string.Join(",", PokemonValidation.GetListFromRange(1, _config.Instance.MaxPokemonId)); } - var validation = PokemonValidation.Validate(poke, _dep.WhConfig.MaxPokemonId); + var validation = PokemonValidation.Validate(poke, _config.Instance.MaxPokemonId); if (validation == null || validation.Valid.Count == 0) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS_OR_NAMES").FormatText(new @@ -566,7 +571,7 @@ await ctx.RespondEmbed : string.Empty) ); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } [ @@ -580,8 +585,8 @@ public async Task PokeMeNotAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (subscription == null || subscription?.Pokemon?.Count == 0) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_NO_POKEMON_SUBSCRIPTIONS").FormatText(new { author = ctx.User.Username }), DiscordColor.Red); @@ -603,11 +608,11 @@ public async Task PokeMeNotAsync(CommandContext ctx, // Loop through all Pokemon subscriptions and remove them subscription.Pokemon.ForEach(x => x.Id.Remove()); await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_SUCCESS_REMOVE_ALL_POKEMON_SUBSCRIPTIONS").FormatText(new { author = ctx.User.Username })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); return; } - var validation = PokemonValidation.Validate(poke, _dep.WhConfig.MaxPokemonId); + var validation = PokemonValidation.Validate(poke, _config.Instance.MaxPokemonId); if (validation.Valid == null || validation.Valid.Count == 0) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS_OR_NAMES").FormatText(new @@ -618,7 +623,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS return; } - var areas = SubscriptionAreas.GetAreas(_dep.WhConfig.Servers[guildId], city); + var areas = SubscriptionAreas.GetAreas(_config.Instance.Servers[guildId], city); var pokemonNames = validation.Valid.Select(x => MasterFile.GetPokemon(x.Key, 0).Name + (string.IsNullOrEmpty(x.Value) ? string.Empty : "-" + x.Value)); var error = false; //foreach (var (pokemonId, form) in validation.Valid) @@ -675,7 +680,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_POKEMON_SUBSCRIPTI author = ctx.User.Username, pokemon = string.Join("**, **", pokemonNames), })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } #endregion @@ -693,12 +698,12 @@ public async Task RaidMeAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var server = _config.Instance.Servers[guildId]; + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); // Check subscription limits if (server.Subscriptions.MaxRaidSubscriptions > 0 && subscription.Raids.Count >= server.Subscriptions.MaxRaidSubscriptions) { @@ -711,7 +716,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_RAID_SUBSCR return; } - var validation = PokemonValidation.Validate(poke, _dep.WhConfig.MaxPokemonId); + var validation = PokemonValidation.Validate(poke, _config.Instance.MaxPokemonId); if (validation.Valid == null || validation.Valid.Count == 0) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS_OR_NAMES").FormatText(new @@ -768,9 +773,9 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_RAID_SUBSCRIPTIONS pokemon = string.Compare(poke, Strings.All, true) == 0 ? Strings.All : string.Join("**, **", pokemonNames), cities = string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") - : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = city }), + : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city }), })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } [ @@ -784,8 +789,8 @@ public async Task RaidMeNotAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (subscription == null || subscription?.Raids.Count == 0) { await ctx.TriggerTypingAsync(); @@ -794,7 +799,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NO_RAID_SUBSCRIPTION author = ctx.User.Username, cities = string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") - : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = city }), + : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city }), }), DiscordColor.Red); return; } @@ -813,11 +818,11 @@ await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NO_RAID_SUBSCRIPTION await ctx.TriggerTypingAsync(); await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_SUCCESS_REMOVE_ALL_RAID_SUBSCRIPTIONS").FormatText(new { author = ctx.User.Username })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); return; } - var validation = PokemonValidation.Validate(poke, _dep.WhConfig.MaxPokemonId); + var validation = PokemonValidation.Validate(poke, _config.Instance.MaxPokemonId); if (validation.Valid == null || validation.Valid.Count == 0) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS_OR_NAMES").FormatText(new @@ -828,7 +833,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS return; } - var areas = SubscriptionAreas.GetAreas(_dep.WhConfig.Servers[guildId], city); + var areas = SubscriptionAreas.GetAreas(_config.Instance.Servers[guildId], city); foreach (var item in validation.Valid) { var pokemonId = item.Key; @@ -874,7 +879,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_RAID_SUBSCRIPTIONS ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = string.Join(", ", areas) }), })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } #endregion @@ -892,12 +897,12 @@ public async Task QuestMeAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var server = _config.Instance.Servers[guildId]; + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); // Check subscription limits if (server.Subscriptions.MaxQuestSubscriptions > 0 && subscription.Quests.Count >= server.Subscriptions.MaxQuestSubscriptions) { @@ -951,9 +956,9 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_QUEST_SUBSCRIPTION reward = rewardKeyword, cities = string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") - : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = city }), + : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city }), })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } [ @@ -967,8 +972,8 @@ public async Task QuestMeNotAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (subscription == null || subscription?.Quests.Count == 0) { await ctx.TriggerTypingAsync(); @@ -977,7 +982,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NO_QUEST_SUBSCRIPTIO author = ctx.User.Username, cities = string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") - : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = city }) + : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city }) }), DiscordColor.Red); return; } @@ -999,11 +1004,11 @@ await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NO_QUEST_SUBSCRIPTIO subscription.Quests.ForEach(x => x.Id.Remove()); await ctx.TriggerTypingAsync(); await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_CONFIRM_SUCCESS_ALL_QUEST_SUBSCRIPTIONS").FormatText(ctx.User.Username)); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); return; } - var areas = SubscriptionAreas.GetAreas(_dep.WhConfig.Servers[guildId], city); + var areas = SubscriptionAreas.GetAreas(_config.Instance.Servers[guildId], city); var subQuest = subscription.Quests.FirstOrDefault(x => string.Compare(x.RewardKeyword, rewardKeyword, true) == 0); // Check if subscribed if (subQuest == null) @@ -1042,9 +1047,9 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_QUEST_SUBSCRIPTION reward = rewardKeyword, cities = string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") - : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = city }), + : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city }), })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } #endregion @@ -1064,12 +1069,12 @@ public async Task GymMeAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var server = _config.Instance.Servers[guildId]; + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); // Check subscription limits if (server.Subscriptions.MaxGymSubscriptions > 0 && subscription.Gyms.Count >= server.Subscriptions.MaxGymSubscriptions) { @@ -1093,7 +1098,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_GYM_SUBSCRI var pokemon = new List(); if (!string.IsNullOrEmpty(pokemonIds)) { - pokemon = PokemonValidation.Validate(pokemonIds, _dep.WhConfig.MaxPokemonId).Valid.Keys.ToList().ConvertAll(x =>(uint)x); + pokemon = PokemonValidation.Validate(pokemonIds, _config.Instance.MaxPokemonId).Valid.Keys.ToList().ConvertAll(x =>(uint)x); } var subGym = subscription.Gyms.FirstOrDefault(x => string.Compare(x.Name, gymName, true) == 0); @@ -1117,7 +1122,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_GYM_SUBSCRIPTION_AD author = ctx.User.Username, gym = gymName, })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } [ @@ -1130,9 +1135,9 @@ public async Task GymMeNotAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (string.Compare(Strings.All, gymName, true) == 0) { var result = await ctx.Confirm(Translator.Instance.Translate("NOTIFY_CONFIRM_REMOVE_ALL_GYM_SUBSCRIPTIONS").FormatText(new @@ -1145,7 +1150,7 @@ public async Task GymMeNotAsync(CommandContext ctx, subscription.Gyms.ForEach(x => x.Id.Remove()); await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_SUCCESS_REMOVE_ALL_GYM_SUBSCRIPTIONS").FormatText(new { author = ctx.User.Username })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); return; } @@ -1158,7 +1163,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_GYM_SUBSCRIPTION_RE author = ctx.User.Username, gym = gymName, })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } #endregion @@ -1176,12 +1181,12 @@ public async Task InvMeAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var server = _config.Instance.Servers[guildId]; + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); // Check subscription limits if (server.Subscriptions.MaxInvasionSubscriptions > 0 && subscription.Invasions.Count >= server.Subscriptions.MaxInvasionSubscriptions) { @@ -1194,7 +1199,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_INVASION_SU return; } - var validation = PokemonValidation.Validate(poke, _dep.WhConfig.MaxPokemonId); + var validation = PokemonValidation.Validate(poke, _config.Instance.MaxPokemonId); if (validation.Valid == null || validation.Valid.Count == 0) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS_OR_NAMES").FormatText(new @@ -1249,9 +1254,9 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_INVASION_SUBSCRIPT pokemon = string.Compare(poke, Strings.All, true) == 0 ? Strings.All : string.Join(", ", validPokemonNames), cities = string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") - : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = city }), + : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city }), })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } [ @@ -1265,8 +1270,8 @@ public async Task InvMeNotAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (subscription == null || subscription?.Invasions.Count == 0) { await ctx.TriggerTypingAsync(); @@ -1275,7 +1280,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NO_INVASION_SUBSCRIP author = ctx.User.Username, cities = string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") - : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = city }) + : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city }) }), DiscordColor.Red ); @@ -1296,11 +1301,11 @@ await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NO_INVASION_SUBSCRIP await ctx.TriggerTypingAsync(); await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_SUCCESS_REMOVE_ALL_INVASION_SUBSCRIPTIONS").FormatText(new { author = ctx.User.Username })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); return; } - var validation = PokemonValidation.Validate(poke, _dep.WhConfig.MaxPokemonId); + var validation = PokemonValidation.Validate(poke, _config.Instance.MaxPokemonId); if (validation.Valid == null || validation.Valid.Count == 0) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS_OR_NAMES").FormatText(new @@ -1311,7 +1316,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS return; } - var areas = SubscriptionAreas.GetAreas(_dep.WhConfig.Servers[guildId], city); + var areas = SubscriptionAreas.GetAreas(_config.Instance.Servers[guildId], city); var valid = string.Join(",", validation.Valid.Keys.ToList()); var subInvasion = subscription.Invasions.FirstOrDefault(x => x.RewardPokemonIdString == valid); // Check if subscribed @@ -1352,10 +1357,10 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_INVASION_SUBSCRIPT pokemon = string.Compare(poke, Strings.All, true) == 0 ? Strings.All : string.Join(", ", validPokemonNames), cities = string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") - : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = city }), + : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city }), })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } #endregion @@ -1376,11 +1381,11 @@ public async Task PvpMeAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; + var server = _config.Instance.Servers[guildId]; var pvpLeague = string.Compare(league, "great", true) == 0 ? PvPLeague.Great : string.Compare(league, "ultra", true) == 0 ? @@ -1394,7 +1399,7 @@ public async Task PvpMeAsync(CommandContext ctx, await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_PVP_LEAGUE").FormatText(new { author = ctx.User.Username, - league = league, + league, }), DiscordColor.Red); return; } @@ -1420,7 +1425,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_PVP_PERCENT return; } - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); // Check subscription limits if (server.Subscriptions.MaxPvPSubscriptions > 0 && subscription.PvP.Count >= server.Subscriptions.MaxPvPSubscriptions) { @@ -1439,9 +1444,9 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_PVP_PERCENT var isAll = string.Compare(Strings.All, poke, true) == 0; if (isAll) { - poke = string.Join(",", PokemonValidation.GetListFromRange(1, _dep.WhConfig.MaxPokemonId)); + poke = string.Join(",", PokemonValidation.GetListFromRange(1, _config.Instance.MaxPokemonId)); } - var validation = PokemonValidation.Validate(poke, _dep.WhConfig.MaxPokemonId); + var validation = PokemonValidation.Validate(poke, _config.Instance.MaxPokemonId); if (validation == null || validation.Valid.Count == 0) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS_OR_NAMES").FormatText(new @@ -1547,7 +1552,7 @@ await ctx.RespondEmbed ? $"\r\n{ctx.User.Username} is already subscribed to **{(isAll || isGen ? "All" : string.Join("**, **", alreadySubscribed))}** notifications with a minimum {pvpLeague} League PvP ranking of '{minimumRank}' or higher and a minimum ranking percentage of {minimumPercent}% and from the following areas: {(areas.Count == server.Geofences.Count ? Strings.All : string.Join(", ", areas))}." : string.Empty) ); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } [ @@ -1562,9 +1567,9 @@ public async Task PvpMeNotAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (subscription == null || subscription?.PvP?.Count == 0) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_NO_PVP_SUBSCRIPTIONS").FormatText(new { author = ctx.User.Username }), DiscordColor.Red); @@ -1584,7 +1589,7 @@ public async Task PvpMeNotAsync(CommandContext ctx, await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_PVP_LEAGUE").FormatText(new { author = ctx.User.Username, - league = league, + league, }), DiscordColor.Red); return; } @@ -1610,11 +1615,11 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_SUCCESS_REMOVE_ALL_ author = ctx.User.Username, league = pvpLeague, })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); return; } - var validation = PokemonValidation.Validate(poke, _dep.WhConfig.MaxPokemonId); + var validation = PokemonValidation.Validate(poke, _config.Instance.MaxPokemonId); if (validation.Valid == null || validation.Valid.Count == 0) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS_OR_NAMES").FormatText(new @@ -1625,9 +1630,9 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_IDS return; } - var areas = SubscriptionAreas.GetAreas(_dep.WhConfig.Servers[guildId], city); + var areas = SubscriptionAreas.GetAreas(_config.Instance.Servers[guildId], city); await RemovePvPSubscription(ctx, subscription, validation, pvpLeague, areas); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } #endregion @@ -1645,12 +1650,12 @@ public async Task LureMeAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var server = _config.Instance.Servers[guildId]; + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); // Check subscription limits if (server.Subscriptions.MaxLureSubscriptions > 0 && subscription.Lures.Count >= server.Subscriptions.MaxLureSubscriptions) { @@ -1703,9 +1708,9 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_LURE_SUBSCRIPTIONS lure = string.Compare(lureTypes, Strings.All, true) == 0 ? Strings.All : string.Join(", ", lures), cities = string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") - : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = city }), + : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city }), })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } [ @@ -1719,8 +1724,8 @@ public async Task LureMeNotAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (subscription == null || subscription?.Lures.Count == 0) { await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NO_LURE_SUBSCRIPTIONS").FormatText(new @@ -1728,7 +1733,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NO_LURE_SUBSCRIPTION author = ctx.User.Username, cities = string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") - : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = city }) + : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city }) }), DiscordColor.Red); return; } @@ -1746,11 +1751,11 @@ await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NO_LURE_SUBSCRIPTION subscription.Lures.ForEach(x => x.Id.Remove()); await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_SUCCESS_REMOVE_ALL_LURE_SUBSCRIPTIONS").FormatText(ctx.User.Username)); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); return; } - var areas = SubscriptionAreas.GetAreas(_dep.WhConfig.Servers[guildId], city); + var areas = SubscriptionAreas.GetAreas(_config.Instance.Servers[guildId], city); var lures = GetLures(lureTypes); foreach (var lureType in lures) { @@ -1791,10 +1796,10 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_LURE_SUBSCRIPTIONS lure = string.Compare(lureTypes, Strings.All, true) == 0 ? Strings.All : string.Join(", ", lures), cities = string.IsNullOrEmpty(city) ? Translator.Instance.Translate("SUBSCRIPTIONS_FROM_ALL_CITIES") - : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city = city }), + : Translator.Instance.Translate("SUBSCRIPTIONS_FROM_CITY").FormatText(new { city }), })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } #endregion @@ -1810,12 +1815,12 @@ public async Task AddAsync(CommandContext ctx) if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var server = _config.Instance.Servers[guildId]; + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); var subType = await ctx.GetSubscriptionTypeSelection(); // TODO: Maybe show current settings for selected info @@ -1837,7 +1842,7 @@ public async Task AddAsync(CommandContext ctx) } var pkmnInput = new PokemonSubscriptionInput(ctx); - var pkmnResult = await pkmnInput.GetPokemonResult(_dep.WhConfig.MaxPokemonId); + var pkmnResult = await pkmnInput.GetPokemonResult(_config.Instance.MaxPokemonId); var ivResult = await pkmnInput.GetIVResult(); var lvlResult = await pkmnInput.GetLevelResult(); var genderResult = await pkmnInput.GetGenderResult(); @@ -1900,7 +1905,7 @@ await ctx.RespondEmbed } var pvpInput = new PvPSubscriptionInput(ctx); - var pvpPokemon = await pvpInput.GetPokemonResult(_dep.WhConfig.MaxPokemonId); + var pvpPokemon = await pvpInput.GetPokemonResult(_config.Instance.MaxPokemonId); var pvpLeague = await pvpInput.GetLeagueResult(); var pvpRank = await pvpInput.GetRankResult(); var pvpPercent = await pvpInput.GetPercentResult(); @@ -1955,7 +1960,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_RAID_SUBSCR } var raidInput = new RaidSubscriptionInput(ctx); - var raidPokemon = await raidInput.GetPokemonResult(_dep.WhConfig.MaxPokemonId); + var raidPokemon = await raidInput.GetPokemonResult(_config.Instance.MaxPokemonId); var raidAreas = await raidInput.GetAreasResult(guildId); var validPokemonNames = string.Join(", ", raidPokemon.Valid.Select(x => MasterFile.GetPokemon(x.Key, 0).Name + (string.IsNullOrEmpty(x.Value) ? string.Empty : "-" + x.Value))); @@ -2065,7 +2070,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_INVASION_SU } var invasionInput = new InvasionSubscriptionInput(ctx); - var invasionPokemon = await invasionInput.GetPokemonResult(_dep.WhConfig.MaxPokemonId); + var invasionPokemon = await invasionInput.GetPokemonResult(_config.Instance.MaxPokemonId); var invasionAreas = await invasionInput.GetAreasResult(guildId); var valid = string.Join(",", invasionPokemon.Valid.ToList()); @@ -2163,7 +2168,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_GYM_SUBSCRIPTION_AD author = ctx.User.Username, gym = gymName, })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } break; #endregion @@ -2171,7 +2176,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_GYM_SUBSCRIPTION_AD await ctx.RespondEmbed($"Invalid entry specified, please try again...", DiscordColor.Red); break; } - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } private async Task, List>> AddPokemonSubscription(CommandContext ctx, SubscriptionObject subscription, PokemonValidation validation, IVResult ivResult, int minLevel, int maxLevel, string gender, List areas) @@ -2196,7 +2201,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_POKEMON_ID" //var pokemon = MasterFile.Instance.Pokedex[pokemonId]; //var name = string.IsNullOrEmpty(form) ? pokemon.Name : pokemon.Name + "-" + form; - var isModOrHigher = await ctx.Client.IsModeratorOrHigher(ctx.User.Id, subscription.GuildId, _dep.WhConfig); + var isModOrHigher = await ctx.Client.IsModeratorOrHigher(ctx.User.Id, subscription.GuildId, _config.Instance); foreach (var (validId, validForm) in validation.Valid) { @@ -2398,12 +2403,12 @@ public async Task RemoveAsync(CommandContext ctx) if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); + if (!_config.Instance.Servers.ContainsKey(guildId)) return; - var server = _dep.WhConfig.Servers[guildId]; - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var server = _config.Instance.Servers[guildId]; + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); var subType = await ctx.GetSubscriptionTypeSelection(); // TODO: Maybe show current settings for selected info @@ -2419,7 +2424,7 @@ public async Task RemoveAsync(CommandContext ctx) } var pkmnInput = new PokemonSubscriptionInput(ctx); - var pkmnResult = await pkmnInput.GetPokemonResult(_dep.WhConfig.MaxPokemonId); + var pkmnResult = await pkmnInput.GetPokemonResult(_config.Instance.MaxPokemonId); var areasResult = await pkmnInput.GetAreasResult(guildId); await RemovePokemonSubscription(ctx, subscription, pkmnResult, areasResult); @@ -2436,7 +2441,7 @@ public async Task RemoveAsync(CommandContext ctx) } var pvpInput = new PvPSubscriptionInput(ctx); - var pvpPokemonResult = await pvpInput.GetPokemonResult(_dep.WhConfig.MaxPokemonId); + var pvpPokemonResult = await pvpInput.GetPokemonResult(_config.Instance.MaxPokemonId); var pvpLeagueResult = await pvpInput.GetLeagueResult(); var pvpAreasResult = await pvpInput.GetAreasResult(guildId); @@ -2454,7 +2459,7 @@ public async Task RemoveAsync(CommandContext ctx) } var raidInput = new RaidSubscriptionInput(ctx); - var raidPokemonResult = await raidInput.GetPokemonResult(_dep.WhConfig.MaxPokemonId); + var raidPokemonResult = await raidInput.GetPokemonResult(_config.Instance.MaxPokemonId); var raidAreasResult = await raidInput.GetAreasResult(guildId); await RemoveRaidSubscription(ctx, subscription, null, raidAreasResult); @@ -2491,7 +2496,7 @@ public async Task RemoveAsync(CommandContext ctx) subscription.Quests.ForEach(x => x.Id.Remove()); await ctx.TriggerTypingAsync(); await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_CONFIRM_SUCCESS_ALL_QUEST_SUBSCRIPTIONS").FormatText(ctx.User.Username)); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); return; } @@ -2546,7 +2551,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_QUEST_SUBSCRIPTION } var invasionInput = new InvasionSubscriptionInput(ctx); - var invasionPokemonResult = await invasionInput.GetPokemonResult(_dep.WhConfig.MaxPokemonId); + var invasionPokemonResult = await invasionInput.GetPokemonResult(_config.Instance.MaxPokemonId); var invasionAreasResult = await invasionInput.GetAreasResult(guildId); var valid = string.Join(",", invasionPokemonResult.Valid.Keys.ToList()); @@ -2613,7 +2618,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_INVASION_SUBSCRIPT subscription.Gyms.ForEach(x => x.Id.Remove()); await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_SUCCESS_REMOVE_ALL_GYM_SUBSCRIPTIONS").FormatText(new { author = ctx.User.Username })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); return; } @@ -2634,7 +2639,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_GYM_SUBSCRIPTION_RE break; } - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } private async Task RemovePokemonSubscription(CommandContext ctx, SubscriptionObject subscription, PokemonValidation validation, List areas) @@ -2742,13 +2747,13 @@ await ctx.RespondEmbed(Translator.Instance.Translate("SUCCESS_PVP_SUBSCRIPTIONS_ { author = ctx.User.Username, pokemon = string.Join("**, **", pokemonNames), - league = league, + league, })); } private async Task RemoveRaidSubscription(CommandContext ctx, SubscriptionObject subscription, PokemonValidation validation, List areas) { - var server = _dep.WhConfig.Servers[subscription.GuildId]; + var server = _config.Instance.Servers[subscription.GuildId]; foreach (var item in validation.Valid) { var pokemonId = item.Key; @@ -2809,7 +2814,7 @@ public async Task ResetAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); if (string.IsNullOrEmpty(mention)) { @@ -2828,7 +2833,7 @@ public async Task ResetAsync(CommandContext ctx, return; } - var isModOrHigher = await ctx.Client.IsModeratorOrHigher(ctx.User.Id, guildId, _dep.WhConfig); + var isModOrHigher = await ctx.Client.IsModeratorOrHigher(ctx.User.Id, guildId, _config.Instance); if (!isModOrHigher) { await ctx.RespondEmbed(Translator.Instance.Translate("MSG_NOT_MODERATOR_OR_HIGHER").FormatText(new { author = ctx.User.Mention }), DiscordColor.Red); @@ -2841,7 +2846,7 @@ public async Task ResetAsync(CommandContext ctx, await ctx.RespondEmbed(Translator.Instance.Translate("MSG_INVALID_USER_MENTION").FormatText(new { author = ctx.User.Mention, - mention = mention, + mention, }), DiscordColor.Red); return; } @@ -2865,13 +2870,15 @@ await ctx.RespondEmbed(Translator.Instance.Translate("MSG_INVALID_USER_MENTION") // TODO: Localize await ctx.RespondEmbed($"{ctx.User.Username} has cleared all of {user.Username}'s subscriptions", DiscordColor.Green); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } #endregion #region Import / Export + /* + * TODO: Fix import settings [ Command("import"), Description("Import your saved notification subscription settings for Pokemon, Raids, Quests, Pokestops, and Gyms.") @@ -2881,7 +2888,7 @@ public async Task ImportAsync(CommandContext ctx) if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_IMPORT_UPLOAD_FILE").FormatText(new { author = ctx.User.Username })); var xc = await _dep.Interactivity.WaitForMessageAsync(x => x.Author.Id == ctx.User.Id && x.Attachments.Count > 0, TimeSpan.FromSeconds(180)); @@ -2899,7 +2906,7 @@ public async Task ImportAsync(CommandContext ctx) return; } - var oldSubscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var oldSubscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (oldSubscription != null) { var result = SubscriptionManager.RemoveAllUserSubscriptions(guildId, ctx.User.Id); @@ -2918,6 +2925,7 @@ public async Task ImportAsync(CommandContext ctx) subscription.Save(); await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_IMPORT_SUCCESS").FormatText(new { author = ctx.User.Username })); } + */ [ Command("export"), @@ -2928,9 +2936,9 @@ public async Task ExportAsync(CommandContext ctx) if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (subscription == null) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_EXPORT_NO_SUBSCRIPTIONS").FormatText(new { author = ctx.User.Username }), DiscordColor.Red); @@ -2941,7 +2949,7 @@ public async Task ExportAsync(CommandContext ctx) var tmpFile = Path.Combine(Path.GetTempPath(), $"{ctx.Guild?.Name}_{ctx.User.Username}_subscriptions_{DateTime.Now:yyyy-MM-dd}.json"); File.WriteAllText(tmpFile, json); - await ctx.RespondWithFileAsync(tmpFile, Translator.Instance.Translate("NOTIFY_EXPORT_SUCCESS").FormatText(new { author = ctx.User.Username })); + // TODO: await ctx.RespondWithFileAsync(tmpFile, Translator.Instance.Translate("NOTIFY_EXPORT_SUCCESS").FormatText(new { author = ctx.User.Username })); } #endregion @@ -2957,13 +2965,13 @@ public async Task IconsAsync(CommandContext ctx) if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); var description = "**Available Icon Styles:**\r\n" + - $"- {string.Join($"{Environment.NewLine}- ", _dep.WhConfig.IconStyles.Keys)}" + + $"- {string.Join($"{Environment.NewLine}- ", _config.Instance.IconStyles.Keys)}" + Environment.NewLine + Environment.NewLine + - $"*Type `{_dep.WhConfig.Servers[guildId].CommandPrefix}set-icons iconStyle` to use that icon style when receiving notifications from {Strings.BotName}.*"; + $"*Type `{_config.Instance.Servers[guildId].CommandPrefix}set-icons iconStyle` to use that icon style when receiving notifications from {Strings.BotName}.*"; var eb = new DiscordEmbedBuilder { Color = DiscordColor.Green, @@ -2989,19 +2997,19 @@ public async Task SetIconAsync(CommandContext ctx, if (!await CanExecute(ctx)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); - if (!_dep.WhConfig.IconStyles.Select(x => x.Key.ToLower()).Contains(iconStyle.ToLower())) + if (!_config.Instance.IconStyles.Select(x => x.Key.ToLower()).Contains(iconStyle.ToLower())) { await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_INVALID_ICON_STYLE").FormatText(new { author = ctx.User.Username, - prefix = _dep.WhConfig.Servers[guildId].CommandPrefix, + prefix = _config.Instance.Servers[guildId].CommandPrefix, }), DiscordColor.Red); return; } - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, ctx.User.Id); if (subscription == null) { await ctx.RespondEmbed(Translator.Instance.Translate("MSG_USER_NOT_SUBSCRIBED").FormatText(ctx.User.Username), DiscordColor.Red); @@ -3016,7 +3024,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_ICON_STYLE_CHANGE") author = ctx.User.Username, style = iconStyle, })); - _dep.SubscriptionProcessor.Manager.ReloadSubscriptions(); + _subProcessor.Manager.ReloadSubscriptions(); } #endregion @@ -3032,7 +3040,10 @@ public async Task StatsAsync(CommandContext ctx) { Title = $"{DateTime.Now.ToLongDateString()} Statistics", Color = DiscordColor.Blurple, - ThumbnailUrl = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQdNi3XTIwl8tkN_D6laRdexk0fXJ-fMr0C_s4ju-bXw2kcDSRI" + Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail + { + Url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQdNi3XTIwl8tkN_D6laRdexk0fXJ-fMr0C_s4ju-bXw2kcDSRI", + }, }; var sb = new StringBuilder(); @@ -3089,7 +3100,7 @@ public async Task StatsAsync(CommandContext ctx) private async Task EnableDisableUserSubscriptions(CommandContext ctx, DiscordUser user, ulong guildId) { - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, user.Id); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, user.Id); if (subscription == null) { await ctx.TriggerTypingAsync(); @@ -3113,7 +3124,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("NOTIFY_ENABLE_DISABLE").Fo })); } - private async Task SendUserSubscriptionSettings(DiscordClient client, DiscordUser receiver, DiscordUser user, ulong guildId) + private async Task SendUserSubscriptionSettings(DiscordClient client, DiscordMember receiver, DiscordUser user, ulong guildId) { var messages = await BuildUserSubscriptionSettings(client, user, guildId); for (var i = 0; i < messages.Count; i++) @@ -3135,7 +3146,7 @@ private async Task SendUserSubscriptionSettings(DiscordClient client, DiscordUse Text = $"{Strings.Creator} | {DateTime.Now}" } }; - await client.SendDirectMessage(receiver, eb.Build()); + await receiver.SendDirectMessage(eb.Build()); } } @@ -3149,11 +3160,11 @@ private async Task> BuildUserSubscriptionSettings(DiscordClient cli return new List { error }; } - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + if (!_config.Instance.Servers.ContainsKey(guildId)) return null; - var server = _dep.WhConfig.Servers[guildId]; - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, user.Id); + var server = _config.Instance.Servers[guildId]; + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, user.Id); var isSubbed = subscription?.Pokemon.Count > 0 || subscription?.PvP.Count > 0 || subscription?.Raids.Count > 0 || subscription?.Quests.Count > 0 || subscription?.Invasions.Count > 0 || subscription?.Gyms.Count > 0 || subscription?.Lures.Count > 0; var hasPokemon = isSubbed && subscription?.Pokemon?.Count > 0; var hasPvP = isSubbed && subscription?.PvP?.Count > 0; @@ -3163,7 +3174,7 @@ private async Task> BuildUserSubscriptionSettings(DiscordClient cli var hasInvasions = isSubbed && subscription?.Invasions?.Count > 0; var hasLures = isSubbed && subscription?.Lures?.Count > 0; var messages = new List(); - var isSupporter = await client.IsSupporterOrHigher(user.Id, guildId, _dep.WhConfig); + var isSupporter = await client.IsSupporterOrHigher(user.Id, guildId, _config.Instance); var areas = server.Geofences.Select(x => x.Name).ToList(); var feeds = member?.Roles?.Select(x => x.Name).Where(x => areas.Contains(x))?.ToList(); @@ -3356,7 +3367,7 @@ private async Task> BuildUserSubscriptionSettings(DiscordClient cli private List GetPvPSubscriptionNames(ulong guildId, ulong userId) { var list = new List(); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, userId); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, userId); var subscribedPvP = subscription.PvP; subscribedPvP.Sort((x, y) => x.PokemonIdString.CompareTo(y.PokemonIdString)); @@ -3400,10 +3411,10 @@ private List GetPvPSubscriptionNames(ulong guildId, ulong userId) private List GetRaidSubscriptionNames(ulong guildId, ulong userId) { var list = new List(); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, userId); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, userId); var subscribedRaids = subscription.Raids; subscribedRaids.Sort((x, y) => x.PokemonId.CompareTo(y.PokemonId)); - var cityRoles = _dep.WhConfig.Servers[guildId].Geofences.Select(x => x.Name.ToLower()); + var cityRoles = _config.Instance.Servers[guildId].Geofences.Select(x => x.Name.ToLower()); foreach (var raid in subscribedRaids) { @@ -3428,7 +3439,7 @@ private List GetRaidSubscriptionNames(ulong guildId, ulong userId) private List GetGymSubscriptionNames(ulong guildId, ulong userId) { var list = new List(); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, userId); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, userId); var subscribedGyms = subscription.Gyms; subscribedGyms.Sort((x, y) => x.Name.CompareTo(y.Name)); foreach (var gym in subscribedGyms) @@ -3442,10 +3453,10 @@ private List GetGymSubscriptionNames(ulong guildId, ulong userId) private List GetQuestSubscriptionNames(ulong guildId, ulong userId) { var list = new List(); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, userId); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, userId); var subscribedQuests = subscription.Quests; subscribedQuests.Sort((x, y) => string.Compare(x.RewardKeyword.ToLower(), y.RewardKeyword.ToLower(), true)); - var cityRoles = _dep.WhConfig.Servers[guildId].Geofences.Select(x => x.Name.ToLower()); + var cityRoles = _config.Instance.Servers[guildId].Geofences.Select(x => x.Name.ToLower()); foreach (var quest in subscribedQuests) { @@ -3463,10 +3474,10 @@ private List GetQuestSubscriptionNames(ulong guildId, ulong userId) private List GetInvasionSubscriptionNames(ulong guildId, ulong userId) { var list = new List(); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, userId); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, userId); var subscribedInvasions = subscription.Invasions; subscribedInvasions.Sort((x, y) => string.Compare(string.Join(", ", x.RewardPokemonId.Select(a => MasterFile.GetPokemon(a, 0).Name)), string.Join(", ", y.RewardPokemonId.Select(b => MasterFile.GetPokemon(b, 0).Name)), true)); - var cityRoles = _dep.WhConfig.Servers[guildId].Geofences.Select(x => x.Name.ToLower()); + var cityRoles = _config.Instance.Servers[guildId].Geofences.Select(x => x.Name.ToLower()); foreach (var invasion in subscribedInvasions) { @@ -3484,10 +3495,10 @@ private List GetInvasionSubscriptionNames(ulong guildId, ulong userId) private List GetLureSubscriptionNames(ulong guildId, ulong userId) { var list = new List(); - var subscription = _dep.SubscriptionProcessor.Manager.GetUserSubscriptions(guildId, userId); + var subscription = _subProcessor.Manager.GetUserSubscriptions(guildId, userId); var subscribedLures = subscription.Lures; subscribedLures.Sort((x, y) => x.LureType.CompareTo(y.LureType)); - var cityRoles = _dep.WhConfig.Servers[guildId].Geofences.Select(x => x.Name.ToLower()); + var cityRoles = _config.Instance.Servers[guildId].Geofences.Select(x => x.Name.ToLower()); foreach (var lure in subscribedLures) { @@ -3506,7 +3517,7 @@ private List GetLureSubscriptionNames(ulong guildId, ulong userId) private DiscordEmbedBuilder BuildExpirationMessage(ulong guildId, DiscordUser user) { - var customerData = _dep.Stripe.GetCustomerData(guildId, user.Id); + var customerData = _stripe.GetCustomerData(guildId, user.Id); if (!customerData.ExpireDate.HasValue) { return null; @@ -3534,20 +3545,20 @@ private static ulong ConvertMentionToUserId(string mention) private async Task CanExecute(CommandContext ctx) { - if (!await ctx.IsDirectMessageSupported(_dep.WhConfig)) + if (!await ctx.IsDirectMessageSupported(_config.Instance)) return false; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds?.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x.Key)).Key ?? 0; - if (guildId == 0 || !_dep.WhConfig.Servers.ContainsKey(guildId)) + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds?.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x.Key)).Key ?? 0; + if (guildId == 0 || !_config.Instance.Servers.ContainsKey(guildId)) return false; - if (!_dep.WhConfig.Servers[guildId].Subscriptions.Enabled) + if (!_config.Instance.Servers[guildId].Subscriptions.Enabled) { await ctx.RespondEmbed(Translator.Instance.Translate("MSG_SUBSCRIPTIONS_NOT_ENABLED").FormatText(new { author = ctx.User.Username }), DiscordColor.Red); return false; } - var isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _dep.WhConfig); + var isSupporter = await ctx.Client.IsSupporterOrHigher(ctx.User.Id, guildId, _config.Instance); if (!isSupporter) { await ctx.DonateUnlockFeaturesMessage(); diff --git a/src/Commands/Owner.cs b/src/Commands/Owner.cs index 0f96d533..dfff8b6e 100644 --- a/src/Commands/Owner.cs +++ b/src/Commands/Owner.cs @@ -8,6 +8,7 @@ using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; + using WhMgr.Configuration; using WhMgr.Data.Subscriptions; using WhMgr.Diagnostics; using WhMgr.Extensions; @@ -17,17 +18,19 @@ [ RequireOwner ] - public class Owner + public class Owner : BaseCommandModule { const string PokemonTrainerClub = "https://sso.pokemon.com/sso/login"; const string NianticLabs = "https://pgorelease.nianticlabs.com/plfe/version"; private static readonly IEventLogger _logger = EventLogger.GetLogger("OWNER", Program.LogLevel); - private readonly Dependencies _dep; + private readonly WhConfigHolder _config; + private readonly SubscriptionProcessor _subProcessor; - public Owner(Dependencies dep) + public Owner(WhConfigHolder config, SubscriptionProcessor subProcessor) { - _dep = dep; + _config = config; + _subProcessor = subProcessor; } [ @@ -63,15 +66,15 @@ public async Task CleanDepartedAsync(CommandContext ctx) { _logger.Debug($"Checking if there are any subscriptions for members that are no longer apart of the server..."); - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); var removed = 0; - var users = _dep.SubscriptionProcessor?.Manager?.Subscriptions; + var users = _subProcessor?.Manager?.Subscriptions; for (var i = 0; i < users.Count; i++) { var user = users[i]; var discordUser = ctx.Client.GetMemberById(guildId, user.UserId); - var isSupporter = ctx.Client.HasSupporterRole(guildId, user.UserId, _dep.WhConfig.Servers[guildId].DonorRoleIds); + var isSupporter = ctx.Client.HasSupporterRole(guildId, user.UserId, _config.Instance.Servers[guildId].DonorRoleIds); if (discordUser == null || !isSupporter) { _logger.Debug($"Removing user {user.UserId} subscription settings because they are no longer a member of the server."); @@ -93,6 +96,7 @@ await ctx.RespondEmbed(Translator.Instance.Translate("REMOVED_TOTAL_DEPARTED_MEM })); } + /* [ Command("sudo"), Description("Executes a command as another user."), @@ -108,6 +112,7 @@ public async Task Sudo(CommandContext ctx, var cmds = ctx.CommandsNext; await cmds.SudoAsync(member, ctx.Channel, command); } + */ [ Command("uptime"), diff --git a/src/Commands/Quests.cs b/src/Commands/Quests.cs index 3c29d8f5..666354e7 100644 --- a/src/Commands/Quests.cs +++ b/src/Commands/Quests.cs @@ -10,18 +10,19 @@ using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; + using WhMgr.Configuration; using WhMgr.Diagnostics; using WhMgr.Extensions; using WhMgr.Localization; - public class Quests + public class Quests : BaseCommandModule { private static readonly IEventLogger _logger = EventLogger.GetLogger("QUESTS", Program.LogLevel); - private readonly Dependencies _dep; + private readonly WhConfigHolder _config; - public Quests(Dependencies dep) + public Quests(WhConfigHolder config) { - _dep = dep; + _config = config; } [ @@ -32,11 +33,11 @@ public Quests(Dependencies dep) public async Task ResetChannelAsync(CommandContext ctx, [Description("Discord channel to reset.")] DiscordChannel channel = null) { - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); if (channel == null) { - var channelIds = _dep.WhConfig.Servers[guildId].QuestChannelIds; + var channelIds = _config.Instance.Servers[guildId].QuestChannelIds; for (var i = 0; i < channelIds.Count; i++) { var qChannel = await ctx.Client.GetChannelAsync(channelIds[i]); diff --git a/src/Commands/Settings.cs b/src/Commands/Settings.cs index 569112e4..72b4db55 100644 --- a/src/Commands/Settings.cs +++ b/src/Commands/Settings.cs @@ -10,6 +10,7 @@ using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; + using WhMgr.Configuration; using WhMgr.Extensions; [ @@ -19,13 +20,13 @@ Hidden, RequirePermissions(Permissions.KickMembers) ] - public class Settings + public class Settings : BaseCommandModule { - private readonly Dependencies _dep; + private readonly WhConfigHolder _config; - public Settings(Dependencies dep) + public Settings(WhConfigHolder config) { - _dep = dep; + _config = config; } [ @@ -38,31 +39,31 @@ public async Task SetAsync(CommandContext ctx, [Description("")] string value) { // TODO: Provide list of available config options to set. - if (!await ctx.IsDirectMessageSupported(_dep.WhConfig)) + if (!await ctx.IsDirectMessageSupported(_config.Instance)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + if (!_config.Instance.Servers.ContainsKey(guildId)) { // TODO: Localize await ctx.RespondEmbed($"{ctx.User.Username} Guild {ctx.Guild?.Name} ({guildId}) not configured in {Strings.ConfigFileName}"); return; } - //var guildConfig = _dep.WhConfig.Servers[guildId]; + //var guildConfig = _config.Instance.Servers[guildId]; switch (key) { case "nest_channel": // TODO: Validate nestChannelId - //_dep.WhConfig.Servers[guildId].NestsChannelId = value; - //_dep.WhConfig.Save(_dep.WhConfig.FileName); + //_config.Instance.Servers[guildId].NestsChannelId = value; + //_config.Instance.Save(_config.Instance.FileName); break; case "prefix": - var oldPrefix = _dep.WhConfig.Servers[guildId].CommandPrefix; + var oldPrefix = _config.Instance.Servers[guildId].CommandPrefix; await ctx.RespondEmbed($"{ctx.User.Username} Command prefix changed from {oldPrefix} to {value}.", DiscordColor.Green); - _dep.WhConfig.Servers[guildId].CommandPrefix = value; - _dep.WhConfig.Save(_dep.WhConfig.FileName); + _config.Instance.Servers[guildId].CommandPrefix = value; + _config.Instance.Save(_config.Instance.FileName); break; case "enable_subscriptions": if (!bool.TryParse(value, out var enableSubscriptions)) @@ -70,8 +71,8 @@ public async Task SetAsync(CommandContext ctx, await ctx.RespondEmbed($"{ctx.User.Username}", DiscordColor.Red); return; } - _dep.WhConfig.Servers[guildId].Subscriptions.Enabled = enableSubscriptions; - _dep.WhConfig.Save(_dep.WhConfig.FileName); + _config.Instance.Servers[guildId].Subscriptions.Enabled = enableSubscriptions; + _config.Instance.Save(_config.Instance.FileName); break; case "cities_require_donor": if (!bool.TryParse(value, out var citiesRequireDonor)) @@ -79,8 +80,8 @@ public async Task SetAsync(CommandContext ctx, await ctx.RespondEmbed($"{ctx.User.Username}", DiscordColor.Red); return; } - _dep.WhConfig.Servers[guildId].CitiesRequireSupporterRole = citiesRequireDonor; - _dep.WhConfig.Save(_dep.WhConfig.FileName); + _config.Instance.Servers[guildId].CitiesRequireSupporterRole = citiesRequireDonor; + _config.Instance.Save(_config.Instance.FileName); break; case "prune_quests": if (!bool.TryParse(value, out var pruneQuests)) @@ -88,17 +89,17 @@ public async Task SetAsync(CommandContext ctx, await ctx.RespondEmbed($"{ctx.User.Username}", DiscordColor.Red); return; } - _dep.WhConfig.Servers[guildId].PruneQuestChannels = pruneQuests; - _dep.WhConfig.Save(_dep.WhConfig.FileName); + _config.Instance.Servers[guildId].PruneQuestChannels = pruneQuests; + _config.Instance.Save(_config.Instance.FileName); break; case "icon_style": - if (!_dep.WhConfig.IconStyles.ContainsKey(value)) + if (!_config.Instance.IconStyles.ContainsKey(value)) { await ctx.RespondEmbed($"{ctx.User.Username}", DiscordColor.Red); return; } - _dep.WhConfig.Servers[guildId].IconStyle = value; - _dep.WhConfig.Save(_dep.WhConfig.FileName); + _config.Instance.Servers[guildId].IconStyle = value; + _config.Instance.Save(_config.Instance.FileName); break; case "shiny_stats": if (!bool.TryParse(value, out var enableShinyStats)) @@ -106,8 +107,8 @@ public async Task SetAsync(CommandContext ctx, await ctx.RespondEmbed($"{ctx.User.Username}", DiscordColor.Red); return; } - _dep.WhConfig.Servers[guildId].ShinyStats.Enabled = enableShinyStats; - _dep.WhConfig.Save(_dep.WhConfig.FileName); + _config.Instance.Servers[guildId].ShinyStats.Enabled = enableShinyStats; + _config.Instance.Save(_config.Instance.FileName); break; } await Task.CompletedTask; @@ -120,19 +121,19 @@ public async Task SetAsync(CommandContext ctx, ] public async Task ListSettingsAsync(CommandContext ctx) { - if (!await ctx.IsDirectMessageSupported(_dep.WhConfig)) + if (!await ctx.IsDirectMessageSupported(_config.Instance)) return; - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(ctx.Guild?.Id ?? 0)) + if (!_config.Instance.Servers.ContainsKey(ctx.Guild?.Id ?? 0)) { // TODO: Localize await ctx.RespondEmbed($"{ctx.User.Username} Guild {ctx.Guild?.Name} ({guildId}) not configured in {Strings.ConfigFileName}"); return; } - var guildConfig = _dep.WhConfig.Servers[guildId]; + var guildConfig = _config.Instance.Servers[guildId]; var eb = new DiscordEmbedBuilder { Color = DiscordColor.Blurple, diff --git a/src/Commands/ShinyStats.cs b/src/Commands/ShinyStats.cs index 17448b76..f970dad4 100644 --- a/src/Commands/ShinyStats.cs +++ b/src/Commands/ShinyStats.cs @@ -15,19 +15,20 @@ using ServiceStack.DataAnnotations; using ServiceStack.OrmLite; + using WhMgr.Configuration; using WhMgr.Data; using WhMgr.Diagnostics; using WhMgr.Extensions; using WhMgr.Localization; - public class ShinyStats + public class ShinyStats : BaseCommandModule { private static readonly IEventLogger _logger = EventLogger.GetLogger("SHINY_STATS", Program.LogLevel); - private readonly Dependencies _dep; + private readonly WhConfigHolder _config; - public ShinyStats(Dependencies dep) + public ShinyStats(WhConfigHolder config) { - _dep = dep; + _config = config; } [ @@ -36,15 +37,15 @@ public ShinyStats(Dependencies dep) ] public async Task GetShinyStatsAsync(CommandContext ctx) { - var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _dep.WhConfig.Servers.ContainsKey(x)); + var guildId = ctx.Guild?.Id ?? ctx.Client.Guilds.Keys.FirstOrDefault(x => _config.Instance.Servers.ContainsKey(x)); - if (!_dep.WhConfig.Servers.ContainsKey(guildId)) + if (!_config.Instance.Servers.ContainsKey(guildId)) { await ctx.RespondEmbed(Translator.Instance.Translate("ERROR_NOT_IN_DISCORD_SERVER"), DiscordColor.Red); return; } - var server = _dep.WhConfig.Servers[guildId]; + var server = _config.Instance.Servers[guildId]; if (!server.ShinyStats.Enabled) return; @@ -61,7 +62,7 @@ public async Task GetShinyStatsAsync(CommandContext ctx) await ctx.Client.DeleteMessages(server.ShinyStats.ChannelId); } - var stats = await GetShinyStats(_dep.WhConfig.Database.Scanner.ToString()); + var stats = await GetShinyStats(_config.Instance.Database.Scanner.ToString()); var sorted = stats.Keys.ToList(); sorted.Sort(); if (sorted.Count > 0) @@ -99,7 +100,7 @@ await statsChannel.SendMessageAsync(Translator.Instance.Translate("SHINY_STATS_M id = pokemon, shiny = pkmnStats.Shiny.ToString("N0"), total = pkmnStats.Total.ToString("N0"), - chance = chance, + chance, })); } Thread.Sleep(500); diff --git a/src/Data/Subscriptions/SubscriptionProcessor.cs b/src/Data/Subscriptions/SubscriptionProcessor.cs index 7f5cdd76..0ef9b381 100644 --- a/src/Data/Subscriptions/SubscriptionProcessor.cs +++ b/src/Data/Subscriptions/SubscriptionProcessor.cs @@ -957,7 +957,7 @@ private void ProcessQueue() } }; - await _servers[item.Subscription.GuildId].SendDirectMessage(item.Member, string.Empty, eb.Build()); + await item.Member.SendDirectMessage(string.Empty, eb.Build()); item.Subscription.RateLimitNotificationSent = true; item.Subscription.Status = NotificationStatusType.None; if (!item.Subscription.Update()) @@ -999,7 +999,7 @@ private void ProcessQueue() // Send direct message notification to user var client = _servers[item.Subscription.GuildId]; - await client.SendDirectMessage(item.Member, item.Embed); + await item.Member.SendDirectMessage(item.Embed); _logger.Info($"[WEBHOOK] Notified user {item.Member.Username} of {item.Description}."); Thread.Sleep(10); } diff --git a/src/Extensions/DiscordExtensions.cs b/src/Extensions/DiscordExtensions.cs index 03198b7b..3a93121e 100644 --- a/src/Extensions/DiscordExtensions.cs +++ b/src/Extensions/DiscordExtensions.cs @@ -10,7 +10,7 @@ using DSharpPlus; using DSharpPlus.CommandsNext; using DSharpPlus.Entities; - using DSharpPlus.Interactivity; + using DSharpPlus.Interactivity.Extensions; using WeatherCondition = POGOProtos.Rpc.GameplayWeatherProto.Types.WeatherCondition; using WhMgr.Configuration; @@ -74,29 +74,29 @@ public static async Task> RespondEmbed(this CommandContext return messagesSent; } - public static async Task SendDirectMessage(this DiscordClient client, DiscordUser user, DiscordEmbed embed) + public static async Task SendDirectMessage(this DiscordMember member, DiscordEmbed embed) { if (embed == null) return null; - return await client.SendDirectMessage(user, string.Empty, embed); + return await member.SendDirectMessage(string.Empty, embed); } - public static async Task SendDirectMessage(this DiscordClient client, DiscordUser user, string message, DiscordEmbed embed) + public static async Task SendDirectMessage(this DiscordMember member, string message, DiscordEmbed embed) { try { - var dm = await client.CreateDmAsync(user); + var dm = await member.CreateDmChannelAsync(); if (dm != null) { - var msg = await dm.SendMessageAsync(message, false, embed); + var msg = await dm.SendMessageAsync(message, embed); return msg; } } catch (Exception) { //_logger.Error(ex); - _logger.Error($"Failed to send DM to user {user.Username}."); + _logger.Error($"Failed to send DM to user {member.Username}."); } return null; @@ -154,7 +154,7 @@ private static async Task DoGetMemberById(DiscordClient client, u DiscordMember member = null; try { - member = members?.FirstOrDefault(x => x.Id == id); + member = members?.FirstOrDefault(x => x.Key == id).Value; } catch { } if (member == null) @@ -294,7 +294,7 @@ public static bool HasSupporterRole(this DiscordClient client, ulong guildId, ul return false; var guild = client.Guilds[guildId]; - var member = guild.Members.FirstOrDefault(x => x.Id == userId); + var member = guild.Members.FirstOrDefault(x => x.Key == userId).Value; if (member == null) { _logger.Error($"Failed to get user with id {userId}."); @@ -357,7 +357,7 @@ public static bool HasRole(this DiscordGuild guild, DiscordMember member, string public static DiscordRole GetRoleFromName(this DiscordGuild guild, string roleName) { - return guild?.Roles.FirstOrDefault(x => string.Compare(x.Name, roleName, true) == 0); + return guild?.Roles.FirstOrDefault(x => string.Compare(x.Value.Name, roleName, true) == 0).Value; } #endregion @@ -419,7 +419,7 @@ public static async Task> DeleteMessages(this Discor public static async Task Confirm(this CommandContext ctx, string message) { await ctx.RespondEmbed(message); - var interactivity = ctx.Client.GetModule(); + var interactivity = ctx.Client.GetInteractivity(); if (interactivity == null) { _logger.Error("Interactivity model failed to load!"); @@ -432,7 +432,7 @@ public static async Task Confirm(this CommandContext ctx, string message) && Regex.IsMatch(x.Content, ConfirmRegex), TimeSpan.FromMinutes(2)); - return Regex.IsMatch(m.Message.Content, YesRegex); + return Regex.IsMatch(m.Result.Content, YesRegex); } #region Colors diff --git a/src/Extensions/DiscordInteractivityExtensions.cs b/src/Extensions/DiscordInteractivityExtensions.cs index 90c7b799..301c636c 100644 --- a/src/Extensions/DiscordInteractivityExtensions.cs +++ b/src/Extensions/DiscordInteractivityExtensions.cs @@ -6,7 +6,7 @@ using DSharpPlus.CommandsNext; using DSharpPlus.Entities; - using DSharpPlus.Interactivity; + using DSharpPlus.Interactivity.Extensions; static class DiscordInteractivityExtensions { @@ -29,17 +29,17 @@ public static async Task GetSubscriptionTypeSelection(this CommandContext c await message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":five:")); await message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":six:")); - var interactivity = ctx.Client.GetInteractivityModule(); + var interactivity = ctx.Client.GetInteractivity(); // TODO: Configurable subscription timeout - var resultReact = await interactivity.WaitForMessageReactionAsync(x => !string.IsNullOrEmpty(x.Name), message, ctx.User, TimeSpan.FromMinutes(3)); - if (resultReact == null) + var resultReact = await interactivity.WaitForReactionAsync(x => !string.IsNullOrEmpty(x.Emoji?.Name), message, ctx.User, TimeSpan.FromMinutes(3)); + if (resultReact.Result == null) { await ctx.RespondEmbed($"Invalid result", DiscordColor.Red); return 0; } await message.DeleteAsync(); - switch (resultReact.Emoji.Name.ToLower()) + switch (resultReact.Result.Emoji?.Name.ToLower()) { case "1⃣": return 1; case "2⃣": return 2; @@ -53,14 +53,14 @@ public static async Task GetSubscriptionTypeSelection(this CommandContext c public static async Task WaitForUserChoice(this CommandContext ctx, bool allowNull = false) { - var interactivity = ctx.Client.GetInteractivityModule(); + var interactivity = ctx.Client.GetInteractivity(); // TODO: Configurable subscription timeout var result = await interactivity.WaitForMessageAsync(x => x.Author.Id == ctx.User.Id && (allowNull && string.IsNullOrEmpty(x.Content)) || (!allowNull && !string.IsNullOrEmpty(x.Content)), TimeSpan.FromMinutes(3)); - var content = result?.Message.Content; + var content = result.Result?.Content; try { // Bot can't delete user messages in DMs - await result.Message?.DeleteAsync(); + await result.Result?.DeleteAsync(); } catch { } return content; diff --git a/src/Net/HttpServer.cs b/src/Net/HttpServer.cs index 9e3168bc..6d1a2ffb 100644 --- a/src/Net/HttpServer.cs +++ b/src/Net/HttpServer.cs @@ -140,7 +140,7 @@ public HttpServer(HttpServerConfig httpConfig) _clearCacheTimer = new System.Timers.Timer { Interval = 60000 * 15 }; _clearCacheTimer.Elapsed += (sender, e) => OnClearCache(); _checkForDuplicates = httpConfig.CheckForDuplicates; - + Initialize(); } @@ -226,49 +226,54 @@ private void RequestHandler() { while (_server.IsListening) { - var context = _server.GetContext(); - var response = context.Response; - - if (context.Request?.InputStream == null) - continue; - - // Read from the POST data input stream of the request - using (var sr = new StreamReader(context.Request.InputStream)) + var contextAsyncResult = _server.BeginGetContext((IAsyncResult ar) => { - try + var context = _server.EndGetContext(ar); + + // Read from the POST data input stream of the request + using (var sr = new StreamReader(context.Request.InputStream)) { - // Read to the end of the stream as a string - var data = sr.ReadToEnd(); - ParseData(data); + try + { + // Read to the end of the stream as a string + var data = sr.ReadToEnd(); + ParseData(data); + } + catch (HttpListenerException hle) + { + _logger.Error(hle); + + //Disconnected, reconnect. + HandleDisconnect(); + return; + } } - catch (HttpListenerException hle) + + try { - _logger.Error(hle); + var response = context?.Response; + if (response != null) + { + // Convert the default response message to UTF8 encoded bytes + var buffer = Encoding.UTF8.GetBytes(Strings.DefaultResponseMessage); + response.ContentLength64 = buffer.Length; - //Disconnected, reconnect. - HandleDisconnect(); + var output = response.OutputStream; + output.Write(buffer, 0, buffer.Length); + output.Close(); + } } - } - - try - { - // Convert the default response message to UTF8 encoded bytes - var buffer = Encoding.UTF8.GetBytes(Strings.DefaultResponseMessage); - response.ContentLength64 = buffer.Length; - if (response?.OutputStream != null) + catch (Exception ex) { - // Write the response buffer to the output stream - response.OutputStream.Write(buffer, 0, buffer.Length); + _logger.Error(ex); } - // Close the response - context.Response.Close(); - } - catch (Exception ex) - { - _logger.Error(ex); - } - Thread.Sleep(10); + }, null); + + WaitHandle.WaitAny(new WaitHandle[] + { + contextAsyncResult.AsyncWaitHandle, + }); } } @@ -304,7 +309,7 @@ private void ParseData(string data) ParseGym(message.Message); break; case GymDetailsData.WebhookHeader: - ParseGymDetails(message.Message); + ParseGymDetails(message.Message); break; case RaidData.WebHookHeader: ParseRaid(message.Message); diff --git a/src/Net/Models/GymDetailsData.cs b/src/Net/Models/GymDetailsData.cs index 6f58cbf8..76a007df 100644 --- a/src/Net/Models/GymDetailsData.cs +++ b/src/Net/Models/GymDetailsData.cs @@ -98,7 +98,10 @@ public DiscordEmbedNotification GenerateGymMessage(ulong guildId, DiscordClient Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), - ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail + { + Url = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + }, Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = Team == PokemonTeam.Mystic ? DiscordColor.Blue : Team == PokemonTeam.Valor ? DiscordColor.Red : diff --git a/src/Net/Models/PokemonData.cs b/src/Net/Models/PokemonData.cs index 153ca8c3..3cf8fe36 100644 --- a/src/Net/Models/PokemonData.cs +++ b/src/Net/Models/PokemonData.cs @@ -440,7 +440,10 @@ public DiscordEmbedNotification GeneratePokemonMessage(ulong guildId, DiscordCli Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), - ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail + { + Url = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + }, Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = MatchesGreatLeague || MatchesUltraLeague ? GetPvPColor(GreatLeague, UltraLeague, MasterFile.Instance.DiscordEmbedColors) diff --git a/src/Net/Models/PokestopData.cs b/src/Net/Models/PokestopData.cs index 6585fb42..02b79067 100644 --- a/src/Net/Models/PokestopData.cs +++ b/src/Net/Models/PokestopData.cs @@ -119,7 +119,10 @@ public DiscordEmbedNotification GeneratePokestopMessage(ulong guildId, DiscordCl Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), - ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail + { + Url = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + }, Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = useInvasion ? new DiscordColor(MasterFile.Instance.DiscordEmbedColors.Pokestops.Invasions) diff --git a/src/Net/Models/QuestData.cs b/src/Net/Models/QuestData.cs index e848061c..39aa01f2 100644 --- a/src/Net/Models/QuestData.cs +++ b/src/Net/Models/QuestData.cs @@ -102,7 +102,10 @@ public DiscordEmbedNotification GenerateQuestMessage(ulong guildId, DiscordClien Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), - ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail + { + Url = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + }, Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = new DiscordColor(MasterFile.Instance.DiscordEmbedColors.Pokestops.Quests), Footer = new DiscordEmbedBuilder.EmbedFooter diff --git a/src/Net/Models/RaidData.cs b/src/Net/Models/RaidData.cs index 5d7c2235..63a6365e 100644 --- a/src/Net/Models/RaidData.cs +++ b/src/Net/Models/RaidData.cs @@ -164,7 +164,10 @@ public DiscordEmbedNotification GenerateRaidMessage(ulong guildId, DiscordClient Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), - ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail + { + Url = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + }, Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = (IsExEligible ? 0 /*ex*/ : int.Parse(Level)).BuildRaidColor(MasterFile.Instance.DiscordEmbedColors), Footer = new DiscordEmbedBuilder.EmbedFooter diff --git a/src/Net/Models/WeatherData.cs b/src/Net/Models/WeatherData.cs index ffa53b5f..57b5b607 100644 --- a/src/Net/Models/WeatherData.cs +++ b/src/Net/Models/WeatherData.cs @@ -121,7 +121,10 @@ public DiscordEmbedNotification GenerateWeatherMessage(ulong guildId, DiscordCli Title = DynamicReplacementEngine.ReplaceText(alert.Title, properties), Url = DynamicReplacementEngine.ReplaceText(alert.Url, properties), ImageUrl = DynamicReplacementEngine.ReplaceText(alert.ImageUrl, properties), - ThumbnailUrl = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail + { + Url = DynamicReplacementEngine.ReplaceText(alert.IconUrl, properties), + }, Description = DynamicReplacementEngine.ReplaceText(alert.Content, properties), Color = GameplayCondition.BuildWeatherColor(MasterFile.Instance.DiscordEmbedColors), Footer = new DiscordEmbedBuilder.EmbedFooter diff --git a/src/Strings.cs b/src/Strings.cs index 6c61ec05..1bf65ed3 100644 --- a/src/Strings.cs +++ b/src/Strings.cs @@ -5,7 +5,6 @@ using System.IO; using System.Reflection; - using POGOProtos.Rpc; using WhMgr.Data.Models; using WeatherCondition = POGOProtos.Rpc.GameplayWeatherProto.Types.WeatherCondition; diff --git a/src/WhMgr.csproj b/src/WhMgr.csproj index caf1934d..dd37215f 100644 --- a/src/WhMgr.csproj +++ b/src/WhMgr.csproj @@ -13,8 +13,8 @@ $(VersionSuffix) 4.2.1.0 $(VersionSuffix) - 4.18.0.0 - 4.18.0.0 + 4.19.0.0 + 4.19.0.0 Windows @@ -36,15 +36,15 @@ - - - + + + - +