public async Task Virar_Membro(CommandContext context)
        {
            if (context.Channel.Id == BotClient.configJson.VirarMembroCanalID)
            {
                DiscordEmbedBuilder.EmbedThumbnail thumbnail = new DiscordEmbedBuilder.EmbedThumbnail();
                thumbnail.Url = context.Client.CurrentUser.AvatarUrl;

                DiscordEmbedBuilder joinEmbed = new DiscordEmbedBuilder
                {
                    Title     = $"Você gostaria de se tornar membro do servidor: \"{context.Guild.Name}\"?",
                    Thumbnail = thumbnail,
                    Color     = DiscordColor.Purple
                };

                DiscordMessage joinMessage = await context.Channel.SendMessageAsync(embed : joinEmbed).ConfigureAwait(false);

                DiscordEmoji reactionEmoji = DiscordEmoji.FromName(context.Client, BotClient.configJson.ReactionEmoji);
                await joinMessage.CreateReactionAsync(reactionEmoji).ConfigureAwait(true);

                InteractivityExtension interactivity = context.Client.GetInteractivity();

                InteractivityResult <MessageReactionAddEventArgs> reactionResult = await interactivity.WaitForReactionAsync(
                    x => x.Message == joinMessage &&
                    x.User == context.User &&
                    (x.Emoji == reactionEmoji)).ConfigureAwait(false);

                if (reactionResult.Result.Emoji == reactionEmoji)
                {
                    await context.Member.GrantRoleAsync(context.Guild.GetRole(BotClient.configJson.TagMembroId)).ConfigureAwait(false);
                }

                IReadOnlyList <DiscordMessage> channelMessages = await context.Channel.GetMessagesAsync(20).ConfigureAwait(false);

                List <DiscordMessage> messagesToDelete = new List <DiscordMessage>();
                foreach (DiscordMessage message in channelMessages)
                {
                    if (message.Id != BotClient.configJson.VirarMembroMensagemId)
                    {
                        messagesToDelete.Add(message);
                    }
                }
                await context.Channel.DeleteMessagesAsync(messagesToDelete).ConfigureAwait(false);
            }
            else
            {
                await context.Channel.SendMessageAsync($"ERR0! Este comando não pode ser usado fora do canal {context.Guild.GetChannel(BotClient.configJson.VirarMembroCanalID).Name}!").ConfigureAwait(false);
            }
        }
Exemple #2
0
        public async Task Status(CommandContext ctx)
        {
            DiscordEmoji rabbitEmoji  = DiscordEmoji.FromName(ctx.Client, ":rabbit2:");
            DiscordEmoji rabbit2Emoji = DiscordEmoji.FromName(ctx.Client, ":rabbit:");
            DiscordEmoji toolsEmoji   = DiscordEmoji.FromName(ctx.Client, ":tools:");
            DiscordEmoji tadaEmoji    = DiscordEmoji.FromName(ctx.Client, ":tada:");
            DiscordEmoji sadEmoji     = DiscordEmoji.FromName(ctx.Client, ":cry:");

            var embedThumbnail = new DiscordEmbedBuilder.EmbedThumbnail
            {
                Url = Links.STATUS_THUMBNAIL_BUN
            };
            var embedFooter = new DiscordEmbedBuilder.EmbedFooter
            {
                Text = "Brought to you with <3 by Kubi, Genghis & pals"
            };

            var embed = new DiscordEmbedBuilder
            {
                Title     = $"{rabbitEmoji} LeafBot Status {toolsEmoji}",
                ImageUrl  = Links.STATUS_BUN,
                Thumbnail = embedThumbnail,
                Footer    = embedFooter,
                Color     = DiscordColor.SpringGreen,
            };

            var     uptime   = (DateTime.Now - Stats.StartTime);
            decimal upDays   = uptime.Days;
            decimal bunYears = Math.Round((upDays / 365) * 7.5M, 6);

            embed.AddField("Version", Program.VERSION, true);
            embed.AddField("DSharp Version", ctx.Client.VersionString, true);
            embed.AddField("Ping", ctx.Client.Ping.ToString(), true);
            embed.AddField("Bunnies served", Stats.BunniesServed.ToString(), true);
            embed.AddField("Commands run", Stats.ExecutedCommands.ToString(), true);
            embed.AddField("Roles picked", Stats.RolesPicked.ToString(), true);
            embed.AddField("Command errors", Stats.CommandErrors == 0 ? $"{tadaEmoji} {Stats.CommandErrors.ToString()} {tadaEmoji}" : Stats.CommandErrors.ToString() + $" {sadEmoji}", true);
            embed.AddField("Guilds", ctx.Client.Guilds.Count.ToString(), true);
            embed.AddField("Uptime", $"{uptime.Days} days {uptime.Hours} hours {uptime.Minutes} minutes {uptime.Seconds} seconds");
            embed.AddField("Age", $"{bunYears} bunny years {rabbit2Emoji}");
            embed.AddField("Connected to", ctx.Guild.Name.ToString(), true);
            embed.AddField("Running on", Stats.PCName, true);

            // Update bunnies served stat (there is a pic of a bunny in the status in bed silly)
            Stats.BunniesServed++;

            await ctx.Channel.SendMessageAsync(embed : embed);
        }
