示例#1
0
文件: Test.cs 项目: Fasuh/bot
        public async Task info(SocketUser user = null)
        {
            if (user == null)
            {
                user = Context.Message.Author;
            }
            dbase.chkserver(Context.Guild);
            string       query = "SELECT * FROM uzytkownicy as u INNER JOIN `servery` as s ON u.Server = s.id WHERE u.user='******' AND s.nid='" + Context.Guild.Id.ToString() + "'";
            MySqlCommand cmd   = new MySqlCommand(query, dbase.connect);

            if (!dbase.HasRows(cmd))
            {
                query = "INSERT INTO `uzytkownicy`(`id`, `user`, `score`, `ranks`, `level`, `link`, `server`) VALUES (null,'" + user.Id.ToString() + "',0 ,null ,1 ,null,  '" + dbase.Chkserver(Context.Guild.Id.ToString()) + "')";
                cmd   = new MySqlCommand(query, dbase.connect);
                dbase.make(cmd);
                query = "SELECT * FROM `uzytkownicy` as u INNER JOIN `servery` as s ON u.Server = s.id WHERE u.user='******' AND s.nid='" + Context.Guild.Id.ToString() + "'";
                cmd   = new MySqlCommand(query, dbase.connect);
            }
            DataTable info    = dbase.Read(cmd);
            var       builder = new Discord.EmbedBuilder();

            builder.WithTitle("Informacje o uzytkowniku " + user.Username);
            builder.WithThumbnailUrl(user.GetAvatarUrl());
            builder.AddField("Ilość punktów:", info.Rows[0][2]);
            builder.AddInlineField("Poziom:", info.Rows[0][4]);
            if (info.Rows[0][5] != null && info.Rows[0][5].ToString() != "")
            {
                builder.AddInlineField("Deviantart:", info.Rows[0][5].ToString());
            }
            builder.WithColor(Color.DarkGreen);
            await Context.Channel.SendMessageAsync("", false, builder);
        }
示例#2
0
//        public static Embed CurrentUserEmbed(ICommandContext Context)
//        {
//            Mock database = DatabaseManager.GetMock();
//            DiscordUser atlasAccount = null;
//            try
//            {
//                atlasAccount =
//                    database.Users.FirstOrDefault(x => (x as DiscordUser).Discordid == (long)Context.User.Id);
//
//            }
//            catch
//            {
//                //Log user not registed
//            }
//            Discord.EmbedBuilder eb = BaseBuilder("", "", ColorPicker.UserModule,
//                new EmbedAuthorBuilder().WithName("Information about " + Context.User.Username),
//                Context.User.GetAvatarUrl());
//            if (atlasAccount != null)
//            {
//                eb.Description = "Displaying user information for the " + Names.Systemname + " account";
//                eb.AddField(new EmbedFieldBuilder().WithName(Names.Systemname + " Information").WithValue(
//                    "**Name:** " + atlasAccount.Name + "\n"+
//                    "**Account created:** " + atlasAccount.CreationDate.ToLongDateString()));
//            }
//            else
//            {
//                eb.AddField(new EmbedFieldBuilder()
//                    .WithValue("User is not registed, use -user register to register now.")
//                    .WithName(Names.Systemname + " Account"));
//            }
//            //eb.WithUrl("http://placeholder.com/user/id/111020301023");
//            string discordInformation = "";
//            try
//            {
//                var user = Context.User as IGuildUser;
//                discordInformation += "**Joined at: **" + user.JoinedAt.Value.Date.ToLongDateString() + "\n";
//            }
//            catch
//            {
//                //Log User not in guild
//            }
//            discordInformation += "**Status:** " + Context.User.Status + "\n";
//
//            if (Context.User.Game != null)
//            {
//                discordInformation += "**Currently Playing: **" + Context.User.Game.Value.Name + "\n";
//            }
//            eb.AddField(new EmbedFieldBuilder().WithName("Discord information").WithValue(discordInformation));
//            //if (atlasAccount != null)
//            //{
//            //    if (atlasAccount.Summoners.Count > 0)
//            //    {
//            //        string summoners = "";
//            //        foreach (var summoner in atlasAccount.Summoners)
//            //        {
//            //            summoners += summoner.Region + ": " + summoner.SummonerId; //TODO Make this a Tier
//            //        }
//            //        eb.AddField(new EmbedFieldBuilder().WithName("Summoner Information").WithValue(summoners));
//            //    }
//            //    else
//            //    {
//            //        eb.AddField(new EmbedFieldBuilder().WithName("Summoner Information")
//            //            .WithValue("This user has no summoners."));
//            //    }
//            //}
//            if (atlasAccount != null)
//            {
//                string accountinfo = "User does not have accounts linked\nUser **-HELPCOMMAND** to get started.";
//                if (atlasAccount.SmashAccount.Username != null && (bool)atlasAccount.SmashAccount.IsVerified)
//                {
//                    accountinfo = "**" + Names.SmashLadder + " account:**\n" + atlasAccount.SmashAccount.Username + " "+
//                                   atlasAccount.SmashAccount.Rank;
//                }
//                eb.AddField("Accounts", accountinfo);
//            }
//
//            return eb.Build();
//        }

