Skip to content

Commit

Permalink
Commit #keineAhnungWas
Browse files Browse the repository at this point in the history
  • Loading branch information
DerBanko committed Jun 1, 2022
1 parent 0e32ecc commit 31c65f0
Show file tree
Hide file tree
Showing 32 changed files with 2,212 additions and 310 deletions.
10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

2 changes: 2 additions & 0 deletions src/main/java/tv/banko/valorantevent/ValorantEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public ValorantEvent() {
try {
this.discord = new Discord(this);
this.tournament = new Tournament(this);

this.tournament.load();
} catch (LoginException | InterruptedException e) {
e.printStackTrace();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/tv/banko/valorantevent/api/RankAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,23 @@ public CompletableFuture<RankAPIResponse> getRank(String nameWithTag) {

if (response.code() != 200) {
future.completeAsync(() -> new RankAPIResponse(response.code(), null));
response.close();
return;
}

ResponseBody body = response.body();

if (body == null) {
future.completeAsync(() -> new RankAPIResponse(404, null));
response.close();
return;
}

JSONObject json = new JSONObject(body.string());

if(json.getInt("status") != 200) {
future.completeAsync(() -> new RankAPIResponse(json.getInt("status"), null));
response.close();
return;
}

Expand All @@ -65,6 +68,8 @@ public CompletableFuture<RankAPIResponse> getRank(String nameWithTag) {
Rank rank = Rank.byId(data.getInt("currenttier"));

future.completeAsync(() -> new RankAPIResponse(200, rank));

response.close();
} catch (IOException e) {
e.printStackTrace();
future.completeAsync(() -> new RankAPIResponse(999, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
import tv.banko.valorantevent.tournament.team.TeamManager;
import tv.banko.valorantevent.util.GameId;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public record TeamCollection(Database database) {

public CompletableFuture<Team> getTeam(GameId gameId) {
CompletableFuture<Team> future = new CompletableFuture<>();
getCollection().find(Filters.eq("id", gameId.toString())).first((document, throwable) -> {
if (throwable == null) {
if (throwable != null || document == null) {
future.complete(null);
return;
}
Expand All @@ -31,6 +29,10 @@ public void loadTeams(TeamManager manager) {
getCollection().find().forEach(document -> {
manager.addTeam(new Team(database.getEvent(), document));
}, (unused, throwable) -> {
if (throwable == null) {
return;
}
throwable.printStackTrace();
});
}

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/tv/banko/valorantevent/discord/Discord.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import net.dv8tion.jda.api.utils.cache.CacheFlag;
import tv.banko.valorantevent.ValorantEvent;
import tv.banko.valorantevent.discord.command.CommandManager;
import tv.banko.valorantevent.discord.guild.GuildHelper;
import tv.banko.valorantevent.discord.listener.InteractionListeners;
import tv.banko.valorantevent.discord.message.TemplateMessage;

import javax.security.auth.login.LoginException;

Expand All @@ -17,12 +19,16 @@ public class Discord {
private final CommandManager command;

private final String guildId;
private final TemplateMessage template;
private final GuildHelper guildHelper;

public Discord(ValorantEvent event) throws LoginException, InterruptedException {
this.event = event;
this.template = new TemplateMessage(this);

this.guildId = System.getenv("GUILD_ID");
this.command = new CommandManager();
this.guildHelper = new GuildHelper(this);

JDABuilder builder = JDABuilder.createDefault(System.getenv("TOKEN"));

Expand All @@ -45,6 +51,14 @@ public JDA getBot() {
return bot;
}

public TemplateMessage getTemplate() {
return template;
}

public GuildHelper getGuildHelper() {
return guildHelper;
}

public String getGuildId() {
return guildId;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package tv.banko.valorantevent.discord.channel;

import net.dv8tion.jda.api.entities.Category;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.TextChannel;
import tv.banko.valorantevent.discord.Discord;
import tv.banko.valorantevent.discord.message.CommitteeMessage;
import tv.banko.valorantevent.tournament.match.Match;

public class CommitteeChannel {

private final Discord discord;
private final Match match;
private final CommitteeMessage message;

private String channelId;

public CommitteeChannel(Discord discord, Match match) {
this.discord = discord;
this.match = match;
this.message = new CommitteeMessage(match);

findCategory();
}

public CommitteeChannel(Discord discord, Match match, String channelId) {
this.discord = discord;
this.match = match;
this.channelId = channelId;
this.message = new CommitteeMessage(match);
}

public TextChannel getChannel() {

Guild guild = discord.getGuildHelper().getGuild();

if (guild == null) {
return null;
}

if (channelId == null) {
return null;
}

return guild.getTextChannelById(channelId);
}

public String getChannelId() {
return channelId;
}

public CommitteeMessage getMessage() {
return message;
}

private void findCategory() {

Guild guild = discord.getGuildHelper().getGuild();

if (guild == null) {
return;
}

String categoryName = "\uD83D\uDC6A | Committee";

Category category = guild.getCategoriesByName(categoryName, true)
.stream().findFirst().orElse(null);

if (category == null) {
guild.createCategory(categoryName).queue(this::createChannel);
return;
}

createChannel(category);
}

private void createChannel(Category category) {
category.createTextChannel("committee-" + match.getId().toString())
.queue(textChannel -> {
channelId = textChannel.getId();
message.startMapVote();
}, Throwable::printStackTrace);
}

}
124 changes: 101 additions & 23 deletions src/main/java/tv/banko/valorantevent/discord/channel/MatchChannel.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package tv.banko.valorantevent.discord.channel;

import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Category;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import tv.banko.valorantevent.discord.Discord;
import tv.banko.valorantevent.tournament.match.Match;
import tv.banko.valorantevent.tournament.team.Team;

import java.util.Collections;
import java.util.List;
Expand All @@ -33,7 +36,7 @@ public MatchChannel(Discord discord, Match match, String channelId) {

public TextChannel getChannel() {

Guild guild = discord.getBot().getGuildById(discord.getGuildId());
Guild guild = discord.getGuildHelper().getGuild();

if (guild == null) {
return null;
Expand All @@ -50,49 +53,124 @@ public String getChannelId() {
return channelId;
}

private void findCategory() {
public void sendChallenge(int round) {
try {
getChannel().sendMessageEmbeds(match.getRoundChallenge(round).getChallenge().getEmbedBuilder(round, match))
.content("Challenge der " + round + ". Runde <@&" + match.getTeam1().getRole().getRoleId() + "> <@&" +
match.getTeam2().getRole().getRoleId() + ">").queue();
} catch (Exception e) {
e.printStackTrace();
}
}

System.out.println("2");
public void sendMatchEnd(int end) {
try {
Team winner;

Team team1 = match.getTeam1();
Team team2 = match.getTeam2();

int wins1 = match.getTeam1Points().getWins();
int wins2 = match.getTeam2Points().getWins();

int challenges1 = match.getTeam1Points().getChallenges();
int challenges2 = match.getTeam2Points().getChallenges();

switch (end) {
case 1 -> winner = team1;
case 2 -> winner = team2;
default -> {
if (challenges1 > challenges2) {
winner = team1;
break;
}

if (challenges2 > challenges1) {
winner = team2;
break;
}

getChannel().sendMessageEmbeds(new EmbedBuilder()
.setTitle("<:check:950493473436487760> | Match beendet")
.setDescription("> Gewinner: *unentschieden*" +

"\n\n__**" + team1.getName() + "**__:" +
"\n> Gewonnene Runden: **" + wins1 +
"\n> Abgeschlossene Challenges: **" + challenges1 +

"\n\n__**" + team2.getName() + "**__:" +
"\n> Gewonnene Runden: **" + wins2 +
"\n> Abgeschlossene Challenges: **" + challenges2)
.build())
.content("Match beendet <@&" + match.getTeam1().getRole().getRoleId() + "> <@&" +
match.getTeam2().getRole().getRoleId() + ">")
.setActionRow(Button.primary("match:button:transcript", "Transcript anzeigen")).queue();
return;
}
}

getChannel().sendMessageEmbeds(new EmbedBuilder()
.setTitle("<:check:950493473436487760> | Match beendet")
.setDescription("> Gewinner: **" + winner.getName() + "**" +

"\n\n__**" + team1.getName() + "**__:" +
"\n> Gewonnene Runden: **" + wins1 +
"\n> Abgeschlossene Challenges: **" + challenges1 +

"\n\n__**" + team2.getName() + "**__:" +
"\n> Gewonnene Runden: **" + wins2 +
"\n> Abgeschlossene Challenges: **" + challenges2)
.build())
.content("Match beendet <@&" + match.getTeam1().getRole().getRoleId() + "> <@&" +
match.getTeam2().getRole().getRoleId() + ">")
.setActionRow(Button.primary("match:button:transcript", "Transcript anzeigen")).queue();
} catch (Exception e) {
e.printStackTrace();
}
}

private void findCategory() {

Guild guild = discord.getBot().getGuildById(discord.getGuildId());
Guild guild = discord.getGuildHelper().getGuild();

if (guild == null) {
System.out.println("3");
return;
}

System.out.println("4");

String categoryName = "\uD83C\uDFB3 | Matches";

Category category = guild.getCategoriesByName(categoryName, true)
.stream().findFirst().orElse(null);

if (category == null) {
System.out.println("5");
guild.createCategory(categoryName).queue(this::createChannel);
return;
}

System.out.println("6");

createChannel(category);
}

private void createChannel(Category category) {
System.out.println("7");

Role publicRole = category.getGuild().getPublicRole();

System.out.println("7,5");

category.createTextChannel("match-" + match.getId().toString())
.addPermissionOverride(publicRole, List.of(Permission.MESSAGE_SEND), List.of(Permission.VIEW_CHANNEL))
.addRolePermissionOverride(match.getTeam1().getRole().getId(), List.of(Permission.VIEW_CHANNEL), Collections.emptyList())
.addRolePermissionOverride(match.getTeam2().getRole().getId(), List.of(Permission.VIEW_CHANNEL), Collections.emptyList())
.queue(textChannel -> channelId = textChannel.getId(), Throwable::printStackTrace);

System.out.println("8");
new Thread(() -> {
Role publicRole = category.getGuild().getPublicRole();

while (match.getTeam1().getRole().getRoleId() == null || match.getTeam2().getRole().getRoleId() == null) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

category.createTextChannel("match-" + match.getId().toString())
.addPermissionOverride(publicRole, List.of(Permission.MESSAGE_SEND), List.of(Permission.VIEW_CHANNEL))
.addRolePermissionOverride(match.getTeam1().getRole().getId(), List.of(Permission.VIEW_CHANNEL), Collections.emptyList())
.addRolePermissionOverride(match.getTeam2().getRole().getId(), List.of(Permission.VIEW_CHANNEL), Collections.emptyList())
.queue(textChannel -> {
channelId = textChannel.getId();
match.getCommittee().getMessage().updateURL();
}, Throwable::printStackTrace);
}).start();
}

}
Loading

0 comments on commit 31c65f0

Please sign in to comment.