private async Task LegalityCheck(IAttachment att, bool verbose)
        {
            var download = await NetUtil.DownloadPKMAsync(att).ConfigureAwait(false);

            if (!download.Success)
            {
                await ReplyAsync(download.ErrorMessage).ConfigureAwait(false);

                return;
            }

            var pkm     = download.Data !;
            var la      = new LegalityAnalysis(pkm);
            var builder = new EmbedBuilder
            {
                Color       = la.Valid ? Color.Green : Color.Red,
                Description = $"Legality Report for {download.SanitizedFileName}:"
            };

            builder.AddField(x =>
            {
                x.Name     = la.Valid ? "Valid" : "Invalid";
                x.Value    = la.Report(verbose);
                x.IsInline = false;
            });

            await ReplyAsync("Here's the legality report!", false, builder.Build()).ConfigureAwait(false);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        public static async Task RepostPKMAsShowdownAsync(this ISocketMessageChannel channel, IAttachment att)
        {
            if (!PKX.IsPKM(att.Size))
            {
                return;
            }
            var result = await NetUtil.DownloadPKMAsync(att).ConfigureAwait(false);

            if (!result.Success)
            {
                return;
            }

            var pkm = result.Data !;
            await channel.SendPKMAsShowdownSetAsync(pkm).ConfigureAwait(false);
        }
        public async Task TradeAsync([Summary("Trade Code")] int code, [Remainder][Summary("Trainer Name to trade to.")] string trainerName)
        {
            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;
            }

            if ((uint)code > MaxTradeCode)
            {
                await ReplyAsync("Trade code should be 0000-9999!").ConfigureAwait(false);

                return;
            }

            var attachment = Context.Message.Attachments.FirstOrDefault();

            if (attachment == default)
            {
                await ReplyAsync("No attachment provided!").ConfigureAwait(false);

                return;
            }

            var att = await NetUtil.DownloadPKMAsync(attachment).ConfigureAwait(false);

            if (!att.Success || !(att.Data is PK8 pk8))
            {
                await ReplyAsync("No PK8 attachment provided!").ConfigureAwait(false);

                return;
            }

            await AddTradeToQueueAsync(code, trainerName, pk8, sudo).ConfigureAwait(false);
        }
        private async Task TradeAsyncAttach(int code, RequestSignificance sig, SocketUser usr)
        {
            var attachment = Context.Message.Attachments.FirstOrDefault();

            if (attachment == default)
            {
                await ReplyAsync("No attachment provided!").ConfigureAwait(false);

                return;
            }

            var att = await NetUtil.DownloadPKMAsync(attachment).ConfigureAwait(false);

            if (!att.Success || !(att.Data is PK8 pk8))
            {
                await ReplyAsync("No PK8 attachment provided!").ConfigureAwait(false);

                return;
            }

            await AddTradeToQueueAsync(code, usr.Username, pk8, sig, usr).ConfigureAwait(false);
        }
        public async Task TradeAsyncAttach([Summary("Trade Code")] int code)
        {
            var sudo = Context.User.GetIsSudo();

            var attachment = Context.Message.Attachments.FirstOrDefault();

            if (attachment == default)
            {
                await ReplyAsync("No attachment provided!").ConfigureAwait(false);

                return;
            }

            var att = await NetUtil.DownloadPKMAsync(attachment).ConfigureAwait(false);

            if (!att.Success || !(att.Data is PK8 pk8))
            {
                await ReplyAsync("No PK8 attachment provided!").ConfigureAwait(false);

                return;
            }

            await AddTradeToQueueAsync(code, Context.User.Username, pk8, sudo).ConfigureAwait(false);
        }
Exemple #7
0
        private async Task TradeAsyncAttach(int code, RequestSignificance sig, SocketUser usr)
        {
            var attachment = Context.Message.Attachments.FirstOrDefault();

            if (attachment == default)
            {
                await ReplyAsync("No attachment provided!").ConfigureAwait(false);

                return;
            }

            var att = await NetUtil.DownloadPKMAsync(attachment).ConfigureAwait(false);

            var pk8 = GetRequest(att);

            if (pk8 == null)
            {
                await ReplyAsync("Attachment provided is not compatible with this module!").ConfigureAwait(false);

                return;
            }

            await AddTradeToQueueAsync(code, usr.Username, pk8, sig, usr).ConfigureAwait(false);
        }