Exemple #1
0
        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);
        }
Exemple #3
0
 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 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);
 }
Exemple #5
0
        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);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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 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);
        }
Exemple #10
0
        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;
            }
Exemple #11
0
        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);
        }
Exemple #12
0
        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);
            }
        }