BenFradet / RiotSharp

C# wrapper for the Riot Games API
http://benfradet.github.io/RiotSharp/
MIT License
300 stars 145 forks source link

How can i get the infos like(LP, Division, Rank) #705

Closed Innoo69 closed 2 years ago

Innoo69 commented 2 years ago

Hey, i found the RiotSharp source on youtube and was interessted to work with .. and now i got a problem where i cant continue working ... could someone help me ?

so my problem is i've look at the issues and found some codes to get the LP, Rank and Divisions. but i think those are really old (from 2014) and i dont have the Methods that those ppl have written i dont have the methods like GetSummoner([Region], [summonername]); or GetEntireLeagues or GetLeagues();

what i want to do is adding a command on my discord bot and with 1 command it should show the Summonername, Level, Rank, LP, Division, and the 3 best Champions he have with the highest masterypoints.

i already have Installed the NuGet Packet RiotSharp 5.0.0-Alpha and also added RiotSharp.dll to the Reffrences.

you guys should also knew that im working first time with an api...

i leave my discord also maybe someone is interessted to help me there : Inno#2285

xXLAOKOONXx commented 2 years ago

Did you try LeagueEndpoint Get League Entries or so? This should work with encrypted summonerId.

Innoo69 commented 2 years ago

I cant find those methods..

