Skip to content

Commit

Permalink
Merge pull request #22 from tors42/chariot-dependency-update
Browse files Browse the repository at this point in the history
Update to chariot-0.0.67
  • Loading branch information
jalpp authored Jun 6, 2023
2 parents 3ae4cf3 + 2e7662e commit 567ce1c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 88 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>io.github.tors42</groupId>
<artifactId>chariot</artifactId>
<version>0.0.66</version>
<version>0.0.67</version>
</dependency>
<dependency>
<groupId>io.github.sornerol</groupId>
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/Controller/LichessBotRunner.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import chariot.Client;
import chariot.model.Enums;
import chariot.model.Event;
import chariot.model.GameEvent;
import chariot.model.GameStateEvent;
import chariot.model.VariantType;
import chariot.model.Enums.Speed;

import com.github.bhlangonijr.chesslib.*;
import com.github.bhlangonijr.chesslib.move.Move;

Expand All @@ -19,7 +22,7 @@ public static void main(String[] args) {
var client = Client.auth(System.getenv("lichess_bot_token"));
var bot = client.bot();
var events = bot.connect().stream();
var username = client.account().profile().get().username().toLowerCase();
var username = client.account().profile().get().name().toLowerCase();
String[] s = {"maia1", "maia5", "maia9", "charibot", "TurtleBot", "SxRandom", "zeekat", "roundmoundofrebounds", "WorstFish", "pawnrobot", "knucklefish", "LeelaRogue"};
int picker = s.length;
int index = new Random().nextInt(picker);
Expand All @@ -38,9 +41,9 @@ public static void main(String[] args) {
case challenge:

var challenge = (Event.ChallengeEvent) event;
boolean std = challenge.challenge().variant().name().equalsIgnoreCase("Standard");
boolean non_rated = challenge.challenge().rated();
boolean isCoores = challenge.challenge().speed().equalsIgnoreCase("correspondence");
boolean std = challenge.challenge().gameType().variant() == VariantType.Variant.standard;
boolean non_rated = challenge.challenge().gameType().rated();
boolean isCoores = challenge.challenge().gameType().timeControl().speed() == Speed.correspondence;
if(std && !non_rated && !isCoores ){
bot.acceptChallenge(event.id());
}else if(non_rated){
Expand Down Expand Up @@ -69,8 +72,8 @@ public static void main(String[] args) {
break;

case gameFinish:
bot.chat(event.id(), "Thanks for playing me! ggs", provider -> provider.player());
bot.chat(event.id(), "Thanks for watching!", provider -> provider.spectator());
bot.chat(event.id(), "Thanks for playing me! ggs");
bot.chatSpectators(event.id(), "Thanks for watching!");

break;

Expand All @@ -84,7 +87,7 @@ public static void main(String[] args) {



bot.chat(event.id(), "omg you are very strong.. I'm scared but hey good luck!!", provider -> provider.player());
bot.chat(event.id(), "omg you are very strong.. I'm scared but hey good luck!!");



Expand All @@ -105,7 +108,7 @@ public static void main(String[] args) {

try {

isWhite[0] = ((GameEvent.Full) gameEvent).white().name().toLowerCase().equals(username);
isWhite[0] = ((GameStateEvent.Full) gameEvent).white().name().toLowerCase().equals(username);
if (isWhite[0]) {
try {

Expand All @@ -128,7 +131,7 @@ public static void main(String[] args) {
case gameState:
try {

var names = ((GameEvent.State) gameEvent).moves().split(" ");
var names = ((GameStateEvent.State) gameEvent).moves().split(" ");
var whiteTurn = names.length % 2 == 0;

if (isWhite[0] == whiteTurn) {
Expand Down
26 changes: 8 additions & 18 deletions src/main/java/Controller/LiveStreamers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chariot.Client;
import chariot.model.StreamerStatus;
import chariot.model.*;
import net.dv8tion.jda.api.EmbedBuilder;

import java.awt.*;
Expand All @@ -18,7 +18,7 @@ public LiveStreamers(Client client){

public EmbedBuilder getTv(){

List<StreamerStatus> live = client.users().liveStreamers().stream().toList();
List<LiveStreamer> live = client.users().liveStreamers().stream().toList();

this.embedBuilder = new EmbedBuilder();

Expand All @@ -27,36 +27,26 @@ public EmbedBuilder getTv(){

for(int i = 0; i < 3; i++){

String title = "";

if(live.get(i).title().isPresent()){
title += live.get(i).title().get();
}else{
title += "";
}
String title = live.get(i).user().title().orElse("");

String presentlink = "";
String TwitchLink = "";
String YoutubeLink = "";

if(live.get(i).stream().service().equals("twitch")){
Optional<String> twitchLinks = live.get(i).streamer().twitch();
if(twitchLinks.isPresent()){
TwitchLink = twitchLinks.get();
if (live.get(i).streamer().twitch() instanceof Some<String> twitch) {
TwitchLink = twitch.value();
presentlink += "[**Twitch** \uD83D\uDD2E ](" + TwitchLink + ") " + "**"+ live.get(i).streamer().headline() + "**"+ "\n\n";

}
}else{
Optional<String> youtubelinks = live.get(i).streamer().youTube();
if(youtubelinks.isPresent()){
YoutubeLink = youtubelinks.get();
if (live.get(i).streamer().youtube() instanceof Some<String> youtube) {
YoutubeLink = youtube.value();
presentlink += "[**Youtube** \uD83D\uDD3A ](" + YoutubeLink + ") " + "**"+ live.get(i).streamer().headline() + "**"+ "\n\n";
}
}



getLivePeople +=" \uD83C\uDF99️ " + title + " **" + live.get(i).id() + "**" + " is **Live**! \n " + presentlink;
getLivePeople +=" \uD83C\uDF99️ " + title + " **" + live.get(i).user().id() + "**" + " is **Live**! \n " + presentlink;


}
Expand Down
70 changes: 23 additions & 47 deletions src/main/java/Controller/UserProfile.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import chariot.Client;
import chariot.model.Enums;
import chariot.model.One;
import chariot.model.PerfStat;
import chariot.model.PerformanceStatistics;
import chariot.model.ProvidedProfile;
import chariot.model.Some;
import chariot.model.User;

import java.util.List;
import java.util.Optional;

public class UserProfile extends UserObject{
Expand All @@ -20,7 +23,7 @@ public UserProfile(Client client, String userParsing){


public String getBlitzRatings(){
One<PerfStat> userBlitz = this.getClient().users().performanceStatisticsByIdAndType(this.getUserID(), Enums.PerfType.blitz);
One<PerformanceStatistics> userBlitz = this.getClient().users().performanceStatisticsByIdAndType(this.getUserID(), Enums.PerfType.blitz);


String blitzRating = " \uD83D\uDD25 **Blitz**: ?";
Expand All @@ -34,7 +37,7 @@ public String getBlitzRatings(){
}

public String getRapidRatings(){
One<PerfStat> userRapid = this.getClient().users().performanceStatisticsByIdAndType(this.getUserID(), Enums.PerfType.rapid);
One<PerformanceStatistics> userRapid = this.getClient().users().performanceStatisticsByIdAndType(this.getUserID(), Enums.PerfType.rapid);

String rapidRating = " \uD83D\uDC07 **Rapid**: ?";

Expand All @@ -47,7 +50,7 @@ public String getRapidRatings(){
}

public String getBulletRatings(){
One<PerfStat> userBullet = this.getClient().users().performanceStatisticsByIdAndType(this.getUserID(), Enums.PerfType.bullet);
One<PerformanceStatistics> userBullet = this.getClient().users().performanceStatisticsByIdAndType(this.getUserID(), Enums.PerfType.bullet);

String bulletRating = "\uD83D\uDD2B **Bullet**: ?";

Expand All @@ -60,7 +63,7 @@ public String getBulletRatings(){
}

public String getClassicalRatings(){
One<PerfStat> usercal = this.getClient().users().performanceStatisticsByIdAndType(this.getUserID(), Enums.PerfType.classical);
One<PerformanceStatistics> usercal = this.getClient().users().performanceStatisticsByIdAndType(this.getUserID(), Enums.PerfType.classical);

String calRating = "\uD83D\uDC22 **Classical**: ?";

Expand Down Expand Up @@ -100,7 +103,7 @@ public String getUserProfile(){

boolean cheater = user.tosViolation();

boolean closedaccount = user.closed();
boolean closedaccount = user.disabled();

if (cheater == true) {
return " This user has violated Lichess Terms of Service";
Expand All @@ -114,69 +117,46 @@ public String getUserProfile(){

if (cheater == false && closedaccount == false) {

Optional<User.Profile> profile = user.profile();
ProvidedProfile profile = user.profile();

if(profile.isPresent()) {
String name = user.id();

String name = user.id();
String bio = profile.bio().orElse("");

String bio = profile.get().bio();
int wins = user.accountStats().win();

int wins = user.count().win();
int lose = user.accountStats().loss();

int lose = user.count().loss();
int all = user.accountStats().all();

int all = user.count().all();
int draw = user.accountStats().draw();

int draw = user.count().draw();
int playing = user.accountStats().playing();

int playing = user.count().playing();

String userUrl = user.url();
String userUrl = user.url().toURL().toString();



boolean pat = user.patron();

String patWings = "";

if (user.profile().isEmpty()) {

return "can't generate profiles for user, not enough profile data";
}



String sayTitle = "";

Optional<String> titledPlayer = user.title();
String sayTitle = user.title().orElse("");

Boolean hasTitle;


if (titledPlayer.isPresent()) {
hasTitle = true;
} else {
hasTitle = false;
}

if (hasTitle == true) {
sayTitle += titledPlayer.get();
} else {
sayTitle += "";
}
Boolean hasTitle = user.title() instanceof Some<String>;

String sayrewards = "";
String embedRewards = "";

List<chariot.model.Trophy> trophies = user.trophies().orElse(List.of());

for (chariot.model.Trophy trophy : user.trophies()) {
for (chariot.model.Trophy trophy : trophies) {

UserTrophy userTrophy = new UserTrophy(trophy);
sayrewards += userTrophy.getImageLink() + "\n";
}

if(!user.trophies().isEmpty()) {
if(!trophies.isEmpty()) {

embedRewards += "\n\n ** \uD83D\uDCA0 Trophies:** \n\n" + sayrewards;

Expand All @@ -186,12 +166,8 @@ public String getUserProfile(){


this.sayProfile += sayTitle + " " + name + " " +StatusEmoji + "\n" +"**All Games**: " + all + "\n" + "** ⚔️ Won:** " + wins + " ** \uD83D\uDE14 Loss:** " + lose + " ** \uD83E\uDD1D Draw:** " + draw + "\n** ♗ Playing:** " + playing + "\n \uD83D\uDCB9 **Ratings**: \n" + this.getBlitzRatings() + "\n" + this.getRapidRatings() + "\n" + this.getBulletRatings() + "\n" + this.getClassicalRatings()+ embedRewards ;
}else{
return "Please add Bio to Your Profile!";
}

}
}
if (userPresent == false) {
return "User Not Present, Please try again";

Expand Down
14 changes: 2 additions & 12 deletions src/main/java/Model/UserDashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,11 @@ public EmbedBuilder getUserDashboard(){



if(userResult.isPresent() && !userResult.get().closed() && !userResult.get().tosViolation()){
if(userResult.isPresent() && !userResult.get().disabled() && !userResult.get().tosViolation()){

User user = userResult.get();

String title = "";

Optional<String> titleplayer = user.title();

if(titleplayer.isPresent()){
title += titleplayer.get();
}else{
title = "";
}


String title = user.title().orElse("");

One<StormDashboard> dash = this.getClient().puzzles().stormDashboard(this.getUserID());

Expand Down

0 comments on commit 567ce1c

Please sign in to comment.