コード例 #1
0
        public async void GetRankRoles(Discord.Server server, Discord.User discorduser)
        {
            SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());

            if

            (settingsRepo.RankByAccount
                 (server.Id)
             == true)
            {
                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
                {
                }
                //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)
                    {
                        string rank = "";
                        try
                        {
                            rank = new RankAPI().GetRankingHarder(summoner, Queue.RankedSolo5x5)
                                   .ToLower();
                        }
                        catch
                        {
                            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());
                        }
                    }
                    else if (settingsRepo.RankCommandType(server.Id) == CommandType.Division)
                    {
                        string rank = "";
                        try
                        {
                            rank = new RankAPI().GetRankingHarder(summoner, Queue.RankedSolo5x5)
                                   .ToLower();
                        }
                        catch
                        {
                        }

                        try
                        {
                            await discorduser.AddRoles(
                                server.GetRole(settingsRepo.GetOverride(rank, server.Id)));
                        }
                        catch
                        {
                            await discorduser.AddRoles(server.FindRoles(rank, false).First());
                        }
                    }
                    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");
                        }
                    }
                }
            }
        }
コード例 #2
0
        public async void RemoveRoles(Discord.Server server, Discord.User discorduser)
        {
            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
            {
                Console.WriteLine("User is not registered.");
            }

            if (summoner != null)
            {
                SettingsRepo  settingsRepo = new SettingsRepo(new SettingsContext());
                List <string> filter       = new List <string>();
                if (settingsRepo.RankCommandType(server.Id) == CommandType.Basic)
                {
                    filter = Ranks.BasicRanks();
                }
                else if (settingsRepo.RankCommandType(server.Id) == CommandType.PerQueue)
                {
                    filter = Ranks.QueueRanks();
                }
                else if (settingsRepo.RankCommandType(server.Id) == CommandType.Division)
                {
                    filter = Ranks.DivisionRanks();
                }
                List <Discord.Role> roles = new List <Discord.Role>();
                foreach (Discord.Role role in discorduser.Roles)
                {
                    foreach (string line in filter)
                    {
                        if (role.Name.ToLower() == line.ToLower())
                        {
                            roles.Add(role);
                        }
                        else
                        {
                            try
                            {
                                if (server.GetRole(settingsRepo.GetOverride(line.ToLower(), server.Id)).Id == role.Id)
                                {
                                    roles.Add(role);
                                }
                            }
                            catch
                            {
                                //no override
                            }
                        }
                    }
                }
                await server.GetUser(discorduser.Id).RemoveRoles(roles.ToArray());

                //foreach (string line in filter)
                //{
                //    Discord.Role r = null;
                //    try
                //    {
                //         r = server.GetRole(settingsRepo.GetOverride(line.ToLower(), server.Id));
                //    }
                //    catch
                //    {
                //        try
                //        {
                //            r = server.FindRoles(line, false).First();
                //        }
                //        catch { }

                //    }
                //    if (r != null)
                //    {
                //        if (discorduser.HasRole(r))
                //        {
                //            roles.Add(r);
                //        }
                //    }
                //}
            }
        }