Exemple #3
0
        public async Task Info(CommandContext ctx, [Description("users ID or mention")] DiscordMember user = null)
        {
            await Task.Delay(5);

            await ctx.Message.DeleteAsync();

            await ctx.TriggerTypingAsync();

            if (user == null)
            {
                user = ctx.Member;
            }
            string              format        = "dddd, MMM dd yyyy HH:mm:ss zzzz";
            CultureInfo         info          = new("en-GB");
            string              joinedstring  = user.JoinedAt.ToString(format, info);
            string              createdstring = user.CreationTimestamp.ToString(format, info);
            DiscordEmbedBuilder embed         = new()
            {
                Color  = new DiscordColor(0xFF6600),
                Author = new DiscordEmbedBuilder.EmbedAuthor
                {
                    Name    = user.Username,
                    IconUrl = user.AvatarUrl
                },
                Description = $"**ID**\t\t\t\t\t\t\t\t\t\t\t\t**Nickname**\n" +
                              $"{user.Id}\t\t\t{user.Nickname ?? "*none*"}\n" +
                              $"**Account created**\n" +
                              $"{createdstring}\n" +
                              $"**Join date**\n" +
                              $"{joinedstring}\n",
                Title     = "User info",
                Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail
                {
                    Url = user.AvatarUrl
                }
            };
            await ctx.RespondAsync(embed : embed);
        }