Edit: could you maybe give me an example ?

  1. this is my code which i have written until now :
  2. [Command("lolaccinfo")] [Alias("info")] public async Task LolAccInfo(string summonername) { try { var api = RiotApi.GetDevelopmentInstance(riotApiKey); var summoner = api.Summoner.GetSummonerByNameAsync(RiotSharp.Misc.Region.Euw, summonername).Result; await ReplyAsync($"SummonerName: {summoner.Name} \nLevel :{summoner.Level} \nTest:"); var allVersion = api.DataDragon.Versions.GetAllAsync().Result; var latestVersion = allVersion[0]; List championMasteries; try { championMasteries = api.ChampionMastery.GetChampionMasteriesAsync(summoner.Region, summoner.Id).Result; } catch (RiotSharpException ex) { return; } foreach (var championMastery in championMasteries) { var id = championMastery.ChampionId; var chname = api.DataDragon.Champions.GetAllAsync(latestVersion).Result.Champions.Values.Single(x => x.Id == id).Name; var level = championMastery.ChampionLevel; var points = championMastery.ChampionPoints; await ReplyAsync($"Championname: {chname} Level: {level} Points: {points}"); //Console.WriteLine($"Championname: {chname} Level: {level} Points: {points}"); } } catch (RiotSharpException ex) { Console.WriteLine(ex); } }
xXLAOKOONXx commented 2 years ago

I am just logged in via phone so kinda difficult.

api.League is the LeagueEndpoint under which you should find the right method.

xXLAOKOONXx commented 2 years ago

And this is your method https://github.com/BenFradet/RiotSharp/blob/develop/RiotSharp/Endpoints/LeagueEndpoint/LeagueEndpoint.cs#L51

Innoo69 commented 2 years ago

that was really helpful how can i get the encrypedsummonerId ? is it summoner.Id, summoner.AccountId or the summoner.PuuID?

xXLAOKOONXx commented 2 years ago

Summoner.Id should be the one to go. In newer endpoints you will find the other ids to be used.

Innoo69 commented 2 years ago

var test = api.League.GetLeagueEntriesBySummonerAsync(RiotSharp.Misc.Region.Euw, summoner.Id); thats what i write ... so basicly when i want to show the current Rank, Division and LP of the player on Console.Writeline(); what i have to write inside Console.Writeline(); something like Console.Writeline(test.Result); ?

AoshiW commented 2 years ago
var test = await api.League.GetLeagueEntriesBySummonerAsync(RiotSharp.Misc.Region.Euw, summoner.Id);
Console.Writeline($"Rank: {Rank} {Division} - {LP}LP");
Innoo69 commented 2 years ago

but the name "Division", "LP" or "Rank" does not exist in the context?

AoshiW commented 2 years ago

it should works now

var test = await api.League.GetLeagueEntriesBySummonerAsync(RiotSharp.Misc.Region.Euw, summoner.Id);
foreach(var item in test)
{
    Console.Writeline($"Rank: {item.Rank} {item .Division} - {item.LP}LP, {item.QueueType}");
}
Innoo69 commented 2 years ago

ok so the item.Rank just shows the divison ... like im Gold 3 and it shows Rank: III - 25 also there is nothing with division but it works like this Tier(Is the Rank you have like For example Gold) the Name Rank(Is the Division) and LeaguePoints is the LP thanks for all :D

btw. thank you Lakoon and AoshiW for the help i never though that someone would help me ...

Innoo69 commented 2 years ago

i actually have 2 more questions its not the same thing as the title says but i didnt want to open a new issue ... i would be really happy if someone could help me

so my code is still there and the same ... and i got at the method LolAccInfo with 1 parameter that should be get the summonername ... but when i type a summoner name with a "Space" in the name something like (summoner name is : "Hi im Inno") then it just gives me an error cause there is only one parameter for the name the question is what can i do to get informations from an account which has a "Space" in his name ...

the second thing where i need help is ... the champion masterys shows all champion masterys but i actually want only the 3 best Champions the player has which is that with the highest points...

i also tried something like

for(int i = 0; i == 3; i++) { foreach (var championMastery in championMasteries) { var id = championMastery.ChampionId; var chname = api.DataDragon.Champions.GetAllAsync(latestVersion).Result.Champions.Values.Single(x => x.Id == id).Name; var level = championMastery.ChampionLevel; var points = championMastery.ChampionPoints; await ReplyAsync($"Championname: {chname} Level: {level} Points: {points}"); } }

or tried with the while loop or do-while loop but those didnt work...

if someone could help me i would be really thankfull :I also sorry if i bother someone im just trying to learn and i really just open a thread for something when i have no more options..

AoshiW commented 2 years ago
  1. what is the exact name of that method?

  2. var championListStatic = await api.DataDragon.Champions.GetAllAsync(latestVersion);
    foreach (var championMastery in championMasteries.Take(3))
    {
    var id = championMastery.ChampionId;
    var chname = championListStatic.Champions.Values.Single(x => x.Id == id).Name;
    var level = championMastery.ChampionLevel;
    var points = championMastery.ChampionPoints;
    Console.WriteLine($"Championname: {chname} Level: {level} Points: {points}");
    }
  3. i didnt want to open a new issue

Discord (if you don't have a Discort, ignore it )

Innoo69 commented 2 years ago
 [Command("lolaccinfo")]

[Alias("info")] public async Task LolAccInfo(string summonername) { try { var api = RiotApi.GetDevelopmentInstance(riotApiKey); var summoner = api.Summoner.GetSummonerByNameAsync(RiotSharp.Misc.Region.Euw, summonername).Result; await ReplyAsync($"SummonerName: {summoner.Name} \nLevel :{summoner.Level} \nTest:"); var allVersion = api.DataDragon.Versions.GetAllAsync().Result; var latestVersion = allVersion[0]; List championMasteries; try { championMasteries = api.ChampionMastery.GetChampionMasteriesAsync(summoner.Region, summoner.Id).Result; } catch (RiotSharpException ex) { return; } foreach (var championMastery in championMasteries) { var id = championMastery.ChampionId; var chname = api.DataDragon.Champions.GetAllAsync(latestVersion).Result.Champions.Values.Single(x => x.Id == id).Name; var level = championMastery.ChampionLevel; var points = championMastery.ChampionPoints; await ReplyAsync($"Championname: {chname} Level: {level} Points: {points}"); //Console.WriteLine($"Championname: {chname} Level: {level} Points: {points}"); } } catch (RiotSharpException ex) { Console.WriteLine(ex); } }

this is the whole code

well, i have discord and im in the discord server thank you for that too :D