コード例 #3
0
        public void GetRank()
        {
            commands.CreateCommand("Rank")
            .Parameter("rank", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                string returnstring = "error";
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    try
                    {
                        new RoleManagementTrigger(BotUser, commands).OverrideDeletion(e.Server);
                    }
                    catch
                    {
                    }
                    SettingsRepo settingsRepo = (new SettingsRepo(new SettingsContext()));
                    if (e.GetArg("rank").Split(' ').First() == "delete" ||
                        e.GetArg("rank").Split(' ').First() == "remove")
                    {
                        foreach (string region in Ranks.BasicRanks())
                        {
                            if (region.ToLower() ==
                                e.GetArg("rank")
                                .Substring(e.GetArg("rank").IndexOf(" ") + 1,
                                           e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1)
                                .ToLower())
                            {
                                try
                                {
                                    ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id);
                                    await e.User.RemoveRoles(e.Server.GetRole(id),
                                                             e.Server.FindRoles(region.ToLower(), false).First());
                                    returnstring = Eng_Default.RoleHasBeenRemoved(region);
                                }
                                catch
                                {
                                }
                            }
                        }
                        foreach (string region in Ranks.QueueRanks())
                        {
                            if (region.ToLower() ==
                                e.GetArg("rank")
                                .Substring(e.GetArg("rank").IndexOf(" ") + 1,
                                           e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1)
                                .ToLower())
                            {
                                try
                                {
                                    ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id);
                                    await e.User.RemoveRoles(e.Server.GetRole(id),
                                                             e.Server.FindRoles(region.ToLower(), false).First());
                                    returnstring = Eng_Default.RoleHasBeenRemoved(region);
                                }
                                catch
                                {
                                }
                            }
                        }
                        foreach (string region in Ranks.DivisionRanks())
                        {
                            if (region.ToLower() ==
                                e.GetArg("rank")
                                .Substring(e.GetArg("rank").IndexOf(" ") + 1,
                                           e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1)
                                .ToLower())
                            {
                                try
                                {
                                    ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id);
                                    await e.User.RemoveRoles(e.Server.GetRole(id),
                                                             e.Server.FindRoles(region.ToLower(), false).First());
                                    returnstring = Eng_Default.RoleHasBeenRemoved(region);
                                }
                                catch
                                {
                                }
                            }
                        }
                        try
                        {
                            foreach (string role in settingsRepo.GetAllOverrides(e.Server.Id))
                            {
                                var replacement = e.Server.GetRole(Convert.ToUInt64(role.Split(':').Last()));
                                if (
                                    e.GetArg("rank")
                                    .Substring(e.GetArg("rank").IndexOf(" ") + 1,
                                               e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1)
                                    .ToLower() == replacement.Name.ToLower())
                                {
                                    await e.User.RemoveRoles(replacement);
                                    returnstring = Eng_Default.RoleHasBeenRemoved(role);
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                    else if (e.GetArg("rank").ToLower() == "list")
                    {
                        if (settingsRepo.RankByAccount(e.Server.Id) == true ||
                            settingsRepo.RankByParameter(e.Server.Id) == true)
                        {
                            returnstring = "Assignable roles on this server:";
                            if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Basic)
                            {
                                foreach (string r in Ranks.BasicRanks())
                                {
                                    returnstring += "\n- " + r;
                                }
                            }
                            else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.PerQueue)
                            {
                                foreach (string r in Ranks.QueueRanks())
                                {
                                    returnstring += "\n- " + r;
                                }
                            }
                            else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Division)
                            {
                                foreach (string r in Ranks.BasicRanks())
                                {
                                    returnstring += "\n- " + r + " V to I";
                                }
                            }
                        }
                        else
                        {
                            returnstring = Eng_Default.ServerDoesNotAllow();
                        }
                    }
                    else if (e.GetArg("rank") == "?" || e.GetArg("rank").ToLower() == "help")
                    {
                        returnstring = "Use the base command -rank to get a rank assigned as your role.";
                        if (settingsRepo.RankByAccount(e.Server.Id) == true)
                        {
                            returnstring +=
                                "\nYou can use *-Rank* to get your ranks based on bound league of legends account.";
                        }
                        if (settingsRepo.RankByParameter(e.Server.Id) == true)
                        {
                            returnstring +=
                                "\nYou can use *-Rank <League rank>* to get a role based on your input";
                            returnstring += "\nRoles you can get on this server are:";
                            if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Basic)
                            {
                                foreach (string r in Ranks.BasicRanks())
                                {
                                    returnstring += "\n- " + r;
                                }
                            }
                            else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.PerQueue)
                            {
                                foreach (string r in Ranks.QueueRanks())
                                {
                                    returnstring += "\n- " + r;
                                }
                            }
                            else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Division)
                            {
                                foreach (string r in Ranks.BasicRanks())
                                {
                                    returnstring += "\n- " + r + " V to I";
                                }
                            }
                        }
                    }
                    else
                    {
                        if (e.GetArg("rank") == "")
                        {
                            //Checks if gettings ranks by account is disabled (Unsure why someone would disable this but hey ¯\_(ツ)_/¯ someone might want so)
                            if (settingsRepo.RankByAccount(e.Server.Id) == true)
                            {
                                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
                                {
                                    returnstring =
                                        Eng_Default.RegisterAccount();
                                }
                                //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(e.Server.Id) == CommandType.Basic)
                                    {
                                        string rank = new RankAPI().GetRankingSimple(summoner,
                                                                                     Queue.RankedSolo5x5);
                                        try
                                        {
                                            await e.User.AddRoles(
                                                e.Server.GetRole(settingsRepo.GetOverride(rank.ToLower(),
                                                                                          e.Server.Id)));
                                        }
                                        catch
                                        {
                                            await e.User.AddRoles(e.Server.FindRoles(rank, false).First());
                                        }
                                        returnstring = Eng_Default.RoleHasBeenGiven(rank);
                                    }
                                    else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Division)
                                    {
                                        string rank =
                                            new RankAPI().GetRankingHarder(summoner, Queue.RankedSolo5x5)
                                            .ToLower();
                                        try
                                        {
                                            await e.User.AddRoles(
                                                e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id)));
                                        }
                                        catch
                                        {
                                            await e.User.AddRoles(e.Server.FindRoles(rank, false).First());
                                        }

                                        returnstring = Eng_Default.RoleHasBeenGiven(rank);
                                    }
                                    else if (settingsRepo.RankCommandType(e.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 e.User.AddRoles(
                                                    e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id)));
                                            }
                                            catch
                                            {
                                                await e.User.AddRoles(e.Server.FindRoles(rank, false).First());
                                            }
                                        }
                                        catch
                                        {
                                            Console.WriteLine(e.User.Name + "doesn't have a soloq rank");
                                        }
                                        try
                                        {
                                            string rank = "Flex " +
                                                          new RankAPI().GetRankingSimple(summoner,
                                                                                         Queue.RankedFlexSR);
                                            try
                                            {
                                                await e.User.AddRoles(
                                                    e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id)));
                                            }
                                            catch
                                            {
                                                await e.User.AddRoles(e.Server.FindRoles(rank, false).First());
                                            }
                                        }
                                        catch
                                        {
                                            Console.WriteLine(e.User.Name + "doesn't have a flex rank");
                                        }
                                        try
                                        {
                                            string rank = "3v3 " +
                                                          new RankAPI().GetRankingSimple(summoner,
                                                                                         Queue.RankedFlexTT);
                                            try
                                            {
                                                await e.User.AddRoles(
                                                    e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id)));
                                            }
                                            catch
                                            {
                                                await e.User.AddRoles(e.Server.FindRoles(rank, false).First());
                                            }
                                        }
                                        catch
                                        {
                                            Console.WriteLine(e.User.Name + "doesn't have a 3v3 rank");
                                        }
                                        returnstring = Eng_Default.RolesHaveBeenGiven();
                                    }
                                }
                            }
                            else
                            {
                                returnstring = Eng_Default.ServerDoesNotAllow();
                            }
                        }
                        else
                        {
                            //Check settings and give ranks according to the parameter
                            if (settingsRepo.RankByParameter(e.Server.Id) == true)
                            {
                                bool found           = false;
                                List <string> filter = new List <string>();
                                if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Basic)
                                {
                                    filter = Ranks.BasicRanks();
                                }

                                else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.PerQueue)
                                {
                                    filter = Ranks.QueueRanks();
                                }
                                foreach (string rank in filter)
                                {
                                    if (e.GetArg("rank").ToLower() == rank.ToLower())
                                    {
                                        try
                                        {
                                            Discord.Role r =
                                                e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id));
                                            if (!settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id))
                                            {
                                                await e.User.AddRoles(r);
                                                returnstring = Eng_Default.RoleHasBeenGiven(r.Name);
                                            }
                                            else
                                            {
                                                returnstring = Eng_Default.RoleHasBeenDisabled();
                                            }
                                        }
                                        catch
                                        {
                                            Discord.Role r = e.Server.FindRoles(rank, false).First();
                                            if (!settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id))
                                            {
                                                await e.User.AddRoles(r);
                                                returnstring = Eng_Default.RoleHasBeenGiven(r.Name);
                                            }
                                            else
                                            {
                                                returnstring = Eng_Default.RoleHasBeenDisabled();
                                            }
                                        }

                                        found = true;
                                    }
                                }
                                if (found == false)
                                {
                                    returnstring = Eng_Default.RoleNotFound(e.GetArg("rank"));
                                }
                            }
                            else
                            {
                                returnstring = Eng_Default.ServerDoesNotAllow();
                            }
                        }
                    }
                }
                else
                {
                    returnstring = Eng_Default.ServerIsNotVerified();
                }


                await e.Channel.SendMessage(returnstring);
            });
        }