Exemple #4
0
        public async Task Records(CommandContext ctx, string level, string character, string version)
        {
            try
            {
                bool gotLvl = SRB2Enums.levelsID.TryGetValue(level.ToUpper(), out SRB2Level srb2Level);

                bool gotCatFg = SRB2Enums.fgCategoriesID.TryGetValue(character.ToLower(), out string categoryFgID);

                bool gotCat = SRB2Enums.categoriesID.TryGetValue(character.ToLower(), out string categoryID);

                bool nights = false;
                if (gotLvl)
                {
                    int mapNumber = SRB2Level.GetMapNumber(srb2Level.MapName);
                    if (mapNumber > 49 && mapNumber < 74)
                    {
                        categoryID = "xd1g1j4d";
                        gotCat     = true;
                        nights     = true;
                    }
                    else if (!gotCat)
                    {
                        categoryID = "xd1g1j4d";
                        gotCat     = true;
                    }
                }

                if (!gotCatFg)
                {
                    gotCatFg = SRB2Enums.fgCategoriesID.TryGetValue(level.ToLower(), out categoryFgID);
                }

                if (!gotLvl && gotCatFg)
                {
                    string goal;
                    if (categoryFgID == "9d8pmg3k")
                    {
                        goal = SRB2Enums.GetGoal(categoryFgID);
                    }
                    else
                    {
                        goal = SRB2Enums.GetGoal(level);
                    }
                    if (goal != "notfound")
                    {
                        bool gotVer = false;

                        string originalVer  = "";
                        string processedVer = "";
                        if (categoryFgID == "9d8pmg3k" || categoryFgID == "9d8pm0qk")
                        {
                            originalVer = string.Join(" ", character + version).ToLower();
                            gotVer      = SRB2Enums.versions.TryGetValue(originalVer, out processedVer);
                        }
                        else
                        {
                            originalVer = version;
                            gotVer      = SRB2Enums.versions.TryGetValue(originalVer, out processedVer);
                        }

                        if (!gotVer && originalVer != "")
                        {
                            throw new Exception("Wrong / Missing version");
                        }

                        Leaderboard leaderboard = FullGameLeaderboard(goal, categoryFgID, processedVer, originalVer);
                        DiscordEmbedBuilder.EmbedFooter    embedFooter  = new DiscordEmbedBuilder.EmbedFooter();
                        DiscordEmbedBuilder.EmbedThumbnail thumbnailUrl = new DiscordEmbedBuilder.EmbedThumbnail();
                        int timeSinceStarted = (DateTime.Now - Program.startedAt).Minutes;
                        embedFooter.Text = $"Last updated {timeSinceStarted} minute(s) ago";
                        Random r            = new Random();
                        int    footerImgNum = r.Next(1, 21);
                        embedFooter.IconUrl = $"http://77.68.95.193/footerimgs/{footerImgNum}.png";
                        var records = new DiscordEmbedBuilder
                        {
                            Title     = $"{goal} | ",
                            Thumbnail = thumbnailUrl,
                            Footer    = embedFooter,
                            Url       = leaderboard.WebLink.AbsoluteUri
                        };
                        CharacterColor(leaderboard, records);
                        if (categoryFgID == "9d8pmg3k" || categoryFgID == "9d8pm0qk")
                        {
                            string formattedCat = leaderboard.Category.Name.Replace(" ", string.Empty);
                            string url          = $"http://77.68.95.193/fgicons/{formattedCat}.png";
                            thumbnailUrl.Url = url;
                            records.Title   += finalVersion;
                        }
                        else
                        {
                            string formattedGoal = goal.Replace(" ", string.Empty).Replace("%", string.Empty);
                            string url           = $"http://77.68.95.193/fgicons/{formattedGoal}.png";
                            thumbnailUrl.Url = url;
                            records.Title   += leaderboard.Category.Name + " | " + finalVersion;
                        }

                        string displayedTimeFormat = Program.timeFormat;
                        if (leaderboard.Records.Count != 0)
                        {
                            if (leaderboard.Records.Any(x => x.Times.PrimaryISO.Value.Hours != 0))
                            {
                                displayedTimeFormat = Program.timeFormatWithHours;
                            }
                        }

                        for (int i = 0; i < leaderboard.Records.Count(); i++)
                        {
                            string playerName = leaderboard.Records[i].Player.Name;
                            string runTime    = leaderboard.Records[i].Times.PrimaryISO.Value.ToString(displayedTimeFormat);
                            records.AddField($"{i + 1}. {playerName} | {runTime}",
                                             leaderboard.Records[i].WebLink.AbsoluteUri);
                        }

                        await ctx.RespondAsync(embed : records);
                    }
                }

                else if (gotCat == true && gotLvl == true)
                {
                    Leaderboard leaderboard;
                    leaderboard = Program.srcClient.Leaderboards.GetLeaderboardForLevel(
                        Program.srb2Game.ID,
                        srb2Level.SrcID,
                        categoryID,
                        5
                        );

                    DiscordEmbedBuilder.EmbedThumbnail thumbnailUrl = new DiscordEmbedBuilder.EmbedThumbnail();
                    thumbnailUrl.Url = "http://77.68.95.193/lvlicons/" + srb2Level.FullName.Replace(" ", string.Empty) + ".png";
                    DiscordEmbedBuilder.EmbedFooter embedFooter = new DiscordEmbedBuilder.EmbedFooter();
                    int timeSinceStarted = (DateTime.Now - Program.startedAt).Minutes;
                    embedFooter.Text = $"Last updated {timeSinceStarted} minute(s) ago";
                    Random r            = new Random();
                    int    footerImgNum = r.Next(1, 21);
                    embedFooter.IconUrl = $"http://77.68.95.193/footerimgs/{footerImgNum}.png";
                    var records = new DiscordEmbedBuilder
                    {
                        Title     = srb2Level.FullName,
                        Thumbnail = thumbnailUrl,
                        Footer    = embedFooter,
                        Url       = leaderboard.WebLink.AbsoluteUri
                    };
                    CharacterColor(leaderboard, records);

                    switch (nights)
                    {
                    case true:
                        records.Color = DiscordColor.Magenta;
                        break;

                    case false:
                        records.Title += " | " + leaderboard.Category.Name;
                        break;
                    }

                    for (int i = 0; i < leaderboard.Records.Count(); i++)
                    {
                        string playerName = leaderboard.Records[i].Player.Name;
                        string runTime    = leaderboard.Records[i].Times.GameTimeISO.Value.ToString(Program.timeFormat);
                        records.AddField($"{i + 1}. {playerName} | {runTime}",
                                         leaderboard.Records[i].WebLink.AbsoluteUri);
                    }
                    await ctx.RespondAsync(embed : records);
                }
                if (!gotLvl && !gotCatFg)
                {
                    throw new Exception("Wrong / Missing parameter: Level (ILs) / Category (Full-game)");
                }
            }
            catch (Exception e)
            {
                await ctx.RespondAsync("Type !help for more info");

                /* await ctx.RespondAsync(e.Source);
                 * await ctx.RespondAsync(e.Message);
                 * await ctx.RespondAsync(e.StackTrace);
                 */
            }
        }
