internal static Role ValidateRole(Server server, string roleName) { if (string.IsNullOrWhiteSpace(roleName)) throw new ArgumentNullException(nameof(roleName)); if (roleName.Trim() == "everyone") roleName = "@everyone"; var role = server.FindRoles(roleName).FirstOrDefault(); if (role == null) throw new NullReferenceException("That role does not exist."); return role; }
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"); } } } } }
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); } }
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); }