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); }); }
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 string GetInfoShort(Summoner summoner) { StaticRiotApi staticApi = StaticRiotApi.GetInstance(Keys.Keys.riotKey); string returnstring = ""; returnstring += "**" + summoner.Name + ": **"; returnstring += "\n**Region:** " + summoner.Region.ToString().ToUpper(); returnstring += "\n**Level:** " + summoner.Level.ToString(); if (summoner.Level == 30) { RankAPI rankApi = new RankAPI(); try { returnstring += "\n**Rankings: **"; if (rankApi.GetRankingHarder(summoner, Queue.RankedSolo5x5) != null) { returnstring += "\nSolo: " + rankApi.GetRankingHarder(summoner, Queue.RankedSolo5x5); } if (rankApi.GetRankingHarder(summoner, Queue.RankedFlexSR) != null) { returnstring += "\nFlex: " + rankApi.GetRankingHarder(summoner, Queue.RankedFlexSR); } if (rankApi.GetRankingHarder(summoner, Queue.RankedFlexTT) != null) { returnstring += "\n3v3: " + rankApi.GetRankingHarder(summoner, Queue.RankedFlexTT); } } catch { } } try { int gamesplayed = new RoleAPI().GetGamesPlayed(summoner); if (gamesplayed != 0) { returnstring += "**\nTotal Solo Games Played:** " + gamesplayed + " games"; } var champList = new ChampionAPI().Get5MainChampions(summoner); returnstring += "**\nMain ranked champions:**"; foreach (var champ in champList) { returnstring += "\n" + champ.Name + ": " + champ.Count + " games."; } } catch { } try { var masteryList = new MasteryAPI().GetChampionMasterys(summoner); masteryList = masteryList.OrderBy(c => c.ChampionLevel).ThenBy(c => c.ChampionPoints).ToList(); masteryList.Reverse(); int champions = 3; if (masteryList.Count < 3) { champions = masteryList.Count; } returnstring += "\n**Highest mastery:** "; for (int i = 0; i < champions; i++) { returnstring += "\n" + staticApi.GetChampion(RiotSharp.Region.br, (Convert.ToInt32((masteryList[i].ChampionId)))).Name + ": Level " + masteryList[i].ChampionLevel.ToString() + ", " + masteryList[i].ChampionPoints.ToString() + " Points"; } } catch { } return(returnstring); }