コード例 #1
0
 public void GetMasteryPoints()
 {
     commands.CreateCommand("Mastery")
     .Do(async(e) =>
     {
         string returnstring       = "";
         SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());
         Summoner summoner         = null;
         try
         {
             DataLibary.Models.User user =
                 new UserRepo(new UserContext()).GetUserByDiscord(e.User.Id);
             summoner =
                 new SummonerAPI().GetSummoner(
                     new SummonerRepo(new SummonerContext()).GetSummonerByUserId(user),
                     ToolKit.LeagueAndDatabase.GetRegionFromDatabaseId(
                         new RegionRepo(new RegionContext()).GetRegionId(user)
                         ));
         }
         catch
         {
         }
         if (settingsRepo.MasteryPointsByAccount(e.Server.Id))
         {
             if (summoner != null)
             {
                 int points = new MasteryAPI().GetPoints(summoner,
                                                         new ChampionAPI().GetChampion(settingsRepo.GetChampionId(e.Server.Id), RiotSharp.Region.eune));
                 Discord.Role r = e.Server.GetRole(settingsRepo.GetRoleByPoints(e.Server.Id, points));
                 await e.User.AddRoles(r);
                 returnstring = Eng_Default.RoleHasBeenGiven(r.Name);
             }
             else
             {
                 returnstring = Eng_Default.RegisterAccount();
             }
         }
         else
         {
             returnstring = Eng_Default.ServerDoesNotAllow();
         }
         await e.Channel.SendMessage(returnstring);
     });
 }
コード例 #2
0
        public async void GetRoles(Discord.Server server, Discord.User discorduser)
        {
            SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());
            Summoner     summoner     = null;

            try
            {
                DataLibary.Models.User user =
                    new UserRepo(new UserContext()).GetUserByDiscord(discorduser.Id);
                summoner =
                    new SummonerAPI().GetSummoner(
                        new SummonerRepo(new SummonerContext()).GetSummonerByUserId(user),
                        ToolKit.LeagueAndDatabase.GetRegionFromDatabaseId(
                            new RegionRepo(new RegionContext()).GetRegionId(user)
                            ));
            }
            catch
            {
            }
            if (settingsRepo.RankByAccount(server.Id) == true)
            {
                //summoner will be null when the item does not excist within the database.
                //This is only done so there will be a proper returnmessage send to the user.
                if (summoner != null)
                {
                    if (settingsRepo.RankCommandType(server.Id) == CommandType.Basic)
                    {
                        try
                        {
                            string rank = new RankAPI().GetRankingSimple(summoner,
                                                                         Queue.RankedSolo5x5);
                            try
                            {
                                await discorduser.AddRoles(
                                    server.GetRole(settingsRepo.GetOverride(rank.ToLower(),
                                                                            server.Id)));
                            }
                            catch
                            {
                                await discorduser.AddRoles(server.FindRoles(rank, false).First());
                            }
                        }
                        catch
                        {
                        }
                    }
                    else if (settingsRepo.RankCommandType(server.Id) == CommandType.Division)
                    {
                        try
                        {
                            string rank =
                                new RankAPI().GetRankingHarder(summoner, Queue.RankedSolo5x5)
                                .ToLower();
                            try
                            {
                                await discorduser.AddRoles(
                                    server.GetRole(settingsRepo.GetOverride(rank, server.Id)));
                            }
                            catch
                            {
                                await discorduser.AddRoles(server.FindRoles(rank, false).First());
                            }
                        }
                        catch { }
                    }
                    else if (settingsRepo.RankCommandType(server.Id) == CommandType.PerQueue)
                    {
                        //Each of these can fail when someone does not have this rank, therefore this isn't in one big Try because it could fail halfway.
                        try
                        {
                            string rank = "Solo " +
                                          new RankAPI().GetRankingSimple(summoner,
                                                                         Queue.RankedSolo5x5);
                            try
                            {
                                await discorduser.AddRoles(
                                    server.GetRole(settingsRepo.GetOverride(rank, server.Id)));
                            }
                            catch
                            {
                                await discorduser.AddRoles(server.FindRoles(rank, false).First());
                            }
                        }
                        catch
                        {
                            Console.WriteLine(discorduser.Name + "doesn't have a soloq rank");
                        }
                        try
                        {
                            string rank = "Flex " +
                                          new RankAPI().GetRankingSimple(summoner,
                                                                         Queue.RankedFlexSR);
                            try
                            {
                                await discorduser.AddRoles(
                                    server.GetRole(settingsRepo.GetOverride(rank, server.Id)));
                            }
                            catch
                            {
                                await discorduser.AddRoles(server.FindRoles(rank, false).First());
                            }
                        }
                        catch
                        {
                            Console.WriteLine(discorduser.Name + "doesn't have a flex rank");
                        }
                        try
                        {
                            string rank = "3v3 " +
                                          new RankAPI().GetRankingSimple(summoner,
                                                                         Queue.RankedFlexTT);
                            try
                            {
                                await discorduser.AddRoles(
                                    server.GetRole(settingsRepo.GetOverride(rank, server.Id)));
                            }
                            catch
                            {
                                await discorduser.AddRoles(server.FindRoles(rank, false).First());
                            }
                        }
                        catch
                        {
                            Console.WriteLine(discorduser.Name + "doesn't have a 3v3 rank");
                        }
                    }
                }
            }
            if (settingsRepo.RegionByAccount(server.Id) && summoner != null)
            {
                //summoner will be null when the item does not excist within the database.
                //This is only done so there will be a proper returnmessage send to the user.

                foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions())
                {
                    if (region.ToLower() == summoner.Region.ToString().ToLower())
                    {
                        try
                        {
                            await discorduser.AddRoles(
                                server.GetRole(settingsRepo.GetOverride(region.ToLower(), server.Id)));
                        }
                        catch
                        {
                            await discorduser.AddRoles(server.FindRoles(region, false).First());
                        }
                    }
                }
            }
            if (settingsRepo.RoleByAccount(server.Id) && summoner != null)
            {
                List <string> filter = new List <string>();
                if (settingsRepo.RoleCommandType(server.Id) == CommandType.Basic)
                {
                    filter = DataLibary.Models.Roles.NormalRoles();
                }
                else if (settingsRepo.RoleCommandType(server.Id) == CommandType.Main)
                {
                    filter = DataLibary.Models.Roles.MainRoles();
                }
                else if (settingsRepo.RoleCommandType(server.Id) == CommandType.Mains)
                {
                    filter = DataLibary.Models.Roles.MainsRoles();
                }



                try
                {
                    string mainrole = new RoleAPI().GetRole(summoner);
                    foreach (string role in filter)
                    {
                        if (role.Contains(mainrole))
                        {
                            try
                            {
                                ulong id = settingsRepo.GetOverride(role.ToLower(), server.Id);
                                await discorduser.AddRoles(server.GetRole(id));
                            }
                            catch
                            {
                                await discorduser.AddRoles(server.FindRoles(role, false).First());
                            }
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("Error in roles");
                }
            }
            if (settingsRepo.MasteryPointsByAccount(server.Id) && summoner != null)
            {
                int points = new MasteryAPI().GetPoints(summoner,
                                                        new ChampionAPI().GetChampion(settingsRepo.GetChampionId(server.Id), RiotSharp.Region.eune));
                Discord.Role r = server.GetRole(settingsRepo.GetRoleByPoints(server.Id, points));
                await discorduser.AddRoles(r);
            }
        }