@ -5,20 +5,19 @@ import com.robrua.orianna.type.core.champion.ChampionStatus;
import com.robrua.orianna.type.core.common.QueueType ;
import com.robrua.orianna.type.core.common.Region ;
import com.robrua.orianna.type.core.common.Side ;
import com.robrua.orianna.type.core.currentgame.BannedChampion ;
import com.robrua.orianna.type.core.currentgame.CurrentGame ;
import com.robrua.orianna.type.core.currentgame.MasteryRank ;
import com.robrua.orianna.type.core.currentgame.Participant ;
import com.robrua.orianna.type.core.league.League ;
import com.robrua.orianna.type.core.league.LeagueEntry ;
import com.robrua.orianna.type.core.staticdata.Champion ;
import com.robrua.orianna.type.core.staticdata.Mastery ;
import com.robrua.orianna.type.core.staticdata.SummonerSpell ;
import com.robrua.orianna.type.core.summoner.Summoner ;
import com.robrua.orianna.type.exception.APIException ;
import net.pingex.discordbot.AbstractModule ;
import net.pingex.discordbot.Command ;
import net.pingex.discordbot.Configuration ;
import net.pingex.discordbot.Controllable ;
import org.apache.commons.lang3.StringUtils ;
import sx.blah.discord.api.IDiscordClient ;
import sx.blah.discord.handle.impl.events.MessageReceivedEvent ;
import sx.blah.discord.handle.obj.IMessage ;
@ -33,6 +32,7 @@ import java.io.IOException;
import java.net.URL ;
import java.util.* ;
import java.util.concurrent.TimeUnit ;
import java.util.function.Consumer ;
import java.util.stream.LongStream ;
/ * *
@ -196,51 +196,19 @@ public class LeagueOfDiscordModule extends AbstractModule
String timeStarted = String . format ( "%02d:%02d" , TimeUnit . SECONDS . toMinutes ( ginfo . getLength ( ) + SPECTATE_TIMESHIFT ) , ginfo . getLength ( ) + SPECTATE_TIMESHIFT - TimeUnit . MINUTES . toSeconds ( TimeUnit . SECONDS . toMinutes ( ginfo . getLength ( ) + SPECTATE_TIMESHIFT ) ) ) ;
sb . append ( ginfo . getQueueType ( ) ) . append ( " started " ) . append ( timeStarted ) . append ( " ago.\n\n" ) ;
// Evaluate max summoner+champ length for padding
int maxNameChampLength = 0 ;
for ( Participant i : ginfo . getParticipants ( ) )
if ( ( i . getSummonerName ( ) . length ( ) + i . getChampion ( ) . getName ( ) . length ( ) + 3 ) > maxNameChampLength )
maxNameChampLength = i . getSummonerName ( ) . length ( ) + i . getChampion ( ) . getName ( ) . length ( ) + 3 ;
// Evaluate sspells name length for padding
int maxSummonerSpellLength = 0 ;
for ( SummonerSpell i : RiotAPI . getSummonerSpells ( ) )
if ( ( i . getName ( ) . length ( ) * 2 + 1 ) > maxSummonerSpellLength )
maxSummonerSpellLength = i . getName ( ) . length ( ) * 2 + 1 ;
loadingMessage . edit ( "Game found. Fetching summoners data..." ) ;
sb . append ( "Team Blue" ) ;
if ( ! ginfo . getBannedChampions ( ) . isEmpty ( ) ) // Bans, if any
{
StringJoiner joinedChamps = new StringJoiner ( "/" ) ;
// WOW, MANY STREAMS, MUCH LAMBDA
ginfo . getBannedChampions ( ) . stream ( ) . filter ( bc - > bc . getTeam ( ) . equals ( Side . BLUE ) ) . forEach ( bc - > joinedChamps . add ( bc . getChampion ( ) . getName ( ) ) ) ;
sb . append ( " - Bans: " ) . append ( joinedChamps . toString ( ) ) ;
}
sb . append ( "\n" ) ;
boolean swapped = false ;
// Do all requests and store them in a temporary object for easier access
ArrayList < CurrentMatchPlayersData > participantsData = new ArrayList < > ( ) ;
for ( Participant i : ginfo . getParticipants ( ) )
{
if ( i . getTeam ( ) . equals ( Side . PURPLE ) & & ! swapped )
{
sb . append ( "\nTeam Purple" ) ;
if ( ! ginfo . getBannedChampions ( ) . isEmpty ( ) ) // Bans, if any
{
StringJoiner joinedChamps = new StringJoiner ( "/" ) ;
// WOW, MANY STREAMS, MUCH LAMBDA
ginfo . getBannedChampions ( ) . stream ( ) . filter ( bc - > bc . getTeam ( ) . equals ( Side . PURPLE ) ) . forEach ( bc - > joinedChamps . add ( bc . getChampion ( ) . getName ( ) ) ) ;
sb . append ( " - Bans: " ) . append ( joinedChamps . toString ( ) ) ;
}
sb . append ( "\n" ) ;
swapped = true ;
}
CurrentMatchPlayersData currentParticipant = new CurrentMatchPlayersData ( ) ;
// Summoner Name + Champ
sb . append ( "* " ) . append ( String . format ( "%1$-" + maxNameChampLength + "s" , i . getSummonerName ( ) + " (" + i . getChampion ( ) . getName ( ) + ")" ) ) . append ( " - " ) ;
currentParticipant . summonerName = i . getSummonerName ( ) ;
currentParticipant . side = i . getTeam ( ) ;
currentParticipant . championName = i . getChampion ( ) . getName ( ) ;
currentParticipant . summonerSpell1Name = i . getSummonerSpell1 ( ) . getName ( ) ;
currentParticipant . summonerSpell2Name = i . getSummonerSpell2 ( ) . getName ( ) ;
// SoloQ Ranked stats
for ( int count = 1 ; count > 0 ; count + + )
@ -249,7 +217,10 @@ public class LeagueOfDiscordModule extends AbstractModule
for ( League j : i . getSummoner ( ) . getLeagueEntries ( ) )
if ( j . getQueueType ( ) . equals ( QueueType . RANKED_SOLO_5x5 ) )
{
sb . append ( String . format ( "%1$-" + 12 + "s" , j . getTier ( ) . toString ( ) + " " + j . getParticipantEntry ( ) . getDivision ( ) ) ) ;
LeagueEntry div = j . getParticipantEntry ( ) ;
currentParticipant . leagueDivision = j . getTier ( ) . toString ( ) + " " + div . getDivision ( ) ;
currentParticipant . LP = div . getLeaguePoints ( ) ;
currentParticipant . ratio = ( int ) Math . round ( ( double ) div . getWins ( ) / ( div . getWins ( ) + div . getLosses ( ) ) * 100 ) ;
count = - 1 ;
break ;
}
@ -259,7 +230,6 @@ public class LeagueOfDiscordModule extends AbstractModule
switch ( e . getStatus ( ) )
{
case NOT_FOUND : // Silently ignore HTTP404 which is OK and means "Unranked"
sb . append ( String . format ( "%1$-" + 12 + "s" , "Unranked" ) ) ;
count = - 1 ;
break ;
case RATE_LIMIT_EXCEEDED :
@ -267,45 +237,90 @@ public class LeagueOfDiscordModule extends AbstractModule
break ;
case INTERNAL_SERVER_ERROR :
case SERVICE_UNAVAILABLE :
if ( count > = 5 ) sb. append ( "(Unavailable)" ) ;
if ( count > = 5 ) currentParticipant. leagueDivision = "(Unavailable)" ;
break ;
default :
throw e ;
}
}
sb . append ( " - " ) ;
// Summoner Spells
sb . append ( String . format ( "%1$-" + maxSummonerSpellLength + "s" , i . getSummonerSpell1 ( ) . getName ( ) + "/" + i . getSummonerSpell2 ( ) . getName ( ) ) ) . append ( " - " ) ;
// Masteries
Mastery keystone = null ;
int ferocity = 0 , cunning = 0 , resolve = 0 ;
for ( MasteryRank j : i . getMasteries ( ) ) // TODO: May crash ? Wait and see
{
if ( LongStream . of ( KEYSTONES_ID ) . anyMatch ( x - > x = = j . getMasteryID ( ) ) )
keystone = j . getMastery ( ) ;
currentParticipant. keystone = j . getMastery ( ) . getName ( ) ;
switch ( j . getMastery ( ) . getType ( ) )
{
case Ferocity :
ferocity + = j . getRank ( ) ;
currentParticipant. masteries [ 0 ] + = j . getRank ( ) ;
break ;
case Cunning :
cu nning + = j . getRank ( ) ;
cu rrentParticipant. masteries [ 1 ] + = j . getRank ( ) ;
break ;
case Resolve :
resolve + = j . getRank ( ) ;
currentParticipant. masteries [ 2 ] + = j . getRank ( ) ;
break ;
}
}
sb . append ( "[" ) . append ( ferocity ) . append ( "/" ) . append ( cunning ) . append ( "/" ) . append ( resolve ) . append ( "] " )
. append ( keystone ! = null ? keystone . getName ( ) : "No keystone" ) ;
// Next guy
participantsData . add ( currentParticipant ) ;
}
// Get all the max /o/
CurrentMatchPlayersData longestNames = participantsData . stream ( ) . max ( ( pd1 , pd2 ) - > Integer . compare ( pd1 . summonerName . length ( ) + pd1 . championName . length ( ) , pd2 . summonerName . length ( ) + pd2 . championName . length ( ) ) ) . get ( ) ;
int maxSummonerChamp = longestNames . summonerName . length ( ) + longestNames . championName . length ( ) + 3 ; // Inkl. " ()"
int maxLDLength = participantsData . stream ( ) . max ( ( pd1 , pd2 ) - > Integer . compare ( pd1 . leagueDivision . length ( ) , pd2 . leagueDivision . length ( ) ) ) . get ( ) . leagueDivision . length ( ) ;
CurrentMatchPlayersData longestSpells = participantsData . stream ( ) . max ( ( pd1 , pd2 ) - > Integer . compare ( pd1 . summonerSpell1Name . length ( ) + pd1 . summonerSpell2Name . length ( ) , pd2 . summonerSpell1Name . length ( ) + pd2 . summonerSpell2Name . length ( ) ) ) . get ( ) ;
int maxSummonerSpell = longestSpells . summonerSpell1Name . length ( ) + longestSpells . summonerSpell2Name . length ( ) + 1 ;
// Format all the things \o\
Consumer < CurrentMatchPlayersData > printer = ( x - > {
sb . append ( "* " ) . append ( StringUtils . rightPad ( x . summonerName + " (" + x . championName + ")" , maxSummonerChamp ) ) . append ( " - " ) ;
sb . append ( StringUtils . rightPad ( x . leagueDivision , maxLDLength ) ) ;
sb . append ( StringUtils . leftPad ( x . leagueDivision . equals ( "Unranked" ) ? "" : x . LP + "LP " + x . ratio + "%" , 11 ) ) . append ( " - " ) ;
sb . append ( StringUtils . rightPad ( x . summonerSpell1Name + "/" + x . summonerSpell2Name , maxSummonerSpell ) ) . append ( " - " ) ;
sb . append ( "[" ) . append ( String . format ( "%02d" , x . masteries [ 0 ] ) )
. append ( "/" ) . append ( String . format ( "%02d" , x . masteries [ 1 ] ) )
. append ( "/" ) . append ( String . format ( "%02d" , x . masteries [ 2 ] ) ) . append ( "] " ) ;
sb . append ( x . keystone ) . append ( "\n" ) ;
} ) ;
// Print all the things \o/
sb . append ( "Team Blue" ) ;
if ( ! ginfo . getBannedChampions ( ) . isEmpty ( ) ) // Bans, if any
{
StringJoiner joinedChamps = new StringJoiner ( "/" ) ;
ginfo . getBannedChampions ( ) . stream ( ) . filter ( bc - > bc . getTeam ( ) . equals ( Side . BLUE ) ) . forEach ( bc - > joinedChamps . add ( bc . getChampion ( ) . getName ( ) ) ) ; // WOW, MUCH STREAMS, MANY LAMBDA
sb . append ( " - Bans: " ) . append ( joinedChamps . toString ( ) ) ;
}
sb . append ( "\n" ) ;
participantsData . stream ( ) . filter ( x - > x . side . equals ( Side . BLUE ) ) . forEach ( printer ) ;
sb . append ( "\nTeam Purple" ) ;
if ( ! ginfo . getBannedChampions ( ) . isEmpty ( ) ) // Bans, if any
{
StringJoiner joinedChamps = new StringJoiner ( "/" ) ;
ginfo . getBannedChampions ( ) . stream ( ) . filter ( bc - > bc . getTeam ( ) . equals ( Side . PURPLE ) ) . forEach ( bc - > joinedChamps . add ( bc . getChampion ( ) . getName ( ) ) ) ; // WOW, MUCH STREAMS, MANY LAMBDA
sb . append ( " - Bans: " ) . append ( joinedChamps . toString ( ) ) ;
}
sb . append ( "\n" ) ;
participantsData . stream ( ) . filter ( x - > x . side . equals ( Side . PURPLE ) ) . forEach ( printer ) ;
return sb . toString ( ) ;
}
private class CurrentMatchPlayersData
{
String summonerName ;
Side side ;
String championName ;
String leagueDivision = "Unranked" ;
int LP ;
int ratio ;
String summonerSpell1Name ;
String summonerSpell2Name ;
int [ ] masteries = new int [ 3 ] ;
String keystone = "No Keystone" ;
}
}