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