Example #1
0
        public static EmbedBuilder BuildMediaEmbed(
            string title,
            IEnumerable <string> media,
            string url               = null,
            string caption           = null,
            Thumbnail thumbnail      = null,
            string footer            = null,
            string captionFooter     = null,
            DateTimeOffset?timestamp = null,
            string iconUrl           = null,
            int maxCaptionLength     = 400,
            int maxCaptionLines      = 8)
        {
            var author = new EmbedAuthorBuilder()
                         .WithName(title);

            if (!string.IsNullOrEmpty(url))
            {
                author.WithUrl(url);
            }

            if (!string.IsNullOrEmpty(iconUrl))
            {
                author.WithIconUrl(iconUrl);
            }

            var embed = new EmbedBuilder()
                        .WithAuthor(author)
                        .WithFooter(footer);

            if (timestamp != null)
            {
                embed.WithTimestamp(timestamp.Value);
            }

            var       buttons          = "";
            const int minCaptionSpace  = 100;
            var       maxButtonsLength = EmbedBuilder.MaxDescriptionLength - minCaptionSpace - (captionFooter?.Length ?? 0);

            if (media.Skip(1).Any())
            {
                // Add only as many buttons as will fit
                var builder = new StringBuilder();
                foreach (var button in media.Take(Math.Min(EmbedMediaCutoff, 9)).Select((y, i) => $"[{(i + 1).ToKeycapEmoji()}]({y})"))
                {
                    var item = button + " ";
                    if (builder.Length + item.Length > maxButtonsLength)
                    {
                        break;
                    }

                    builder.Append(item);
                }

                buttons = builder.ToString();
            }
            else if (thumbnail?.IsVideo ?? false)
            {
                buttons = $"[▶️ Play]({thumbnail.VideoUrl})";
            }

            var       description      = new StringBuilder();
            const int lineBreaksBuffer = 5;
            var       captionSpace     = EmbedBuilder.MaxDescriptionLength - buttons.Length - (captionFooter?.Length ?? 0) - lineBreaksBuffer;

            if (!string.IsNullOrEmpty(caption))
            {
                description.Append(caption.Truncate(Math.Min(maxCaptionLength, captionSpace)).TruncateLines(maxCaptionLines, trim: true) + "\n\n");
            }

            if (!string.IsNullOrEmpty(captionFooter))
            {
                description.AppendLine(captionFooter);
            }

            description.Append(buttons);

            embed.WithDescription(description.ToString());

            if (thumbnail != null)
            {
                embed.WithImageUrl(thumbnail.Url);
            }

            return(embed);
        }
Example #2
0
        public async Task UserAbout(IUser user = null)
        {
            var userSpecified = user as SocketGuildUser ?? Context.User as SocketGuildUser;

            if (userSpecified == null)
            {
                await ReplyAsync("User not found, please try again.");

                return;
            }

            EmbedAuthorBuilder eab = new EmbedAuthorBuilder();

            if (!String.IsNullOrEmpty(userSpecified.Nickname))
            {
                eab.WithName("About " + userSpecified.Nickname);
            }
            else
            {
                eab.WithName("About " + userSpecified.Username);
            }

            eab.WithUrl(Configuration.Load().PROFILE_URL_ID_TAGGED + userSpecified.Id);

            EmbedFooterBuilder efb = new EmbedFooterBuilder();

            if (userSpecified.IsTeamMember())
            {
                eab.WithIconUrl(userSpecified.GetEmbedAuthorBuilderIconUrl());
            }
            if (!String.IsNullOrEmpty(userSpecified.GetFooterText()))
            {
                efb.WithText(userSpecified.GetFooterText());
                efb.WithIconUrl(userSpecified.GetEmbedFooterBuilderIconUrl());
            }

            EmbedBuilder eb = new EmbedBuilder()
                              .WithAuthor(eab)
                              .WithFooter(efb)
                              .WithThumbnailUrl(userSpecified.GetAvatarUrl())
                              .WithDescription(User.Load(userSpecified.Id).About)
                              .WithColor(userSpecified.GetCustomRGB());

            if (!String.IsNullOrEmpty(userSpecified.GetName()))
            {
                eb.AddField("Name", userSpecified.GetName(), true);
            }

            if (!String.IsNullOrEmpty(userSpecified.GetGender()))
            {
                eb.AddField("Gender", userSpecified.GetGender(), true);
            }

            if (!String.IsNullOrEmpty(userSpecified.GetPronouns()))
            {
                eb.AddField("Pronouns", userSpecified.GetPronouns(), true);
            }

            eb.AddField("Level", userSpecified.GetLevel(), true);
            eb.AddField("EXP", userSpecified.GetEXP() + " (" + (Math.Round(userSpecified.EXPToLevelUp()) - userSpecified.GetEXP()) + " EXP to level up)", true);
            eb.AddField("Account Created", userSpecified.UserCreateDate(), true);
            eb.AddField("Joined Guild", userSpecified.GuildJoinDate(), true);

            if (!String.IsNullOrEmpty(userSpecified.GetMinecraftUsername()))
            {
                eb.AddField("Minecraft Username", userSpecified.GetMinecraftUsername(), true);
            }

            if (!String.IsNullOrEmpty(userSpecified.GetWebsiteUrl()))
            {
                eb.AddField(StringConfiguration.Load().DefaultWebsiteName,
                            "[" + (userSpecified.GetWebsiteName() ?? StringConfiguration.Load().DefaultWebsiteName) + "](" +
                            userSpecified.GetWebsiteUrl() + ")", true);
            }

            if (!String.IsNullOrEmpty(userSpecified.GetInstagramUsername()))
            {
                eb.AddField("Instagram",
                            "[" + userSpecified.GetInstagramUsername() + "](https://www.instagram.com/" +
                            userSpecified.GetInstagramUsername() + "/)", true);
            }

            if (!String.IsNullOrEmpty(userSpecified.GetSnapchatUsername()))
            {
                eb.AddField("Snapchat",
                            "[" + userSpecified.GetSnapchatUsername() + "](https://www.snapchat.com/add/" +
                            userSpecified.GetSnapchatUsername() + "/)", true);
            }

            if (!String.IsNullOrEmpty(userSpecified.GetGitHubUsername()))
            {
                eb.AddField("GitHub",
                            "[" + userSpecified.GetGitHubUsername() + "](https://github.com/" +
                            userSpecified.GetGitHubUsername() + "/)", true);
            }

            if (!String.IsNullOrEmpty(userSpecified.GetPokemonGoFriendCode()))
            {
                eb.AddField("Pokémon Go Friend Code",
                            "[" + userSpecified.GetPokemonGoFriendCode() +
                            "](https://chart.googleapis.com/chart?chs=300x300&cht=qr&" +
                            userSpecified.GetPokemonGoFriendCode().Replace(" ", "") + "&choe=UTF-8)", true);
            }

            if (!String.IsNullOrEmpty(userSpecified.GetCustomPrefix()))
            {
                eb.AddField("Custom Prefix", userSpecified.GetCustomPrefix(), true);
            }

            eb.AddField("Profile", "[Online Profile](" + Configuration.Load().PROFILE_URL_ID_TAGGED + userSpecified.Id + ")", true);

            await ReplyAsync("", false, eb.Build());
        }