Exemple #5
0
 public static async Task Stream_Notification(object Client, PresenceUpdateEventArgs e)
 {
     _ = Task.Run(async() =>
     {
         if (e.User != null)
         {
             DiscordGuild guild = e.User.Presence.Guild;
             DB.StreamNotifications StreamNotification = DB.DBLists.StreamNotifications.FirstOrDefault(w => w.Server_ID == guild.Id);
             DiscordChannel channel = guild.GetChannel(Convert.ToUInt64(StreamNotification.Channel_ID));
             if (Program.ServerIdList.Contains(guild.Id))
             {
                 LiveStreamer streamer = new()
                 {
                     User  = e.User,
                     Time  = DateTime.Now,
                     Guild = guild
                 };
                 int ItemIndex;
                 try
                 {
                     ItemIndex = LiveStreamerList.FindIndex(a => a.User.Id == e.User.Id &&
                                                            a.Guild.Id == e.User.Presence.Guild.Id);
                 }
                 catch (Exception)
                 {
                     ItemIndex = -1;
                 }
                 if (ItemIndex >= 0 &&
                     e.User.Presence.Activities.FirstOrDefault(w => w.Name.ToLower() == "twitch" || w.Name.ToLower() == "youtube") == null)
                 {
                     //removes user from list
                     if (LiveStreamerList[ItemIndex].Time.AddHours(StreamCheckDelay) < DateTime.Now &&
                         e.User.Presence.Activities.FirstOrDefault(w => w.Name.ToLower() == "twitch" || w.Name.ToLower() == "youtube") == LiveStreamerList[ItemIndex].User.Presence.Activities.FirstOrDefault(w => w.Name.ToLower() == "twitch" || w.Name.ToLower() == "youtube"))
                     {
                         LiveStreamerList.RemoveAt(ItemIndex);
                     }
                 }
                 else if (ItemIndex == -1 &&
                          e.User.Presence.Activities.FirstOrDefault(w => w.Name.ToLower() == "twitch" || w.Name.ToLower() == "youtube") != null &&
                          e.User.Presence.Activities.FirstOrDefault(w => w.Name.ToLower() == "twitch" || w.Name.ToLower() == "youtube").ActivityType.Equals(ActivityType.Streaming))
                 {
                     DiscordMember StreamMember = await guild.GetMemberAsync(e.User.Id);
                     bool role          = false, game = false;
                     string gameTitle   = e.User.Presence.Activities.FirstOrDefault(w => w.Name.ToLower() == "twitch" || w.Name.ToLower() == "youtube").RichPresence.State;
                     string streamTitle = e.User.Presence.Activities.FirstOrDefault(w => w.Name.ToLower() == "twitch" || w.Name.ToLower() == "youtube").RichPresence.Details;
                     string streamURL   = e.User.Presence.Activities.FirstOrDefault(w => w.Name.ToLower() == "twitch" || w.Name.ToLower() == "youtube").StreamUrl;
                     if (StreamNotification.Roles_ID != null)
                     {
                         foreach (DiscordRole urole in StreamMember.Roles)
                         {
                             foreach (decimal roleid in StreamNotification.Roles_ID)
                             {
                                 if (urole.Id == roleid)
                                 {
                                     role = true;
                                     break;
                                 }
                             }
                         }
                     }
                     else if (StreamNotification.Roles_ID == null)
                     {
                         role = true;
                     }
                     if (StreamNotification.Games != null)
                     {
                         foreach (string ugame in StreamNotification.Games)
                         {
                             try
                             {
                                 if (gameTitle == ugame)
                                 {
                                     game = true;
                                     break;
                                 }
                             }
                             catch { game = false; }
                         }
                     }
                     else if (StreamNotification.Games == null)
                     {
                         game = true;
                     }
                     if (game && role)
                     {
                         DiscordEmbedBuilder embed = new()
                         {
                             Color  = new DiscordColor(0x6441A5),
                             Author = new DiscordEmbedBuilder.EmbedAuthor
                             {
                                 IconUrl = e.User.AvatarUrl,
                                 Name    = "STREAM",
                                 Url     = streamURL
                             },
                             Description = $"**Streamer:**\n {e.User.Mention}\n\n" +
                                           $"**Game:**\n{gameTitle}\n\n" +
                                           $"**Stream title:**\n{streamTitle}\n\n" +
                                           $"**Stream Link:**\n{streamURL}",
                             Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail
                             {
                                 Url = e.User.AvatarUrl
                             },
                             Title = $"Check out {e.User.Username} is now Streaming!"
                         };
                         await channel.SendMessageAsync(embed: embed);
                         //adds user to list
                         LiveStreamerList.Add(streamer);
                     }
                 }
             }
         }
     });
     await Task.Delay(1);
 }
