Skip to content

Commit 92b66a2

Browse files
Add the /emote command
1 parent 62b86fd commit 92b66a2

3 files changed

Lines changed: 125 additions & 0 deletions

File tree

src/main/java/technobot/commands/CommandRegistry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public CommandRegistry(TechnoBot bot) {
7474
new JokeCommand(bot),
7575
new MemeCommand(bot),
7676
new CuteCommand(bot),
77+
new EmoteCommand(bot),
7778
new NsfwCommand(bot),
7879
new EightBallCommand(bot),
7980
new GoogleCommand(bot),
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package technobot.commands.fun;
2+
3+
import net.dv8tion.jda.api.EmbedBuilder;
4+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
5+
import net.dv8tion.jda.api.interactions.commands.OptionType;
6+
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
7+
import okhttp3.Call;
8+
import okhttp3.Callback;
9+
import okhttp3.Request;
10+
import okhttp3.Response;
11+
import technobot.TechnoBot;
12+
import technobot.commands.Category;
13+
import technobot.commands.Command;
14+
import technobot.data.json.Emote;
15+
import technobot.util.embeds.EmbedColor;
16+
import technobot.util.embeds.EmbedUtils;
17+
18+
import java.io.IOException;
19+
20+
/**
21+
* Command that generates an image to match an emotion.
22+
*
23+
* @author TechnoVision
24+
*/
25+
public class EmoteCommand extends Command {
26+
27+
public EmoteCommand(TechnoBot bot) {
28+
super(bot);
29+
this.name = "emote";
30+
this.description = "Express your emotions virtually.";
31+
this.category = Category.FUN;
32+
this.args.add(new OptionData(OptionType.STRING, "emote", "The emotion to express.", true)
33+
.addChoice("angry", "mad")
34+
.addChoice("blush", "blush")
35+
.addChoice("celebrate", "celebrate")
36+
.addChoice("clap", "clap")
37+
.addChoice("confused", "confused")
38+
.addChoice("cry", "cry")
39+
.addChoice("dance", "dance")
40+
.addChoice("facepalm", "facepalm")
41+
.addChoice("happy", "happy")
42+
.addChoice("laugh", "laugh")
43+
.addChoice("pout", "pout")
44+
.addChoice("shrug", "shrug")
45+
.addChoice("shy", "shy")
46+
.addChoice("sigh", "sigh")
47+
.addChoice("slowclap", "slowclap")
48+
.addChoice("scared", "scared")
49+
.addChoice("sleep", "sleep")
50+
.addChoice("yawn", "yawn"));
51+
}
52+
53+
@Override
54+
public void execute(SlashCommandInteractionEvent event) {
55+
String url = "https://api.otakugifs.xyz/gif?reaction=";
56+
String emote = event.getOption("emote").getAsString();
57+
url += emote;
58+
59+
String text = event.getUser().getName() + " ";
60+
switch (emote) {
61+
case "mad" -> text += "doesn't like that.";
62+
case "blush" -> text += "has turned into a tomato.";
63+
case "celebrate" -> text += "is ready to celebrate!";
64+
case "clap" -> text += "claps excitedly.";
65+
case "confused" -> text += "is really confused.";
66+
case "cry" -> text += "needs a hug...";
67+
case "dance" -> text += "is dancing!";
68+
case "facepalm" -> text += "is in disbelief.";
69+
case "happy" -> text += "smiles.";
70+
case "laugh" -> text += "laughs out loud.";
71+
case "pout" -> text += "is in a bad mood.";
72+
case "shrug" -> text += "doesn't care...";
73+
case "shy" -> text += "is feeling timid.";
74+
case "sigh" -> text += "is disappointed.";
75+
case "slowclap" -> text += "is not amused.";
76+
case "scared" -> text += "fears for their life.";
77+
case "sleep" -> text += "falls into a deep sleep.";
78+
case "yawn" -> text += "is getting very sleepy.";
79+
}
80+
81+
// Asynchronous API call
82+
Request request = new Request.Builder().url(url).build();
83+
String finalText = text;
84+
bot.httpClient.newCall(request).enqueue(new Callback() {
85+
@Override
86+
public void onFailure(Call call, IOException e) {
87+
String text = "I was unable to fetch that emote!";
88+
event.replyEmbeds(EmbedUtils.createError(text)).setEphemeral(true).queue();
89+
}
90+
91+
@Override
92+
public void onResponse(Call call, final Response response) throws IOException {
93+
if (!response.isSuccessful()) throw new IOException();
94+
Emote entity = bot.gson.fromJson(response.body().string(), Emote.class);
95+
96+
EmbedBuilder embed = new EmbedBuilder()
97+
.setColor(EmbedColor.DEFAULT.color)
98+
.setAuthor(finalText, null, event.getUser().getEffectiveAvatarUrl())
99+
.setImage(entity.getUrl());
100+
event.replyEmbeds(embed.build()).queue();
101+
}
102+
});
103+
}
104+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package technobot.data.json;
2+
3+
/**
4+
* Represents an anime emote retrieved from an API.
5+
* Used by OkHttp and Gson to convert JSON to java code.
6+
*
7+
* @author TechnoVision
8+
*/
9+
public class Emote {
10+
11+
private String url;
12+
13+
public Emote(String url) {
14+
this.url = url;
15+
}
16+
17+
public String getUrl() {
18+
return url;
19+
}
20+
}

0 commit comments

Comments
 (0)