Skip to content

Commit

Permalink
v0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Statuxia committed Jul 16, 2022
1 parent d1bbf81 commit 3557c88
Show file tree
Hide file tree
Showing 8 changed files with 616 additions and 62 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
mainClassName = "me.statuxia.Main"

group 'me.statuxia'
version '0.1.2'
version '0.1.3'

repositories {
mavenCentral()
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/me/statuxia/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package me.statuxia;

import me.statuxia.commands.Admin;
import me.statuxia.commands.Everyone;
import me.statuxia.utils.Config;
import me.statuxia.voice.Voice;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
Expand All @@ -24,6 +26,8 @@ public static void main(String[] args)
.setActivity(Activity.watching(">help"))
.setStatus(OnlineStatus.ONLINE)
.addEventListeners(new Admin())
.addEventListeners(new Voice())
.addEventListeners(new Everyone())
.build();
bot = jda.getSelfUser();
}
Expand Down
77 changes: 63 additions & 14 deletions src/main/java/me/statuxia/commands/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
import me.statuxia.utils.MySQLConnector;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.GuildChannel;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;

import java.awt.*;
import java.sql.SQLException;
import java.util.EnumSet;
import java.util.Objects;

public class Admin extends ListenerAdapter {


@Override
public void onMessageReceived(MessageReceivedEvent event) {
Member member = event.getMember();
Expand All @@ -26,10 +26,6 @@ public void onMessageReceived(MessageReceivedEvent event) {

Message msg = event.getMessage();
if (!member.hasPermission(Permission.ADMINISTRATOR)) {
embed.setTitle("Something's wrong...");
embed.setDescription("You don't have permissions to do that.");
embed.setColor(Color.RED);
msg.replyEmbeds(embed.build()).queue();
return;
}
if (!event.isFromGuild()) {
Expand All @@ -48,7 +44,7 @@ public void onMessageReceived(MessageReceivedEvent event) {
return;
}

if (msg.getContentRaw().toLowerCase().startsWith(Config.PREFIX + "create")) {
if (msg.getContentRaw().toLowerCase().startsWith(Config.PREFIX + "voice create")) {
msg.getGuild().createVoiceChannel("[ + ]").setParent(msg.getCategory()).queue(channel -> {
try {
MySQLConnector.newChannelInserter(channel.getGuild().getIdLong(), channel.getIdLong());
Expand All @@ -60,13 +56,66 @@ public void onMessageReceived(MessageReceivedEvent event) {
throw new RuntimeException(e);
}
});
}

return;
if (msg.getContentRaw().toLowerCase().startsWith(Config.PREFIX + "voice block")) {
String[] content = msg.getContentRaw().split(" ");
String userString = content[content.length - 1].replaceAll("[<@!>]+", "");
Member user = msg.getGuild().getMemberById(userString);

if (user == null) {
embed.setTitle("Block!");
embed.setDescription("There is no user with id " + userString);
embed.setColor(Color.GREEN);
msg.replyEmbeds(embed.build()).queue();
return;
}

try {
long channelID = MySQLConnector.getChannelByGuildID(event.getGuild().getIdLong());
if (channelID == 0L) return;

GuildChannel channel = event.getGuild().getGuildChannelById(channelID);
if (channel == null) return;

channel.getManager().putPermissionOverride(user, null, EnumSet.of(Permission.VOICE_CONNECT)).queue();
embed.setTitle("Block!");
embed.setDescription(user.getAsMention() + " now can't join to the " + channel.getAsMention());
embed.setColor(Color.RED);
msg.replyEmbeds(embed.build()).queue();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
msg.reply("I don't know command " + msg.getContentRaw()).queue();
}

// TO DO
// Make this comamnds:
// >voice block {@user/id} - blocks the possibility of creating a channel.
}
if (msg.getContentRaw().toLowerCase().startsWith(Config.PREFIX + "voice unblock")) {
String[] content = msg.getContentRaw().split(" ");
String userString = content[content.length - 1].replaceAll("[<@!>]+", "");
Member user = msg.getGuild().getMemberById(userString);

if (user == null) {
embed.setTitle("Block!");
embed.setDescription("There is no user with id " + userString);
embed.setColor(Color.GREEN);
msg.replyEmbeds(embed.build()).queue();
return;
}

try {
long channelID = MySQLConnector.getChannelByGuildID(event.getGuild().getIdLong());
if (channelID == 0L) return;

GuildChannel channel = event.getGuild().getGuildChannelById(channelID);
if (channel == null) return;

channel.getManager().putPermissionOverride(user, EnumSet.of(Permission.VOICE_CONNECT), null).queue();
embed.setTitle("Unblock!");
embed.setDescription(user.getAsMention() + " now can join to the " + channel.getAsMention());
embed.setColor(Color.GREEN);
msg.replyEmbeds(embed.build()).queue();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
Loading

0 comments on commit 3557c88

Please sign in to comment.