Beispiel #1
0
        public async Task ExecuteAsync(DiscordRestClient rest, PartnerSenderArguments senderArguments)
        {
            if (senderArguments.DevelopmentStressTest)
            {
                await ExecuteStressTestMessage(rest);

                return;
            }

            bool vanity       = this.Match.VanityInvite is not null && this.Match.DonorRank >= DonorService.VANITY_LIMIT;
            bool attachEmbeds = this.Match.DonorRank >= DonorService.EMBED_LIMIT;

            DiscordWebhookBuilder?hook = new DiscordWebhookBuilder()
                                         .WithContent($"{this.Match.Message}\n\n" +
                                                      $"https://discord.gg/" +
                                                      $"{(vanity ? this.Match.VanityInvite : this.Match.Invite)}")
                                         .WithUsername($"{this.Match.GuildName} | Partner Bot");

            if (attachEmbeds)
            {
                if (this.Match.DonorRank >= DonorService.HIGHEST_RANK)
                {
                    hook.AddEmbeds(this.Match.MessageEmbeds);
                }
                else if (this.Match.MessageEmbeds.Count > 0)
                {
                    hook.AddEmbed(this.Match.MessageEmbeds[0]);
                }
            }

            hook.AddEmbed(new DiscordEmbedBuilder()
                          .WithColor(DiscordColor.Gray)
                          .WithTitle("Partner Bot Advertisment")
                          .WithDescription($"**ID:** {this.Match.GuildId}")
                          .WithFooter($"pb-advert{(this.Match.NSFW ? " | NSFW" : "")}",
                                      rest.CurrentApplication.GetAvatarUrl(ImageFormat.Png))
                          .WithImageUrl(this.Match.Banner));

            if (!string.IsNullOrWhiteSpace(this.Match.GuildIcon))
            {
                hook.WithAvatarUrl(this.Match.GuildIcon);
            }

            await rest.ExecuteWebhookAsync(this.WebhookId, this.WebhookToken, hook);

            if (this.ExtraMessage is not null)
            {
                var eDat = new PartnerData(this, this.ExtraMessage);

                await eDat.ExecuteAsync(rest, senderArguments);
            }
        }
Beispiel #2
0
        private async Task <DiscordWebhookBuilder> GetInteractionEditAsync(Partner partner, bool isChanged = false,
                                                                           DiscordChannel?channel          = null, string?errorMessage = null)
        {
            var builder = new DiscordWebhookBuilder()
                          .AddEmbed(await GetRequiermentsEmbed(partner, channel));

            foreach (var item in await GetComponents(partner, isChanged))
            {
                builder.AddComponents(item);
            }

            if (errorMessage is not null)
            {
                builder.AddEmbed(ErrorBase().WithDescription(errorMessage));
            }

            return(builder);
        }
