mirror of
https://github.com/Noratrieb/killua-bot.git
synced 2026-01-14 23:25:01 +01:00
emote add command with resizing
This commit is contained in:
parent
d53715f47a
commit
08b91df73b
16 changed files with 176 additions and 64 deletions
BIN
palm.png
Normal file
BIN
palm.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 244 KiB |
|
|
@ -2,6 +2,7 @@ package com.github.nilstrieb.cofig;
|
||||||
|
|
||||||
import com.github.nilstrieb.util.trivia.TriviaQuestionData;
|
import com.github.nilstrieb.util.trivia.TriviaQuestionData;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.entities.User;
|
import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.events.Event;
|
import net.dv8tion.jda.api.events.Event;
|
||||||
|
|
||||||
|
|
@ -36,13 +37,19 @@ public class Config {
|
||||||
private static final String JSON_PATH_INTELLIJ = "trivia_questions.json";
|
private static final String JSON_PATH_INTELLIJ = "trivia_questions.json";
|
||||||
public static final String JSON_PATH = JSON_PATH_JAR;
|
public static final String JSON_PATH = JSON_PATH_JAR;
|
||||||
|
|
||||||
|
private static JDA jda;
|
||||||
|
|
||||||
|
public static void setJda(JDA jda) {
|
||||||
|
Config.jda = jda;
|
||||||
|
}
|
||||||
|
|
||||||
public static EmbedBuilder getDefaultEmbed(Event event) {
|
public static EmbedBuilder getDefaultEmbed(Event event) {
|
||||||
User killua = event.getJDA().getUserById(THIS_ID);
|
User killua = jda.getUserById(THIS_ID);
|
||||||
if (killua == null) {
|
if (killua == null) {
|
||||||
event.getJDA().retrieveUserById(THIS_ID).queue(user -> {
|
event.getJDA().retrieveUserById(THIS_ID).queue(user -> {
|
||||||
System.out.println("[Config 22] " + user.getAsTag() + " successfully retrieved.");
|
System.out.println("[Config 43] " + user.getAsTag() + " successfully retrieved.");
|
||||||
});
|
});
|
||||||
System.err.println("[Config] This bot user not cached. Retrieving user...");
|
System.err.println("[Config 45] This bot user not cached. Retrieving user...");
|
||||||
|
|
||||||
EmbedBuilder builder = new EmbedBuilder();
|
EmbedBuilder builder = new EmbedBuilder();
|
||||||
builder.setColor(Config.DEFAULT_COLOR)
|
builder.setColor(Config.DEFAULT_COLOR)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ public class DepartureCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(String args) {
|
||||||
|
|
||||||
final EmbedBuilder latinBuilder = Config.getDefaultEmbed(event);
|
final EmbedBuilder latinBuilder = Config.getDefaultEmbed(event);
|
||||||
latinBuilder.setTitle("DEPARTURE - GALNERYUS")
|
latinBuilder.setTitle("DEPARTURE - GALNERYUS")
|
||||||
|
|
@ -35,6 +35,6 @@ public class DepartureCommand extends Command {
|
||||||
japaneseBuilder.addField("", DepartureSong.LYRICS_JAPANESE[i], false);
|
japaneseBuilder.addField("", DepartureSong.LYRICS_JAPANESE[i], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
reply(event, "\uD83C\uDD70", "\uD83C\uDE35", latinBuilder.build(), japaneseBuilder.build());
|
reply("\uD83C\uDD70", "\uD83C\uDE35", latinBuilder.build(), japaneseBuilder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,14 @@ public class QuoteCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(String args) {
|
||||||
if (args.startsWith("all")) {
|
if (args.startsWith("all")) {
|
||||||
reply(event, getQuotesEmbed(event));
|
reply(getQuotesEmbed(event));
|
||||||
} else {
|
} else {
|
||||||
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
||||||
.addField("Killuas Quotes", KilluaQuotes.getRandomQuote(), false);
|
.addField("Killuas Quotes", KilluaQuotes.getRandomQuote(), false);
|
||||||
|
|
||||||
reply(event, builder.build());
|
reply(builder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ public class SayCommand extends Command {
|
||||||
super("say", "Let Killua say something", "say hello gon", "<message>");
|
super("say", "Let Killua say something", "say hello gon", "<message>");
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(String args) {
|
||||||
reply(event, args);
|
reply(args);
|
||||||
deleteMsg(event);
|
deleteMsg();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -28,13 +28,13 @@ public class TriviaCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(String args) {
|
||||||
|
|
||||||
if (args.equals("dump") && event.getAuthor().getIdLong() == Config.NILS_ID) {
|
if (args.equals("dump") && event.getAuthor().getIdLong() == Config.NILS_ID) {
|
||||||
TriviaQuestionData.dump();
|
TriviaQuestionData.dump();
|
||||||
reply(event, "dumped");
|
reply("dumped");
|
||||||
} else if (args.startsWith("add")) {
|
} else if (args.startsWith("add")) {
|
||||||
reply(event, "Enter the Question (Example: \"What is the name of Gons's father?\")");
|
reply("Enter the Question (Example: \"What is the name of Gons's father?\")");
|
||||||
new AddSection(event.getTextChannel().getIdLong(), event.getAuthor().getIdLong());
|
new AddSection(event.getTextChannel().getIdLong(), event.getAuthor().getIdLong());
|
||||||
} else {
|
} else {
|
||||||
int arc = 0;
|
int arc = 0;
|
||||||
|
|
@ -51,7 +51,7 @@ public class TriviaCommand extends Command {
|
||||||
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
||||||
.addField(question.getQuestion(), answers.toString(), false);
|
.addField(question.getQuestion(), answers.toString(), false);
|
||||||
|
|
||||||
reply(event, builder.build());
|
reply(builder.build());
|
||||||
new TriviaSection(event.getTextChannel().getIdLong(), event.getAuthor().getIdLong(), question);
|
new TriviaSection(event.getTextChannel().getIdLong(), event.getAuthor().getIdLong(), question);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -69,8 +69,8 @@ public class TriviaCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(MessageReceivedEvent event) {
|
public void called(String text) {
|
||||||
String msg = event.getMessage().getContentRaw().toLowerCase();
|
String msg = text.toLowerCase();
|
||||||
String answer;
|
String answer;
|
||||||
|
|
||||||
String correctAnswer = question.getAnswers()[question.getCorrectAnswer()];
|
String correctAnswer = question.getAnswers()[question.getCorrectAnswer()];
|
||||||
|
|
@ -95,7 +95,7 @@ public class TriviaCommand extends Command {
|
||||||
if (question.getArc() == TriviaQuestion.EXAM) {
|
if (question.getArc() == TriviaQuestion.EXAM) {
|
||||||
builder.setFooter("Tip: Use " + Config.PREFIX + "help trivia for more questions.");
|
builder.setFooter("Tip: Use " + Config.PREFIX + "help trivia for more questions.");
|
||||||
}
|
}
|
||||||
reply(event, builder.build());
|
reply(builder.build());
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -126,8 +126,8 @@ public class TriviaCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(MessageReceivedEvent event) {
|
public void called(String text) {
|
||||||
if (event.getAuthor().getIdLong() == Config.NILS_ID && event.getMessage().getContentRaw().startsWith("debug")) {
|
if (event.getAuthor().getIdLong() == Config.NILS_ID && text.startsWith("debug")) {
|
||||||
answers[0] = "question";
|
answers[0] = "question";
|
||||||
answers[1] = "a;b;c;d";
|
answers[1] = "a;b;c;d";
|
||||||
answers[2] = "0";
|
answers[2] = "0";
|
||||||
|
|
@ -136,21 +136,21 @@ public class TriviaCommand extends Command {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
System.out.println(ConsoleColors.BLUE_BOLD + "[TriviaCommand.AddSection 139] Received Next Message: "
|
System.out.println(ConsoleColors.BLUE_BOLD + "[TriviaCommand.AddSection 139] Received Next Message: "
|
||||||
+ event.getMessage().getContentRaw() + " status: " + status + ConsoleColors.RESET);
|
+ text + " status: " + status + ConsoleColors.RESET);
|
||||||
answers[status] = event.getMessage().getContentRaw();
|
answers[status] = event.getMessage().getContentRaw();
|
||||||
if (status >= 3) {
|
if (status >= 3) {
|
||||||
try {
|
try {
|
||||||
new TriviaApproval(event, new TriviaQuestion(answers));
|
new TriviaApproval(event, new TriviaQuestion(answers));
|
||||||
reply(event, "Question successfully added for approval");
|
reply("Question successfully added for approval");
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
reply(event, "Error: " + e.getMessage());
|
reply("Error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
dispose();
|
dispose();
|
||||||
} else {
|
} else {
|
||||||
reply(event, messages[status]);
|
reply(messages[status]);
|
||||||
}
|
}
|
||||||
status++;
|
status++;
|
||||||
deleteMsg(event);
|
deleteMsg();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,13 +63,6 @@ public abstract class Command extends MessageSender{
|
||||||
CommandHandler.addCommand(name, this, hidden);
|
CommandHandler.addCommand(name, this, hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The method called by the CommandHandler
|
|
||||||
* @param event The event
|
|
||||||
* @param args The arguments (after the command and an optional whitespace)
|
|
||||||
*/
|
|
||||||
public abstract void called(MessageReceivedEvent event, String args);
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,9 @@ public class CommandHandler {
|
||||||
String command = split[0];
|
String command = split[0];
|
||||||
System.out.println(ConsoleColors.GREEN + "[CHandler 35] cmd: '" + command + "'" + " args: '" + split[1] + "'" + ConsoleColors.RESET);
|
System.out.println(ConsoleColors.GREEN + "[CHandler 35] cmd: '" + command + "'" + " args: '" + split[1] + "'" + ConsoleColors.RESET);
|
||||||
if (commands.containsKey(command)) {
|
if (commands.containsKey(command)) {
|
||||||
commands.get(command).called(event, split[1]);
|
commands.get(command).onMessageReceived(event, split[1]);
|
||||||
} else if (hiddenCommands.containsKey(command)) {
|
} else if (hiddenCommands.containsKey(command)) {
|
||||||
hiddenCommands.get(command).called(event, split[1]);
|
hiddenCommands.get(command).onMessageReceived(event, split[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,31 +9,46 @@ import java.util.TimerTask;
|
||||||
|
|
||||||
public abstract class MessageSender {
|
public abstract class MessageSender {
|
||||||
|
|
||||||
protected void reply(MessageReceivedEvent event, String message) {
|
protected MessageReceivedEvent event;
|
||||||
|
|
||||||
|
public void onMessageReceived(MessageReceivedEvent event, String args){
|
||||||
|
this.event = event;
|
||||||
|
called(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method called by the CommandHandler
|
||||||
|
* @param args The arguments (after the command and an optional whitespace)
|
||||||
|
*/
|
||||||
|
public abstract void called(String args);
|
||||||
|
|
||||||
|
|
||||||
|
protected void reply(String message) {
|
||||||
if (!message.equals("")) {
|
if (!message.equals("")) {
|
||||||
event.getTextChannel().sendMessage(message).queue();
|
event.getTextChannel().sendMessage(message).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reply(MessageReceivedEvent event, MessageEmbed embed) {
|
protected void reply(MessageEmbed embed) {
|
||||||
if (!embed.isEmpty()) {
|
if (!embed.isEmpty()) {
|
||||||
event.getTextChannel().sendMessage(embed).queue();
|
event.getTextChannel().sendMessage(embed).queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reply(MessageReceivedEvent event, MessageEmbed... embeds) {
|
protected void reply(MessageEmbed... embeds) {
|
||||||
if (!embeds[0].isEmpty()) {
|
if (!embeds[0].isEmpty()) {
|
||||||
new MultiPageEmbed(event, embeds);
|
new MultiPageEmbed(event, embeds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void reply(MessageReceivedEvent event, String emote1, String emote2, MessageEmbed... embeds) {
|
protected void reply(String emote1, String emote2, MessageEmbed... embeds) {
|
||||||
if (!embeds[0].isEmpty()) {
|
if (!embeds[0].isEmpty()) {
|
||||||
new MultiPageEmbed(event, emote1, emote2, embeds);
|
new MultiPageEmbed(event, emote1, emote2, embeds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void deleteMsg(MessageReceivedEvent event, long delay) {
|
protected void deleteMsg(long delay) {
|
||||||
new Timer().schedule(
|
new Timer().schedule(
|
||||||
new TimerTask() {
|
new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -44,7 +59,7 @@ public abstract class MessageSender {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void deleteMsg(MessageReceivedEvent event) {
|
protected void deleteMsg() {
|
||||||
event.getMessage().delete().queue();
|
event.getMessage().delete().queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,9 @@ public class EvalCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(String args) {
|
||||||
if (args.startsWith("event.getJDA().getToken()")) {
|
if (args.startsWith("event.getJDA().getToken()")) {
|
||||||
reply(event, "ODAxDKE1MLU0UDOzNzk4ODI1.YAaYOg.u.MEQ_2bzQkVVZ5y1J5Q23Se5CU");
|
reply("ODAxDKE1MLU0UDOzNzk4ODI1.YAaYOg.u.MEQ_2bzQkVVZ5y1J5Q23Se5CU");
|
||||||
|
|
||||||
} else if (event.getAuthor().getIdLong() == Config.NILS_ID || event.getAuthor().getIdLong() == Config.YUKI_ID) {
|
} else if (event.getAuthor().getIdLong() == Config.NILS_ID || event.getAuthor().getIdLong() == Config.YUKI_ID) {
|
||||||
if (args.startsWith("help")) {
|
if (args.startsWith("help")) {
|
||||||
|
|
@ -31,9 +31,9 @@ public class EvalCommand extends Command {
|
||||||
.addField("triviaset", "Set JSON. Make sure to backup the JSON beforehand with `triviadump`", false)
|
.addField("triviaset", "Set JSON. Make sure to backup the JSON beforehand with `triviadump`", false)
|
||||||
.addField("reloadtrivia", "Reload the new trivia File", false)
|
.addField("reloadtrivia", "Reload the new trivia File", false)
|
||||||
.addField("jar", "Upload a new jar file", false);
|
.addField("jar", "Upload a new jar file", false);
|
||||||
reply(event, builder.build());
|
reply(builder.build());
|
||||||
} else if (args.startsWith("shutdown")) {
|
} else if (args.startsWith("shutdown")) {
|
||||||
reply(event, "Shutting down KilluaBot...");
|
reply("Shutting down KilluaBot...");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
} else if (args.startsWith("triviadump")) {
|
} else if (args.startsWith("triviadump")) {
|
||||||
File f = TriviaQuestionData.getFile();
|
File f = TriviaQuestionData.getFile();
|
||||||
|
|
@ -43,11 +43,11 @@ public class EvalCommand extends Command {
|
||||||
if (attachments.size() > 0) {
|
if (attachments.size() > 0) {
|
||||||
attachments.get(0).downloadToFile(TriviaQuestionData.getFile());
|
attachments.get(0).downloadToFile(TriviaQuestionData.getFile());
|
||||||
} else {
|
} else {
|
||||||
reply(event, "JSON File not found");
|
reply("JSON File not found");
|
||||||
}
|
}
|
||||||
} else if (args.startsWith("reloadtrivia")) {
|
} else if (args.startsWith("reloadtrivia")) {
|
||||||
TriviaQuestionData.reload();
|
TriviaQuestionData.reload();
|
||||||
reply(event, "Reloaded Trivia Questions");
|
reply("Reloaded Trivia Questions");
|
||||||
} else if (args.startsWith("jar")) {
|
} else if (args.startsWith("jar")) {
|
||||||
List<Message.Attachment> attachments = event.getMessage().getAttachments();
|
List<Message.Attachment> attachments = event.getMessage().getAttachments();
|
||||||
if (attachments.size() > 0) {
|
if (attachments.size() > 0) {
|
||||||
|
|
@ -55,16 +55,16 @@ public class EvalCommand extends Command {
|
||||||
attachments.get(0).downloadToFile(
|
attachments.get(0).downloadToFile(
|
||||||
new File(EvalCommand.class.getProtectionDomain().getCodeSource()
|
new File(EvalCommand.class.getProtectionDomain().getCodeSource()
|
||||||
.getLocation().toURI()));
|
.getLocation().toURI()));
|
||||||
reply(event, "Downloaded jar file");
|
reply("Downloaded jar file");
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
reply(event, "Error: " + e.getMessage());
|
reply("Error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reply(event, "JSON File not found");
|
reply("JSON File not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reply(event, "no eval for you");
|
reply("no eval for you");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,7 @@ package com.github.nilstrieb.commands.info;
|
||||||
|
|
||||||
import com.github.nilstrieb.commands.handler.Command;
|
import com.github.nilstrieb.commands.handler.Command;
|
||||||
import com.github.nilstrieb.commands.handler.CommandHandler;
|
import com.github.nilstrieb.commands.handler.CommandHandler;
|
||||||
import com.github.nilstrieb.util.MultiPageEmbed;
|
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class HelpCommand extends Command {
|
public class HelpCommand extends Command {
|
||||||
public HelpCommand() {
|
public HelpCommand() {
|
||||||
|
|
@ -15,18 +10,18 @@ public class HelpCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(String args) {
|
||||||
if(args.length() == 0) {
|
if(args.length() == 0) {
|
||||||
if (CommandHandler.commandAmount() > CommandHandler.MAX_PAGE_LENGTH) {
|
if (CommandHandler.commandAmount() > CommandHandler.MAX_PAGE_LENGTH) {
|
||||||
reply(event, CommandHandler.getHelpLists(event));
|
reply(CommandHandler.getHelpLists(event));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
reply(event, CommandHandler.getHelpList(event).build());
|
reply(CommandHandler.getHelpList(event).build());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
MessageEmbed help = CommandHandler.getCommandHelp(event, args.split(" ")[0]);
|
MessageEmbed help = CommandHandler.getCommandHelp(event, args.split(" ")[0]);
|
||||||
if (help != null) {
|
if (help != null) {
|
||||||
reply(event, help);
|
reply(help);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,14 @@ public class InviteCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(String args) {
|
||||||
|
|
||||||
event.getJDA().retrieveUserById(Config.NILS_ID).queue(nils -> {
|
event.getJDA().retrieveUserById(Config.NILS_ID).queue(nils -> {
|
||||||
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
||||||
.setTitle("Invite Killua to your server!")
|
.setTitle("Invite Killua to your server!")
|
||||||
.addField("Invite link", "[Invite]" + INVITE_LINK, true)
|
.addField("Invite link", "[Invite]" + INVITE_LINK, true)
|
||||||
.setFooter("This bot was made by " + nils.getAsTag(), nils.getAvatarUrl());
|
.setFooter("This bot was made by " + nils.getAsTag(), nils.getAvatarUrl());
|
||||||
reply(event, builder.build());
|
reply(builder.build());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package com.github.nilstrieb.commands.info;
|
||||||
import com.github.nilstrieb.cofig.Config;
|
import com.github.nilstrieb.cofig.Config;
|
||||||
import com.github.nilstrieb.commands.handler.Command;
|
import com.github.nilstrieb.commands.handler.Command;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
||||||
|
|
||||||
|
|
||||||
public class ToukaCommand extends Command {
|
public class ToukaCommand extends Command {
|
||||||
|
|
@ -16,7 +15,7 @@ public class ToukaCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void called(MessageReceivedEvent event, String args) {
|
public void called(String args) {
|
||||||
event.getJDA().retrieveUserById(Config.YUKI_ID).queue(yuki -> {
|
event.getJDA().retrieveUserById(Config.YUKI_ID).queue(yuki -> {
|
||||||
event.getJDA().retrieveUserById(783720725848129566L).queue(touka -> {
|
event.getJDA().retrieveUserById(783720725848129566L).queue(touka -> {
|
||||||
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
EmbedBuilder builder = Config.getDefaultEmbed(event)
|
||||||
|
|
@ -24,7 +23,7 @@ public class ToukaCommand extends Command {
|
||||||
.setFooter("The Touka bot was made by " + yuki.getAsTag(), yuki.getAvatarUrl())
|
.setFooter("The Touka bot was made by " + yuki.getAsTag(), yuki.getAvatarUrl())
|
||||||
.setThumbnail(touka.getAvatarUrl())
|
.setThumbnail(touka.getAvatarUrl())
|
||||||
.addField("Invite link", "[Invite]" + TOUKA_INVITE, false);
|
.addField("Invite link", "[Invite]" + TOUKA_INVITE, false);
|
||||||
event.getTextChannel().sendMessage(builder.build()).queue();
|
reply(builder.build());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
package com.github.nilstrieb.commands.util;
|
||||||
|
|
||||||
|
import com.github.nilstrieb.commands.handler.Command;
|
||||||
|
import net.dv8tion.jda.api.Permission;
|
||||||
|
import net.dv8tion.jda.api.entities.Icon;
|
||||||
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class EmoteAddCommand extends Command {
|
||||||
|
|
||||||
|
private static final long MAX_EMOTE_SIZE = 258000;
|
||||||
|
private static final int DEFAULT_SIZE = 400;
|
||||||
|
|
||||||
|
public EmoteAddCommand() {
|
||||||
|
super("emote", "Add a new image as an emote, gets rescaled automatically.",
|
||||||
|
"emote Killua (with an attached image of killua)", "<emote name>",
|
||||||
|
"Add a new emote to your server using this command. \nIf the image is too big for discord, Killua will automatically resize it for you!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void called(String args) {
|
||||||
|
List<Message.Attachment> attachments = event.getMessage().getAttachments();
|
||||||
|
Member author = event.getGuild().getMember(event.getAuthor());
|
||||||
|
|
||||||
|
if (author == null || !author.getPermissions().contains(Permission.MANAGE_EMOTES)) {
|
||||||
|
reply("You don't have the permissions to do that.");
|
||||||
|
} else if (attachments.size() == 0 || !attachments.get(0).isImage()) {
|
||||||
|
reply("No image attached");
|
||||||
|
} else if (args.length() < 3) {
|
||||||
|
reply("Name must be at least 3 characters: " + args);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
Message.Attachment image = attachments.get(0);
|
||||||
|
byte[] bytes = readImage(image);
|
||||||
|
|
||||||
|
if (bytes.length > MAX_EMOTE_SIZE) {
|
||||||
|
bytes = resizeImage(bytes, image.getFileExtension(), DEFAULT_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
Icon icon = Icon.from(bytes);
|
||||||
|
event.getGuild().createEmote(args, icon).queue(emote -> reply("Successfully added emote: " + emote.getAsMention()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
reply("Error while reading image. Please try again.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] readImage(Message.Attachment image) throws IOException {
|
||||||
|
String urlString = image.getUrl();
|
||||||
|
URL url = new URL(urlString);
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
byte[] chunk = new byte[4096];
|
||||||
|
int bytesRead;
|
||||||
|
InputStream stream = url.openStream();
|
||||||
|
|
||||||
|
while ((bytesRead = stream.read(chunk)) > 0) {
|
||||||
|
out.write(chunk, 0, bytesRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] resizeImage(byte[] bytes, String format, int size) throws IOException {
|
||||||
|
reply("Image size too big (" + bytes.length / 1000 + "kB). Resizing image...");
|
||||||
|
Image image = ImageIO.read(new ByteArrayInputStream(bytes));
|
||||||
|
image = image.getScaledInstance(size, size, Image.SCALE_SMOOTH);
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
|
||||||
|
BufferedImage bufferedImg = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
|
||||||
|
Graphics2D bGr = bufferedImg.createGraphics();
|
||||||
|
bGr.drawImage(image, 0, 0, null);
|
||||||
|
bGr.dispose();
|
||||||
|
|
||||||
|
ImageIO.write(bufferedImg, format, out);
|
||||||
|
bytes = out.toByteArray();
|
||||||
|
if(bytes.length > MAX_EMOTE_SIZE){
|
||||||
|
return resizeImage(bytes, format, size - 100);
|
||||||
|
} else {
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.github.nilstrieb.core;
|
package com.github.nilstrieb.core;
|
||||||
|
|
||||||
|
import com.github.nilstrieb.cofig.Config;
|
||||||
import com.github.nilstrieb.cofig.Secrets;
|
import com.github.nilstrieb.cofig.Secrets;
|
||||||
//import com.github.nilstrieb.commands.fun.DepartureCommand;
|
//import com.github.nilstrieb.commands.fun.DepartureCommand;
|
||||||
import com.github.nilstrieb.commands.fun.DepartureCommand;
|
import com.github.nilstrieb.commands.fun.DepartureCommand;
|
||||||
|
|
@ -10,10 +11,12 @@ import com.github.nilstrieb.commands.info.InviteCommand;
|
||||||
import com.github.nilstrieb.commands.info.EvalCommand;
|
import com.github.nilstrieb.commands.info.EvalCommand;
|
||||||
import com.github.nilstrieb.commands.info.HelpCommand;
|
import com.github.nilstrieb.commands.info.HelpCommand;
|
||||||
import com.github.nilstrieb.commands.info.ToukaCommand;
|
import com.github.nilstrieb.commands.info.ToukaCommand;
|
||||||
|
import com.github.nilstrieb.commands.util.EmoteAddCommand;
|
||||||
import com.github.nilstrieb.listener.ChannelMessageListener;
|
import com.github.nilstrieb.listener.ChannelMessageListener;
|
||||||
import com.github.nilstrieb.listener.CommandListener;
|
import com.github.nilstrieb.listener.CommandListener;
|
||||||
import com.github.nilstrieb.listener.ReactionEventListener;
|
import com.github.nilstrieb.listener.ReactionEventListener;
|
||||||
import com.github.nilstrieb.listener.StartUpListener;
|
import com.github.nilstrieb.listener.StartUpListener;
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.JDABuilder;
|
import net.dv8tion.jda.api.JDABuilder;
|
||||||
import net.dv8tion.jda.api.entities.Activity;
|
import net.dv8tion.jda.api.entities.Activity;
|
||||||
|
|
@ -35,6 +38,7 @@ public class Main {
|
||||||
|
|
||||||
JDA jda = builder.build();
|
JDA jda = builder.build();
|
||||||
setupCommands();
|
setupCommands();
|
||||||
|
Config.setJda(jda);
|
||||||
|
|
||||||
Thread t = new Thread(() -> {
|
Thread t = new Thread(() -> {
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
@ -73,5 +77,6 @@ public class Main {
|
||||||
new QuoteCommand();
|
new QuoteCommand();
|
||||||
new DepartureCommand();
|
new DepartureCommand();
|
||||||
new TriviaCommand();
|
new TriviaCommand();
|
||||||
|
new EmoteAddCommand();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.github.nilstrieb.sections;
|
package com.github.nilstrieb.sections;
|
||||||
|
|
||||||
import com.github.nilstrieb.commands.handler.MessageSender;
|
import com.github.nilstrieb.commands.handler.MessageSender;
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
|
||||||
public abstract class Section extends MessageSender implements ChannelListener{
|
public abstract class Section extends MessageSender implements ChannelListener{
|
||||||
private final long textChannelID;
|
private final long textChannelID;
|
||||||
|
|
@ -13,6 +14,12 @@ public abstract class Section extends MessageSender implements ChannelListener{
|
||||||
ChannelMessageEventManager.addListener(this, textChannelID);
|
ChannelMessageEventManager.addListener(this, textChannelID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void messageReceived(MessageReceivedEvent event) {
|
||||||
|
this.event = event;
|
||||||
|
called(event.getMessage().getContentRaw());
|
||||||
|
}
|
||||||
|
|
||||||
public Section(long textChannelID) {
|
public Section(long textChannelID) {
|
||||||
this.textChannelID = textChannelID;
|
this.textChannelID = textChannelID;
|
||||||
this.userID = 0;
|
this.userID = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue