This commit is contained in:
Tyler Murphy 2022-08-22 14:16:35 -04:00
parent f64c64c127
commit 2081810bfe
37 changed files with 286 additions and 167 deletions

27
pom.xml
View file

@ -9,6 +9,8 @@
<version>1.0</version> <version>1.0</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
</properties> </properties>
@ -21,24 +23,25 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version> <version>3.2.4</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
</filters>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
</configuration>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
<goals> <goals>
<goal>shade</goal> <goal>shade</goal>
</goals> </goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
</filters>
<minimizeJar>true</minimizeJar>
</configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>

View file

@ -39,7 +39,7 @@ public class Ken {
this.log = LoggerFactory.getLogger(Ken.class); this.log = LoggerFactory.getLogger(Ken.class);
try { try {
api = JDABuilder.createDefault(config.getString("botToken")) api = JDABuilder.createDefault(config.getString("botToken"))
.setActivity(Activity.playing("Use "+config.getString("prefix")+"help")) .setActivity(Activity.playing("@Ken | /help"))
.setMemberCachePolicy(MemberCachePolicy.ALL) .setMemberCachePolicy(MemberCachePolicy.ALL)
.enableIntents(GatewayIntent.GUILD_MEMBERS) .enableIntents(GatewayIntent.GUILD_MEMBERS)
.build() .build()

View file

@ -1,28 +0,0 @@
package net.tylermurphy.ken.api;
import net.tylermurphy.ken.api.wrapper.HTTPMethod;
import net.tylermurphy.ken.api.wrapper.JsonRequest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class E621API {
public static String request(String query){
JSONObject json = (JSONObject) new JsonRequest()
.setURL("https://e621.net/posts.json?tags="+query)
.setType(HTTPMethod.GET)
.request();
try {
System.out.println(json.toString());
JSONArray results = json.getJSONArray("posts");
int choice = (int) (Math.random()*results.length()-1);
JSONObject post = (JSONObject) results.get(choice);
JSONObject file = post.getJSONObject("file");
return file.getString("url");
} catch (JSONException e) {
return null;
}
}
}

View file

@ -1,4 +1,4 @@
package net.tylermurphy.ken.api.wrapper; package net.tylermurphy.ken.api;
public enum HTTPMethod { public enum HTTPMethod {

View file

@ -1,4 +1,4 @@
package net.tylermurphy.ken.api.wrapper; package net.tylermurphy.ken.api;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;

View file

@ -1,4 +1,4 @@
package net.tylermurphy.ken.api.wrapper; package net.tylermurphy.ken.api;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;

View file

@ -1,30 +0,0 @@
package net.tylermurphy.ken.api;
import net.tylermurphy.ken.api.wrapper.HTTPMethod;
import net.tylermurphy.ken.api.wrapper.XmlRequest;
import org.json.JSONException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class Rule34API {
public static String request(String query){
Document doc = (Document) new XmlRequest()
.setURL("https://rule34.xxx/index.php?page=dapi&s=post&q=index&tags="+ query)
.setType(HTTPMethod.GET)
.request();
try {
NodeList nList = doc.getElementsByTagName("post");
int choice = (int) (Math.random()*nList.getLength()-1);
if(choice < 0) return null;
Node node = nList.item(choice);
Element element = (Element) node;
return element.getAttribute("file_url");
} catch (JSONException e) {
return null;
}
}
}

View file

@ -1,4 +1,4 @@
package net.tylermurphy.ken.api.wrapper; package net.tylermurphy.ken.api;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;

View file

@ -10,10 +10,12 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.interactions.commands.build.Commands; import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData; import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import net.dv8tion.jda.api.interactions.components.buttons.Button; import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.dv8tion.jda.api.requests.restaction.WebhookMessageAction; import net.dv8tion.jda.api.requests.restaction.WebhookMessageAction;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.util.*;
import org.reflections.Reflections; import org.reflections.Reflections;
import org.reflections.scanners.MethodAnnotationsScanner; import org.reflections.scanners.MethodAnnotationsScanner;
@ -63,6 +65,19 @@ public class Responder extends ListenerAdapter {
Option option = method.getAnnotation(Option.class); Option option = method.getAnnotation(Option.class);
data = data.addOption(option.type(), option.name(), option.description(), option.required()); data = data.addOption(option.type(), option.name(), option.description(), option.required());
} }
if(method.isAnnotationPresent(Selections.class)){
Selection[] selections = method.getAnnotation(Selections.class).value();
for(Selection selection : selections){
OptionData optionData = new OptionData(selection.type(), selection.name(), selection.description(), selection.required());
Arrays.stream(selection.choices()).forEach(choice -> optionData.addChoice(choice, choice.toLowerCase(Locale.ROOT)));
data.addOptions(optionData);
}
} else if(method.isAnnotationPresent(Selection.class)){
Selection selection = method.getAnnotation(Selection.class);
OptionData optionData = new OptionData(selection.type(), selection.name(), selection.description(), selection.required());
Arrays.stream(selection.choices()).forEach(choice -> optionData.addChoice(choice, choice.toLowerCase(Locale.ROOT)));
data.addOptions(optionData);
}
api.upsertCommand(data).queue(); api.upsertCommand(data).queue();
} }

View file

@ -4,8 +4,8 @@ import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Option; import net.tylermurphy.ken.util.Option;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import java.util.List; import java.util.List;

View file

@ -2,8 +2,8 @@ package net.tylermurphy.ken.command.fun;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Option; import net.tylermurphy.ken.util.Option;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.image.GifFactory; import net.tylermurphy.ken.image.GifFactory;

View file

@ -0,0 +1,90 @@
package net.tylermurphy.ken.command.main;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.util.ButtonCallback;
import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response;
public class Help {
private final int PAGES = 5;
@Command(name="help", description="Gets information about all the commands in the plugin")
public Response execute(Member sender){
return Response.success(getPage(sender, 1)).addSecondaryButton("help", "previous", "Previous").addSecondaryButton("help", "next", "Next");
}
@ButtonCallback(name="help")
public Response onButton(String id, Message message, Member sender){
int page;
int pages = PAGES;
if (message != null && message.getEmbeds().size() > 0 && message.getEmbeds().get(0) != null) {
page = Integer.parseInt(message.getEmbeds().get(0).getFooter().getText().split("/")[0].substring(5));
} else {
page = 0;
}
if(id.equals("previous"))
page = page - 1 < 1 ? pages : page - 1;
else
page = page + 1 > pages ? 1 : page + 1;
return Response.success(getPage(sender, page));
}
private MessageEmbed getPage(Member sender, int page) {
String name = Ken.getInstance().getConfig().getString("botName");
String supportServer = Ken.getInstance().getConfig().getString("supportServer");
EmbedBuilder[] embeds = new EmbedBuilder[]{
Ken.getInstance().getDefaultEmbed()
.setAuthor(name + " Command List", sender.getAvatarUrl())
.appendDescription(
"These are all the commands that are included with "+name+"\n" +
"Read below to see what each command does, and what parameters the\n" +
"command requires. Any questions? Join our [discord support server](https://discord.gg/"+supportServer+")"
).setFooter("Page "+page+"/"+PAGES),
Ken.getInstance().getDefaultEmbed()
.setAuthor(name + " Command List", sender.getAvatarUrl())
.setTitle(":pen_ballpoint: **Main Commands**")
.appendDescription("**/help** Gives a list of commands\n")
.appendDescription("**/purge <amount>** Purges an amount of messages from a channel\n")
.setFooter("Page "+page+"/"+PAGES),
Ken.getInstance().getDefaultEmbed()
.setAuthor(name + " Command List", sender.getAvatarUrl())
.setTitle(":musical_note: **Music Commands**")
.appendDescription("**/play <query>** Plays a song in a voice channel\n")
.appendDescription("**/join** Make the bot join your audio channel\n")
.appendDescription("**/leave** Make the bot leave your audio channel\n")
.appendDescription("**/pause** Pause the current playing track\n")
.appendDescription("**/resume** Resume the current paused track\n")
.appendDescription("**/stop** Stop the current playing track and clear queue\n")
.appendDescription("**/skip** Vote to skip the current track\n")
.appendDescription("**/forceskip** Force skip the current track\n")
.appendDescription("**/loop** Loop the current track\n")
.appendDescription("**/loopqueue** Loop the current song queue\n")
.appendDescription("**/remove <index>** Remove a song from the queue\n")
.appendDescription("**/nowplaying** See what track is currently playing\n")
.appendDescription("**/queue** View the current song queue\n")
.setFooter("Page "+page+"/"+PAGES),
Ken.getInstance().getDefaultEmbed()
.setAuthor(name + " Command List", sender.getAvatarUrl())
.setTitle(":game_die: **Game Commands**")
.appendDescription("**/d6** Roll a d6 die\n")
.appendDescription("**/d8** Roll a d8 die\n")
.appendDescription("**/d12** Roll a d12 die\n")
.appendDescription("**/d20** Roll a d20 die\n")
.appendDescription("**/dice <sides>** Roll a dice with set sides\n")
.setFooter("Page "+page+"/"+PAGES),
Ken.getInstance().getDefaultEmbed()
.setAuthor(name + " Command List", sender.getAvatarUrl())
.setTitle(":underage: **NSFW Commands**")
.appendDescription("**/rule34 <query>** Search on rule34\n")
.appendDescription("**/e612 <query>** Search on e621\n")
.setFooter("Page "+page+"/"+PAGES)
};
return embeds[page-1].build();
}
}

View file

@ -1,13 +1,13 @@
package net.tylermurphy.ken.command.util; package net.tylermurphy.ken.command.main;
import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.GuildMessageChannel; import net.dv8tion.jda.api.entities.GuildMessageChannel;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Option; import net.tylermurphy.ken.util.Option;
import net.tylermurphy.ken.command.Requirement; import net.tylermurphy.ken.util.Requirement;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import java.util.List; import java.util.List;

View file

@ -5,7 +5,7 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.GuildMusicManager; import net.tylermurphy.ken.music.GuildMusicManager;
import net.tylermurphy.ken.music.MusicPermissions; import net.tylermurphy.ken.music.MusicPermissions;

View file

@ -4,7 +4,7 @@ import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.GuildMusicManager; import net.tylermurphy.ken.music.GuildMusicManager;
import net.tylermurphy.ken.music.MusicPermissions; import net.tylermurphy.ken.music.MusicPermissions;

View file

@ -4,7 +4,7 @@ import net.dv8tion.jda.api.entities.AudioChannel;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.MusicPermissions; import net.tylermurphy.ken.music.MusicPermissions;

View file

@ -6,7 +6,7 @@ import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.GuildMusicManager; import net.tylermurphy.ken.music.GuildMusicManager;
import net.tylermurphy.ken.music.MusicPermissions; import net.tylermurphy.ken.music.MusicPermissions;

View file

@ -6,7 +6,7 @@ import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.GuildMusicManager; import net.tylermurphy.ken.music.GuildMusicManager;
import net.tylermurphy.ken.music.MusicPermissions; import net.tylermurphy.ken.music.MusicPermissions;

View file

@ -6,7 +6,7 @@ import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.GuildMusicManager; import net.tylermurphy.ken.music.GuildMusicManager;
import net.tylermurphy.ken.music.PlayerManager; import net.tylermurphy.ken.music.PlayerManager;

View file

@ -6,7 +6,7 @@ import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.GuildMusicManager; import net.tylermurphy.ken.music.GuildMusicManager;
import net.tylermurphy.ken.music.MusicPermissions; import net.tylermurphy.ken.music.MusicPermissions;

View file

@ -6,8 +6,8 @@ import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Option; import net.tylermurphy.ken.util.Option;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.PlayerManager; import net.tylermurphy.ken.music.PlayerManager;

View file

@ -6,10 +6,9 @@ import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.interactions.components.buttons.Button;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.ButtonCallback; import net.tylermurphy.ken.util.ButtonCallback;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.GuildMusicManager; import net.tylermurphy.ken.music.GuildMusicManager;
import net.tylermurphy.ken.music.PlayerManager; import net.tylermurphy.ken.music.PlayerManager;
@ -36,7 +35,7 @@ public class Queue {
PlayerManager playerManager = Ken.getInstance().getPlayerManager(); PlayerManager playerManager = Ken.getInstance().getPlayerManager();
GuildMusicManager musicManager = playerManager.getGuildMusicManager(guild); GuildMusicManager musicManager = playerManager.getGuildMusicManager(guild);
int page, pages; int page, pages;
if (message != null && message.getEmbeds().get(0) != null) { if (message != null && message.getEmbeds().size() > 0 && message.getEmbeds().get(0) != null) {
page = Integer.parseInt(message.getEmbeds().get(0).getFooter().getText().split("/")[0].substring(5)); page = Integer.parseInt(message.getEmbeds().get(0).getFooter().getText().split("/")[0].substring(5));
pages = Integer.parseInt(message.getEmbeds().get(0).getFooter().getText().split("/")[1]); pages = Integer.parseInt(message.getEmbeds().get(0).getFooter().getText().split("/")[1]);
} else { } else {

View file

@ -7,8 +7,8 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Option; import net.tylermurphy.ken.util.Option;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.GuildMusicManager; import net.tylermurphy.ken.music.GuildMusicManager;
import net.tylermurphy.ken.music.MusicPermissions; import net.tylermurphy.ken.music.MusicPermissions;

View file

@ -6,7 +6,7 @@ import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.GuildMusicManager; import net.tylermurphy.ken.music.GuildMusicManager;
import net.tylermurphy.ken.music.MusicPermissions; import net.tylermurphy.ken.music.MusicPermissions;

View file

@ -8,7 +8,7 @@ import net.dv8tion.jda.api.entities.GuildMessageChannel;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.GuildMusicManager; import net.tylermurphy.ken.music.GuildMusicManager;
import net.tylermurphy.ken.music.PlayerManager; import net.tylermurphy.ken.music.PlayerManager;

View file

@ -6,7 +6,7 @@ import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.music.GuildMusicManager; import net.tylermurphy.ken.music.GuildMusicManager;
import net.tylermurphy.ken.music.MusicPermissions; import net.tylermurphy.ken.music.MusicPermissions;

View file

@ -0,0 +1,51 @@
package net.tylermurphy.ken.command.nsfw;
import net.dv8tion.jda.api.entities.GuildMessageChannel;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.api.HTTPMethod;
import net.tylermurphy.ken.api.JsonRequest;
import net.tylermurphy.ken.command.Response;
import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.util.Selection;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List;
public class Akaneko {
@Command(name="akaneko", description=":underage: Searches for an image off of akaneko")
@Selection(name="type", description="Type of post you want to get", type=OptionType.STRING, required=true, choices={"ass","bdsm","cum","hentai","femdom","doujin","maid","orgy","panties","nsfwwallpapers","nsfwmobilewallpapers","netorare","gifs","gif","blowjob","feet","pussy","uglybastard","uniform","gangbang","foxgirl","cumslut","glasses","thighs","tentacles","masturbation","school","yuri","succubus"})
public Response execute(GuildMessageChannel channel, List<Object> args){
if(!(channel instanceof TextChannel)) {
return Response.error("This command can only be used in a text channel");
}
TextChannel textChannel = (TextChannel) channel;
if(!textChannel.isNSFW()){
return Response.error("This command can only be used in an NSFW channel");
}
String url = request((String)args.get(0));
if(url == null){
return Response.error("Unable to find post with search: "+args.get(0));
} else {
if(url.endsWith(".mp4") || url.endsWith(".webm"))
return Response.success(url);
return Response.success(Ken.getInstance().getDefaultEmbed().setImage(url).build());
}
}
private String request(String query){
JSONObject json = (JSONObject) new JsonRequest()
.setURL("https://akaneko-api.herokuapp.com/api/"+query)
.setType(HTTPMethod.GET)
.request();
try {
return json.getString("url");
} catch (JSONException e) {
return null;
}
}
}

View file

@ -4,10 +4,14 @@ import net.dv8tion.jda.api.entities.GuildMessageChannel;
import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.api.E621API; import net.tylermurphy.ken.api.HTTPMethod;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.api.JsonRequest;
import net.tylermurphy.ken.command.Option; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.util.Option;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.List; import java.util.List;
@ -23,7 +27,7 @@ public class E621 {
if(!textChannel.isNSFW()){ if(!textChannel.isNSFW()){
return Response.error("This command can only be used in an NSFW channel"); return Response.error("This command can only be used in an NSFW channel");
} }
String url = E621API.request(args.get(0)); String url = request(args.get(0));
if(url == null){ if(url == null){
return Response.error("Unable to find post with search: "+args.get(0)); return Response.error("Unable to find post with search: "+args.get(0));
} else { } else {
@ -33,4 +37,20 @@ public class E621 {
} }
} }
private String request(String query){
JSONObject json = (JSONObject) new JsonRequest()
.setURL("https://e621.net/posts.json?tags="+query)
.setType(HTTPMethod.GET)
.request();
try {
JSONArray results = json.getJSONArray("posts");
int choice = (int) (Math.random()*results.length()-1);
JSONObject post = (JSONObject) results.get(choice);
JSONObject file = post.getJSONObject("file");
return file.getString("url");
} catch (JSONException e) {
return null;
}
}
} }

View file

@ -4,10 +4,16 @@ import net.dv8tion.jda.api.entities.GuildMessageChannel;
import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.tylermurphy.ken.Ken; import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.api.Rule34API; import net.tylermurphy.ken.api.HTTPMethod;
import net.tylermurphy.ken.command.Command; import net.tylermurphy.ken.api.XmlRequest;
import net.tylermurphy.ken.command.Option; import net.tylermurphy.ken.util.Command;
import net.tylermurphy.ken.util.Option;
import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.Response;
import org.json.JSONException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.List; import java.util.List;
@ -15,7 +21,7 @@ public class Rule34 {
@Command(name="rule34",description=":underage: Searches for an image off of rule34") @Command(name="rule34",description=":underage: Searches for an image off of rule34")
@Option(name="query",description="Search query for rule34",type=OptionType.STRING,required=true) @Option(name="query",description="Search query for rule34",type=OptionType.STRING,required=true)
public Response execute(GuildMessageChannel channel, List<String> args){ public Response execute(GuildMessageChannel channel, List<Object> args){
if(!(channel instanceof TextChannel)) { if(!(channel instanceof TextChannel)) {
return Response.error("This command can only be used in a text channel"); return Response.error("This command can only be used in a text channel");
} }
@ -23,7 +29,7 @@ public class Rule34 {
if(!textChannel.isNSFW()){ if(!textChannel.isNSFW()){
return Response.error("This command can only be used in an NSFW channel"); return Response.error("This command can only be used in an NSFW channel");
} }
String url = Rule34API.request(args.get(0)); String url = request((String)args.get(0));
if(url == null){ if(url == null){
return Response.error("Unable to find post with search: "+args.get(0)); return Response.error("Unable to find post with search: "+args.get(0));
} else { } else {
@ -33,4 +39,21 @@ public class Rule34 {
} }
} }
private String request(String query) {
Document doc = (Document) new XmlRequest()
.setURL("https://rule34.xxx/index.php?page=dapi&s=post&q=index&tags=" + query)
.setType(HTTPMethod.GET)
.request();
try {
NodeList nList = doc.getElementsByTagName("post");
int choice = (int) (Math.random() * nList.getLength() - 1);
if (choice < 0) return null;
Node node = nList.item(choice);
Element element = (Element) node;
return element.getAttribute("file_url");
} catch (JSONException e) {
return null;
}
}
} }

View file

@ -1,52 +0,0 @@
package net.tylermurphy.ken.command.util;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.tylermurphy.ken.Ken;
import net.tylermurphy.ken.command.Command;
import net.tylermurphy.ken.command.Response;
public class Help {
@Command(name="help", description="Gets information about all the commands in the plugin")
public Response execute(Member sender){
String name = Ken.getInstance().getConfig().getString("botName");
String supportServer = Ken.getInstance().getConfig().getString("supportServer");
EmbedBuilder main = Ken.getInstance().getDefaultEmbed()
.setAuthor(name + " Command List", sender.getAvatarUrl())
.appendDescription(
"These are all the commands that are included with "+name+"\n" +
"Read below to see what each command does, and what parameters the\n" +
"command requires. Any questions? Join our [discord support server](https://discord.gg/"+supportServer+")"
);
EmbedBuilder essential = Ken.getInstance().getDefaultEmbed()
.setTitle(":pen_ballpoint: **Main Commands**")
.appendDescription("**/help** Gives a list of commands\n")
.appendDescription("**/purge <amount>** Purges an amount of messages from a channel\n");
EmbedBuilder music = Ken.getInstance().getDefaultEmbed()
.setTitle(":musical_note: **Music Commands**")
.appendDescription("**/play <query>** Plays a song in a voice channel\n")
.appendDescription("**/join** Make the bot join your audio channel\n")
.appendDescription("**/leave** Make the bot leave your audio channel\n")
.appendDescription("**/pause** Pause the current playing track\n")
.appendDescription("**/resume** Resume the current paused track\n")
.appendDescription("**/stop** Stop the current playing track and clear queue\n")
.appendDescription("**/skip** Vote to skip the current track\n")
.appendDescription("**/forceskip** Force skip the current track\n")
.appendDescription("**/loop** Loop the current track\n")
.appendDescription("**/loopqueue** Loop the current song queue\n")
.appendDescription("**/remove <index>** Remove a song from the queue\n")
.appendDescription("**/nowplaying** See what track is currently playing\n")
.appendDescription("**/queue** View the current song queue\n");
EmbedBuilder game = Ken.getInstance().getDefaultEmbed()
.setTitle(":game_die: **Game Commands**")
.appendDescription("**/d6** Roll a d6 die\n")
.appendDescription("**/d8** Roll a d8 die\n")
.appendDescription("**/d12** Roll a d12 die\n")
.appendDescription("**/d20** Roll a d20 die\n")
.appendDescription("**/dice <sides>** Roll a dice with set sides\n");
sender.getUser().openPrivateChannel().complete().sendMessageEmbeds(main.build(), essential.build(), music.build(), game.build()).queue();
return Response.success(":grey_question: Sent help message. Check your DMs!");
}
}

View file

@ -1,4 +1,4 @@
package net.tylermurphy.ken.command; package net.tylermurphy.ken.util;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View file

@ -1,4 +1,4 @@
package net.tylermurphy.ken.command; package net.tylermurphy.ken.util;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View file

@ -1,4 +1,4 @@
package net.tylermurphy.ken.command; package net.tylermurphy.ken.util;
import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.OptionType;

View file

@ -1,4 +1,4 @@
package net.tylermurphy.ken.command; package net.tylermurphy.ken.util;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View file

@ -1,4 +1,4 @@
package net.tylermurphy.ken.command; package net.tylermurphy.ken.util;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;

View file

@ -0,0 +1,16 @@
package net.tylermurphy.ken.util;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import java.lang.annotation.*;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(Selections.class)
public @interface Selection {
OptionType type();
String name();
String description();
String[] choices();
boolean required() default false;
}

View file

@ -0,0 +1,12 @@
package net.tylermurphy.ken.util;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Selections {
Selection[] value();
}