Beispiel #3
0
        public async Task Faq(InteractionContext ctx,
                              [Choice("discordinstall", "discordinstall")]
                              [Option("option", "option")]
                              string option,
                              [Option("atuser", "user to mention")] DiscordUser user = null !)
        {
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            switch (option)
            {
            case "discordinstall":
                var embed = new DiscordEmbedBuilder()
                {
                    Title       = Formatter.Underline(Formatter.Bold("Please do not run these commands as root")),
                    Description = "How to install discord using xbps-src \n" + Formatter.BlockCode(@"git clone https://github.com/void-linux/void-packages
cd void-packages
./xbps-src binary-bootstrap
echo XBPS_ALLOW_RESTRICTED=yes > etc/conf
./xbps-src pkg discord
sudo xbps-install --repository=hostdir/binpkgs/nonfree discord", "bash")
                };

                var build = new DiscordWebhookBuilder();

                if (user != null)
                {
                    embed.Description += $"\n{user.Mention}";
                }
                build.AddEmbed(embed);

                await ctx.EditResponseAsync(build);

                return;

                break;

            case "":
                break;
            }
            await ctx.DeleteResponseAsync();
        }
Beispiel #4
0
        public async Task GetTLDR(InteractionContext ctx,
                                  [Option("page", "page to find")] string name,
                                  [Option("platform", "Specifies the platform to be used")]
                                  Platform platform = Platform.Linux,
                                  [Option("language", "Specifies the preferred language for the page returned")]
                                  string?language = null

                                  )
        {
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            if (!await CheckCache(ctx))
            {
                await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Cache update failed"));
            }


            name = name.ToLower();
            name = name.Replace(' ', '-');


            var index = await GetIndex();

            var page = index.Commands.FirstOrDefault(x => x.Name == name);

            //if page not found, redownload cache and try again
            if (page == null)
            {
                await CheckCache(ctx);

                index = await GetIndex();

                page = index.Commands.FirstOrDefault(x => x.Name == name);

                if (page == null)
                {
                    await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("page not found"));

                    return;
                }
            }


            var targets = page.Targets.Where(x => x.Os == platform).ToList();

            if (!targets.Any())
            {
                //fallback to common
                targets = page.Targets.Where(x => x.Os == Platform.Common).ToList();

                //fallback to random platform
                if (!targets.Any())
                {
                    targets = page.Targets.ToList();
                }
            }

            if (language != null)
            {
                var langTargets = targets.Where(x => x.Language == language)
                                  .ToList();
                if (!langTargets.Any())
                {
                    await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("page not found in chosen language"));

                    return;
                }

                targets = langTargets;
            }
            else
            {
                //default to english
                var langTargets = targets.Where(x => x.Language == "en")
                                  .ToList();

                if (langTargets.Any())
                {
                    targets = langTargets;
                }
            }

            var finalTarget = targets.FirstOrDefault();

            if (finalTarget == null)
            {
                await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("page not found"));

                return;
            }

            var lines = await GetPageFromTarget(name, finalTarget);


            var builder = new DiscordWebhookBuilder();

            var embed = new DiscordEmbedBuilder()
                        .WithTitle($"tldr page: {lines.FirstOrDefault()?.Remove(0, 2)} ({finalTarget.Os})")
                        .WithAuthor("tldr pages", "https://tldr.sh/", "https://tldr.sh/assets/img/icon.png")
                        .WithColor(new DiscordColor("#54B59A"))
                        .WithDescription(string.Join("\n", lines.Skip(1)).Replace("\n\n", "\n"))
                        .WithFooter("tldr - collaborative cheatsheets for console commands ",
                                    "https://github.githubassets.com/images/icons/emoji/unicode/1f4da.png")
                        .Build();

            builder.AddEmbed(embed);

            if (finalTarget.Os != Platform.Common && finalTarget.Os != platform)
            {
                var warningEmbed = new DiscordEmbedBuilder()
                                   .WithTitle($"Platform: {finalTarget.Os}")
                                   .WithColor(DiscordColor.Red)
                                   .Build();
                builder.AddEmbed(warningEmbed);
            }

            await ctx.EditResponseAsync(builder);
        }
Beispiel #5
0
        public async Task GetTLDR(InteractionContext ctx,
                                  [Option("page", "page to find")] string page,
                                  [Choice("linux", "linux")]
                                  [Choice("osx", "osx")]
                                  [Choice("windows", "windows")]
                                  [Choice("android", "android")]
                                  [Choice("sunos", "sunos")]
                                  [Choice("common", "common")]
                                  [Option("platform", "Specifies the platform to be used")]
                                  string platform = "linux",

                                  // [Option("language", "Specifies the preferred language for the page returned")]
                                  // string? language = null,
                                  [Option("update", "Updates the offline cache of pages")]
                                  bool update = false
                                  )
        {
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            if (update || !Directory.Exists("tldr-cache"))
            {
                await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Updating cache..."));

                try
                {
                    await UpdateCache();

                    await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Cache updated"));
                }
                catch (Exception e)
                {
                    await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Cache update failed"));

                    return;
                }
            }

            //language ??= ctx.Guild.PreferredLocale;

            page = page.ToLower();
            page = page.Replace(' ', '-');
            var path = FindPage(page, platform);

            if (path == null)
            {
                await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("page not found"));

                return;
            }

            var lines = await File.ReadAllLinesAsync(path);

            var builder = new DiscordWebhookBuilder();

            var resultPlatform = path.Split('/')[2];

            var embed = new DiscordEmbedBuilder()
                        .WithTitle($"tldr page: {lines.FirstOrDefault()?.Remove(0, 2)} ({resultPlatform})")
                        .WithAuthor("tldr pages", "https://tldr.sh/", "https://tldr.sh/assets/img/icon.png")
                        .WithColor(new DiscordColor("#54B59A"))
                        .WithDescription(string.Join("\n", lines.Skip(1)).Replace("\n\n", "\n"))
                        .WithFooter("tldr - collaborative cheatsheets for console commands ",
                                    "https://github.githubassets.com/images/icons/emoji/unicode/1f4da.png")
                        .Build();

            builder.AddEmbed(embed);

            if (resultPlatform != "common" && resultPlatform != platform)
            {
                var warningEmbed = new DiscordEmbedBuilder()
                                   .WithTitle("Platform: " + resultPlatform)
                                   .WithColor(DiscordColor.Red)
                                   .Build();
                builder.AddEmbed(warningEmbed);
            }

            await ctx.EditResponseAsync(builder);
        }