Example #3
0
        public async Task Sihirdar([Remainder] string isim)
        {
            try
            {
                if (l == 1)
                {
                    await Context.Channel.SendMessageAsync(isim + " Aranıyor...");
                }
                else
                {
                    await Context.Channel.SendMessageAsync("Searching for " + isim + "...");
                }
                kills   = new string[5];
                deaths  = new string[5];
                assists = new string[5];
                result  = new string[5];
                isim.Replace(" ", "%20");


                // 1
                riot.summonerbul(isim);
                riot.macbilgi(riot.summonerid, riot.mac1id);
                kills[0]   = riot.kill;
                deaths[0]  = riot.death;
                assists[0] = riot.assist;
                result[0]  = riot.macsonuc;
                // 2
                riot.summonerbul(isim);
                riot.macbilgi(riot.summonerid, riot.mac2id);
                kills[1]   = riot.kill;
                deaths[1]  = riot.death;
                assists[1] = riot.assist;
                result[1]  = riot.macsonuc;
                // 3
                riot.summonerbul(isim);
                riot.macbilgi(riot.summonerid, riot.mac3id);
                kills[2]   = riot.kill;
                deaths[2]  = riot.death;
                assists[2] = riot.assist;
                result[2]  = riot.macsonuc;
                // 4
                riot.summonerbul(isim);
                riot.macbilgi(riot.summonerid, riot.mac4id);
                kills[3]   = riot.kill;
                deaths[3]  = riot.death;
                assists[3] = riot.assist;
                result[3]  = riot.macsonuc;
                // 5
                riot.summonerbul(isim);
                riot.macbilgi(riot.summonerid, riot.mac5id);
                kills[4]   = riot.kill;
                deaths[4]  = riot.death;
                assists[4] = riot.assist;
                result[4]  = riot.macsonuc;

                var eb = new EmbedBuilder()
                {
                    Title = "", Description = "**Maçlar**", Color = Color.Blue
                };
                if (l == 0)
                {
                    eb = new EmbedBuilder()
                    {
                        Title = "", Description = "**Matches**", Color = Color.Blue
                    }
                }
                ;
                string newname = riot.summonername;
                newname.First().ToString().ToUpper();
                EmbedAuthorBuilder MyAuthorBuilder = new EmbedAuthorBuilder();
                if (l == 1)
                {
                    MyAuthorBuilder.WithName(newname + " - Tüm profil için tıkla");
                }
                else
                {
                    MyAuthorBuilder.WithName(newname + " - Click for complete profile");
                }
                MyAuthorBuilder.WithIconUrl("https://i.hizliresim.com/JlvA4B.jpg");
                eb.WithAuthor(MyAuthorBuilder);
                for (int i = 0; i < 5; i++)
                {
                    if (result[i] == "Zafer")
                    {
                        if (l == 1)
                        {
                            result[i] = ":white_check_mark: Zafer";
                        }
                        else
                        {
                            result[i] = ":white_check_mark: Win";
                        }
                    }
                    if (result[i] == "Bozgun")
                    {
                        if (l == 1)
                        {
                            result[i] = ":no_entry_sign: Bozgun";
                        }
                        else
                        {
                            result[i] = ":no_entry_sign: Loss";
                        }
                    }
                }
                EmbedFieldBuilder MyEmbedField = new EmbedFieldBuilder();
                MyEmbedField.WithIsInline(true);
                MyEmbedField.WithName(result[0]);
                MyEmbedField.WithValue(kills[0] + "/" + deaths[0] + "/" + assists[0]);
                eb.AddField(MyEmbedField);

                EmbedFieldBuilder MyEmbedField2 = new EmbedFieldBuilder();
                MyEmbedField2.WithIsInline(true);
                MyEmbedField2.WithName(result[1]);
                MyEmbedField2.WithValue(kills[1] + "/" + deaths[1] + "/" + assists[1]);
                eb.AddField(MyEmbedField2);

                EmbedFieldBuilder MyEmbedField3 = new EmbedFieldBuilder();
                MyEmbedField3.WithIsInline(true);
                MyEmbedField3.WithName(result[2]);
                MyEmbedField3.WithValue(kills[2] + "/" + deaths[2] + "/" + assists[2]);
                eb.AddField(MyEmbedField3);

                EmbedFieldBuilder MyEmbedField4 = new EmbedFieldBuilder();
                MyEmbedField4.WithIsInline(true);
                MyEmbedField4.WithName(result[3]);
                MyEmbedField4.WithValue(kills[3] + "/" + deaths[3] + "/" + assists[3]);
                eb.AddField(MyEmbedField4);

                EmbedFieldBuilder MyEmbedField5 = new EmbedFieldBuilder();
                MyEmbedField5.WithIsInline(true);
                MyEmbedField5.WithName(result[4]);
                MyEmbedField5.WithValue(kills[4] + "/" + deaths[4] + "/" + assists[4]);
                eb.AddField(MyEmbedField5);

                EmbedFieldBuilder MyEmbedField6 = new EmbedFieldBuilder();
                MyEmbedField6.WithIsInline(true);
                MyEmbedField6.WithName("...");
                MyEmbedField6.WithValue("...");
                eb.AddField(MyEmbedField6);

                eb.WithUrl("http://www.lolking.net/summoner/tr/" + riot.summonerid2);

                await Context.Channel.SendMessageAsync("", false, eb);
            }
            catch (Exception e)
            {
                if (l == 1)
                {
                    await Context.Channel.SendMessageAsync("```İşlemi gerçekleştirirken bir hata meydana geldi.\n" + e.Message + "\nAPI Anahtarını güncelleyin. \ndeveloper.riotgames.com```");
                }
                else
                {
                    await Context.Channel.SendMessageAsync("```Error: \n" + e.Message + "" + "\nUpdate the API key. \ndeveloper.riotgames.com```");
                }
            }
        }
