Fixed Commands not being registered
This commit is contained in:
parent
e545385e32
commit
24c5fe30b0
@ -3,10 +3,13 @@ package tech.nevets.constelliabot;
|
|||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.JDABuilder;
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
import net.dv8tion.jda.api.entities.Activity;
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
|
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||||
import org.simpleyaml.configuration.file.YamlFile;
|
import org.simpleyaml.configuration.file.YamlFile;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
public class Bot {
|
public class Bot {
|
||||||
public static JDA jda;
|
public static JDA jda;
|
||||||
private static YamlFile config;
|
private static YamlFile config;
|
||||||
@ -20,6 +23,12 @@ public class Bot {
|
|||||||
prefix = Config.getConfig().getString("bot.prefix");
|
prefix = Config.getConfig().getString("bot.prefix");
|
||||||
|
|
||||||
jda = JDABuilder.createDefault(token)
|
jda = JDABuilder.createDefault(token)
|
||||||
|
.disableCache(EnumSet.of(
|
||||||
|
CacheFlag.CLIENT_STATUS,
|
||||||
|
CacheFlag.ACTIVITY,
|
||||||
|
CacheFlag.EMOTE
|
||||||
|
))
|
||||||
|
.enableCache(CacheFlag.VOICE_STATE)
|
||||||
.addEventListeners(new Listener())
|
.addEventListeners(new Listener())
|
||||||
.build();
|
.build();
|
||||||
getActivity();
|
getActivity();
|
||||||
@ -34,6 +43,8 @@ public class Bot {
|
|||||||
jda.getPresence().setActivity(Activity.competing(config.getString("bot.action")));
|
jda.getPresence().setActivity(Activity.competing(config.getString("bot.action")));
|
||||||
} else if (config.getString("bot.activity").equalsIgnoreCase("listening")) {
|
} else if (config.getString("bot.activity").equalsIgnoreCase("listening")) {
|
||||||
jda.getPresence().setActivity(Activity.listening(config.getString("bot.action")));
|
jda.getPresence().setActivity(Activity.listening(config.getString("bot.action")));
|
||||||
|
} else if (config.getString("bot.activity").equalsIgnoreCase("debug")) {
|
||||||
|
jda.getPresence().setActivity(Activity.listening("my prefix " + prefix));
|
||||||
} else {
|
} else {
|
||||||
jda.getPresence().setActivity(Activity.playing("on Constellia SMP!"));
|
jda.getPresence().setActivity(Activity.playing("on Constellia SMP!"));
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,8 @@ public class Config {
|
|||||||
ymlFile.addDefault("command.api.dog.key", "00000000-0000-0000-0000-000000000000");
|
ymlFile.addDefault("command.api.dog.key", "00000000-0000-0000-0000-000000000000");
|
||||||
ymlFile.addDefault("command.api.fox.url", "https://randomfox.ca/floof/");
|
ymlFile.addDefault("command.api.fox.url", "https://randomfox.ca/floof/");
|
||||||
ymlFile.addDefault("command.api.panda.url", "https://some-random-api.ml/img/panda");
|
ymlFile.addDefault("command.api.panda.url", "https://some-random-api.ml/img/panda");
|
||||||
ymlFile.addDefault("command.api.redpanda.url", "https://some-random-api.ml/img/red_panda");
|
//ymlFile.addDefault("command.api.redpanda.url", "https://some-random-api.ml/img/red_panda");
|
||||||
ymlFile.addDefault("command.api.bird.url", "https://some-random-api.ml/img/birb");
|
//ymlFile.addDefault("command.api.bird.url", "https://some-random-api.ml/img/birb");
|
||||||
ymlFile.addDefault("verbose", false);
|
ymlFile.addDefault("verbose", false);
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,17 +1,37 @@
|
|||||||
package tech.nevets.constelliabot;
|
package tech.nevets.constelliabot;
|
||||||
|
|
||||||
|
import me.duncte123.botcommons.BotCommons;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.events.ReadyEvent;
|
import net.dv8tion.jda.api.events.ReadyEvent;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import tech.nevets.constelliabot.commands.CommandManager;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class Listener extends ListenerAdapter {
|
public class Listener extends ListenerAdapter {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(Listener.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(Listener.class);
|
||||||
|
private final CommandManager manager = new CommandManager();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReady(@Nonnull ReadyEvent event) {
|
public void onReady(@Nonnull ReadyEvent event) {
|
||||||
LOGGER.info("{} is ready", event.getJDA().getSelfUser().getAsTag());
|
LOGGER.info("{} is ready", event.getJDA().getSelfUser().getAsTag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGuildMessageReceived(@Nonnull GuildMessageReceivedEvent event) {
|
||||||
|
User user = event.getAuthor();
|
||||||
|
|
||||||
|
if (user.isBot() || event.isWebhookMessage()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String raw = event.getMessage().getContentRaw();
|
||||||
|
|
||||||
|
if (raw.startsWith(Bot.prefix)) {
|
||||||
|
manager.handle(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package tech.nevets.constelliabot.commands;
|
package tech.nevets.constelliabot.commands;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
import tech.nevets.constelliabot.Config;
|
import tech.nevets.constelliabot.Bot;
|
||||||
import tech.nevets.constelliabot.commands.debug.PingCmd;
|
import tech.nevets.constelliabot.commands.debug.PingCmd;
|
||||||
import tech.nevets.constelliabot.commands.games.CoinFlipCmd;
|
import tech.nevets.constelliabot.commands.games.CoinFlipCmd;
|
||||||
import tech.nevets.constelliabot.commands.games.DadJokeCmd;
|
import tech.nevets.constelliabot.commands.games.DadJokeCmd;
|
||||||
import tech.nevets.constelliabot.commands.games.DiceCmd;
|
import tech.nevets.constelliabot.commands.games.DiceCmd;
|
||||||
import tech.nevets.constelliabot.commands.info.HelpCmd;
|
import tech.nevets.constelliabot.commands.info.HelpCmd;
|
||||||
|
import tech.nevets.constelliabot.commands.music.JoinCmd;
|
||||||
import tech.nevets.constelliabot.commands.pictures.CatCmd;
|
import tech.nevets.constelliabot.commands.pictures.CatCmd;
|
||||||
import tech.nevets.constelliabot.commands.pictures.DogCmd;
|
import tech.nevets.constelliabot.commands.pictures.DogCmd;
|
||||||
import tech.nevets.constelliabot.commands.pictures.FoxCmd;
|
import tech.nevets.constelliabot.commands.pictures.FoxCmd;
|
||||||
@ -32,6 +33,7 @@ public class CommandManager {
|
|||||||
addCommand(new FoxCmd());
|
addCommand(new FoxCmd());
|
||||||
addCommand(new GoodMorningCmd());
|
addCommand(new GoodMorningCmd());
|
||||||
addCommand(new HelpCmd(this));
|
addCommand(new HelpCmd(this));
|
||||||
|
//addCommand(new JoinCmd());
|
||||||
addCommand(new PandaCmd());
|
addCommand(new PandaCmd());
|
||||||
addCommand(new PingCmd());
|
addCommand(new PingCmd());
|
||||||
}
|
}
|
||||||
@ -64,10 +66,8 @@ public class CommandManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handle(GuildMessageReceivedEvent event) {
|
public void handle(GuildMessageReceivedEvent event) {
|
||||||
String prefix = Config.getConfig().getString("bot.prefix");
|
|
||||||
|
|
||||||
String[] split = event.getMessage().getContentRaw()
|
String[] split = event.getMessage().getContentRaw()
|
||||||
.replaceFirst("(?i)" + Pattern.quote(prefix), "")
|
.replaceFirst("(?i)" + Pattern.quote(Bot.prefix), "")
|
||||||
.split("\\s+");
|
.split("\\s+");
|
||||||
|
|
||||||
String invoke = split[0].toLowerCase();
|
String invoke = split[0].toLowerCase();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package tech.nevets.constelliabot.commands.info;
|
package tech.nevets.constelliabot.commands.info;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
import tech.nevets.constelliabot.Bot;
|
import tech.nevets.constelliabot.Bot;
|
||||||
import tech.nevets.constelliabot.commands.CommandContext;
|
import tech.nevets.constelliabot.commands.CommandContext;
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
package tech.nevets.constelliabot.commands.music;
|
||||||
|
|
||||||
|
import net.dv8tion.jda.api.entities.GuildVoiceState;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel;
|
||||||
|
import net.dv8tion.jda.api.entities.VoiceChannel;
|
||||||
|
import net.dv8tion.jda.api.managers.AudioManager;
|
||||||
|
import tech.nevets.constelliabot.commands.CommandContext;
|
||||||
|
import tech.nevets.constelliabot.commands.ICommand;
|
||||||
|
|
||||||
|
public class JoinCmd implements ICommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(CommandContext ctx) {
|
||||||
|
final TextChannel channel = ctx.getChannel();
|
||||||
|
final Member self = ctx.getSelfMember();
|
||||||
|
final GuildVoiceState selfVoiceState = self.getVoiceState();
|
||||||
|
|
||||||
|
if (selfVoiceState.inVoiceChannel()) {
|
||||||
|
channel.sendMessage("I am already in a voice channel").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Member member = ctx.getMember();
|
||||||
|
final GuildVoiceState memberVoiceState = member.getVoiceState();
|
||||||
|
|
||||||
|
if (!memberVoiceState.inVoiceChannel()) {
|
||||||
|
channel.sendMessage("You need to be in a voice channel to run this command").queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final AudioManager audioManager = ctx.getGuild().getAudioManager();
|
||||||
|
final VoiceChannel memberChannel = memberVoiceState.getChannel();
|
||||||
|
|
||||||
|
audioManager.openAudioConnection(memberChannel);
|
||||||
|
channel.sendMessageFormat("Connecting to `\uD83D\uDD0A %s`", memberChannel.getName()).queue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "join";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelp() {
|
||||||
|
return "Makes the bot join your voice channel";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user