Exemple #6
0
        public static DiscordEmbed GetUserWarnings(DiscordGuild Guild, DiscordUser User, bool AdminCommand = false)
        {
            DB.DBLists.LoadServerRanks();
            DB.DBLists.LoadWarnings();
            List <DB.ServerRanks> ServerRanks = DB.DBLists.ServerRanks;
            List <DB.Warnings>    warnings    = DB.DBLists.Warnings;
            bool UserCheck          = false;
            int  kcount             = 0,
                 bcount             = 0,
                 wlevel             = 0,
                 wcount             = 0,
                 splitcount         = 1;
            StringBuilder Reason    = new();
            var           UserStats = ServerRanks.FirstOrDefault(f => User.Id == f.User_ID && Guild.Id == f.Server_ID);

            if (UserStats != null)
            {
                UserCheck = true;
                kcount    = UserStats.Kick_Count;
                bcount    = UserStats.Ban_Count;
                wlevel    = UserStats.Warning_Level;
                var WarningsList = warnings.Where(w => w.User_ID == User.Id && w.Server_ID == Guild.Id).ToList();
                if (!AdminCommand)
                {
                    WarningsList.RemoveAll(w => w.Type == "note");
                }
                wcount = WarningsList.Count(w => w.Type == "warning");
                foreach (var item in WarningsList)
                {
                    switch (item.Type)
                    {
                    case "ban":
                        Reason.Append("[🔨]");
                        break;

                    case "kick":
                        Reason.Append("[🥾]");
                        break;

                    case "note":
                        Reason.Append("[❔]");
                        break;

                    default:     // warning
                        if (item.Active)
                        {
                            Reason.Append("[✅] ");
                        }
                        else
                        {
                            Reason.Append("[❌] ");
                        }
                        break;
                    }
                    string addedInfraction = $"**ID:**{item.ID_Warning}\t**By:** <@{item.Admin_ID}>\t**Date:** {item.Date}\n**Reason:** {item.Reason}\n **Type:**\t{item.Type}";

                    if (Reason.Length + addedInfraction.Length > 1023 * splitcount)
                    {
                        Reason.Append("~split~");
                        splitcount++;
                    }
                    Reason.AppendLine(addedInfraction);
                }
                if (WarningsList.Count == 0)
                {
                    Reason.AppendLine("User has no warnings.");
                }
            }
            DiscordEmbedBuilder embed = new()
            {
                Color  = new DiscordColor(0xFF6600),
                Author = new DiscordEmbedBuilder.EmbedAuthor
                {
                    Name    = User.Username,
                    IconUrl = User.AvatarUrl
                },
                Description = $"",
                Title       = "User kick Count",
                Thumbnail   = new DiscordEmbedBuilder.EmbedThumbnail
                {
                    Url = User.AvatarUrl
                }
            };

            embed.AddField("Warning level: ", $"{wlevel}", true);
            embed.AddField("Times warned: ", $"{wcount}", true);
            embed.AddField("Times kicked: ", $"{kcount}", true);
            embed.AddField("Times banned: ", $"{bcount}", true);
            string[] SplitReason = Reason.ToString().Split("~split~");
            for (int i = 0; i < SplitReason.Length; i++)
            {
                embed.AddField($"Infraction({i + 1}/{SplitReason.Length})", SplitReason[i], false);
            }
            if (!UserCheck)
            {
                return(new DiscordEmbedBuilder
                {
                    Color = new DiscordColor(0xFF6600),
                    Author = new DiscordEmbedBuilder.EmbedAuthor
                    {
                        Name = User.Username,
                        IconUrl = User.AvatarUrl
                    },
                    Description = "This user has no warning, kick and/or ban history in this server."
                });
            }
            else
            {
                return(embed);
            }
        }