//        public static Embed CurrentServerEmbed(IGuild guild)
//        {
//            DiscordServer server;
//            var database = DatabaseManager.GetMock();
//            try
//            {
//                server = database.Servers.FirstOrDefault(x => x.ServerId == guild.Id);
//            }
//            catch
//            {
//                server = null;
//            }
//
//            Discord.EmbedBuilder builder = BaseBuilder("", "Information about this server known to " + Names.BotName, ColorPicker.ServerModule, new EmbedAuthorBuilder().WithName(guild.Name), guild.IconUrl);
//            builder.AddField(new EmbedFieldBuilder().WithName("Discord Information")
//                .WithValue("**Name:** " + guild.Name + "\n"
//                           + "**Users:** " + (guild as SocketGuild).Users.Count + "\n"
//                           + "**Created at:** " + guild.CreatedAt.DateTime.ToLongDateString() + "\n"
//                           + "**Owner:** " + guild.GetOwnerAsync().Result.Username));
//            if (server == null)
//            {
//                builder.AddField(new EmbedFieldBuilder().WithName(Names.Systemname + " Information")
//                    .WithValue(
//                        "Server is not linked to an account. Let the owner use -server register *<Tier>* to start"));
//            }
//            else
//            {
//                builder.AddField(new EmbedFieldBuilder().WithName(Names.Systemname + " Information").WithValue(
//                    "**Name: **" + server.Name+"\n"+
//                    "**Description: **"+ server.Description+"\n"+
//                    "**Joined at: **" + server.JoinDateTime.ToLongDateString()+"\n"+
//                    "**Votes: **" + server.Votes));
//            }
//            return builder.Build();
//        }
//
//        public static Embed ServerList(string filter)
//        {
//            Discord.EmbedBuilder builder = BaseBuilder("", "All servers known ordered by votes.", ColorPicker.ServerModule, new EmbedAuthorBuilder().WithName(Names.Systemname + " server list"), null);
//            if (string.IsNullOrEmpty(filter)) //No parameter is given and we should display the full server list
//            {
//                List<DiscordServer> servers = DatabaseManager.GetMock().Servers.ToList();
//                //Add servers from other sources
//                var orderedServers = servers.OrderBy(x => x.Votes).ToList();
//                int maxservers = 5; //Maximal servers to display
//                if (maxservers > orderedServers.Count()) maxservers = orderedServers.Count;
//
//                for (int i = 0; i < maxservers; i++)
//                {
//
//                    builder.AddField(new EmbedFieldBuilder().WithName(orderedServers[i].Name)
//                        .WithValue("**Votes:** " + orderedServers[i].Votes + "\n" +
//                                   "**Description: **" + orderedServers[i].Description));
//                }
//            }
//            return builder.Build();
//        }
        //Base Builder
        public static Discord.EmbedBuilder BaseBuilder(string title, string description, Color color,
                                                       EmbedAuthorBuilder authorBuilder, string thumbnailurl)
        {
            Discord.EmbedBuilder builder = new Discord.EmbedBuilder().WithColor(color).WithFooter(Names.BotName).WithCurrentTimestamp();
            if (!string.IsNullOrEmpty(description))
            {
                builder.WithDescription(description);
            }
            if (!string.IsNullOrEmpty(title))
            {
                builder.WithTitle(title);
            }
            if (authorBuilder != null)
            {
                builder.WithAuthor(authorBuilder);
            }
            if (!string.IsNullOrEmpty(thumbnailurl))
            {
                builder.WithThumbnailUrl(thumbnailurl);
            }
            return(builder);
        }