Example #4
0
        private async Task Update()
        {
            if (this.Message == null)
            {
                return;
            }
            string display = this.DisplayCallback?.Invoke(this.Data[this.CurrentIndex]);

            await this.Message.ModifyAsync(prop =>
            {
                if (this.Embed != null)
                {
                    Embed oldEmbed       = this.Embed;
                    EmbedBuilder builder = new EmbedBuilder();
                    builder
                    .WithLimitedTitle(oldEmbed.Title)
                    .WithLimitedDescription(display);

                    if (oldEmbed.Color.HasValue)
                    {
                        builder.WithColor(oldEmbed.Color.Value);
                    }

                    if (oldEmbed.Timestamp.HasValue)
                    {
                        builder.WithTimestamp(oldEmbed.Timestamp.Value);
                    }

                    if (oldEmbed.Author.HasValue)
                    {
                        EmbedAuthor oldAuthor            = oldEmbed.Author.Value;
                        EmbedAuthorBuilder authorBuilder = new EmbedAuthorBuilder();
                        authorBuilder
                        .WithIconUrl(oldAuthor.IconUrl)
                        .WithName(oldAuthor.Name)
                        .WithUrl(oldAuthor.Url);
                        builder.WithAuthor(authorBuilder);
                    }

                    if (oldEmbed.Footer.HasValue)
                    {
                        EmbedFooter oldFooter            = oldEmbed.Footer.Value;
                        EmbedFooterBuilder footerBuilder = new EmbedFooterBuilder();
                        footerBuilder
                        .WithText(oldFooter.Text)
                        .WithIconUrl(oldFooter.IconUrl);
                        builder.WithFooter(footerBuilder);
                    }

                    this.DisplayEmbedCallback?.Invoke(this.Data[this.CurrentIndex], builder);

                    this.Embed = builder.Build();
                    prop.Embed = this.Embed;
                }
                else
                {
                    prop.Content = display;
                }
            });

            this.Refresh();
        }