Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update DiscordSocial depend #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
compileOnly("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")
annotationProcessor("com.velocitypowered:velocity-api:3.1.2-SNAPSHOT")

implementation("net.dv8tion:JDA:5.0.0-alpha.9") {
implementation("net.dv8tion:JDA:5.0.0-beta.2") {
exclude module: 'opus-java'
}
implementation('org.telegram:telegrambots:6.0.1')
Expand All @@ -52,7 +52,7 @@ dependencies {
implementation('org.bstats:bstats-velocity:3.0.0')
compileOnly('com.github.spotbugs:spotbugs-annotations:4.6.0')

implementation("com.maxmind.geoip2:geoip2:3.0.1")
implementation('com.maxmind.geoip2:geoip2:3.0.2')
implementation("org.apache.commons:commons-compress:1.21")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

import java.util.List;
import java.util.stream.Collectors;
import javax.security.auth.login.LoginException;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.exceptions.InvalidTokenException;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.LayoutComponent;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle;
import net.dv8tion.jda.api.requests.GatewayIntent;
Expand All @@ -54,11 +55,14 @@ public void init() throws SocialInitializationException {
try {
this.jda = JDABuilder
.create(Settings.IMP.MAIN.DISCORD.TOKEN, GatewayIntent.DIRECT_MESSAGES)
.disableCache(CacheFlag.ACTIVITY, CacheFlag.VOICE_STATE, CacheFlag.EMOTE, CacheFlag.CLIENT_STATUS, CacheFlag.ONLINE_STATUS)
.disableCache(
CacheFlag.ACTIVITY, CacheFlag.VOICE_STATE, CacheFlag.EMOJI, CacheFlag.CLIENT_STATUS, CacheFlag.ONLINE_STATUS, CacheFlag.STICKER,
CacheFlag.FORUM_TAGS
)
.build();

this.jda.addEventListener(new Listener(this::proceedMessage, this::proceedButton));
} catch (LoginException e) {
} catch (InvalidTokenException e) {
throw new SocialInitializationException(e);
}
}
Expand Down Expand Up @@ -87,20 +91,21 @@ public void onPlayerRemoved(SocialPlayer player) {

@SuppressWarnings("ConstantConditions")
private void parseCommands(Long id, List<String> commands) {
User user = this.jda.getUserById(id);
for (String argsString : commands) {
String[] args = argsString.split(" ");
String command = args[0];
switch (command) {
case "addrole": {
long roleId = Long.parseLong(args[1]);
Role role = this.jda.getRoleById(roleId);
role.getGuild().addRoleToMember(id, role).queue();
role.getGuild().addRoleToMember(user, role).queue();
break;
}
case "remrole": {
long roleId = Long.parseLong(args[1]);
Role role = this.jda.getRoleById(roleId);
role.getGuild().removeRoleFromMember(id, role).queue();
role.getGuild().removeRoleFromMember(user, role).queue();
break;
}
default: {
Expand All @@ -118,7 +123,7 @@ public void sendMessage(Long id, String content, List<List<ButtonItem>> buttons)
return;
}

List<ActionRow> actionRowList = buttons.stream().map(row ->
List<LayoutComponent> actionRowList = buttons.stream().map(row ->
ActionRow.of(row.stream().map(e -> {
ButtonStyle style;

Expand Down Expand Up @@ -149,7 +154,7 @@ public void sendMessage(Long id, String content, List<List<ButtonItem>> buttons)
.submit()
.thenAccept(privateChannel -> privateChannel
.sendMessage(content)
.setActionRows(actionRowList)
.setComponents(actionRowList)
.submit()
.exceptionally(e -> {
e.printStackTrace();
Expand Down