Deleted BGSoftwareBot.java
This commit is contained in:
parent
971f71b78d
commit
9feca17513
@ -1,26 +0,0 @@
|
|||||||
dependencies {
|
|
||||||
implementation(project(":core"))
|
|
||||||
implementation("net.dv8tion:JDA:4.2.0_228")
|
|
||||||
implementation("com.jagrosh:jda-utilities:3.0.5")
|
|
||||||
implementation("javax.json:javax.json-api:1.0")
|
|
||||||
}
|
|
||||||
|
|
||||||
val jar by tasks.getting(Jar::class) {
|
|
||||||
manifest {
|
|
||||||
attributes["Main-Class"] = "zone.themcgamer.discordbot.MGZBot"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks {
|
|
||||||
processResources {
|
|
||||||
val tokens = mapOf("version" to project.version)
|
|
||||||
from(sourceSets["main"].resources.srcDirs) {
|
|
||||||
filter<org.apache.tools.ant.filters.ReplaceTokens>("tokens" to tokens)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shadowJar {
|
|
||||||
archiveFileName.set("${project.rootProject.name}-${project.name}-v${project.version}.jar")
|
|
||||||
destinationDir = file("$rootDir/output")
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot;
|
|
||||||
|
|
||||||
import com.jagrosh.jdautilities.command.CommandClientBuilder;
|
|
||||||
import lombok.Getter;
|
|
||||||
import net.dv8tion.jda.api.JDA;
|
|
||||||
import net.dv8tion.jda.api.JDABuilder;
|
|
||||||
import net.dv8tion.jda.api.OnlineStatus;
|
|
||||||
import net.dv8tion.jda.api.entities.Activity;
|
|
||||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
|
||||||
import zone.themcgamer.discordbot.command.impl.*;
|
|
||||||
import zone.themcgamer.discordbot.events.GuildListener;
|
|
||||||
import zone.themcgamer.discordbot.events.HasteBinListener;
|
|
||||||
import zone.themcgamer.discordbot.events.MainGuildListener;
|
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class BGSoftwareBot {
|
|
||||||
@Getter private static BGSoftwareBot instance;
|
|
||||||
|
|
||||||
private JDA jda;
|
|
||||||
|
|
||||||
public BGSoftwareBot() {
|
|
||||||
instance = this;
|
|
||||||
long time = System.currentTimeMillis();
|
|
||||||
|
|
||||||
CommandClientBuilder commandClientBuilder = new CommandClientBuilder();
|
|
||||||
commandClientBuilder.setPrefix(BotConstants.PREFIX);
|
|
||||||
commandClientBuilder.setActivity(Activity.playing("BG-Software Harold"));
|
|
||||||
commandClientBuilder.setStatus(OnlineStatus.ONLINE);
|
|
||||||
commandClientBuilder.setOwnerId(BotConstants.OWNER_ID);
|
|
||||||
for (String botAdmin : BotConstants.BOT_ADMINS)
|
|
||||||
commandClientBuilder.setCoOwnerIds(botAdmin);
|
|
||||||
commandClientBuilder.useHelpBuilder(false);
|
|
||||||
|
|
||||||
commandClientBuilder.addCommand(new SetActivityCommand());
|
|
||||||
commandClientBuilder.addCommand(new InviteCommand());
|
|
||||||
commandClientBuilder.addCommand(new MessageCommand());
|
|
||||||
commandClientBuilder.addCommand(new EditMessageCommand());
|
|
||||||
commandClientBuilder.addCommand(new AddReactionToMessageCommand());
|
|
||||||
commandClientBuilder.addCommand(new MemberCountCommand());
|
|
||||||
commandClientBuilder.addCommand(new PingCommand());
|
|
||||||
|
|
||||||
try {
|
|
||||||
jda = JDABuilder.createDefault(BotConstants.TOKEN)
|
|
||||||
.setCallbackPool(Executors.newScheduledThreadPool(10))
|
|
||||||
.setActivity(Activity.playing("Booting up..."))
|
|
||||||
.setStatus(OnlineStatus.IDLE)
|
|
||||||
.enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_EMOJIS)
|
|
||||||
.addEventListeners(
|
|
||||||
commandClientBuilder.build(),
|
|
||||||
new MainGuildListener(this),
|
|
||||||
new GuildListener(this),
|
|
||||||
new HasteBinListener())
|
|
||||||
.build();
|
|
||||||
jda.awaitReady();
|
|
||||||
} catch (LoginException | InterruptedException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("Done (" + (System.currentTimeMillis() - time) + ")! For help, type \"help\" or \"?\"\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
new BGSoftwareBot();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nicholas
|
|
||||||
*/
|
|
||||||
public class BotConstants {
|
|
||||||
public static final String TOKEN = "ODQ1Njk2NDk0ODA3OTQxMTcx.YKkuPA.g9Xhoc_r-tnlf8sYes9LAIL2vaE";
|
|
||||||
public static final String PREFIX = ".";
|
|
||||||
|
|
||||||
public static final String OWNER_ID = "504069946528104471"; // Joel
|
|
||||||
public static final String[] BOT_ADMINS = new String[] {
|
|
||||||
"544533281992081408", // Omer_R
|
|
||||||
};
|
|
||||||
|
|
||||||
// Default Lines
|
|
||||||
public static final String COPYRIGHT = "© BG-Software - " + Calendar.getInstance().get(Calendar.YEAR);
|
|
||||||
|
|
||||||
// Channels
|
|
||||||
public static final String HAROLD_LOG = "845706257779654656";
|
|
||||||
public static final String WILDINSPECT = "554282614702211087";
|
|
||||||
public static final String WILDBUSTER = "554282630779109377";
|
|
||||||
public static final String WILDSTACKER = "554282642980470785";
|
|
||||||
public static final String WILDTOOLS = "554282655441747998";
|
|
||||||
public static final String WILDCHEST = "554282670272544769";
|
|
||||||
public static final String WILDLOADERS = "751895102422777886";
|
|
||||||
public static final String SUPERIORSKYBLOCK = "554282577322704896";
|
|
||||||
|
|
||||||
//Categories
|
|
||||||
public static final String SUPPORT_CATEGORY = "554281400145281025";
|
|
||||||
|
|
||||||
//Role IDS
|
|
||||||
public static final String SUPPORT_TEAM = "818064395636703243";
|
|
||||||
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.command;
|
|
||||||
|
|
||||||
import com.jagrosh.jdautilities.command.Command;
|
|
||||||
import com.jagrosh.jdautilities.command.CommandEvent;
|
|
||||||
import zone.themcgamer.discordbot.BotConstants;
|
|
||||||
import zone.themcgamer.discordbot.guild.Guild;
|
|
||||||
import zone.themcgamer.discordbot.utilities.GuildUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nicholas
|
|
||||||
*/
|
|
||||||
public abstract class BaseCommand extends Command {
|
|
||||||
protected List<Guild> guilds; // The guilds the command can be executed in
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(CommandEvent event) {
|
|
||||||
if (!guilds.contains(GuildUtils.matchGuild(event.getGuild().getId())))
|
|
||||||
return;
|
|
||||||
List<String> args = new ArrayList<>();
|
|
||||||
if (event.getArgs() != null && event.getArgs().length() > 0) {
|
|
||||||
String[] split = event.getMessage().getContentRaw()
|
|
||||||
.replaceFirst("(?i)" + Pattern.quote(BotConstants.PREFIX), "")
|
|
||||||
.split("\\s+");
|
|
||||||
args = Arrays.asList(split);
|
|
||||||
}
|
|
||||||
execute(event, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void execute(CommandEvent event, List<String> args);
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.command.impl;
|
|
||||||
|
|
||||||
import com.jagrosh.jdautilities.command.CommandEvent;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
|
||||||
import zone.themcgamer.discordbot.BGSoftwareBot;
|
|
||||||
import zone.themcgamer.discordbot.command.BaseCommand;
|
|
||||||
import zone.themcgamer.discordbot.guild.Guild;
|
|
||||||
import zone.themcgamer.discordbot.utilities.EmbedUtils;
|
|
||||||
import zone.themcgamer.discordbot.utilities.MessageUtils;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AddReactionToMessageCommand extends BaseCommand {
|
|
||||||
public AddReactionToMessageCommand() {
|
|
||||||
name = "addreaction";
|
|
||||||
aliases = new String[] { "react" };
|
|
||||||
help = "Edit a message from the bot.";
|
|
||||||
arguments = "<channelID> <messageID> <reaction>";
|
|
||||||
userPermissions = new Permission[] { Permission.ADMINISTRATOR };
|
|
||||||
guildOnly = true;
|
|
||||||
guilds = Arrays.asList(Guild.MAIN, Guild.TEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(CommandEvent event, List<String> args) {
|
|
||||||
if (args.size() < 3) {
|
|
||||||
MessageUtils.sendUsageMessage(event.getTextChannel(),this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextChannel textChannelById = BGSoftwareBot.getInstance().getJda().getTextChannelById(args.get(1));
|
|
||||||
if (textChannelById == null) {
|
|
||||||
event.reply("Channel does not exist!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
textChannelById.addReactionById(args.get(2), args.get(3)).queue(message -> {
|
|
||||||
|
|
||||||
}, error -> {
|
|
||||||
EmbedBuilder embedBuilder = EmbedUtils.errorEmbed();
|
|
||||||
embedBuilder.setDescription(error.getLocalizedMessage());
|
|
||||||
event.reply(embedBuilder.build());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
53
bgsoftware-discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/EditMessageCommand.java
53
bgsoftware-discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/EditMessageCommand.java
@ -1,53 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.command.impl;
|
|
||||||
|
|
||||||
import com.jagrosh.jdautilities.command.CommandEvent;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
|
||||||
import zone.themcgamer.discordbot.BGSoftwareBot;
|
|
||||||
import zone.themcgamer.discordbot.command.BaseCommand;
|
|
||||||
import zone.themcgamer.discordbot.guild.Guild;
|
|
||||||
import zone.themcgamer.discordbot.utilities.EmbedUtils;
|
|
||||||
import zone.themcgamer.discordbot.utilities.MessageUtils;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class EditMessageCommand extends BaseCommand {
|
|
||||||
public EditMessageCommand() {
|
|
||||||
name = "edit";
|
|
||||||
aliases = new String[] { "editmessage" };
|
|
||||||
help = "Edit a message from the bot.";
|
|
||||||
arguments = "<channelID> <messageID> <title> <description>";
|
|
||||||
userPermissions = new Permission[] { Permission.ADMINISTRATOR };
|
|
||||||
guildOnly = true;
|
|
||||||
guilds = Arrays.asList(Guild.MAIN, Guild.TEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(CommandEvent event, List<String> args) {
|
|
||||||
if (args.size() < 3) {
|
|
||||||
MessageUtils.sendUsageMessage(event.getTextChannel(), this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextChannel textChannelById = BGSoftwareBot.getInstance().getJda().getTextChannelById(args.get(1));
|
|
||||||
if (textChannelById == null) {
|
|
||||||
event.reply("Channel does not exist!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EmbedBuilder embedBuilder = EmbedUtils.defaultEmbed();
|
|
||||||
embedBuilder.setTitle(args.get(3).replace("_", " "));
|
|
||||||
embedBuilder.setDescription(event.getMessage().getContentRaw()
|
|
||||||
.replace("." + args.get(0), "")
|
|
||||||
.replace(args.get(1), "")
|
|
||||||
.replace(args.get(2), "")
|
|
||||||
.replace(args.get(3), ""));
|
|
||||||
textChannelById.editMessageById(args.get(2), embedBuilder.build()).queue(message -> {
|
|
||||||
event.replySuccess("Message has been edited!");
|
|
||||||
}, error -> {
|
|
||||||
event.reply("Message with this ID does not exist, are you sure this is the right id?");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.command.impl;
|
|
||||||
|
|
||||||
import com.jagrosh.jdautilities.command.CommandEvent;
|
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
|
||||||
import zone.themcgamer.discordbot.command.BaseCommand;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class InviteCommand extends BaseCommand {
|
|
||||||
|
|
||||||
public InviteCommand() {
|
|
||||||
name = "invite";
|
|
||||||
aliases = new String[]{"createinvite"};
|
|
||||||
help = "Create invite link via the bot";
|
|
||||||
guildOnly = true;
|
|
||||||
guilds = Collections.singletonList(zone.themcgamer.discordbot.guild.Guild.MAIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(CommandEvent event, List<String> args) {
|
|
||||||
Guild guild = event.getGuild();
|
|
||||||
|
|
||||||
TextChannel textChannelById = guild.getTextChannelById(791015530001596456L);
|
|
||||||
if (textChannelById == null)
|
|
||||||
return;
|
|
||||||
textChannelById.createInvite()
|
|
||||||
.timeout(1, TimeUnit.DAYS)
|
|
||||||
.setTemporary(true).queue(inviteLink -> {
|
|
||||||
event.getMember().getUser().openPrivateChannel().queue(privateChannel -> {
|
|
||||||
privateChannel.sendMessage("I have generated an invite link for you! This invite link will work for 24 hours! " + inviteLink.getUrl()).queue();
|
|
||||||
event.reply("Check your dm's!");
|
|
||||||
}, error -> {
|
|
||||||
event.replyError("Could not sent you a dm!");
|
|
||||||
}); }, error -> {
|
|
||||||
event.replyError("Coulnd't create an invite link due an error!");
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
26
bgsoftware-discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/JsonParseCommand.java
26
bgsoftware-discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/JsonParseCommand.java
@ -1,26 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.command.impl;
|
|
||||||
|
|
||||||
import com.jagrosh.jdautilities.command.CommandEvent;
|
|
||||||
import zone.themcgamer.discordbot.command.BaseCommand;
|
|
||||||
import zone.themcgamer.discordbot.guild.Guild;
|
|
||||||
import zone.themcgamer.discordbot.utilities.MessageUtils;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class JsonParseCommand extends BaseCommand {
|
|
||||||
public JsonParseCommand() {
|
|
||||||
name = "jsonparse";
|
|
||||||
help = "Parse your json!";
|
|
||||||
arguments = "<json>";
|
|
||||||
guildOnly = true;
|
|
||||||
guilds = Arrays.asList(Guild.MAIN, Guild.TEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(CommandEvent event, List<String> args) {
|
|
||||||
if (args.size() < 1) {
|
|
||||||
MessageUtils.sendUsageMessage(event.getTextChannel(), this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
37
bgsoftware-discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/MemberCountCommand.java
37
bgsoftware-discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/MemberCountCommand.java
@ -1,37 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.command.impl;
|
|
||||||
|
|
||||||
import com.jagrosh.jdautilities.command.CommandEvent;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import zone.themcgamer.discordbot.command.BaseCommand;
|
|
||||||
import zone.themcgamer.discordbot.guild.Guild;
|
|
||||||
import zone.themcgamer.discordbot.utilities.EmbedUtils;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MemberCountCommand extends BaseCommand {
|
|
||||||
|
|
||||||
public MemberCountCommand() {
|
|
||||||
name = "membercount";
|
|
||||||
aliases = new String[]{"members"};
|
|
||||||
help = "Shows the amount of members in the guild";
|
|
||||||
cooldown = 10;
|
|
||||||
arguments = "";
|
|
||||||
guildOnly = true;
|
|
||||||
guilds = Arrays.asList(Guild.MAIN, Guild.TEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(CommandEvent event, List<String> args) {
|
|
||||||
net.dv8tion.jda.api.entities.Guild guild = event.getGuild();
|
|
||||||
guild.loadMembers().onSuccess(members -> {
|
|
||||||
EmbedBuilder embedBuilder = EmbedUtils.defaultEmbed();
|
|
||||||
embedBuilder.setTitle("Member Count");
|
|
||||||
embedBuilder.addField("Humans", String.valueOf(members.stream().filter(member -> !member.getUser().isBot()).count()), true);
|
|
||||||
embedBuilder.addField("Bots", String.valueOf(members.stream().filter(member -> member.getUser().isBot()).count()), true);
|
|
||||||
|
|
||||||
event.getChannel().sendMessage(embedBuilder.build()).queue();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.command.impl;
|
|
||||||
|
|
||||||
import com.jagrosh.jdautilities.command.CommandEvent;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
|
||||||
import zone.themcgamer.discordbot.command.BaseCommand;
|
|
||||||
import zone.themcgamer.discordbot.guild.Guild;
|
|
||||||
import zone.themcgamer.discordbot.utilities.EmbedUtils;
|
|
||||||
import zone.themcgamer.discordbot.utilities.MessageUtils;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MessageCommand extends BaseCommand {
|
|
||||||
public MessageCommand() {
|
|
||||||
name = "message";
|
|
||||||
aliases = new String[] { "say" };
|
|
||||||
help = "Announce something in an embed format.";
|
|
||||||
arguments = "<title> <description>";
|
|
||||||
userPermissions = new Permission[] { Permission.ADMINISTRATOR };
|
|
||||||
guildOnly = true;
|
|
||||||
guilds = Arrays.asList(Guild.MAIN, Guild.TEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(CommandEvent event, List<String> args) {
|
|
||||||
if (args.size() < 1) {
|
|
||||||
MessageUtils.sendUsageMessage(event.getTextChannel(),this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO a way to add images, and such to the embeds.
|
|
||||||
EmbedBuilder embedBuilder = EmbedUtils.defaultEmbed();
|
|
||||||
embedBuilder.setTitle(args.get(1).replace("_", " "));
|
|
||||||
embedBuilder.setDescription(event.getMessage().getContentRaw().replace(args.get(1), "").replace("." + args.get(0), ""));
|
|
||||||
event.getChannel().sendMessage(embedBuilder.build()).queue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.command.impl;
|
|
||||||
|
|
||||||
import com.jagrosh.jdautilities.command.CommandEvent;
|
|
||||||
import zone.themcgamer.discordbot.command.BaseCommand;
|
|
||||||
import zone.themcgamer.discordbot.guild.Guild;
|
|
||||||
import zone.themcgamer.discordbot.utilities.EmbedUtils;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class PingCommand extends BaseCommand {
|
|
||||||
|
|
||||||
private static long inputTime;
|
|
||||||
|
|
||||||
public static void setInputTime(long inputTimeLong) {
|
|
||||||
inputTime = inputTimeLong;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Color getColorByPing(long ping) {
|
|
||||||
if (ping < 100)
|
|
||||||
return Color.cyan;
|
|
||||||
if (ping < 400)
|
|
||||||
return Color.green;
|
|
||||||
if (ping < 700)
|
|
||||||
return Color.yellow;
|
|
||||||
if (ping < 1000)
|
|
||||||
return Color.orange;
|
|
||||||
return Color.red;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PingCommand() {
|
|
||||||
name = "ping";
|
|
||||||
aliases = new String[]{"latency"};
|
|
||||||
help = "Get the latency of the bot to the guild.";
|
|
||||||
guildOnly = true;
|
|
||||||
guilds = Arrays.asList(Guild.MAIN, Guild.TEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(CommandEvent event, List<String> args) {
|
|
||||||
long processing = new Date().getTime() - inputTime;
|
|
||||||
long ping = event.getJDA().getGatewayPing();
|
|
||||||
event.getTextChannel().sendMessage(EmbedUtils.defaultEmbed().setColor(getColorByPing(ping)).setDescription(
|
|
||||||
String.format(":ping_pong: **Pong!**\n\nThe bot took `%s` milliseconds to response.\nIt took `%s` milliseconds to parse the command and the ping is `%s` milliseconds.",
|
|
||||||
processing + ping, processing, ping)
|
|
||||||
).build()).queue();
|
|
||||||
}
|
|
||||||
}
|
|
44
bgsoftware-discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/SetActivityCommand.java
44
bgsoftware-discordbot/src/main/java/zone/themcgamer/discordbot/command/impl/SetActivityCommand.java
@ -1,44 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.command.impl;
|
|
||||||
|
|
||||||
import com.jagrosh.jdautilities.command.CommandEvent;
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
|
||||||
import net.dv8tion.jda.api.entities.Activity;
|
|
||||||
import zone.themcgamer.discordbot.BGSoftwareBot;
|
|
||||||
import zone.themcgamer.discordbot.command.BaseCommand;
|
|
||||||
import zone.themcgamer.discordbot.guild.Guild;
|
|
||||||
import zone.themcgamer.discordbot.utilities.EmbedUtils;
|
|
||||||
import zone.themcgamer.discordbot.utilities.MessageUtils;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nicholas
|
|
||||||
*/
|
|
||||||
public class SetActivityCommand extends BaseCommand {
|
|
||||||
public SetActivityCommand() {
|
|
||||||
name = "setactivity";
|
|
||||||
help = "Set the bot activity.";
|
|
||||||
arguments = "<message>";
|
|
||||||
userPermissions = new Permission[] { Permission.ADMINISTRATOR };
|
|
||||||
guildOnly = true;
|
|
||||||
guilds = Arrays.asList(Guild.MAIN, Guild.TEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void execute(CommandEvent event, List<String> args) {
|
|
||||||
if (args.size() < 1) {
|
|
||||||
MessageUtils.sendUsageMessage(event.getTextChannel(),this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String activity = args.stream().skip(1).collect(Collectors.joining(" "));
|
|
||||||
BGSoftwareBot.getInstance().getJda().getPresence().setActivity(Activity.playing(activity));
|
|
||||||
event.getChannel().sendMessage(EmbedUtils.successEmbed()
|
|
||||||
.setThumbnail(event.getAuthor().getAvatarUrl())
|
|
||||||
.setTitle("Activity updated!")
|
|
||||||
.appendDescription(event.getAuthor().getAsTag() + " updated the bot activity to \"" + activity + "\".")
|
|
||||||
.build()
|
|
||||||
).queue();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.events;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import net.dv8tion.jda.api.entities.Category;
|
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
|
||||||
import zone.themcgamer.discordbot.BGSoftwareBot;
|
|
||||||
import zone.themcgamer.discordbot.BotConstants;
|
|
||||||
import zone.themcgamer.discordbot.utilities.EmbedUtils;
|
|
||||||
import zone.themcgamer.discordbot.utilities.GuildUtils;
|
|
||||||
import zone.themcgamer.discordbot.utilities.Responses;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class GuildListener extends ListenerAdapter {
|
|
||||||
private final BGSoftwareBot main;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onGuildMessageReceived(@Nonnull GuildMessageReceivedEvent event) {
|
|
||||||
Member member = event.getMember();
|
|
||||||
String contentRaw = event.getMessage().getContentRaw().toLowerCase();
|
|
||||||
String name = event.getChannel().getName();
|
|
||||||
|
|
||||||
if (member == null)
|
|
||||||
return;
|
|
||||||
if (member.getUser().isBot())
|
|
||||||
return;
|
|
||||||
if (GuildUtils.hasRole(member, BotConstants.SUPPORT_TEAM) == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (Responses value : Responses.values()) {
|
|
||||||
if (Arrays.asList(value.getTriggerWords()).contains(contentRaw)) {
|
|
||||||
if (!value.isRequireHelpCategory())
|
|
||||||
return;
|
|
||||||
if (!value.getRequiredChannel().equals(event.getChannel().getId()))
|
|
||||||
return;
|
|
||||||
EmbedBuilder embedBuilder = EmbedUtils.defaultEmbed();
|
|
||||||
embedBuilder.setTitle(value.getTitle().replace("{plugin}", (isSupportCategory(event.getMessage().getCategory()) ? name : value.getDefaultReplace())));
|
|
||||||
embedBuilder.setDescription(value.getDescription().replace("{plugin}", (isSupportCategory(event.getMessage().getCategory()) ? name : value.getDefaultReplace())));
|
|
||||||
event.getMessage().reply(embedBuilder.build()).queue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isSupportCategory(Category category) {
|
|
||||||
if (category == null)
|
|
||||||
return false;
|
|
||||||
return (category.getId().equals(BotConstants.SUPPORT_CATEGORY));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.events;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
|
||||||
import zone.themcgamer.discordbot.utilities.EmbedUtils;
|
|
||||||
import zone.themcgamer.discordbot.utilities.HasteBinHandler;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class HasteBinListener extends ListenerAdapter {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onGuildMessageReceived(@Nonnull GuildMessageReceivedEvent event) {
|
|
||||||
Member member = event.getMember();
|
|
||||||
if (member == null)
|
|
||||||
return;
|
|
||||||
if (member.getUser().isBot())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (event.getMessage().getContentRaw().contains("java.lang.")) {
|
|
||||||
HasteBinHandler hasteBinHandler = new HasteBinHandler();
|
|
||||||
try {
|
|
||||||
String url = hasteBinHandler.post(event.getMessage().getContentDisplay(), false);
|
|
||||||
EmbedBuilder embedBuilder = EmbedUtils.warnEmbed();
|
|
||||||
embedBuilder.setTitle("Hastebin");
|
|
||||||
embedBuilder.setDescription("I've noticed you pasted an error, this error has been pasted in hastebin for you!\n" +
|
|
||||||
"Please use this link and report it at github!");
|
|
||||||
embedBuilder.addField("Error", url, false);
|
|
||||||
} catch (IOException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.events;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
|
||||||
import net.dv8tion.jda.api.entities.User;
|
|
||||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
|
||||||
import zone.themcgamer.discordbot.BGSoftwareBot;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class MainGuildListener extends ListenerAdapter {
|
|
||||||
private final BGSoftwareBot mgzBot;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onGuildMemberJoin(@Nonnull GuildMemberJoinEvent event) {
|
|
||||||
Member member = event.getMember();
|
|
||||||
User user = event.getUser();
|
|
||||||
Guild guild = event.getGuild();
|
|
||||||
if (user.isBot())
|
|
||||||
return;
|
|
||||||
if (!guild.getId().equals(zone.themcgamer.discordbot.guild.Guild.MAIN.getGuildId()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.events;
|
|
||||||
|
|
||||||
public class TestGuildListener {
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.guild;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Nicholas
|
|
||||||
*/
|
|
||||||
@AllArgsConstructor @Getter
|
|
||||||
public enum Guild {
|
|
||||||
MAIN("554276823010246687"),
|
|
||||||
TEST("845696905496363078");
|
|
||||||
|
|
||||||
private final String guildId;
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.utilities;
|
|
||||||
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import zone.themcgamer.discordbot.BGSoftwareBot;
|
|
||||||
import zone.themcgamer.discordbot.BotConstants;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
public class EmbedUtils {
|
|
||||||
public static EmbedBuilder successEmbed() {
|
|
||||||
return defaultEmbed().setColor(Color.decode("#41bc7f"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EmbedBuilder errorEmbed() {
|
|
||||||
return defaultEmbed().setTitle("Oops!")
|
|
||||||
.setColor(Color.decode("#d74742"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EmbedBuilder warnEmbed() {
|
|
||||||
return defaultEmbed().setColor(Color.decode("#f85b2e"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EmbedBuilder defaultEmbed() {
|
|
||||||
return new EmbedBuilder()
|
|
||||||
.setColor(Color.decode("#1DD0D5"))
|
|
||||||
.setTimestamp(LocalDateTime.now())
|
|
||||||
.setFooter(BotConstants.COPYRIGHT, BGSoftwareBot.getInstance().getJda().getSelfUser().getEffectiveAvatarUrl());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.utilities;
|
|
||||||
|
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
|
||||||
import net.dv8tion.jda.api.entities.Role;
|
|
||||||
import zone.themcgamer.discordbot.guild.Guild;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author JohannesHQ
|
|
||||||
*/
|
|
||||||
public class GuildUtils {
|
|
||||||
public static Guild matchGuild(String guildId) {
|
|
||||||
return Arrays.stream(Guild.values()).filter(guild -> guild.getGuildId().equals(guildId)).findFirst().orElse(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Role hasRole(Member member, String id) {
|
|
||||||
List<Role> roles = member.getRoles();
|
|
||||||
return roles.stream()
|
|
||||||
.filter(role -> role.getId().equals(id)) // filter by role name
|
|
||||||
.findFirst() // take first result
|
|
||||||
.orElse(null); // else return null
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.utilities;
|
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
public class HasteBinHandler {
|
|
||||||
public String post(String text, boolean raw) throws IOException {
|
|
||||||
byte[] postData = text.getBytes(StandardCharsets.UTF_8);
|
|
||||||
int postDataLength = postData.length;
|
|
||||||
|
|
||||||
String requestURL = "https://hastebin.com/documents/";
|
|
||||||
URL url = new URL(requestURL);
|
|
||||||
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
|
|
||||||
conn.setDoOutput(true);
|
|
||||||
conn.setInstanceFollowRedirects(false);
|
|
||||||
conn.setRequestMethod("POST");
|
|
||||||
conn.setRequestProperty("User-Agent", "Hastebin Java Api");
|
|
||||||
conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
|
|
||||||
conn.setUseCaches(false);
|
|
||||||
|
|
||||||
String response = null;
|
|
||||||
DataOutputStream wr;
|
|
||||||
try {
|
|
||||||
wr = new DataOutputStream(conn.getOutputStream());
|
|
||||||
wr.write(postData);
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
|
||||||
response = reader.readLine();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.contains("\"key\"")) {
|
|
||||||
response = response.substring(response.indexOf(":") + 2, response.length() - 2);
|
|
||||||
|
|
||||||
String postURL = raw ? "https://hastebin.com/raw/" : "https://hastebin.com/";
|
|
||||||
response = postURL + response;
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.utilities;
|
|
||||||
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.entities.TextChannel;
|
|
||||||
import zone.themcgamer.discordbot.BGSoftwareBot;
|
|
||||||
import zone.themcgamer.discordbot.BotConstants;
|
|
||||||
import zone.themcgamer.discordbot.command.BaseCommand;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class MessageUtils {
|
|
||||||
public static void sendUsageMessage(TextChannel textChannel, BaseCommand command) {
|
|
||||||
textChannel.sendMessage(EmbedUtils.errorEmbed()
|
|
||||||
.appendDescription("Usage: " + BotConstants.PREFIX + command.getName() + " " + command.getArguments())
|
|
||||||
.build()
|
|
||||||
).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendLogMessage(Message message) {
|
|
||||||
Objects.requireNonNull(getLogChannel()).sendMessage(message).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendLogMessage(EmbedBuilder embedBuilder) {
|
|
||||||
Objects.requireNonNull(getLogChannel()).sendMessage(embedBuilder.build()).queue();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TextChannel getLogChannel() {
|
|
||||||
TextChannel logChannel = BGSoftwareBot.getInstance().getJda().getTextChannelById(BotConstants.HAROLD_LOG);
|
|
||||||
if (logChannel == null) {
|
|
||||||
Objects.requireNonNull(BGSoftwareBot.getInstance().getJda().getUserById("504069946528104471"))
|
|
||||||
.openPrivateChannel().queue(privateChannel ->
|
|
||||||
privateChannel.sendMessage("There was an error while sending a log message, the channel id is " +
|
|
||||||
"invalid or does not exist.").queue());
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return logChannel;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
package zone.themcgamer.discordbot.utilities;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import zone.themcgamer.discordbot.BotConstants;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Getter
|
|
||||||
public enum Responses {
|
|
||||||
PURCHASE("Purchase",
|
|
||||||
new String[] {"purchase", "buy"},
|
|
||||||
"Premium plugins at no cost!",
|
|
||||||
"Since 1st January, 2021, " +
|
|
||||||
"{plugin} is free, with all the features included to make sure you get the best quality for no cost!\u200B\n"+
|
|
||||||
"You can download the plugin [here](https://bg-software.com/{plugin})",
|
|
||||||
"Are all plugins",
|
|
||||||
false,
|
|
||||||
null),
|
|
||||||
ERROR("error",
|
|
||||||
new String[] {"java.lang", "org.bukkit.event", "error occurred while enabling", "error"},
|
|
||||||
"No errors!",
|
|
||||||
"Please do not paste stack-traces and or errors here!\n" +
|
|
||||||
"please report them at our [github](https://github.com/BG-Software-LLC)!",
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
null),
|
|
||||||
COMMANDS("commands",
|
|
||||||
new String[] {"commands", "cmds"},
|
|
||||||
"{plugin} - Commands",
|
|
||||||
"You can find the list of commands [here](https://wiki.bg-software.com/#/{plugin}/?id=commands)",
|
|
||||||
"not found",
|
|
||||||
true,
|
|
||||||
null),
|
|
||||||
DISABLE("Disable Commands",
|
|
||||||
new String[] {"disable command", "permissions"},
|
|
||||||
"How to disable a command?",
|
|
||||||
"All commands are based on permissions. If you want to disable or enable a command just give them the permission or not. You can find all permissions at the wiki of the plugin!\n" +
|
|
||||||
"You can find the permissions [here](https://wiki.bg-software.com/#/{plugin}/?id=permissions)",
|
|
||||||
"not found",
|
|
||||||
true,
|
|
||||||
null),
|
|
||||||
WIKI("Wiki",
|
|
||||||
new String[] {"wiki", "about"},
|
|
||||||
"{plugin} - Wiki",
|
|
||||||
"[Click here](https://bg-software.com/{plugin}/) for the wiki of the plugin {plugin}",
|
|
||||||
"not found",
|
|
||||||
true,
|
|
||||||
null),
|
|
||||||
PLACEHOLDERS("Placeholders",
|
|
||||||
new String[] {"placeholders"},
|
|
||||||
"{plugin} - Placeholders",
|
|
||||||
"You can find all placeholders of this plugin [here](https://wiki.bg-software.com/#/{plugin}/?id=placeholders)",
|
|
||||||
"not found",
|
|
||||||
true,
|
|
||||||
null),
|
|
||||||
WILDSTACKER_LOOT_TABLES("Loot Tables",
|
|
||||||
new String[] {"loot tables", "loot"},
|
|
||||||
"Loot Tables",
|
|
||||||
"Loot tables are used to store all the loot data of entities.\n" +
|
|
||||||
"They cannot be disabled, and they are used to calculate loot faster.\n" +
|
|
||||||
"They can be changed however you want, as long as you follow the formatting rules.\n" +
|
|
||||||
"\n" +
|
|
||||||
"Every file is represented as a \"loot table\". Loot tables contain global settings and pairs.\n" +
|
|
||||||
"Pairs contain the items, and can be manipulated differently to get different results.\n" +
|
|
||||||
"\n" +
|
|
||||||
"[Click Here](https://wiki.bg-software.com/#/wildstacker/loot-tables/) for more information!",
|
|
||||||
"not found",
|
|
||||||
true,
|
|
||||||
BotConstants.WILDSTACKER),
|
|
||||||
NOT_SAVING("No data saving",
|
|
||||||
new String[] {"not saving"},
|
|
||||||
"Is your settings not saving?",
|
|
||||||
"If you're using `/{plugin} settings` and you changed settings, make sure to go back to the main menu" +
|
|
||||||
"and click the `Save Settings` button.",
|
|
||||||
"pluginName",
|
|
||||||
false,
|
|
||||||
null);
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final String[] triggerWords;
|
|
||||||
private final String title;
|
|
||||||
private final String description;
|
|
||||||
private final String defaultReplace;
|
|
||||||
private final boolean requireHelpCategory;
|
|
||||||
private final String requiredChannel;
|
|
||||||
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
Manifest-Version: 1.0
|
|
||||||
Main-Class: zone.themcgamer.discordbot.MGZBot
|
|
||||||
|
|
@ -14,4 +14,3 @@ include("arcade")
|
|||||||
include("skyblock")
|
include("skyblock")
|
||||||
include("discordbot")
|
include("discordbot")
|
||||||
include("testing")
|
include("testing")
|
||||||
include("bgsoftware-discordbot")
|
|
||||||
|
Reference in New Issue
Block a user