Exemple #7
0
        public async Task FgRecords(CommandContext ctx, string category, string character, string version)
        {
            try
            {
                bool gotCatFg = SRB2Enums.fgCategoriesID.TryGetValue(character.ToLower(), out string categoryFgID); //checking for the character to get the ID off of it

                if (!gotCatFg)
                {
                    if (!SRB2Enums.fgCategoriesID.TryGetValue(category.ToLower(), out categoryFgID))
                    {
                        categoryFgID = "ndx46012";
                    }                                                                                                               // checking for all emblems / srb1 (since they're as the first argument when typing the command), if not defaulting to sonic
                }

                string goal;
                if (categoryFgID == "9d8pmg3k") //all emblems
                {
                    goal = SRB2Enums.GetGoal(categoryFgID);
                }
                else //everything else
                {
                    goal = SRB2Enums.GetGoal(category);
                }

                bool gotVer = false;

                string originalVer  = "";
                string processedVer = "";
                if (categoryFgID == "9d8pmg3k" || categoryFgID == "9d8pm0qk")
                {
                    originalVer = string.Join(" ", character + version).ToLower();
                    gotVer      = SRB2Enums.versions.TryGetValue(originalVer, out processedVer);
                }
                else
                {
                    originalVer = version;
                    gotVer      = SRB2Enums.versions.TryGetValue(originalVer, out processedVer);
                }

                if (!gotVer && originalVer != "")
                {
                    throw new ParsingException("Wrong / Missing version");
                }

                Leaderboard leaderboard = FullGameLeaderboard(goal, categoryFgID, processedVer, originalVer);
                DiscordEmbedBuilder.EmbedFooter    embedFooter  = new DiscordEmbedBuilder.EmbedFooter();
                DiscordEmbedBuilder.EmbedThumbnail thumbnailUrl = new DiscordEmbedBuilder.EmbedThumbnail();
                embedFooter.Text = Program.s.RandomStat();
                Random r            = new Random();
                int    footerImgNum = r.Next(1, 21);
                embedFooter.IconUrl = $"https://roborecords.org/footerimgs/{footerImgNum}.png";
                var records = new DiscordEmbedBuilder
                {
                    Title     = $"{goal} | ",
                    Thumbnail = thumbnailUrl,
                    Footer    = embedFooter,
                    Url       = leaderboard.WebLink.AbsoluteUri,
                    Color     = CharacterColor(leaderboard),
                };
                if (categoryFgID == "9d8pmg3k" || categoryFgID == "9d8pm0qk")
                {
                    string formattedCat = leaderboard.Category.Name.Replace(" ", string.Empty);
                    string url          = $"https://roborecords.org/fgicons/{formattedCat}.png";
                    thumbnailUrl.Url = url;
                    records.Title   += finalVersion;
                }
                else
                {
                    string formattedGoal = goal.Replace(" ", string.Empty).Replace("%", string.Empty);
                    string url           = $"https://roborecords.org/fgicons/{formattedGoal}.png";
                    thumbnailUrl.Url = url;
                    records.Title   += leaderboard.Category.Name + " | " + finalVersion;
                }

                string displayedTimeFormat = Program.timeFormatWithMinutes;
                if (leaderboard.Records.Count != 0)
                {
                    if (leaderboard.Records.Any(x => x.Times.PrimaryISO.Value.Hours != 0))
                    {
                        displayedTimeFormat = Program.timeFormatWithHours;
                    }
                }

                for (int i = 0; i < leaderboard.Records.Count(); i++)
                {
                    Record currentRecord = leaderboard.Records[i];
                    string playerName    = currentRecord.Player.Name;
                    string runTime       = currentRecord.Times.PrimaryISO.Value.ToString(displayedTimeFormat).TrimStart(new Char[] { '0' });
                    records.AddField($"{i + 1}. {playerName} | {runTime}",
                                     "Submitted on " + currentRecord.DateSubmitted.Value.ToString("d") +
                                     ", " +
                                     DSharpPlus.Formatter.MaskedUrl("Link", currentRecord.WebLink, "Submission Link")
                                     );
                }

                await ctx.RespondAsync(embed : records);
            }
            catch (ParsingException p)
            {
                await ctx.RespondAsync(p.Message);

                await ctx.RespondAsync("Type !help for more info");
            }
            catch (Exception e)
            {
                await ctx.RespondAsync($"Internal Error \n{e.Message} \n{e.Source} \n{e.StackTrace}");
            }
        }