示例#3
0
        public static Discord.EmbedBuilder UserInfo(string username)
        {
            RootObject root = RequestHandler.GetUserByName(username);
            User       user = root.user;

            Discord.EmbedBuilder builder = Builders.BaseBuilder("Link to " + Names.SmashLadder + " Profile", "All information known about **" + user.username + "**",
                                                                ColorPicker.SmashModule,
                                                                new EmbedAuthorBuilder().WithName(Names.SmashLadder)
                                                                .WithUrl("http://www.smashladder.com"), "");
            builder.WithThumbnailUrl("https://www.smashladder.com/images/subhypepikachu-logo.png");
            if (user.selected_flair != null)
            {
                builder.WithAuthor(new EmbedAuthorBuilder().WithName(Names.SmashLadder)
                                   .WithUrl("http://www.smashladder.com").WithIconUrl("http:" + user.selected_flair.url));
            }
            string location = "";

            if (!string.IsNullOrEmpty(user.location.Locality))
            {
                location += user.location.Locality + ", ";
            }
            if (!string.IsNullOrEmpty(user.location.State))
            {
                location += user.location.State + ", ";
            }
            if (!string.IsNullOrEmpty(user.location.Country.name))
            {
                location += user.location.Country.name;
            }
            string status = "Offline";
            string sub    = "";

            if (user.is_online != null)
            {
                status = "Online";
            }
            if (user.is_subscribed != null)
            {
                sub = "**User is subscribed!**\n";
            }
            builder.AddField(new EmbedFieldBuilder().WithName("Profile").WithValue(
                                 "**Name: **" + user.username + "\n" +
                                 "**Member Since: **" + user.member_since.full.ToLongDateString() + "\n" +
                                 "**Location: **" + location + "\n" +
                                 "**Status message: **" + user.away_message + "\n" +
                                 "**Total matches played: **" + user.total_matches_played + "\n" +
                                 "**Status: **" + status + "\n" + sub
                                 ));
            var filteredgames = user.ladder_information.AllGames.Where(x => x != null).ToList();

            try
            {
                filteredgames = filteredgames.Where(x => x.league.stats.RankedPlayed != 0).ToList();
            }
            catch
            {
                //No ranked games played
            }
            foreach (var game in filteredgames)
            {
                try
                {
                    var characters = "";
                    var count      = 3;
                    if (game.characters.Count < count)
                    {
                        count = game.characters.Count;
                    }
                    if (count != 0)
                    {
                        characters = "**Characters:**\n";
                        for (int i = 0; i < count; i++)
                        {
                            characters += "**  " + game.characters[i].name + ": **" + game.characters[i].percent + "%\n";
                        }
                    }
                    var rank = "**Ranked: **Unranked\n";
                    if (!string.IsNullOrEmpty(game.league.Tier))
                    {
                        rank = "**Ranked: **" + game.league.Tier + " " + game.league.Division + "\n";
                    }
                    builder.AddField(new EmbedFieldBuilder().WithName(game.name).WithValue(
                                         "**Total ranked games played: **" + game.league.stats.RankedPlayed + "\n" +
                                         rank +
                                         characters
                                         ));
                }
                catch
                {
                }
            }

            if (root.now_playing != null)
            {
                string type = "Friendlies";
                if (root.now_playing.is_ranked)
                {
                    type = "Ranked";
                }

                string rankp1 = "Unranked";
                try
                {
                    var games1 = root.now_playing.player1.ladder_information.AllGames;
                    games1 = games1.Where(x => x != null).ToList();
                    SmashHandler.DataTypes.Game gamep1 = games1.Single(x => x.id == root.now_playing.ladder.id);
                    if (!string.IsNullOrEmpty(gamep1.league.Tier))
                    {
                        rankp1 = gamep1.league.Tier + " " + gamep1.league.Division;
                    }
                }
                catch { }
                string rankp2 = "Unranked";
                try
                {
                    var games2 = root.now_playing.player2.ladder_information.AllGames;
                    games2 = games2.Where(x => x != null).ToList();
                    SmashHandler.DataTypes.Game gamep2 = games2.Single(x => x.id == root.now_playing.ladder.id);
                    if (!string.IsNullOrEmpty(gamep2.league.Tier))
                    {
                        rankp2 = gamep2.league.Tier + " " + gamep2.league.Division;
                    }
                }
                catch { }
                builder.AddField(new EmbedFieldBuilder().WithName("Currently Playing").WithValue(
                                     "**" + root.now_playing.ladder_name + " " + type + "**: \n" +
                                     "Using " + root.now_playing.preferred_build.name + "\n" +
                                     root.now_playing.player1.username + " " + "(" + rankp1 + ")" + " vs " + root.now_playing.player2.username + " (" + rankp2 + ")"));
            }
            builder.WithUrl(user.profile_url);
            return(builder);
        }
