Hax dev #50
9 changed files with 139 additions and 78 deletions
0
DEBUG
Normal file
0
DEBUG
Normal file
|
|
@ -18,7 +18,6 @@ import net.dv8tion.jda.api.sharding.DefaultShardManagerBuilder;
|
||||||
import net.dv8tion.jda.api.sharding.ShardManager;
|
import net.dv8tion.jda.api.sharding.ShardManager;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Hadder {
|
public class Hadder {
|
||||||
|
|
@ -41,7 +40,7 @@ public class Hadder {
|
||||||
|
|
||||||
builder.setShardsTotal(1);
|
builder.setShardsTotal(1);
|
||||||
builder.setActivity(Activity.streaming("on the BigBotNetwork", "https://twitch.tv/BigBotNetwork"));
|
builder.setActivity(Activity.streaming("on the BigBotNetwork", "https://twitch.tv/BigBotNetwork"));
|
||||||
builder.setToken(config.getToken());
|
builder.setToken(config.getBotToken());
|
||||||
|
|
||||||
|
|
||||||
CommandHandler commandHandler = new CommandHandler(
|
CommandHandler commandHandler = new CommandHandler(
|
||||||
|
|
@ -58,14 +57,15 @@ public class Hadder {
|
||||||
new GitHubCommand(),
|
new GitHubCommand(),
|
||||||
new ScreenshareCommand(),
|
new ScreenshareCommand(),
|
||||||
new RebootCommand(),
|
new RebootCommand(),
|
||||||
new EqualsCommand()), config);
|
new EqualsCommand(),
|
||||||
|
new GuildPrefixCommand()), config);
|
||||||
|
|
||||||
builder.addEventListeners(
|
builder.addEventListeners(
|
||||||
new MentionListener(),
|
new MentionListener(rethink),
|
||||||
new PrivateMessageListener(),
|
new PrivateMessageListener(),
|
||||||
new CommandListener(rethink, commandHandler),
|
new CommandListener(rethink, commandHandler),
|
||||||
new GuildListener(rethink),
|
new GuildListener(rethink, config),
|
||||||
new ReadyListener(rethink));
|
new ReadyListener(rethink, config));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
shardManager = builder.build();
|
shardManager = builder.build();
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ public class BanCommand implements Command {
|
||||||
if (event.getMessage().getMentionedMembers().size() == 1) {
|
if (event.getMessage().getMentionedMembers().size() == 1) {
|
||||||
Member victim = event.getMessage().getMentionedMembers().get(0);
|
Member victim = event.getMessage().getMentionedMembers().get(0);
|
||||||
if (!event.getAuthor().getId().equals(victim.getId())) {
|
if (!event.getAuthor().getId().equals(victim.getId())) {
|
||||||
if (event.getJDA().getSelfUser().getId().equals(victim.getId())) {
|
if (!event.getJDA().getSelfUser().getId().equals(victim.getId())) {
|
||||||
if (event.getGuild().getSelfMember().canInteract(victim)) {
|
if (event.getGuild().getSelfMember().canInteract(victim)) {
|
||||||
event.getGuild().ban(victim, 0, "Banned by " + event.getAuthor().getAsTag()).queue();
|
event.getGuild().ban(victim, 0, "Banned by " + event.getAuthor().getAsTag()).queue();
|
||||||
EmbedBuilder builder = new EmbedBuilder();
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,12 @@ public class CommandHandler {
|
||||||
|
|
||||||
public void handle(MessageReceivedEvent event, Rethink rethink, String prefix) {
|
public void handle(MessageReceivedEvent event, Rethink rethink, String prefix) {
|
||||||
StringBuilder regexBuilder = new StringBuilder().append("\\").append(prefix);
|
StringBuilder regexBuilder = new StringBuilder().append("\\").append(prefix);
|
||||||
String invoke = event.getMessage().getContentRaw().replaceFirst(regexBuilder.toString(), "").split(" ")[0];
|
String invoke = event.getMessage().getContentRaw().replaceFirst(prefix, "").split(" ")[0];
|
||||||
for (Command cmd : commandList) {
|
for (Command cmd : commandList) {
|
||||||
for (String label : cmd.labels()) {
|
for (String label : cmd.labels()) {
|
||||||
if (label.equals(invoke)) {
|
if (label.equals(invoke)) {
|
||||||
String argString = event.getMessage().getContentRaw()
|
String argString = event.getMessage().getContentRaw()
|
||||||
.replaceFirst(regexBuilder.toString(), "").replaceFirst(invoke, "");
|
.replaceFirst(prefix, "").replaceFirst(invoke, "");
|
||||||
if (argString.startsWith(" ")) argString = argString.replaceFirst(" ", "");
|
if (argString.startsWith(" ")) argString = argString.replaceFirst(" ", "");
|
||||||
String[] args = argString.split(" ");
|
String[] args = argString.split(" ");
|
||||||
if (args.length>0&&args[0].equals("")) args = new String[0];
|
if (args.length>0&&args[0].equals("")) args = new String[0];
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ public class Config {
|
||||||
|
|
||||||
private String defaultConfigContent() {
|
private String defaultConfigContent() {
|
||||||
return new JSONStringer().object()
|
return new JSONStringer().object()
|
||||||
.key("Token").value(null)
|
|
||||||
.key("Owners").value(new Long[]{477141528981012511L, 261083609148948488L})
|
.key("Owners").value(new Long[]{477141528981012511L, 261083609148948488L})
|
||||||
.key("Database").object()
|
.key("Database").object()
|
||||||
.key("IP").value("127.0.0.1")
|
.key("IP").value("127.0.0.1")
|
||||||
|
|
@ -51,11 +50,20 @@ public class Config {
|
||||||
.key("DBName").value("Hadder")
|
.key("DBName").value("Hadder")
|
||||||
.key("Username").value(null)
|
.key("Username").value(null)
|
||||||
.key("Password").value(null)
|
.key("Password").value(null)
|
||||||
|
.endObject()
|
||||||
|
.key("Tokens").object()
|
||||||
|
.key("BotToken").value(null)
|
||||||
|
.key("Giphy").value(null)
|
||||||
|
.key("MythicalBotList").value(null)
|
||||||
|
.key("BotsForDiscord").value(null)
|
||||||
|
.key("DiscordBotList").value(null)
|
||||||
|
.key("DiscordBestBots").value(null)
|
||||||
|
.key("DiscordBoats").value(null)
|
||||||
.endObject().endObject().toString();
|
.endObject().endObject().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getToken() {
|
public String getBotToken() {
|
||||||
return config.getString("Token");
|
return config.getJSONObject("Tokens").getString("BotToken");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Object> getOwners() {
|
public List<Object> getOwners() {
|
||||||
|
|
@ -82,4 +90,27 @@ public class Config {
|
||||||
return config.getJSONObject("Database").getString("Password");
|
return config.getJSONObject("Database").getString("Password");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getGiphyToken() {
|
||||||
|
return config.getJSONObject("Tokens").getString("Giphy");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMythicalBotListToken() {
|
||||||
|
return config.getJSONObject("Tokens").getString("MythicalBotList");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBotsForDiscordToken() {
|
||||||
|
return config.getJSONObject("Tokens").getString("BotsForDiscord");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDiscordBotListToken() {
|
||||||
|
return config.getJSONObject("Tokens").getString("DiscordBotList");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDiscordBestBotsToken() {
|
||||||
|
return config.getJSONObject("Tokens").getString("DiscordBestBots");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDiscordBoatsToken() {
|
||||||
|
return config.getJSONObject("Tokens").getString("DiscordBoats");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ package com.bbn.hadder.listener;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bbn.hadder.Rethink;
|
import com.bbn.hadder.Rethink;
|
||||||
|
import com.bbn.hadder.core.Config;
|
||||||
import com.bbn.hadder.utils.BotList;
|
import com.bbn.hadder.utils.BotList;
|
||||||
import com.bbn.hadder.utils.MessageEditor;
|
import com.bbn.hadder.utils.MessageEditor;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
|
@ -19,9 +20,11 @@ import java.time.Instant;
|
||||||
public class GuildListener extends ListenerAdapter {
|
public class GuildListener extends ListenerAdapter {
|
||||||
|
|
||||||
private Rethink rethink;
|
private Rethink rethink;
|
||||||
|
private Config config;
|
||||||
|
|
||||||
public GuildListener(Rethink rethink) {
|
public GuildListener(Rethink rethink, Config config) {
|
||||||
this.rethink = rethink;
|
this.rethink = rethink;
|
||||||
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onGuildJoin(GuildJoinEvent event) {
|
public void onGuildJoin(GuildJoinEvent event) {
|
||||||
|
|
@ -42,7 +45,7 @@ public class GuildListener extends ListenerAdapter {
|
||||||
.setTimestamp(Instant.now())
|
.setTimestamp(Instant.now())
|
||||||
.build()).queue();
|
.build()).queue();
|
||||||
|
|
||||||
BotList.post();
|
new BotList(config).post();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onGuildLeave(GuildLeaveEvent event) {
|
public void onGuildLeave(GuildLeaveEvent event) {
|
||||||
|
|
@ -56,7 +59,7 @@ public class GuildListener extends ListenerAdapter {
|
||||||
.setTimestamp(Instant.now())
|
.setTimestamp(Instant.now())
|
||||||
.build()).queue();
|
.build()).queue();
|
||||||
|
|
||||||
BotList.post();
|
new BotList(config).post();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
|
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.bbn.hadder.listener;
|
package com.bbn.hadder.listener;
|
||||||
|
|
||||||
|
import com.bbn.hadder.Rethink;
|
||||||
import com.bbn.hadder.utils.MessageEditor;
|
import com.bbn.hadder.utils.MessageEditor;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.entities.ChannelType;
|
import net.dv8tion.jda.api.entities.ChannelType;
|
||||||
|
|
@ -10,6 +11,12 @@ import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class MentionListener extends ListenerAdapter {
|
public class MentionListener extends ListenerAdapter {
|
||||||
|
|
||||||
|
private Rethink rethink;
|
||||||
|
|
||||||
|
public MentionListener(Rethink rethink) {
|
||||||
|
this.rethink = rethink;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
|
public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
|
||||||
if (event.isFromType(ChannelType.TEXT)) {
|
if (event.isFromType(ChannelType.TEXT)) {
|
||||||
|
|
@ -18,7 +25,9 @@ public class MentionListener extends ListenerAdapter {
|
||||||
.setTitle("Hello I'm Hadder.")
|
.setTitle("Hello I'm Hadder.")
|
||||||
.setAuthor(event.getJDA().getSelfUser().getName(), event.getJDA().getSelfUser().getAvatarUrl(), event.getJDA().getSelfUser().getAvatarUrl())
|
.setAuthor(event.getJDA().getSelfUser().getName(), event.getJDA().getSelfUser().getAvatarUrl(), event.getJDA().getSelfUser().getAvatarUrl())
|
||||||
.addField("Users", String.valueOf(event.getJDA().getUsers().size()), false)
|
.addField("Users", String.valueOf(event.getJDA().getUsers().size()), false)
|
||||||
.addField("Guilds", String.valueOf(event.getJDA().getGuilds().size()), false);
|
.addField("Guilds", String.valueOf(event.getJDA().getGuilds().size()), false)
|
||||||
|
.addField("Prefix (User)", rethink.getUserPrefix(event.getAuthor().getId()), false)
|
||||||
|
.addField("Prefix (Guild)", rethink.getServerPrefix(event.getGuild().getId()), false);
|
||||||
event.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, builder).build()).queue();
|
event.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, builder).build()).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.bbn.hadder.listener;
|
package com.bbn.hadder.listener;
|
||||||
|
|
||||||
import com.bbn.hadder.Rethink;
|
import com.bbn.hadder.Rethink;
|
||||||
|
import com.bbn.hadder.core.Config;
|
||||||
import com.bbn.hadder.utils.BotList;
|
import com.bbn.hadder.utils.BotList;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
|
@ -12,9 +13,11 @@ import javax.annotation.Nonnull;
|
||||||
public class ReadyListener extends ListenerAdapter {
|
public class ReadyListener extends ListenerAdapter {
|
||||||
|
|
||||||
private Rethink rethink;
|
private Rethink rethink;
|
||||||
|
private Config config;
|
||||||
|
|
||||||
public ReadyListener(Rethink rethink) {
|
public ReadyListener(Rethink rethink, Config config) {
|
||||||
this.rethink = rethink;
|
this.rethink = rethink;
|
||||||
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -29,6 +32,6 @@ public class ReadyListener extends ListenerAdapter {
|
||||||
rethink.insertServer(g.getId());
|
rethink.insertServer(g.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
BotList.post();
|
new BotList(config).post();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ package com.bbn.hadder.utils;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import com.bbn.hadder.Hadder;
|
import com.bbn.hadder.Hadder;
|
||||||
|
import com.bbn.hadder.core.Config;
|
||||||
import okhttp3.MediaType;
|
import okhttp3.MediaType;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
|
|
@ -22,83 +23,97 @@ public class BotList {
|
||||||
private static String BotsForDiscord = "https://botsfordiscord.com/api/bot/637002314162372639";
|
private static String BotsForDiscord = "https://botsfordiscord.com/api/bot/637002314162372639";
|
||||||
private static String DiscordBotList = "https://discordbotlist.com/api/bots/637002314162372639/stats";
|
private static String DiscordBotList = "https://discordbotlist.com/api/bots/637002314162372639/stats";
|
||||||
private static String DiscordBestBots = "https://discordsbestbots.xyz/api/bots/637002314162372639/stats";
|
private static String DiscordBestBots = "https://discordsbestbots.xyz/api/bots/637002314162372639/stats";
|
||||||
|
private static String DiscordBoats = "https://discord.boats/api/bot/637002314162372639";
|
||||||
|
|
||||||
private static JSONObject json = new JSONObject();
|
private Config config;
|
||||||
|
|
||||||
public static void post() {
|
public BotList(Config config) {
|
||||||
json.put("server_count", Hadder.shardManager.getGuilds().size());
|
this.config = config;
|
||||||
json.put("guilds", Hadder.shardManager.getGuilds().size());
|
}
|
||||||
json.put("users", Hadder.shardManager.getUsers().size());
|
|
||||||
|
|
||||||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), json.toString());
|
public void post() {
|
||||||
|
if (Files.notExists(Paths.get("./DEBUG"))) {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("server_count", Hadder.shardManager.getGuilds().size());
|
||||||
|
json.put("guilds", Hadder.shardManager.getGuilds().size());
|
||||||
|
json.put("users", Hadder.shardManager.getUsers().size());
|
||||||
|
|
||||||
File configfile = new File("./config.json");
|
RequestBody body = RequestBody.create(MediaType.parse("application/json"), json.toString());
|
||||||
|
|
||||||
JSONObject config = null;
|
// Mythical Bot List
|
||||||
try {
|
|
||||||
config = new JSONObject(new String(Files.readAllBytes(Paths.get(configfile.toURI()))));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mythical Bot List
|
Request mythicalbotlist = new Request.Builder()
|
||||||
|
.url(MythicalBotList)
|
||||||
|
.post(body)
|
||||||
|
.addHeader("Authorization", config.getMythicalBotListToken())
|
||||||
|
.build();
|
||||||
|
|
||||||
Request mythicalbotlist = new Request.Builder()
|
try {
|
||||||
.url(MythicalBotList)
|
new OkHttpClient().newCall(mythicalbotlist).execute().close();
|
||||||
.post(body)
|
System.out.println("Successfully posted count for the Mythical Bot List!");
|
||||||
.addHeader("Authorization", config.getString("MythicalBotList"))
|
} catch (IOException e) {
|
||||||
.build();
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
// BotsForDiscord
|
||||||
new OkHttpClient().newCall(mythicalbotlist).execute().close();
|
|
||||||
System.out.println("Successfully posted count for the Mythical Bot List!");
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
// BotsForDiscord
|
Request botsfordiscord = new Request.Builder()
|
||||||
|
.url(BotsForDiscord)
|
||||||
|
.post(body)
|
||||||
|
.addHeader("Authorization", config.getBotsForDiscordToken())
|
||||||
|
.build();
|
||||||
|
|
||||||
Request botsfordiscord = new Request.Builder()
|
try {
|
||||||
.url(BotsForDiscord)
|
new OkHttpClient().newCall(botsfordiscord).execute().close();
|
||||||
.post(body)
|
System.out.println("Successfully posted count to Bots For Discord!");
|
||||||
.addHeader("Authorization", config.getString("BotsForDiscord"))
|
} catch (IOException e) {
|
||||||
.build();
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
// Discord Bot List
|
||||||
new OkHttpClient().newCall(botsfordiscord).execute().close();
|
|
||||||
System.out.println("Successfully posted count to Bots For Discord!");
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Discord Bot List
|
Request discordbotlist = new Request.Builder()
|
||||||
|
.url(DiscordBotList)
|
||||||
|
.post(body)
|
||||||
|
.addHeader("Authorization", "Bot " + config.getDiscordBotListToken())
|
||||||
|
.build();
|
||||||
|
|
||||||
Request discordbotlist = new Request.Builder()
|
try {
|
||||||
.url(DiscordBotList)
|
new OkHttpClient().newCall(discordbotlist).execute().close();
|
||||||
.post(body)
|
System.out.println("Successfully posted count for the Discord Bot List");
|
||||||
.addHeader("Authorization", "Bot " + config.getString("DiscordBotList"))
|
} catch (IOException e) {
|
||||||
.build();
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
// Discord Best Bots
|
||||||
new OkHttpClient().newCall(discordbotlist).execute().close();
|
|
||||||
System.out.println("Successfully posted count for the Discord Bot List");
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Discord Best Bots
|
Request discordbestbots = new Request.Builder()
|
||||||
|
.url(DiscordBestBots)
|
||||||
|
.post(body)
|
||||||
|
.addHeader("Authorization", config.getDiscordBestBotsToken())
|
||||||
|
.build();
|
||||||
|
|
||||||
Request discordbestbots = new Request.Builder()
|
try {
|
||||||
.url(DiscordBestBots)
|
new OkHttpClient().newCall(discordbestbots).execute().close();
|
||||||
.post(body)
|
System.out.println("Successfully posted count to Discord Best Bots!");
|
||||||
.addHeader("Authorization", config.getString("DiscordBestBots"))
|
} catch (IOException e) {
|
||||||
.build();
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
// Discord Boats
|
||||||
new OkHttpClient().newCall(discordbestbots).execute().close();
|
|
||||||
System.out.println("Successfully posted count to Discord Best Bots!");
|
Request discordboats = new Request.Builder()
|
||||||
} catch (IOException e) {
|
.url(DiscordBoats)
|
||||||
e.printStackTrace();
|
.post(body)
|
||||||
|
.addHeader("Authorization", config.getDiscordBoatsToken())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try {
|
||||||
|
new OkHttpClient().newCall(discordboats).execute().close();
|
||||||
|
System.out.println("Successfully posted count to Discord Boats!");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue