diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 17bd127..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1 +0,0 @@ -custom: https://donatebot.io/checkout/448554629282922527 diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 83d7c35..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,94 +0,0 @@ -# Citizen Code of Conduct - -## 1. Purpose - -A primary goal of Hadder is to be inclusive to the largest number of contributors, with the most varied and diverse backgrounds possible. As such, we are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, ability, ethnicity, socioeconomic status, and religion (or lack thereof). - -This code of conduct outlines our expectations for all those who participate in our community, as well as the consequences for unacceptable behavior. - -We invite all those who participate in Hadder to help us create safe and positive experiences for everyone. - -## 2. Open [Source/Culture/Tech] Citizenship - -A supplemental goal of this Code of Conduct is to increase open [source/culture/tech] citizenship by encouraging participants to recognize and strengthen the relationships between our actions and their effects on our community. - -Communities mirror the societies in which they exist and positive action is essential to counteract the many forms of inequality and abuses of power that exist in society. - -If you see someone who is making an extra effort to ensure our community is welcoming, friendly, and encourages all participants to contribute to the fullest extent, we want to know. - -## 3. Expected Behavior - -The following behaviors are expected and requested of all community members: - - * Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community. - * Exercise consideration and respect in your speech and actions. - * Attempt collaboration before conflict. - * Refrain from demeaning, discriminatory, or harassing behavior and speech. - * Be mindful of your surroundings and of your fellow participants. Alert community leaders if you notice a dangerous situation, someone in distress, or violations of this Code of Conduct, even if they seem inconsequential. - * Remember that community event venues may be shared with members of the public; please be respectful to all patrons of these locations. - -## 4. Unacceptable Behavior - -The following behaviors are considered harassment and are unacceptable within our community: - - * Violence, threats of violence or violent language directed against another person. - * Sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory jokes and language. - * Posting or displaying sexually explicit or violent material. - * Posting or threatening to post other people's personally identifying information ("doxing"). - * Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability. - * Inappropriate photography or recording. - * Inappropriate physical contact. You should have someone's consent before touching them. - * Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances. - * Deliberate intimidation, stalking or following (online or in person). - * Advocating for, or encouraging, any of the above behavior. - * Sustained disruption of community events, including talks and presentations. - -## 5. Weapons Policy - -No weapons will be allowed at Hadder events, community spaces, or in other spaces covered by the scope of this Code of Conduct. Weapons include but are not limited to guns, explosives (including fireworks), and large knives such as those used for hunting or display, as well as any other item used for the purpose of causing injury or harm to others. Anyone seen in possession of one of these items will be asked to leave immediately, and will only be allowed to return without the weapon. Community members are further expected to comply with all state and local laws on this matter. - -## 6. Consequences of Unacceptable Behavior - -Unacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated. - -Anyone asked to stop unacceptable behavior is expected to comply immediately. - -If a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event). - -## 7. Reporting Guidelines - -If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. admin@bigbotnetwork.de. - - - -Additionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress. - -## 8. Addressing Grievances - -If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify BigBotNetwork with a concise description of your grievance. Your grievance will be handled in accordance with our existing governing policies. - - - -## 9. Scope - -We expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues--online and in-person--as well as in all one-on-one communications pertaining to community business. - -This code of conduct and its related procedures also applies to unacceptable behavior occurring outside the scope of community activities when such behavior has the potential to adversely affect the safety and well-being of community members. - -## 10. Contact info - -admin@bigbotnetwork.de - -## 11. License and attribution - -The Citizen Code of Conduct is distributed by [Stumptown Syndicate](http://stumptownsyndicate.org) under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/). - -Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy). - -_Revision 2.3. Posted 6 March 2017._ - -_Revision 2.2. Posted 4 February 2016._ - -_Revision 2.1. Posted 23 June 2014._ - -_Revision 2.0, adopted by the [Stumptown Syndicate](http://stumptownsyndicate.org) board on 10 January 2013. Posted 17 March 2013._ diff --git a/pom.xml b/pom.xml index ae4c80a..365a5b9 100644 --- a/pom.xml +++ b/pom.xml @@ -19,20 +19,29 @@ junit junit - 4.11 + LATEST test net.dv8tion JDA - 4.0.0_54 + LATEST org.json json - 20190722 + LATEST + + + com.rethinkdb + rethinkdb-driver + LATEST + + + com.google.code.gson + gson + LATEST - @@ -45,14 +54,11 @@ - - maven-clean-plugin 3.1.0 - maven-resources-plugin 3.0.2 @@ -77,7 +83,6 @@ maven-deploy-plugin 2.8.2 - maven-site-plugin 3.7.1 diff --git a/src/main/java/com/bbn/hadder/Hadder.java b/src/main/java/com/bbn/hadder/Hadder.java index e7fdfd6..ffc15da 100644 --- a/src/main/java/com/bbn/hadder/Hadder.java +++ b/src/main/java/com/bbn/hadder/Hadder.java @@ -1,8 +1,8 @@ package com.bbn.hadder; -import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.TestCommand; import com.bbn.hadder.commands.moderation.BanCommand; +import com.bbn.hadder.commands.settings.PrefixCommand; import com.bbn.hadder.core.CommandHandler; import com.bbn.hadder.listener.*; import net.dv8tion.jda.api.entities.Activity; @@ -33,6 +33,9 @@ public class Hadder { e.printStackTrace(); } + Rethink.connect(); + + DefaultShardManagerBuilder builder = new DefaultShardManagerBuilder(); builder.setShardsTotal(1); @@ -41,11 +44,14 @@ public class Hadder { CommandHandler.cmdlist.put("test", new TestCommand()); CommandHandler.cmdlist.put("ban", new BanCommand()); + CommandHandler.cmdlist.put("prefix", new PrefixCommand()); builder.addEventListeners( new MentionListener(), new PrivateMessageListener(), - new CommandListener()); + new CommandListener(), + new GuildJoinListener(), + new GuildLeaveListener()); try { ShardManager shardManager = builder.build(); diff --git a/src/main/java/com/bbn/hadder/Rethink.java b/src/main/java/com/bbn/hadder/Rethink.java new file mode 100644 index 0000000..ac28f7f --- /dev/null +++ b/src/main/java/com/bbn/hadder/Rethink.java @@ -0,0 +1,73 @@ +package com.bbn.hadder; + +import com.rethinkdb.RethinkDB; +import com.rethinkdb.net.Connection; +import com.rethinkdb.net.Cursor; +import com.google.gson.JsonParser; + +import java.util.NoSuchElementException; + +/* + * @author Skidder / GregTCLTK + */ + +public class Rethink { + private static RethinkDB r = RethinkDB.r; + static Connection conn; + + public static boolean connect() { + try { + conn = r.connection().hostname("127.0.0.1").db("Hadder").port(28015).connect(); + System.out.println("CONNECTED"); + } catch (Exception e) { + System.out.println(e.toString()); + System.out.println("CONNECTION FAILED"); + } + return true; + } + + public static void disconnect() { + conn.close(); + System.out.println("DISCONNECTED"); + } + + public static String get(String table, String where, String value, String column) { + try { + Cursor cursor = r.table(table).filter(row -> row.g(where.toLowerCase()).eq(value)).run(conn); + if (cursor.hasNext()) { + String sad = new JsonParser().parse(cursor.next().toString()).getAsJsonObject().get(column).toString(); + if (sad.startsWith("\"") && sad.endsWith("\"")) { + return sad.substring(1, sad.length()-1); + } else { + return sad; + } + } else return null; + } catch (NoSuchElementException e) { + return null; + } catch (Exception e) { + e.printStackTrace(); + } + return "<3"; + } + + public static String update(String table, String whatvalue, String where, String wherevalue) { + String out=""; + try { + Cursor cursor = r.table(table).get(whatvalue).update(r.hashMap(where, wherevalue)).run(conn); + out=cursor.toString(); + } catch (ClassCastException ignored) {} + return out; + } + + public static String insertServer(String id) { + String out = ""; + try { + Cursor cursor = r.table("server") + .insert(r.hashMap("id", id) + .with("prefix", "h.") + ).run(conn); + out = cursor.next().toString(); + } catch (ClassCastException ignored) {} + return out; + } +} diff --git a/src/main/java/com/bbn/hadder/commands/Command.java b/src/main/java/com/bbn/hadder/commands/Command.java index 9b1cf42..95b1468 100644 --- a/src/main/java/com/bbn/hadder/commands/Command.java +++ b/src/main/java/com/bbn/hadder/commands/Command.java @@ -7,5 +7,5 @@ package com.bbn.hadder.commands; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; public interface Command { - void executed(MessageReceivedEvent event); + void executed(String[] args, MessageReceivedEvent event); } diff --git a/src/main/java/com/bbn/hadder/commands/TestCommand.java b/src/main/java/com/bbn/hadder/commands/TestCommand.java index b12de03..4fd5742 100644 --- a/src/main/java/com/bbn/hadder/commands/TestCommand.java +++ b/src/main/java/com/bbn/hadder/commands/TestCommand.java @@ -8,7 +8,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; public class TestCommand implements Command { - public void executed(MessageReceivedEvent event) { + public void executed(String[] args, MessageReceivedEvent event) { event.getTextChannel().sendMessage("TEST my friends").queue(); } } diff --git a/src/main/java/com/bbn/hadder/commands/moderation/BanCommand.java b/src/main/java/com/bbn/hadder/commands/moderation/BanCommand.java index e39afff..ac52215 100644 --- a/src/main/java/com/bbn/hadder/commands/moderation/BanCommand.java +++ b/src/main/java/com/bbn/hadder/commands/moderation/BanCommand.java @@ -13,7 +13,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; public class BanCommand implements Command { - public void executed(MessageReceivedEvent event) { + public void executed(String[] args, MessageReceivedEvent event) { if (event.getGuild().getMemberById(event.getAuthor().getId()).hasPermission(Permission.BAN_MEMBERS) || event.getGuild().getOwner().getId().equals(event.getAuthor().getId())) { if (event.getMessage().getMentionedMembers().size() == 1) { Member victim = event.getMessage().getMentionedMembers().get(0); diff --git a/src/main/java/com/bbn/hadder/commands/owner/ShutdownCommand.java b/src/main/java/com/bbn/hadder/commands/owner/ShutdownCommand.java new file mode 100644 index 0000000..aea13fc --- /dev/null +++ b/src/main/java/com/bbn/hadder/commands/owner/ShutdownCommand.java @@ -0,0 +1,26 @@ +package com.bbn.hadder.commands.owner; + +/* + * @author Skidder / GregTCLTK + */ + +import com.bbn.hadder.Rethink; +import com.bbn.hadder.commands.Command; +import com.bbn.hadder.utils.MessageEditor; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + +public class ShutdownCommand implements Command { + @Override + public void executed(String[] args, MessageReceivedEvent event) { + if (event.getAuthor().getId().equals("477141528981012511") || event.getAuthor().getId().equals("261083609148948488")) { + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, builder).setTitle("Shutdown").build()).queue(); + event.getJDA().shutdown(); + Rethink.disconnect(); + } else { + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.NO_PERMISSION, builder).build()).queue(); + } + } +} diff --git a/src/main/java/com/bbn/hadder/commands/settings/PrefixCommand.java b/src/main/java/com/bbn/hadder/commands/settings/PrefixCommand.java new file mode 100644 index 0000000..d72a6c5 --- /dev/null +++ b/src/main/java/com/bbn/hadder/commands/settings/PrefixCommand.java @@ -0,0 +1,39 @@ +package com.bbn.hadder.commands.settings; + +/* + * @author Skidder / GregTCLTK + */ + +import com.bbn.hadder.Rethink; +import com.bbn.hadder.commands.Command; +import com.bbn.hadder.utils.MessageEditor; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; + + +public class PrefixCommand implements Command { + public void executed(String[] args, MessageReceivedEvent event) { + if (event.getGuild().getMemberById(event.getAuthor().getId()).hasPermission(Permission.MANAGE_SERVER)) { + if (args.length == 1) { + if (!args[0].contains("\"")) { + + Rethink.update("server", event.getGuild().getId(), "prefix", args[0]); + + EmbedBuilder builder = new EmbedBuilder(); + + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.INFO, builder).setTitle("✅ Successfully set ✅").setDescription("I successfully set the new prefix for this server to " + args[0]).build()).queue(); + } else { + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.WARNING, builder).setDescription("The prefix must not contain **\"**").build()).queue(); + } + } else { + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.WARNING, builder).setDescription("You have to set a prefix.").build()).queue(); + } + } else { + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.Messagetype.NO_PERMISSION, builder).build()).queue(); + } + } +} diff --git a/src/main/java/com/bbn/hadder/core/CommandHandler.java b/src/main/java/com/bbn/hadder/core/CommandHandler.java index be80d24..902cc90 100644 --- a/src/main/java/com/bbn/hadder/core/CommandHandler.java +++ b/src/main/java/com/bbn/hadder/core/CommandHandler.java @@ -14,7 +14,7 @@ public class CommandHandler { public static void handleCommand(CommandParser.commandContainer cmd) { if(cmdlist.containsKey(cmd.invoke)) { - cmdlist.get(cmd.invoke).executed(cmd.event); + cmdlist.get(cmd.invoke).executed(cmd.args, cmd.event); } } diff --git a/src/main/java/com/bbn/hadder/core/CommandParser.java b/src/main/java/com/bbn/hadder/core/CommandParser.java index b658312..a801d9f 100644 --- a/src/main/java/com/bbn/hadder/core/CommandParser.java +++ b/src/main/java/com/bbn/hadder/core/CommandParser.java @@ -4,6 +4,7 @@ package com.bbn.hadder.core; * @author Skidder / GregTCLTK */ +import com.bbn.hadder.Rethink; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import java.util.ArrayList; @@ -12,7 +13,7 @@ import java.util.Collections; public class CommandParser { public static commandContainer parser(String raw, MessageReceivedEvent event) { - String cmd = raw.replaceFirst("h.", ""); + String cmd = raw.replaceFirst(Rethink.get("server", "id", event.getGuild().getId(), "prefix"), ""); String[] cmdsplit = cmd.split(" "); String invoke = cmdsplit[0]; ArrayList split = new ArrayList<>(); diff --git a/src/main/java/com/bbn/hadder/listener/CommandListener.java b/src/main/java/com/bbn/hadder/listener/CommandListener.java index d1a4e0d..a3cfa4f 100644 --- a/src/main/java/com/bbn/hadder/listener/CommandListener.java +++ b/src/main/java/com/bbn/hadder/listener/CommandListener.java @@ -1,5 +1,6 @@ package com.bbn.hadder.listener; +import com.bbn.hadder.Rethink; import com.bbn.hadder.core.CommandHandler; import com.bbn.hadder.core.CommandParser; import net.dv8tion.jda.api.Permission; @@ -18,7 +19,7 @@ public class CommandListener extends ListenerAdapter { @Override public void onMessageReceived(@Nonnull MessageReceivedEvent event) { if (event.isFromType(ChannelType.TEXT)) { - if (event.getMessage().getContentRaw().startsWith("h.")) { + if (event.getMessage().getContentRaw().startsWith(Rethink.get("server", "id", event.getGuild().getId(), "prefix"))) { if (!event.getAuthor().isBot()) { CommandHandler.handleCommand(CommandParser.parser(event.getMessage().getContentRaw(), event)); } else if (event.getGuild().getSelfMember().hasPermission(Permission.MESSAGE_ADD_REACTION)) { diff --git a/src/main/java/com/bbn/hadder/listener/GuildJoinListener.java b/src/main/java/com/bbn/hadder/listener/GuildJoinListener.java new file mode 100644 index 0000000..cdea693 --- /dev/null +++ b/src/main/java/com/bbn/hadder/listener/GuildJoinListener.java @@ -0,0 +1,16 @@ +package com.bbn.hadder.listener; + +/* + * @author Skidder / GregTCLTK + */ + +import com.bbn.hadder.Rethink; +import net.dv8tion.jda.api.events.guild.GuildJoinEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.jetbrains.annotations.NotNull; + +public class GuildJoinListener extends ListenerAdapter { + public void onGuildJoin(@NotNull GuildJoinEvent event) { + Rethink.insertServer(event.getGuild().getId()); + } +} diff --git a/src/main/java/com/bbn/hadder/listener/GuildLeaveListener.java b/src/main/java/com/bbn/hadder/listener/GuildLeaveListener.java new file mode 100644 index 0000000..fc65d2e --- /dev/null +++ b/src/main/java/com/bbn/hadder/listener/GuildLeaveListener.java @@ -0,0 +1,16 @@ +package com.bbn.hadder.listener; + +/* + * @author Skidder / GregTCLTK + */ + +import net.dv8tion.jda.api.events.guild.GuildLeaveEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.jetbrains.annotations.NotNull; + +public class GuildLeaveListener extends ListenerAdapter { + public void onGuildLeave(@NotNull GuildLeaveEvent event) { + + + } +} diff --git a/src/main/java/com/bbn/hadder/utils/MessageEditor.java b/src/main/java/com/bbn/hadder/utils/MessageEditor.java index 976ed1c..0595fef 100644 --- a/src/main/java/com/bbn/hadder/utils/MessageEditor.java +++ b/src/main/java/com/bbn/hadder/utils/MessageEditor.java @@ -25,7 +25,7 @@ public class MessageEditor { break; case NO_SELF_PERMISSION: - embedBuilder.setTitle("⛔ No Permission ⛔").setDescription("Unfortunately, I do not have the required ban rights to perform this action").setColor(Color.RED); + embedBuilder.setTitle("⛔ No Permission ⛔").setDescription("Unfortunately, I do not have the required rights to perform this action").setColor(Color.RED); break; } return embedBuilder;