示例#4
0
        public async Task PlayerPerformance(string playerName, [Remainder] string tournamentName)
        {
            var message = await ReplyAsync("Getting data...");

            var tournament = RequestHandler.GetTournamentRoot(tournamentName);

            if (tournament.entities == null)
            {
                var embed = Builders.BaseBuilder("Tournament not found", "", Color.Red, null, "");
                await ReplyAsync("", embed : embed.Build());
            }
            var bracketPhases = tournament.entities.phase.Where(x => x.groupCount == 1).ToList();

            Discord.EmbedBuilder builder = Builders.BaseBuilder(playerName + " Results For " + tournament.entities.tournament.name, "", Color.Red, null, "");
            bool   playerFound           = false;
            double wins   = 0;
            double losses = 0;

            foreach (var bracketPhase in bracketPhases)
            {
                var phaseId = bracketPhase.id;
                var group   = tournament.entities.groups.FirstOrDefault(x => x.phaseId == phaseId);
                var result  = RequestHandler.GetResultSets(group.id);
                var players = result.Entities.Player;
                var player  = players.Where(x => x.GamerTag.ToLower().Trim().Contains(playerName.ToLower().Trim()))
                              .ToList();
                if (player.Count == 1) //player is found, lets go
                {
                    playerFound = true;
                    builder.WithTitle($"{player[0].GamerTag} Results at {tournament.entities.tournament.name}");
                    var sets = result.Entities.Sets.Where(x =>
                                                          x.Entrant1Id == Convert.ToInt64(player[0].EntrantId) ||
                                                          x.Entrant2Id == Convert.ToInt64(player[0].EntrantId)).ToList();
                    string setinfo = "";
                    sets = sets.OrderBy(x => x.CompletedAt).ToList();
                    var characters = new List <string>()
                    {
                        "Bowser",
                        "Captain Falcon",
                        "Donkey Kong",
                        "Dr. Mario",
                        "Falco",
                        "Fox",
                        "Ganondorf",
                        "Ice Climbers",
                        "Jigglypuff",
                        "Kirby",
                        "Link",
                        "Luigi",
                        "Mario",
                        "Marth",
                        "Mewtwo",
                        "Mr. Game And Watch",
                        "Ness",
                        "Peach",
                        "Pichu",
                        "Pikachu",
                        "Roy",
                        "Samus",
                        "Sheik",
                        "Yoshi",
                        "Young Link",
                        "Zelda"
                    };
                    Event  prevEvent = null;
                    string eventInfo = "";
                    foreach (var set in sets)
                    {
                        var setEvent = tournament.entities.Event.FirstOrDefault(x => x.id == set.EventId);
                        if (prevEvent == null)
                        {
                            prevEvent = setEvent;
                        }
                        if (prevEvent.id != setEvent.id)
                        {
                            builder.AddInlineField(prevEvent.name, eventInfo);
                            prevEvent = setEvent;
                            eventInfo = "";
                        }
                        int    playerPlace = 1;
                        Player player2     = null;
                        if (Convert.ToInt64(player[0].EntrantId) == set.Entrant1Id)
                        {
                            player2 = players.FirstOrDefault(x => set.Entrant2Id == Convert.ToInt64(x.EntrantId));
                        }
                        else
                        {
                            player2     = players.FirstOrDefault(x => set.Entrant1Id == Convert.ToInt64(x.EntrantId));
                            playerPlace = 2;
                        }
                        if (player2 != null)
                        {
                            string gameinfo = "";
                            foreach (var game in set.Games)
                            {
                                gameinfo +=
                                    $"{characters[(int) game.Entrant1P1CharacterId - 1]} {game.Entrant1P1Stocks} - {game.Entrant2P1Stocks} {characters[(int) game.Entrant2P1CharacterId - 1]}\n";
                            }
                            if (gameinfo == "")
                            {
                                gameinfo = "Nothing available\n";
                            }
                            if (playerPlace == 1 && set.Entrant1Score != null && set.Entrant2Score != null)
                            {
                                eventInfo +=
                                    $"**{set.FullRoundText}:**\n{player[0].GamerTag} - {player2.GamerTag}: {set.Entrant1Score} - {set.Entrant2Score}\n" +
                                    gameinfo + "\n";
                                if (set.Entrant1Score != null)
                                {
                                    wins += (double)set.Entrant1Score;
                                }
                                if (set.Entrant2Score != null)
                                {
                                    losses += (double)set.Entrant2Score;
                                }
                            }
                            else if (set.Entrant1Score != null && set.Entrant2Score != null)
                            {
                                eventInfo +=
                                    $"**{set.FullRoundText}:**\n{player2.GamerTag} - {player[0].GamerTag}: {set.Entrant1Score} - {set.Entrant2Score}\n" +
                                    $"{gameinfo}\n";
                                if (set.Entrant2Score != null)
                                {
                                    wins += (double)set.Entrant1Score;
                                }
                                if (set.Entrant1Score != null)
                                {
                                    losses += (double)set.Entrant2Score;
                                }
                            }
                        }
                    }
                    //builder.AddField("Results", ssetinfo);
                    var imageurl = player[0].Images.FirstOrDefault(x => x.Type == "profile");
                    if (imageurl != null)
                    {
                        builder.WithThumbnailUrl(imageurl.Url);
                    }
                    if (wins != 0 && losses != 0)
                    {
                        eventInfo += $"\n" +
                                     $"***Overall performance***\n" +
                                     $"**Games Won: **{wins}\n" +
                                     $"**Games Lost: **{losses}\n" +
                                     $"**Winrate: **{Math.Round((wins / (wins + losses) * 100), 2)}%";
                    }

                    builder.AddInlineField(prevEvent.name, eventInfo);
                }
            }
            if (!playerFound)
            {
                builder = Builders.BaseBuilder("Player not found", "", Color.Red, null, "");
            }
            await ReplyAsync("", embed : builder.Build());

            await message.DeleteAsync();
        }