コード例 #4
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);
            }
        }
コード例 #5
0
ファイル: RoleCommand.cs プロジェクト: bartdebever/AtlasBot
        public void GetRole()
        {
            commands.CreateCommand("Role")
            .Do(async(e) =>
            {
                string returnstring       = "";
                SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    if (settingsRepo.RoleByAccount(e.Server.Id))
                    {
                        List <string> filter = new List <string>();
                        if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Basic)
                        {
                            filter = DataLibary.Models.Roles.NormalRoles();
                        }
                        else if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Main)
                        {
                            filter = DataLibary.Models.Roles.MainRoles();
                        }
                        else if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Mains)
                        {
                            filter = DataLibary.Models.Roles.MainsRoles();
                        }

                        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
                        {
                            returnstring = Eng_Default.RegisterAccount();
                        }
                        //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)
                        {
                            string mainrole = new RoleAPI().GetRole(summoner);
                            foreach (string role in filter)
                            {
                                if (role.Contains(mainrole))
                                {
                                    try
                                    {
                                        ulong id = settingsRepo.GetOverride(role.ToLower(), e.Server.Id);
                                        await e.User.AddRoles(e.Server.GetRole(id));
                                        returnstring = Eng_Default.RoleHasBeenGiven(role);
                                    }
                                    catch
                                    {
                                        await e.User.AddRoles(e.Server.FindRoles(role, false).First());
                                        returnstring = Eng_Default.RoleHasBeenGiven(role);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    returnstring = Eng_Default.ServerIsNotVerified();
                }
                await e.Channel.SendMessage(returnstring);
            });
        }
コード例 #6
0
ファイル: RoleCommand.cs プロジェクト: bartdebever/AtlasBot
        public void GetRoleParameter()
        {
            commands.CreateCommand("Role")
            .Parameter("Role", ParameterType.Required)
            .Parameter("Optional", ParameterType.Optional)
            .Do(async(e) =>
            {
                string returnstring = "";
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());
                    List <string> filter      = new List <string>();
                    if (e.GetArg("Role").ToLower() == "?" || e.GetArg("Role").ToLower() == "help")
                    {
                        if (settingsRepo.RoleByParameter(e.Server.Id) || settingsRepo.RoleByAccount(e.Server.Id))
                        {
                            returnstring = "You can use -Role to assign a role based on a League of Legends role.";
                            if (settingsRepo.RoleByAccount(e.Server.Id))
                            {
                                returnstring +=
                                    "\nYou can use *-Role* to get your role automatically assigned based on your linked League of Legends account.";
                            }
                            if (settingsRepo.RoleByParameter(e.Server.Id))
                            {
                                returnstring += "\nYou can use *-Role <Role>* to assgined yourself a role." +
                                                "\nFor all assignable roles use -Role list.";
                            }
                        }
                    }

                    if (settingsRepo.RoleByParameter(e.Server.Id))
                    {
                        if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Basic)
                        {
                            filter = DataLibary.Models.Roles.NormalRoles();
                        }
                        else if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Main)
                        {
                            filter = DataLibary.Models.Roles.MainRoles();
                        }
                        else if (settingsRepo.RoleCommandType(e.Server.Id) == CommandType.Mains)
                        {
                            filter = DataLibary.Models.Roles.MainsRoles();
                        }


                        if (e.GetArg("Role").ToLower() == "list")
                        {
                            returnstring = "These roles are getable on the server:```";
                            foreach (string role in filter)
                            {
                                returnstring += "\n- " + role;
                            }
                            returnstring += "```";
                        }
                        else if (e.GetArg("Role").ToLower() == "remove")
                        {
                            foreach (string role in filter)
                            {
                                if (role.ToLower().Contains(e.GetArg("Optional").ToLower()))
                                {
                                    try
                                    {
                                        await e.User.RemoveRoles(
                                            e.Server.GetRole(settingsRepo.GetOverride(role.ToLower(),
                                                                                      e.Server.Id)));
                                        await e.User.RemoveRoles(e.Server.FindRoles(role, false).First());
                                        returnstring = Eng_Default.RoleHasBeenRemoved(role);
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (string role in filter)
                            {
                                if (role.ToLower().Contains(e.GetArg("Role").ToLower()))
                                {
                                    try
                                    {
                                        ulong id = settingsRepo.GetOverride(role.ToLower(), e.Server.Id);
                                        await e.User.AddRoles(e.Server.GetRole(id));
                                        returnstring = Eng_Default.RoleHasBeenGiven(role);
                                    }
                                    catch
                                    {
                                        await e.User.AddRoles(e.Server.FindRoles(role, false).First());
                                        returnstring = Eng_Default.RoleHasBeenGiven(role);
                                    }
                                }
                            }
                        }
                    }
                    else if (e.GetArg("Role").ToLower() != "?" && e.GetArg("Role").ToLower() != "help")
                    {
                        returnstring = Eng_Default.ServerDoesNotAllow();
                    }
                }
                else
                {
                    returnstring = Eng_Default.ServerIsNotVerified();
                }

                await e.Channel.SendMessage(returnstring);
            });
        }
