public async Task UnBlackListUsers([Summary("Mentioned users that need to be unblacklisted")][Remainder] string content) { if (!await IsOwner(Context.Message.Author).ConfigureAwait(false)) { await ReplyAsync("You are not permitted to use this command.").ConfigureAwait(false); return; } var users = Context.Message.MentionedUsers.Select(z => z.Id); var blusers = ReusableActions.GetListFromString(SysCordInstance.Self.Hub.Config.DiscordBlackList); var iter = blusers.ToList(); // Deepclone foreach (var ch in iter) { if (!ulong.TryParse(ch, out var uid) || !users.Contains(uid)) { continue; } blusers.Remove(uid.ToString()); } SysCordInstance.Self.Hub.Config.DiscordBlackList = string.Join(", ", blusers); await ReplyAsync("Un-Blacklisted mentioned users from using the bot!").ConfigureAwait(false); }
public async Task GiveawayItemAsync([Summary("ID/Name of Item to Recieve")] string Item) { var code = Info.GetRandomTradeCode(); var poolDB = Info.Hub.GiveawayPoolDatabase; GiveawayPoolEntry?entry; var content = ReusableActions.StripCodeBlock(Item); bool reqIsIndex = int.TryParse(content, out var poolId); // Check if the user provided an index rather than name if (!reqIsIndex) // Not an integer so treat it as a name { await ReplyAsync($"\"{content}\" is not a valid Pool ID, use \"{Info.Hub.Config.Discord.CommandPrefix}itempool\" for a full list of available Items and provide the entries ID.").ConfigureAwait(false); return; } else { entry = poolDB.GetEntry(SysCord.ITEM_POOL, poolId); if (entry == null) { await ReplyAsync($"\"{content}\" is not a valid Pool ID, use \"{Info.Hub.Config.Discord.CommandPrefix}itempool\" for a full list of available Items and provide the entries ID.").ConfigureAwait(false); return; } } var sig = Context.User.GetFavor(); await Context.AddToQueueAsync(code, Context.User.Username, sig, entry.PK8, PokeRoutineType.LinkTrade, PokeTradeType.Giveaway, Context.User, entry).ConfigureAwait(false); }
public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content) { const int gen = 8; content = ReusableActions.StripCodeBlock(content); var set = new ShowdownSet(content); if (set.InvalidLines.Count != 0) { var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}"; await ReplyAsync(msg).ConfigureAwait(false); return; } var sav = AutoLegalityWrapper.GetTrainerInfo(gen); var pkm = sav.GetLegal(set, out _); var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[set.Species]; var invalid = !(pkm is PK8) || (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality); if (invalid) { var imsg = $"Oops! I wasn't able to create something from that. Here's my best attempt for that {spec}!"; await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false); return; } pkm.ResetPartyStats(); var sudo = Context.User.GetIsSudo(); await AddTradeToQueueAsync(code, Context.User.Username, (PK8)pkm, sudo).ConfigureAwait(false); }
public static async Task ReplyWithLegalizedSetAsync(this ISocketMessageChannel channel, ITrainerInfo sav, ShowdownSet set) { if (set.Species <= 0) { await channel.SendMessageAsync("Oops! I wasn't able to interpret your message! If you intended to convert something, please double check what you're pasting!").ConfigureAwait(false); return; } var template = AutoLegalityWrapper.GetTemplate(set); var pkm = sav.GetLegal(template, out var result); if (SysCordInstance.Self.Hub.Config.Trade.EggTrade && pkm.Nickname == "Egg") { TradeExtensions.EggTrade((PK8)pkm); } if (SysCordInstance.Self.Hub.Config.Trade.DittoTrade && set.Species == 132) { TradeExtensions.DittoTrade(pkm); } var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; var reason = result == "Timeout" ? "That set took too long to generate." : "I wasn't able to create something from that."; var msg = la.Valid ? $"Here's your ({result}) legalized PKM for {spec} ({la.EncounterOriginal.Name})!" : $"Oops! {reason} Here's my best attempt for that {spec}!"; await channel.SendPKMAsync(pkm, msg + $"\n{ReusableActions.GetFormattedShowdownText(pkm)}").ConfigureAwait(false); }
public static async Task ReplyWithLegalizedSetAsync(this ISocketMessageChannel channel, string content) { content = ReusableActions.StripCodeBlock(content); var set = new ShowdownSet(content); var sav = AutoLegalityWrapper.GetTrainerInfo(set.Format); await channel.ReplyWithLegalizedSetAsync(sav, set).ConfigureAwait(false); }
public async Task AddLogAsync() { if (!Context.GetIsSudo()) { await ReplyAsync("You are not permitted to use this command.").ConfigureAwait(false); return; } var c = Context.Channel; var cid = c.Id; if (Channels.TryGetValue(cid, out _)) { await ReplyAsync("Already logging here.").ConfigureAwait(false); return; } AddLogChannel(c, cid); // Add to discord global loggers (saves on program close) var loggers = ReusableActions.GetListFromString(SysCordInstance.Self.Hub.Config.GlobalDiscordLoggers); loggers.Add(cid.ToString()); SysCordInstance.Self.Hub.Config.GlobalDiscordLoggers = string.Join(", ", new HashSet <string>(loggers)); await ReplyAsync("Added logging output to this channel!").ConfigureAwait(false); }
public async Task RemoveSudoUsers([Summary("Mentioned users will be removed from the global sudo list")][Remainder] string content) { if (!await IsOwner(Context.Message.Author).ConfigureAwait(false)) { await ReplyAsync("You are not permitted to use this command.").ConfigureAwait(false); return; } var users = Context.Message.MentionedUsers; var userids = users.Select(z => z.Id.ToString()); var sudos = ReusableActions.GetListFromString(SysCordInstance.Self.Hub.Config.GlobalSudoList); var iter = sudos.ToList(); // Deepclone foreach (var ch in iter) { if (!ulong.TryParse(ch, out var uid) || !userids.Contains(uid.ToString())) { continue; } sudos.Remove(uid.ToString()); } SysCordInstance.Self.Hub.Config.GlobalSudoList = string.Join(", ", new HashSet <string>(sudos)); // unique values await ReplyAsync("Mentioned users are no longer sudo users for the bot!").ConfigureAwait(false); }
public async Task TradeAsync([Summary("Showdown Set")][Remainder] string content) { const int gen = 8; content = ReusableActions.StripCodeBlock(content); var set = new ShowdownSet(content); var sav = AutoLegalityExtensions.GetTrainerInfo(gen); var pkm = sav.GetLegal(set, out var result); var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[set.Species]; var msg = la.Valid ? $"Here's your ({result}) legalized PKM for {spec} ({la.EncounterOriginal.Name})!" : $"Oops! I wasn't able to create something from that. Here's my best attempt for that {spec}!"; if (!la.Valid || !(pkm is PK8 pk8)) { await ReplyAsync(msg).ConfigureAwait(false); return; } pk8.ResetPartyStats(); var code = Info.GetRandomTradeCode(); var sudo = Context.User.GetIsSudo(); await AddTradeToQueueAsync(code, Context.User.Username, pk8, sudo).ConfigureAwait(false); }
public static async Task ReplyWithLegalizedSetAsync(this ISocketMessageChannel channel, string content, int gen) { content = ReusableActions.StripCodeBlock(content); var set = new ShowdownSet(content); var sav = TrainerSettings.GetSavedTrainerData(gen); await channel.ReplyWithLegalizedSetAsync(sav, set).ConfigureAwait(false); }
public async Task UnBlackListIDs([Summary("Comma Separated Discord IDs")][Remainder] string content) { if (!await IsOwner(Context.Message.Author).ConfigureAwait(false)) { await ReplyAsync("You are not permitted to use this command.").ConfigureAwait(false); return; } var users = content.Split(new[] { ",", ", ", " " }, StringSplitOptions.RemoveEmptyEntries); var userids = ReusableActions.GetListFromString(SysCordInstance.Self.Hub.Config.DiscordBlackList); var iter = userids.ToList(); // Deepcopy foreach (var user in iter) { if (!ulong.TryParse(user, out var uid) || !users.Contains(uid.ToString())) { continue; } userids.Remove(uid.ToString()); } SysCordInstance.Self.Hub.Config.DiscordBlackList = string.Join(", ", new HashSet <string>(userids)); // empty string joins await ReplyAsync("Un-Blacklisted listed IDs from using the bot!").ConfigureAwait(false); }
public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content) { const int gen = 8; content = ReusableActions.StripCodeBlock(content); SpecifyOT(content, out string specifyOT); if (specifyOT != string.Empty) { content = System.Text.RegularExpressions.Regex.Replace(content, @"OT:(\S*\s?\S*\s?\S*)?$\W?", "", System.Text.RegularExpressions.RegexOptions.Multiline); } var set = new ShowdownSet(content); var template = AutoLegalityWrapper.GetTemplate(set); if (set.InvalidLines.Count != 0) { var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}"; await ReplyAsync(msg).ConfigureAwait(false); return; } var sav = AutoLegalityWrapper.GetTrainerInfo(gen); var pkm = sav.GetLegal(template, out _); if (specifyOT != string.Empty) { pkm.OT_Name = specifyOT; } var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; var invalid = !(pkm is PK8) || (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality); if (invalid && !Info.Hub.Config.Trade.Memes) { var imsg = $"Oops! I wasn't able to create something from that. Here's my best attempt for that {spec}!"; await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false); return; } else if (Info.Hub.Config.Trade.Memes) { if (await TrollAsync(invalid, template).ConfigureAwait(false)) { return; } } pkm.ResetPartyStats(); var sudo = Context.User.GetIsSudo(); await AddTradeToQueueAsync(code, Context.User.Username, (PK8)pkm, sudo).ConfigureAwait(false); }
public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content) { const int gen = 8; content = ReusableActions.StripCodeBlock(content); var set = new ShowdownSet(content); var template = AutoLegalityWrapper.GetTemplate(set); if (set.InvalidLines.Count != 0) { var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}"; await ReplyAsync(msg).ConfigureAwait(false); return; } var sav = AutoLegalityWrapper.GetTrainerInfo(gen); var pkm = sav.GetLegal(template, out _); if (Info.Hub.Config.Trade.DittoTrade && pkm.Species == 132) { TradeExtensions.DittoTrade(pkm); } if (Info.Hub.Config.Trade.EggTrade && pkm.Nickname == "Egg") { TradeExtensions.EggTrade((PK8)pkm); } var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; var invalid = !(pkm is PK8) || (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality); if (invalid && !Info.Hub.Config.Trade.Memes) { var imsg = $"Oops! I wasn't able to create something from that. Here's my best attempt for that {spec}!"; await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false); return; } else if (Info.Hub.Config.Trade.Memes) { if (await TrollAsync(invalid, template).ConfigureAwait(false)) { return; } } pkm.ResetPartyStats(); var sig = Context.User.GetFavor(); await AddTradeToQueueAsync(code, Context.User.Username, (PK8)pkm, sig, Context.User).ConfigureAwait(false); }
public static async Task ReplyWithLegalizedSetAsync(this ISocketMessageChannel channel, ITrainerInfo sav, ShowdownSet set) { if (set.Species <= 0) { await channel.SendMessageAsync("Oops! I wasn't able to interpret your message! If you intended to convert something, please double check what you're pasting!").ConfigureAwait(false); return; } var pkm = sav.GetLegal(set, out var result); var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[set.Species]; var msg = la.Valid ? $"Here's your ({result}) legalized PKM for {spec} ({la.EncounterOriginal.Name})!" : $"Oops! I wasn't able to create something from that. Here's my best attempt for that {spec}!"; await channel.SendPKMAsync(pkm, msg + $"\n{ReusableActions.GetFormattedShowdownText(pkm)}").ConfigureAwait(false); }
public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content) { content = ReusableActions.StripCodeBlock(content); var set = new ShowdownSet(content); var template = AutoLegalityWrapper.GetTemplate(set); if (set.InvalidLines.Count != 0) { var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}"; await ReplyAsync(msg).ConfigureAwait(false); return; } try { var sav = AutoLegalityWrapper.GetTrainerInfo <T>(); var pkm = sav.GetLegal(template, out var result); var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; pkm = PKMConverter.ConvertToType(pkm, typeof(T), out _) ?? pkm; if (pkm is not T pk || !la.Valid) { var reason = result == "Timeout" ? $"That {spec} set took too long to generate." : $"I wasn't able to create a {spec} from that set."; var imsg = $"Oops! {reason}"; if (result == "Failed") { imsg += $"\n{AutoLegalityWrapper.GetLegalizationHint(template, sav, pkm)}"; } await ReplyAsync(imsg).ConfigureAwait(false); return; } pk.ResetPartyStats(); var sig = Context.User.GetFavor(); await AddTradeToQueueAsync(code, Context.User.Username, pk, sig, Context.User).ConfigureAwait(false); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) #pragma warning restore CA1031 // Do not catch general exception types { LogUtil.LogSafe(ex, nameof(TradeModule <T>)); var msg = $"Oops! An unexpected problem happened with this Showdown Set:\n```{string.Join("\n", set.GetSetLines())}```"; await ReplyAsync(msg).ConfigureAwait(false); } }
public static async Task ReplyWithLegalizedSetAsync(this ISocketMessageChannel channel, ITrainerInfo sav, ShowdownSet set) { if (set.Species <= 0) { await channel.SendMessageAsync("Oops! I wasn't able to interpret your message! If you intended to convert something, please double check what you're pasting!").ConfigureAwait(false); return; } try { var template = AutoLegalityWrapper.GetTemplate(set); var pkm = sav.GetLegal(template, out var result); if (pkm is PK8 && pkm.Nickname.ToLower() == "egg" && Breeding.CanHatchAsEgg(pkm.Species)) { TradeExtensions <PK8> .EggTrade(pkm); } else if (pkm is PB8 && pkm.Nickname.ToLower() == "egg" && Breeding.CanHatchAsEgg(pkm.Species)) { TradeExtensions <PB8> .EggTrade(pkm); } var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; if (!la.Valid) { var reason = result == "Timeout" ? $"That {spec} set took too long to generate." : $"I wasn't able to create a {spec} from that set."; var imsg = $"Oops! {reason}"; if (result == "Failed") { imsg += $"\n{AutoLegalityWrapper.GetLegalizationHint(template, sav, pkm)}"; } await channel.SendMessageAsync(imsg).ConfigureAwait(false); return; } var msg = $"Here's your ({result}) legalized PKM for {spec} ({la.EncounterOriginal.Name})!"; await channel.SendPKMAsync(pkm, msg + $"\n{ReusableActions.GetFormattedShowdownText(pkm)}").ConfigureAwait(false); } catch (Exception ex) { LogUtil.LogSafe(ex, nameof(AutoLegalityExtensionsDiscord)); var msg = $"Oops! An unexpected problem happened with this Showdown Set:\n```{string.Join("\n", set.GetSetLines())}```"; await channel.SendMessageAsync(msg).ConfigureAwait(false); } }
public static void RestoreChannels(DiscordSocketClient discord) { var cfg = SysCordInstance.Settings; var channels = ReusableActions.GetListFromString(cfg.EchoChannels); foreach (var ch in channels) { if (!ulong.TryParse(ch, out var cid)) { continue; } var c = (ISocketMessageChannel)discord.GetChannel(cid); AddEchoChannel(c, cid); } EchoUtil.Echo("Added echo notification to Discord channel(s) on Bot startup."); }
public async Task BlackListUsers([Summary("Mentioned users that need to be blacklisted")][Remainder] string content) { if (!await IsOwner(Context.Message.Author).ConfigureAwait(false)) { await ReplyAsync("You are not permitted to use this command.").ConfigureAwait(false); return; } var users = Context.Message.MentionedUsers; var userids = users.Select(z => z.Id.ToString()); var blacklist = ReusableActions.GetListFromString(SysCordInstance.Self.Hub.Config.DiscordBlackList); blacklist.AddRange(userids); SysCordInstance.Self.Hub.Config.DiscordBlackList = string.Join(", ", new HashSet <string>(blacklist)); // unique values await ReplyAsync("Blacklisted mentioned users from using the bot!").ConfigureAwait(false); }
public async Task SudoUsers([Summary("Mentioned users will be added to the global sudo list")][Remainder] string content) { if (!await IsOwner(Context.Message.Author).ConfigureAwait(false)) { await ReplyAsync("You are not permitted to use this command.").ConfigureAwait(false); return; } var users = Context.Message.MentionedUsers; var userids = users.Select(z => z.Id.ToString()); var sudos = ReusableActions.GetListFromString(SysCordInstance.Self.Hub.Config.GlobalSudoList); sudos.AddRange(userids); SysCordInstance.Self.Hub.Config.GlobalSudoList = string.Join(", ", new HashSet <string>(sudos)); // unique values await ReplyAsync("Mentioned users are now sudo users for the bot!").ConfigureAwait(false); }
public async Task TradeAsync([Summary("Showdown Set")][Remainder] string content) { var cfg = Info.Hub.Config; var sudo = Context.GetIsSudo(cfg); var allowed = sudo || (Context.GetHasRole(cfg.DiscordRoleCanTrade) && Info.CanQueue); if (!sudo && !Info.CanQueue) { await ReplyAsync("Sorry, I am not currently accepting queue requests!").ConfigureAwait(false); return; } if (!allowed) { await ReplyAsync("Sorry, you are not permitted to use this command!").ConfigureAwait(false); return; } const int gen = 8; content = ReusableActions.StripCodeBlock(content); var set = new ShowdownSet(content); var sav = AutoLegalityExtensions.GetTrainerInfo(gen); var pkm = sav.GetLegal(set, out var result); var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[set.Species]; var msg = la.Valid ? $"Here's your ({result}) legalized PKM for {spec} ({la.EncounterOriginal.Name})!" : $"Oops! I wasn't able to create something from that. Here's my best attempt for that {spec}!"; if (!la.Valid || !(pkm is PK8 pk8)) { await ReplyAsync(msg).ConfigureAwait(false); return; } pk8.ResetPartyStats(); var code = Info.GetRandomTradeCode(); await AddTradeToQueueAsync(code, Context.User.Username, pk8, sudo).ConfigureAwait(false); }
public static void RestoreLogging(DiscordSocketClient discord) { var cfg = SysCordInstance.Settings; var channels = ReusableActions.GetListFromString(cfg.LoggingChannels); foreach (var ch in channels) { if (!ulong.TryParse(ch, out var cid)) { continue; } var c = (ISocketMessageChannel)discord.GetChannel(cid); AddLogChannel(c, cid); } LogUtil.LogInfo("Added logging to Discord channel(s) on Bot startup.", "Discord"); }
public async Task AddEchoAsync() { var c = Context.Channel; var cid = c.Id; if (Channels.TryGetValue(cid, out _)) { await ReplyAsync("Already start notifying here.").ConfigureAwait(false); return; } AddEchoChannel(c, cid); // Add to discord global loggers (saves on program close) var loggers = ReusableActions.GetListFromString(SysCordInstance.Settings.EchoChannels); loggers.Add(cid.ToString()); SysCordInstance.Settings.EchoChannels = string.Join(", ", new HashSet <string>(loggers)); await ReplyAsync("Added Echo output to this channel!").ConfigureAwait(false); }
public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content) { const int gen = 8; content = ReusableActions.StripCodeBlock(content); var set = new ShowdownSet(content); var template = AutoLegalityWrapper.GetTemplate(set); if (set.InvalidLines.Count != 0) { var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}"; await ReplyAsync(msg).ConfigureAwait(false); return; } var sav = AutoLegalityWrapper.GetTrainerInfo(gen); var pkm = sav.GetLegal(template, out var result); if (Info.Hub.Config.Trade.DittoTrade && pkm.Species == 132) { TradeExtensions.DittoTrade(pkm); } if (Info.Hub.Config.Trade.EggTrade && pkm.Nickname == "Egg") { TradeExtensions.EggTrade((PK8)pkm); } var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; pkm = PKMConverter.ConvertToType(pkm, typeof(PK8), out _) ?? pkm; if (Info.Hub.Config.Trade.Memes && await TrollAsync(pkm is not PK8 || !la.Valid, template).ConfigureAwait(false)) { return; }
public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content) { const int gen = 8; content = ReusableActions.StripCodeBlock(content); var set = new ShowdownSet(content); var template = AutoLegalityWrapper.GetTemplate(set); if (set.InvalidLines.Count != 0) { var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}"; await ReplyAsync(msg).ConfigureAwait(false); return; } var sav = AutoLegalityWrapper.GetTrainerInfo(gen); var pkm = sav.GetLegal(template, out var result); var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; pkm = PKMConverter.ConvertToType(pkm, typeof(PK8), out _) ?? pkm; if (pkm is not PK8 || !la.Valid) { var reason = result == "Timeout" ? "That set took too long to generate." : "I wasn't able to create something from that."; var imsg = $"Oops! {reason} Here's my best attempt for that {spec}!"; await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false); return; } pkm.ResetPartyStats(); var sig = Context.User.GetFavor(); await AddTradeToQueueAsync(code, Context.User.Username, (PK8)pkm, sig, Context.User).ConfigureAwait(false); }
public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content) { content = ReusableActions.StripCodeBlock(content); var set = new ShowdownSet(content); var template = AutoLegalityWrapper.GetTemplate(set); if (set.InvalidLines.Count != 0) { var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}"; await ReplyAsync(msg).ConfigureAwait(false); return; } try { var sav = AutoLegalityWrapper.GetTrainerInfo <T>(); var pkm = sav.GetLegal(template, out var result); if (pkm.Species == 132) { TradeExtensions <T> .DittoTrade(pkm); } if (pkm.Nickname.ToLower() == "egg" && Breeding.CanHatchAsEgg(pkm.Species)) { TradeExtensions <T> .EggTrade(pkm); } var la = new LegalityAnalysis(pkm); var spec = GameInfo.Strings.Species[template.Species]; pkm = EntityConverter.ConvertToType(pkm, typeof(T), out _) ?? pkm; bool memes = Info.Hub.Config.Trade.Memes && await TradeAdditionsModule <T> .TrollAsync(Context, pkm is not T || !la.Valid, pkm).ConfigureAwait(false); if (memes) { return; } if (pkm is not T pk || !la.Valid) { var reason = result == "Timeout" ? $"That {spec} set took too long to generate." : $"I wasn't able to create a {spec} from that set."; var imsg = $"Oops! {reason}"; if (result == "Failed") { imsg += $"\n{AutoLegalityWrapper.GetLegalizationHint(template, sav, pkm)}"; } await ReplyAsync(imsg).ConfigureAwait(false); return; } pk.ResetPartyStats(); var sig = Context.User.GetFavor(); await AddTradeToQueueAsync(code, Context.User.Username, pk, sig, Context.User).ConfigureAwait(false); } catch (Exception ex) { LogUtil.LogSafe(ex, nameof(TradeModule <T>)); var msg = $"Oops! An unexpected problem happened with this Showdown Set:\n```{string.Join("\n", set.GetSetLines())}```"; await ReplyAsync(msg).ConfigureAwait(false); } }
public static async Task ReplyWithLegalizedSetAsync(this ISocketMessageChannel channel, IAttachment att) { var download = await NetUtil.DownloadPKMAsync(att).ConfigureAwait(false); if (!download.Success) { await channel.SendMessageAsync(download.ErrorMessage).ConfigureAwait(false); return; } var pkm = download.Data !; if (new LegalityAnalysis(pkm).Valid) { await channel.SendMessageAsync($"{download.SanitizedFileName}: Already legal.").ConfigureAwait(false); return; } var legal = pkm.LegalizePokemon(); if (!new LegalityAnalysis(legal).Valid) { await channel.SendMessageAsync($"{download.SanitizedFileName}: Unable to legalize.").ConfigureAwait(false); return; } legal.RefreshChecksum(); var msg = $"Here's your legalized PKM for {download.SanitizedFileName}!\n{ReusableActions.GetFormattedShowdownText(legal)}"; await channel.SendPKMAsync(legal, msg).ConfigureAwait(false); }
public void TradeFinished(PokeRoutineExecutor routine, PokeTradeDetail <T> info, T result) { OnFinish?.Invoke(routine); var tradedToUser = Data.Species; string message; var hub = new PokeTradeHub <PK8>(new PokeTradeHubConfig()); var qInfo = new TradeQueueInfo <PK8>(hub); if (qInfo.Count != 0) { string gameText = $"{SysCordInstance.Settings.BotGameStatus.Replace("{0}", $"Completed Trade #{info.ID}")}"; Context.Client.SetGameAsync(gameText).ConfigureAwait(false); } else { string gameText = $"{SysCordInstance.Settings.BotGameStatus.Replace("{0}", $"Queue is Empty")}"; Context.Client.SetGameAsync(gameText).ConfigureAwait(false); } if (Data.IsEgg && info.Type == PokeTradeType.EggRoll) { message = tradedToUser != 0 ? $"Trade finished. Enjoy your Mysterious egg!" : "Trade finished!"; } if (Data.IsEgg && info.Type == PokeTradeType.LanRoll) { message = tradedToUser != 0 ? $"Trade finished. Enjoy your Really Illegal Egg!" : "Trade finished!"; } else { message = tradedToUser != 0 ? $"Trade finished. Enjoy your {(Species)tradedToUser}!" : "Trade finished!"; } Trader.SendMessageAsync(message).ConfigureAwait(false); if (result.Species != 0 && Hub.Config.Discord.ReturnPK8s) { Trader.SendPKMAsync(result, $"Here is what you traded me!{(info.Type != PokeTradeType.LanTrade && info.Type != PokeTradeType.LanRoll /* Don't want people thinking Showdown works on LAN */? $"\n{ReusableActions.GetFormattedShowdownText(result)}" : "")}").ConfigureAwait(false); } }