示例#5
0
        public async Task GetInfo([Remainder] string name)
        {
            Discord.EmbedBuilder builder = null;
            var root = RequestHandler.GetTournamentRoot(name);

            if (root.entities != null)
            {
                if (!root.entities.tournament.Private)
                {
                    var tournament = root.entities.tournament;
                    builder = Builders.BaseBuilder(tournament.name, "", Color.DarkGreen, null,
                                                   null);
                    var baseDate  = new DateTime(1970, 1, 1, 0, 0, 0);
                    var startDate = baseDate.AddSeconds(tournament.startAt);
                    var endDate   = baseDate.AddSeconds(tournament.endAt);
                    builder.AddField("Information",
                                     $"**Name: **{tournament.name}\n" +
                                     $"**Venue: **{tournament.venueName}\n" +
                                     $"**Venue Adress: **{tournament.venueAddress}\n" +
                                     $"**Timezone: **{tournament.timezone.Replace("/", " ").Replace("_", "")}\n" +
                                     $"**From **{startDate.ToLongDateString()} \n" +
                                     $"**To:** {endDate.ToLongDateString()}");
                    if (root.entities.videogame != null && root.entities.videogame.Count < 20)
                    {
                        foreach (var game in root.entities.videogame)
                        {
                            var    events = root.entities.Event.Where(x => x.videogameId == game.id).ToList();
                            string info   = "";
                            events.ForEach(x => info += "- " + x.name + "\n");
                            builder.AddInlineField(game.name, info);
                        }
                    }
                    else if (root.entities.videogame != null)
                    {
                        string info = "**Games Available:**\n";

                        foreach (var videoGame in root.entities.videogame)
                        {
                            if (info.Length > 900)
                            {
                                info += "For more info check Smash.gg";
                                break;
                            }
                            info += videoGame.name + "\n";
                        }
                        builder.AddField("Games", info);
                    }

                    var image = tournament.images.FirstOrDefault(x => x.type == "profile");
                    if (image != null)
                    {
                        builder.WithThumbnailUrl(image.url);
                    }
                    var banner = tournament.images.FirstOrDefault(x => x.type == "banner");
                    if (banner != null)
                    {
                        builder.ImageUrl = banner.url;
                    }
                }
                else
                {
                    builder = Builders.BaseBuilder("Tournament is private.", "", Color.Red, null, "");
                    builder.AddField("No access", "The tournament you are trying to access is labeled as private in Smash.gg\nWhile we could technically show you the data, we decided not to be unethical and protect the user.");
                }
            }
            else
            {
                builder = Builders.BaseBuilder("Tournament was not found.", "", Color.Red, null, "");
            }
            await ReplyAsync("", embed : builder.Build());
        }