コード例 #7
0
        public Discord.Role RoleSearch(Discord.Server server, string parameter)
        {
            Discord.Role r            = null;
            SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext());

            if (settingsRepo.RankByParameter(server.Id) == true)
            {
                List <string> filter = new List <string>();
                if (settingsRepo.RankCommandType(server.Id) == CommandType.Basic)
                {
                    filter = Ranks.BasicRanks();
                }

                else if (settingsRepo.RankCommandType(server.Id) == CommandType.PerQueue)
                {
                    filter = Ranks.QueueRanks();
                }
                foreach (string rank in filter)
                {
                    if (parameter.ToLower() == rank.ToLower())
                    {
                        try
                        {
                            return(server.GetRole(settingsRepo.GetOverride(rank, server.Id)));
                        }
                        catch
                        {
                            return(server.FindRoles(rank, false).First());
                        }
                    }
                }
            }
            if (settingsRepo.RoleByParameter(server.Id))
            {
                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();
                }
                foreach (string role in filter)
                {
                    if (role.ToLower().Contains(parameter.ToLower()))
                    {
                        try
                        {
                            ulong id = settingsRepo.GetOverride(role.ToLower(), server.Id);
                            r = server.GetRole(id);
                            if (r == null)
                            {
                                throw new Exception();
                            }
                        }
                        catch
                        {
                            return(server.FindRoles(role, false).First());
                        }
                    }
                }
            }

            if (settingsRepo.RegionByParameter(server.Id))
            {
                foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions())
                {
                    if (parameter.ToLower() == region.ToLower())
                    {
                        try
                        {
                            return(server.GetRole(settingsRepo.GetOverride(region.ToLower(), server.Id)));
                        }
                        catch
                        {
                            var temp = server.FindRoles(region, false).First();
                            if (settingsRepo.IsRoleDisabled(temp.Name.ToLower(), server.Id))
                            {
                            }
                            else
                            {
                                return(temp);
                            }
                        }
                    }
                }
            }
            foreach (string role in settingsRepo.GetAllOverrides(server.Id))
            {
                var temp = server.GetRole(Convert.ToUInt64(role.Substring(role.IndexOf(":") + 1, role.Length - role.IndexOf(":") - 1)));
                if (parameter.ToLower() == temp.Name.ToLower() || parameter.ToLower() == role.Split(':').First().ToLower())
                {
                    return(temp);
                }
            }
            return(r);
        }
