Exemplo n.º 1
0
        /// <summary>
        /// Check whether the showdown text is supposed to be loaded via a text file. If so, set the clipboard to its contents.
        /// </summary>
        /// <returns>output boolean that tells if the data provided is valid or not</returns>
        private static string?GetTextShowdownData()
        {
            bool skipClipboardCheck = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;

            if (!skipClipboardCheck && Clipboard.ContainsText())
            {
                var txt = Clipboard.GetText();
                if (ShowdownUtil.IsTextShowdownData(txt))
                {
                    return(txt);
                }
            }

            if (!WinFormsUtil.OpenSAVPKMDialog(new[] { "txt" }, out var path))
            {
                WinFormsUtil.Alert("No data provided.");
                return(null);
            }

            var text = File.ReadAllText(path).TrimEnd();

            if (ShowdownUtil.IsTextShowdownData(text))
            {
                return(text);
            }

            WinFormsUtil.Alert("Text file with invalid data provided. Please provide a text file with proper Showdown data");
            return(null);
        }
Exemplo n.º 2
0
        private static void VerifyContents(this TeamPasteInfo tpi, string name, int[] speciesPresent)
        {
            tpi.Valid.Should().BeTrue("Data should exist for this paste");
            tpi.Title.Should().Be(name, "Data should have a title present");

            var team    = ShowdownUtil.ShowdownSets(tpi.Sets);
            var species = team.ConvertAll(s => s.Species);
            var hasAll  = speciesPresent.All(species.Contains);

            hasAll.Should().BeTrue("Specific species are expected");
        }
Exemplo n.º 3
0
        // 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);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Imports <see cref="ShowdownSet"/> list(s) originating from a concatenated list.
        /// </summary>
        /// <param name="source">Text containing <see cref="ShowdownSet"/> data</param>
        public static void Import(string source)
        {
            if (ShowdownUtil.IsTeamBackup(source))
            {
                var teams = ShowdownTeamSet.GetTeams(source).ToArray();
                var names = teams.Select(z => z.Summary);
                WinFormsUtil.Alert("Generating the following teams:", string.Join(Environment.NewLine, names));
                Import(teams.SelectMany(z => z.Team).ToList());
                return;
            }

            var sets = ShowdownUtil.ShowdownSets(source);

            Import(sets);
        }
Exemplo n.º 5
0
        // 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);
        }
Exemplo n.º 6
0
        public static bool AddToWaitingList(string setstring, string username, ulong mUserId, out string msg)
        {
            if (!MiraiQQBot <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>();
                var pkm = sav.GetLegal(template, out var result);

                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 = result == "Timeout" ? "Set took too long to generate." : "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);
        }