Exemple #8
0
        public async Task Records(CommandContext ctx, string level, string character)
        {
            try
            {
                bool gotLvl = SRB2Enums.levelsID.TryGetValue(level.ToUpper(), out SRB2Level srb2Level);

                bool gotCat = SRB2Enums.categoriesID.TryGetValue(character.ToLower(), out string categoryID);

                bool nights = false;
                if (gotLvl)
                {
                    int mapNumber = SRB2Level.GetMapNumber(srb2Level.MapName);
                    if (mapNumber > 49 && mapNumber < 74)
                    {
                        categoryID = "xd1g1j4d";
                        gotCat     = true;
                        nights     = true;
                    }
                }

                if (!gotCat)
                {
                    throw new ParsingException("Wrong / Missing parameter: Character");
                }

                if (!gotLvl)
                {
                    throw new ParsingException("Wrong / Missing parameter: Level");
                }

                if (gotCat && gotLvl)
                {
                    Leaderboard leaderboard;
                    leaderboard = Program.srcClient.Leaderboards.GetLeaderboardForLevel(
                        Program.srb2Game.ID,
                        srb2Level.SrcID,
                        categoryID,
                        5
                        );

                    DiscordEmbedBuilder.EmbedThumbnail thumbnailUrl = new DiscordEmbedBuilder.EmbedThumbnail();
                    thumbnailUrl.Url = @"https://roborecords.org/lvlicons/" + srb2Level.FullName.Replace(" ", string.Empty) + ".png";
                    DiscordEmbedBuilder.EmbedFooter embedFooter = new DiscordEmbedBuilder.EmbedFooter();
                    embedFooter.Text = Program.s.RandomStat();
                    Random r            = new Random();
                    int    footerImgNum = r.Next(1, 21);
                    embedFooter.IconUrl = $"https://roborecords.org/footerimgs/{footerImgNum}.png";
                    var records = new DiscordEmbedBuilder
                    {
                        Title     = srb2Level.FullName + " | " + leaderboard.Category.Name,
                        Thumbnail = thumbnailUrl,
                        Footer    = embedFooter,
                        Url       = leaderboard.WebLink.AbsoluteUri,
                        Color     = nights ? DiscordColor.Magenta : CharacterColor(leaderboard)
                    };

                    for (int i = 0; i < leaderboard.Records.Count(); i++)
                    {
                        Record currentRecord       = leaderboard.Records[i];
                        string playerName          = currentRecord.Player.Name;
                        string displayedTimeFormat = currentRecord.Times.Primary.Value.Minutes != 0 ? Program.timeFormatWithMinutes : Program.timeFormat;

                        string runTime = currentRecord.Times.GameTimeISO.Value.ToString(displayedTimeFormat).TrimStart(new Char[] { '0' });

                        records.AddField($"{i + 1}. {playerName} | {runTime}",
                                         "Submitted on " + currentRecord.DateSubmitted.Value.ToString("d") +
                                         ", " +
                                         DSharpPlus.Formatter.MaskedUrl("Link", currentRecord.WebLink, "Submission Link")
                                         );
                    }
                    await ctx.RespondAsync(embed : records);
                }
            }
            catch (ParsingException p)
            {
                await ctx.RespondAsync(p.Message);

                await ctx.RespondAsync("Type !help for more info");
            }
            catch (Exception e)
            {
                await ctx.RespondAsync("Internal Error");

                await ctx.RespondAsync(e.Message);
            }
        }