예제 #1
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);
            }
        }
예제 #2
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);
     });
 }
예제 #3
0
 public void AdminMastery()
 {
     commands.CreateCommand("ConfigMastery")
     .Parameter("CommandType")
     .Parameter("Parameter", ParameterType.Optional)
     .Parameter("Points", ParameterType.Optional)
     .Do(async(e) =>
     {
         string returnstring       = "";
         SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());
         ServerRepo serverRepo     = new ServerRepo(new ServerContext());
         if (serverRepo.IsServerVerified(e.Server.Id) && serverRepo.IsAdmin(e.User.Id, e.Server.Id))
         {
             if (e.GetArg("CommandType") == "?" || e.GetArg("CommandType").ToLower() == "help")
             {
                 returnstring =
                     "**This command can be used to configure the Mastery Point system on your server.**" +
                     "\nUse *-ConfigMastery champion <champion>* to set a champion for your server:" +
                     "\nExample: -ConfigMastery champion Thresh" +
                     "\n\nUse *-ConfigMastery list* to get a list of all the roles you have set up." +
                     "\n\nUse *-ConfigMastery add <RoleName> <Amount>* to add a rank to the system:" +
                     "\nExample: -ConfigMastery add \"1 Million\" 1000000" +
                     "\n\nUse *-ConfigMastery remove <Points>* to remove a milestone rank:" +
                     "\nExample: -ConfigMastery remove 1000000";
             }
             else if (e.GetArg("CommandType").ToLower() == "champion")
             {
                 try
                 {
                     settingsRepo.SetChampionId(e.Server.Id, new ChampionAPI().GetChampionId(e.GetArg("Parameter").ToString()));
                     returnstring = "Champion set to " + e.GetArg("Parameter");
                 }
                 catch
                 {
                     returnstring = "Did not find champion called " + e.GetArg("Parameter");
                 }
             }
             else if (e.GetArg("CommandType").ToLower() == "list")
             {
                 try
                 {
                     returnstring = "Server looks at mastery points for " +
                                    new ChampionAPI().GetChampionName(
                         settingsRepo.GetChampionId(e.Server.Id));
                     returnstring += "\nRoles for this server: ```";
                     foreach (string line in settingsRepo.GetAllMasteryRoles(e.Server.Id))
                     {
                         returnstring += "\n" + line.Split(':').First() + " points uses role: " +
                                         e.Server.GetRole(Convert.ToUInt64(line.Split(':').Last())).Name;
                     }
                     returnstring += "\n```";
                 }
                 catch
                 {
                     returnstring = "No champion or role found, please set this up first!";
                 }
             }
             else if (e.GetArg("CommandType").ToLower() == "add")
             {
                 try
                 {
                     Discord.Role r = e.Server.FindRoles(e.GetArg("Parameter"), false).First();
                     settingsRepo.SetRoleByPoints(r.Id, e.Server.Id, Convert.ToInt32(e.GetArg("Points")));
                     returnstring = "Added to the list!";
                 }
                 catch
                 {
                     returnstring = "Failed to add, role not found.";
                 }
             }
             else if (e.GetArg("CommandType").ToLower() == "remove")
             {
                 try
                 {
                     settingsRepo.RemoveRoleByPoints(e.Server.Id, Convert.ToInt32(e.GetArg("Parameter")));
                     returnstring = "Removed the role with the points " + e.GetArg("Parameter");
                 }
                 catch
                 {
                     returnstring = "Failed to remove the role with points " + e.GetArg("Parameter");
                 }
             }
         }
         await e.Channel.SendMessage(returnstring);
     });
 }