// Helper functions for commands public static bool AddToWaitingList(string setstring, string display, string username, bool sub, out string msg) { if (!TwitchBot.Info.GetCanQueue()) { msg = "Sorry, I am not currently accepting queue requests!"; return(false); } var set = ShowdownUtil.ConvertToShowdown(setstring); if (set == null) { msg = $"Skipping trade, @{username}: Empty nickname provided for the species."; return(false); } var template = AutoLegalityWrapper.GetTemplate(set); if (template.Species < 1) { msg = $"Skipping trade, @{username}: Please read what you are supposed to type as the command argument."; return(false); } if (set.InvalidLines.Count != 0) { msg = $"Skipping trade, @{username}: Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}"; return(false); } var sav = AutoLegalityWrapper.GetTrainerInfo(PKX.Generation); PKM pkm = sav.GetLegal(template, out var result); if (!pkm.CanBeTraded()) { msg = $"Skipping trade, @{username}: Provided Pokémon content is blocked from trading!"; return(false); } var valid = new LegalityAnalysis(pkm).Valid; if (valid && pkm is PK8 pk8) { var tq = new TwitchQueue(pk8, new PokeTradeTrainerInfo(display), username, sub); TwitchBot.QueuePool.RemoveAll(z => z.UserName == username); // remove old requests if any TwitchBot.QueuePool.Add(tq); msg = $"@{username} - added to the waiting list. Please whisper your trade code to me! Your request from the waiting list will be removed if you are too slow!"; return(true); } var reason = result == "Timeout" ? "Set took too long to generate." : "Unable to legalize the Pokémon."; msg = $"Skipping trade, @{username}: {reason}"; return(false); }
public static bool AddToWaitingList(PKM pkm, string username, ulong mUserId, out string msg) { if (!MiraiQQBot <T> .Info.GetCanQueue()) { msg = "Sorry, I am not currently accepting queue requests!"; return(false); } try { if (!pkm.CanBeTraded()) { msg = $"Skipping trade, @{username}: Provided Pokemon content is blocked from trading!"; return(false); } if (pkm is T pk) { var valid = new LegalityAnalysis(pkm).Valid; if (valid) { var tq = new MiraiQQQueue <T>(pk, new PokeTradeTrainerInfo(username, mUserId), mUserId); MiraiQQBot <T> .QueuePool.RemoveAll(z => z.QQ == mUserId); // remove old requests if any MiraiQQBot <T> .QueuePool.Add(tq); msg = $"@{username} - added to the waiting list. Your request from the waiting list will be removed if you are too slow!"; return(true); } } var reason = "Unable to legalize the Pokemon."; msg = $"Skipping trade, @{username}: {reason}"; } #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(MiraiQQCommandsHelper <T>)); msg = $"Skipping trade, @{username}: An unexpected problem occurred."; } return(false); }
// Helper functions for commands public static bool AddToWaitingList(string setstring, string display, string username, out string msg) { if (!TwitchBot.Info.GetCanQueue()) { msg = "Sorry, I am not currently accepting queue requests!"; return(false); } ShowdownSet set = TwitchShowdownUtil.ConvertToShowdown(setstring); if (set.Species < 1) { msg = $"Skipping trade, @{username}: Please read what you are supposed to type as the command argument."; return(false); } if (set.InvalidLines.Count != 0) { msg = $"Skipping trade, @{username}: Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}"; return(false); } var sav = AutoLegalityWrapper.GetTrainerInfo(PKX.Generation); PKM pkm = sav.GetLegal(set, out _); if (!pkm.CanBeTraded()) { msg = $"Skipping trade, @{username}: Provided Pokémon content is blocked from trading!"; return(false); } var valid = new LegalityAnalysis(pkm).Valid; if (valid && pkm is PK8 pk8) { var tq = new TwitchQueue(pk8, new PokeTradeTrainerInfo(display), username); TwitchBot.QueuePool.Add(tq); msg = $"@{username} - added to the waiting list. Please whisper to me your trade code! Your request from the waiting list will be removed if you are too slow!"; return(true); } msg = $"Skipping trade, @{username}: Unable to legalize the Pokémon."; return(false); }
// Helper functions for commands public static bool AddToWaitingList(string setstring, string display, string username, ulong mUserId, bool sub, out string msg) { if (!TwitchBot <T> .Info.GetCanQueue()) { msg = "Sorry, I am not currently accepting queue requests!"; return(false); } var set = ShowdownUtil.ConvertToShowdown(setstring); if (set == null) { msg = $"Skipping trade, @{username}: Empty nickname provided for the species."; return(false); } var template = AutoLegalityWrapper.GetTemplate(set); if (template.Species < 1) { msg = $"Skipping trade, @{username}: Please read what you are supposed to type as the command argument."; return(false); } if (set.InvalidLines.Count != 0) { msg = $"Skipping trade, @{username}: Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}"; return(false); } try { var sav = AutoLegalityWrapper.GetTrainerInfo <T>(); PKM pkm = sav.GetLegal(template, out var result); var nickname = pkm.Nickname.ToLower(); if (nickname == "egg" && Breeding.CanHatchAsEgg(pkm.Species)) { TradeExtensions <T> .EggTrade(pkm); } if (pkm.Species == 132 && (nickname.Contains("atk") || nickname.Contains("spa") || nickname.Contains("spe") || nickname.Contains("6iv"))) { TradeExtensions <T> .DittoTrade(pkm); } if (!pkm.CanBeTraded()) { msg = $"Skipping trade, @{username}: Provided Pokémon content is blocked from trading!"; return(false); } if (pkm is T pk) { var valid = new LegalityAnalysis(pkm).Valid; if (valid) { var tq = new TwitchQueue <T>(pk, new PokeTradeTrainerInfo(display, mUserId), username, sub); TwitchBot <T> .QueuePool.RemoveAll(z => z.UserName == username); // remove old requests if any TwitchBot <T> .QueuePool.Add(tq); msg = $"@{username} - added to the waiting list. Please whisper your trade code to me! Your request from the waiting list will be removed if you are too slow!"; return(true); } } var reason = result == "Timeout" ? "Set took too long to generate." : "Unable to legalize the Pokémon."; msg = $"Skipping trade, @{username}: {reason}"; } #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(TwitchCommandsHelper <T>)); msg = $"Skipping trade, @{username}: An unexpected problem occurred."; } return(false); }
public static bool IsLegal(this PKM pkm) => new LegalityAnalysis(pkm).Valid&& pkm.CanBeTraded();