コード例 #8
0
        public void GetRegion()
        {
            commands.CreateCommand("region")
            .Parameter("region", ParameterType.Unparsed)
            .Do(async(e) =>
            {
                try { new RoleManagementTrigger(BotUser, commands).OverrideDeletion(e.Server); } catch { }
                string returnstring = "error";
                if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id))
                {
                    string command = "";
                    try
                    {
                        command = e.GetArg("region").Substring(0, e.GetArg("region").IndexOf(" ")).ToLower();
                    }
                    catch { }

                    SettingsRepo settingsRepo = (new SettingsRepo(new SettingsContext()));
                    if (e.GetArg("region").ToLower() == "help" || e.GetArg("region") == "?")
                    {
                        if (settingsRepo.RegionByAccount(e.Server.Id) == true ||
                            settingsRepo.RegionByParameter(e.Server.Id) == true)
                        {
                            returnstring = "You can use the -Region command to assign a region role to yourself.";
                            if (settingsRepo.RegionByAccount(e.Server.Id) == true)
                            {
                                returnstring +=
                                    "\nYou can use *-Region* to get your region based on your bound League of Legends account.";
                            }
                            if (settingsRepo.RegionByParameter(e.Server.Id) == true)
                            {
                                returnstring +=
                                    "\nYou can use *-Region <League Region>* to assign a region to yourself.\nUse *-Region list* to see all the regions on this server.";
                            }
                        }

                        else
                        {
                            returnstring = Eng_Default.ServerDoesNotAllow();
                        }
                    }
                    else if (command == "remove" || command == "delete")
                    {
                        foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions())
                        {
                            if (region.ToLower() == e.GetArg("region").Split(' ').Last().ToLower())
                            {
                                try
                                {
                                    ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id);
                                    await e.User.RemoveRoles(e.Server.GetRole(id));
                                    returnstring = Eng_Default.RoleHasBeenRemoved(region);
                                    await e.User.RemoveRoles(e.Server.FindRoles(region.ToLower(), false).First());
                                    returnstring = Eng_Default.RoleHasBeenRemoved(region);
                                }
                                catch
                                {
                                }
                            }
                        }
                        try
                        {
                            foreach (string role in settingsRepo.GetAllOverrides(e.Server.Id))
                            {
                                var replacement = e.Server.GetRole(Convert.ToUInt64(role.Split(':').Last()));
                                if (e.GetArg("region").Substring(e.GetArg("region").IndexOf(" ") + 1, e.GetArg("region").Length - e.GetArg("region").IndexOf(" ") - 1).ToLower() == replacement.Name.ToLower())
                                {
                                    await e.User.RemoveRoles(replacement);
                                    returnstring = Eng_Default.RoleHasBeenRemoved(role);
                                }
                            }
                        }
                        catch { }
                    }
                    else if (e.GetArg("region").ToLower() == "list")
                    {
                        if (settingsRepo.RegionByParameter(e.Server.Id) == true ||
                            settingsRepo.RegionByAccount(e.Server.Id) == true)
                        {
                            returnstring            = "Assignable regions on this server:\n```";
                            List <string> overrides = new List <string>();
                            try
                            {
                                overrides = settingsRepo.GetAllOverrides(e.Server.Id);
                            }
                            catch { }
                            foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions())
                            {
                                bool found = false;
                                if (overrides != null)
                                {
                                    foreach (string over in overrides)
                                    {
                                        if (region.ToLower() == over.Substring(0, over.IndexOf(":")).ToLower())
                                        {
                                            returnstring += "\n- " + e.Server.GetRole(Convert.ToUInt64(over.Substring(over.IndexOf(":") + 1, over.Length - over.IndexOf(":") - 1))).Name;
                                            found         = true;
                                        }
                                    }
                                }
                                if (found == false)
                                {
                                    returnstring += "\n- " + region;
                                }
                            }
                            returnstring += "```";
                        }
                        else
                        {
                            returnstring = Eng_Default.ServerDoesNotAllow();
                        }
                    }
                    else
                    {
                        if (settingsRepo.RegionByAccount(e.Server.Id) == true && e.GetArg("region") == "")
                        {
                            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
                            {
                                returnstring = Eng_Default.RegisterAccount();
                            }
                            //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)
                            {
                                foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions())
                                {
                                    if (region.ToLower() == summoner.Region.ToString().ToLower())
                                    {
                                        try
                                        {
                                            await e.User.AddRoles(
                                                e.Server.GetRole(settingsRepo.GetOverride(region.ToLower(), e.Server.Id)));
                                            returnstring = Eng_Default.RoleHasBeenGiven(region);
                                        }
                                        catch
                                        {
                                            await e.User.AddRoles(e.Server.FindRoles(region, false).First());
                                            returnstring = Eng_Default.RoleHasBeenGiven(region);
                                        }
                                    }
                                }
                            }
                        }
                        else if (e.GetArg("region") == "" && settingsRepo.RegionByAccount(e.Server.Id) == false)
                        {
                            returnstring = Eng_Default.ServerDoesNotAllow();
                        }
                        else if (settingsRepo.RegionByParameter(e.Server.Id) == true)
                        {
                            bool found = false;
                            foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions())
                            {
                                if (e.GetArg("region").ToLower() == region.ToLower())
                                {
                                    try
                                    {
                                        Discord.Role r =
                                            e.Server.GetRole(settingsRepo.GetOverride(region.ToLower(), e.Server.Id));
                                        if (settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id))
                                        {
                                            returnstring = Eng_Default.RoleHasBeenDisabled();
                                        }
                                        else
                                        {
                                            await e.User.AddRoles(r);
                                            returnstring = Eng_Default.RoleHasBeenGiven(r.Name);
                                        }

                                        found = true;
                                    }
                                    catch
                                    {
                                        Discord.Role r = e.Server.FindRoles(region, false).First();
                                        if (settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id))
                                        {
                                            returnstring = Eng_Default.RoleHasBeenDisabled();
                                        }
                                        else
                                        {
                                            await e.User.AddRoles(r);
                                            returnstring = Eng_Default.RoleHasBeenGiven(r.Name);
                                        }
                                        found = true;
                                    }
                                }
                            }
                            foreach (string role in settingsRepo.GetAllOverrides(e.Server.Id))
                            {
                                var replacement = e.Server.GetRole(Convert.ToUInt64(role.Substring(role.IndexOf(":") + 1, role.Length - role.IndexOf(":") - 1)));
                                if (e.GetArg("region").ToLower() == replacement.Name.ToLower())
                                {
                                    await e.User.AddRoles(replacement);
                                    returnstring = Eng_Default.RoleHasBeenGiven(role);
                                    found        = true;
                                }
                            }
                            if (found == false)
                            {
                                returnstring = Eng_Default.RoleNotFound(e.GetArg("region"));
                            }
                        }
                        else
                        {
                            returnstring = Eng_Default.ServerDoesNotAllow();
                        }
                    }
                }
                else
                {
                    returnstring = Eng_Default.ServerIsNotVerified();
                }

                await e.Channel.SendMessage(returnstring);
            });
        }