Merge pull request #46 from BigBotNetwork/hax-dev
The ting goes grrrrra
This commit is contained in:
commit
23c7af5ba5
5 changed files with 193 additions and 2 deletions
|
|
@ -2,7 +2,9 @@ package com.bbn.hadder;
|
|||
|
||||
import com.bbn.hadder.commands.general.*;
|
||||
import com.bbn.hadder.commands.fun.GifCommand;
|
||||
import com.bbn.hadder.commands.misc.EqualsCommand;
|
||||
import com.bbn.hadder.commands.misc.GitHubCommand;
|
||||
import com.bbn.hadder.commands.misc.ScreenshareCommand;
|
||||
import com.bbn.hadder.commands.moderation.*;
|
||||
import com.bbn.hadder.commands.owner.RebootCommand;
|
||||
import com.bbn.hadder.commands.owner.ShutdownCommand;
|
||||
|
|
@ -53,7 +55,21 @@ public class Hadder {
|
|||
builder.setToken(config.getString("Token"));
|
||||
|
||||
|
||||
CommandHandler.cmdlist.addAll(List.of(new HelpCommand(), new TestCommand(), new BanCommand(), new PrefixCommand(), new ShutdownCommand(), new KickCommand(), new PingCommand(), new GifCommand(), new ClearCommand(), new GitHubCommand(), new RebootCommand()));
|
||||
CommandHandler.cmdlist.addAll(
|
||||
List.of(
|
||||
new HelpCommand(),
|
||||
new TestCommand(),
|
||||
new BanCommand(),
|
||||
new PrefixCommand(),
|
||||
new ShutdownCommand(),
|
||||
new KickCommand(),
|
||||
new PingCommand(),
|
||||
new GifCommand(),
|
||||
new ClearCommand(),
|
||||
new GitHubCommand(),
|
||||
new ScreenshareCommand(),
|
||||
new RebootCommand(),
|
||||
new EqualsCommand()));
|
||||
|
||||
builder.addEventListeners(
|
||||
new MentionListener(),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
package com.bbn.hadder.commands.misc;
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.utils.EventWaiter;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class EqualsCommand implements Command {
|
||||
@Override
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
event.getChannel().sendMessage(
|
||||
new MessageEditor()
|
||||
.setDefaultSettings(
|
||||
MessageEditor.Messagetype.INFO,
|
||||
new EmbedBuilder()
|
||||
.setTitle("Please send me the first String")
|
||||
).build()
|
||||
).queue();
|
||||
new EventWaiter().newOnMessageEventWaiter(msgevent -> {
|
||||
String firstString = msgevent.getMessage().getContentRaw();
|
||||
event.getChannel().sendMessage(
|
||||
new MessageEditor()
|
||||
.setDefaultSettings(
|
||||
MessageEditor.Messagetype.INFO,
|
||||
new EmbedBuilder()
|
||||
.setTitle("Please send me the second String")
|
||||
).build()
|
||||
).queue();
|
||||
new EventWaiter().newOnMessageEventWaiter(msgevent2 -> {
|
||||
String secondString = msgevent2.getMessage().getContentRaw();
|
||||
event.getChannel().sendMessage(
|
||||
new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, new EmbedBuilder()
|
||||
.setTitle((firstString.equals(secondString)) ? "Yes! The first string equals the second string!" : "Well yes, but actually No. This isn't the same.")
|
||||
.addField("First String", firstString, false)
|
||||
.addField("Second String", secondString, false)
|
||||
.addField("Result", String.valueOf(firstString.equals(secondString)), false)
|
||||
).build()
|
||||
).queue();
|
||||
}, event.getJDA(), event.getAuthor());
|
||||
}, event.getJDA(), event.getAuthor());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] labels() {
|
||||
return new String[]{"equals"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "Check's if two string are equal to each other";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String usage() {
|
||||
return "equals";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package com.bbn.hadder.commands.misc;
|
||||
|
||||
import com.bbn.hadder.commands.Command;
|
||||
import com.bbn.hadder.utils.EventWaiter;
|
||||
import com.bbn.hadder.utils.MessageEditor;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ScreenshareCommand implements Command {
|
||||
@Override
|
||||
public void executed(String[] args, MessageReceivedEvent event) {
|
||||
if (args.length>0) {
|
||||
if (args[0].matches("[0-9]*")&&args.length==1) {
|
||||
for (VoiceChannel vc : event.getGuild().getVoiceChannels()) {
|
||||
try {
|
||||
if (vc.getIdLong() == Long.parseLong(args[0])) {
|
||||
event.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, new EmbedBuilder()
|
||||
.setTitle("Here's your Url to share your Screen")
|
||||
.setDescription("http://discordapp.com/channels/" + event.getGuild().getId() + "/" + vc.getId() + "/")).build()).queue();
|
||||
return;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
event.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.ERROR, new EmbedBuilder()
|
||||
.setTitle("Wait, thats illegal")
|
||||
.setDescription("This Id is invalid. \nMaybe you entered a wrong Id? \n\nNote: Make sure the Voicechannel is on this Guild.")).build()).queue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<VoiceChannel> vcs = event.getGuild().getVoiceChannelsByName(String.join(" ", args), true);
|
||||
if (vcs.size() > 1) {
|
||||
EmbedBuilder eb = new EmbedBuilder()
|
||||
.setTitle("Please Choose a Voicechannel")
|
||||
.setDescription("There is more than one channel with this name");
|
||||
for (int i = 0; i < vcs.size(); i++) {
|
||||
VoiceChannel voiceChannel = vcs.get(i);
|
||||
eb.addField(i + ": " + voiceChannel.getName(), voiceChannel.getId(), false);
|
||||
}
|
||||
event.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.WARNING, eb).build()).queue();
|
||||
new EventWaiter().newOnMessageEventWaiter(msgevent -> {
|
||||
try {
|
||||
int i = Integer.parseInt(msgevent.getMessage().getContentRaw());
|
||||
if (vcs.size() > i) {
|
||||
event.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, new EmbedBuilder()
|
||||
.setTitle("Here's your Url to share your Screen")
|
||||
.setDescription("http://discordapp.com/channels/" + event.getGuild().getId() + "/" + vcs.get(i).getId() + "/")).build()).queue();
|
||||
} else {
|
||||
|
||||
event.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.ERROR, new EmbedBuilder()
|
||||
.setTitle("You specified a wrong number!")).build()).queue();
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
event.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.ERROR, new EmbedBuilder()
|
||||
.setTitle("Wait, thats illegal")
|
||||
.setDescription("This isn't a Number.")).build()).queue();
|
||||
}
|
||||
}, event.getJDA(), event.getAuthor());
|
||||
} else if (vcs.size()==0) {
|
||||
event.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.ERROR, new EmbedBuilder()
|
||||
.setTitle("Hol' up")
|
||||
.setDescription("There is no Voicechannel named like this. \n\nNote: Make sure the Voicechannel is on this Guild.")).build()).queue();
|
||||
} else {
|
||||
event.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, new EmbedBuilder()
|
||||
.setTitle("Here's your Url to share your Screen")
|
||||
.setDescription("http://discordapp.com/channels/" + event.getGuild().getId() + "/" + vcs.get(0).getId() + "/")).build()).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] labels() {
|
||||
return new String[]{"screenshare"};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "Give you a link with the screenshare url";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String usage() {
|
||||
return "screenshare <voicechannelid|voicechannelname>";
|
||||
}
|
||||
}
|
||||
29
src/main/java/com/bbn/hadder/utils/EventWaiter.java
Normal file
29
src/main/java/com/bbn/hadder/utils/EventWaiter.java
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package com.bbn.hadder.utils;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class EventWaiter {
|
||||
|
||||
public void newOnMessageEventWaiter(Consumer<GuildMessageReceivedEvent> onEvent, JDA jda, User user) {
|
||||
Object listener = new ListenerAdapter() {
|
||||
@Override
|
||||
public void onGuildMessageReceived(@Nonnull GuildMessageReceivedEvent event) {
|
||||
if (user==null) {
|
||||
onEvent.accept(event);
|
||||
event.getJDA().getShardManager().removeEventListener(this);
|
||||
} else if (event.getAuthor().getId().equals(user.getId())) {
|
||||
onEvent.accept(event);
|
||||
event.getJDA().getShardManager().removeEventListener(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
jda.getShardManager().addEventListener(listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ public class MessageEditor {
|
|||
break;
|
||||
|
||||
case WARNING:
|
||||
embedBuilder.setTitle("⚠ Warning ⚠").setColor(Color.ORANGE);
|
||||
embedBuilder.setColor(Color.ORANGE);
|
||||
break;
|
||||
|
||||
case NO_PERMISSION:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue