Compare commits

...

3 commits

Author SHA1 Message Date
Anya eebc73ac0c 0.6.0-pre
This changes all commands to use EmbedUI.
This also changes most commands to give more info about what parameters the user sent.
2022-03-29 04:52:52 -07:00
Anya e291c7d2d8 Added EmbedUI
This is a reference class for creating embeds.
It contains common strings & colors for use in commands and listeners.
2022-03-29 03:33:03 -07:00
Anya b8e0b9a1c8 Update readme.md 2022-03-28 23:24:25 -07:00
10 changed files with 166 additions and 129 deletions

View file

@ -7,7 +7,7 @@
<groupId>moe.oko</groupId>
<artifactId>Kiafumi</artifactId>
<name>Kiafumi</name>
<version>0.5</version>
<version>0.6.0-pre</version>
<packaging>jar</packaging>
<url>https://oko.moe/kiafumi.htm</url>

View file

@ -1,13 +1,23 @@
# Kiafumi
A kitchen-sink discord bot designed to replace [Skyra](https://skyra.pw) v7 for use in the [HC](https://discord.gg/utgAEV2) network.
It's written in [JDA](https://github.com/DV8FromTheWorld/JDA) and is intended to be resource conscious where possible.
It's written in Java, using [JDA](https://github.com/DV8FromTheWorld/JDA). User feedback is greatly encouraged!
### Credits & Thanks
+ [oko](https://oko.moe) (Development + Moral Support)
+ [Tiddy](https://tiddy.oko.moe) (Development + Being an Angel)
+ [Laika](http://alpinia.link) (Development + Java Shenanigans)
+ [Favna](https://favware.tech), for maintaining [Ribbon](https://github.com/favna/ribbon) from 2017-2019, & Skyra to this day!
### Installation
1. Download from the [Releases](https://fem.mint.lgbt/oko/kiafumi/releases), or compile with `mvn clean package`.
2. Run `Kiafumi-x.x.jar` in an empty directory.
3. Create a new MariaDB(**Not** MySQL) database.
4. Open and configure the generated `config.yml`.
5. Run `Kiafumi-x.x.jar` again.
### License
Copyright © 2022 oko, under the [ISC License](./LICENSE)

View file

@ -5,6 +5,7 @@ import moe.oko.Kiafumi.listener.MainListener;
import moe.oko.Kiafumi.model.KiafumiDB;
import moe.oko.Kiafumi.model.ServerManager;
import moe.oko.Kiafumi.util.CommandInfo;
import moe.oko.Kiafumi.util.EmbedUI;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
@ -20,7 +21,6 @@ import org.simpleyaml.configuration.file.YamlConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
@ -173,11 +173,11 @@ public class Kiafumi {
info("Loaded " + activeCommands.size() + " commands.");
EmbedBuilder eb = new EmbedBuilder()
.setTitle("Kiafumi Online")
.setColor(EmbedUI.SUCCESS)
.setAuthor("Kiafumi", null, Kiafumi.JDA.getSelfUser().getAvatarUrl())
.setTitle("Online")
.setFooter("Created by Oko, Laika, and Tiddy")
.setColor(new Color(0x6271c1))
.setTimestamp(ZonedDateTime.now())
.setAuthor("Kiafumi!", null, Kiafumi.JDA.getSelfUser().getAvatarUrl());
.setTimestamp(ZonedDateTime.now());
JDA.getTextChannelById(config.getLogChannel()).sendMessageEmbeds(eb.build()).queue();
}

View file

@ -1,6 +1,7 @@
package moe.oko.Kiafumi.command;
import moe.oko.Kiafumi.util.CommandInfo;
import moe.oko.Kiafumi.util.EmbedUI;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
@ -8,15 +9,15 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import java.awt.*;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
// TODO: Make this actually a Dreidel, and use this code for a fight command.
public class DreidelCommand extends CommandClass {
private boolean enabled = true;
private boolean enabled = false;
@Override
public boolean isEnabled() {
return enabled;
@ -34,31 +35,30 @@ public class DreidelCommand extends CommandClass {
@Override
public void newCommand(String name, SlashCommandInteractionEvent e) {
switch (name) {
case "dreidel":
if ("dreidel".equals(name)) {
e.deferReply().queue();
List<User> usersForRng = new ArrayList<>();
for(OptionMapping option : e.getOptions()) {
for (OptionMapping option : e.getOptions()) {
usersForRng.add(option.getAsUser());
}
//Done, now roll
EmbedBuilder eb = new EmbedBuilder()
.setColor(Color.PINK)
.setColor(EmbedUI.INFO)
.setTitle("Rolling...")
.setDescription("*VROOOOOOOOOOOOOOOOM*")
.setFooter("Kiafumi - Maintained by oko.moe")
.setFooter(EmbedUI.BRAND)
.setTimestamp(ZonedDateTime.now());
e.getHook().sendMessageEmbeds(eb.build()).queue();
Random rng = new Random();
User pickedUser = usersForRng.get(rng.nextInt(usersForRng.size()));
EmbedBuilder eb1 = new EmbedBuilder()
.setColor(Color.PINK)
.setFooter("Kiafumi - Maintained by oko.moe")
.setTimestamp(ZonedDateTime.now())
.setColor(EmbedUI.INFO)
.setTitle("The dreidel has spoken...")
.setDescription(pickedUser.getName() + " is the lucky winner!")
.setThumbnail(pickedUser.getAvatarUrl())
.setDescription(pickedUser.getName() + " is the lucky winner!");
e.getHook().editOriginalEmbeds(eb1.build()).completeAfter(5, TimeUnit.SECONDS);
.setFooter(EmbedUI.BRAND) // TODO: Make this show the list of participants
.setTimestamp(ZonedDateTime.now());
e.getHook().editOriginalEmbeds(eb1.build()).completeAfter(3, TimeUnit.SECONDS);
}
}

View file

@ -1,6 +1,7 @@
package moe.oko.Kiafumi.command;
import moe.oko.Kiafumi.util.CommandInfo;
import moe.oko.Kiafumi.util.EmbedUI;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -8,7 +9,6 @@ import net.dv8tion.jda.api.interactions.commands.OptionType;
import org.bitnick.net.duckduckgo.WebSearch;
import org.bitnick.net.duckduckgo.entity.SearchResult;
import java.awt.Color;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
@ -33,8 +33,7 @@ public class DuckCommand extends CommandClass{
@Override
public void newCommand(String name, SlashCommandInteractionEvent e) {
switch (name) {
case "search":
if ("search".equals(name)) {
e.deferReply().queue();
String option = e.getOption("query").getAsString();
WebSearch ws = WebSearch.instanceOf();
@ -43,22 +42,21 @@ public class DuckCommand extends CommandClass{
sr = ws.instantAnswerSearch(option);
} catch (Exception ex) {
EmbedBuilder eb = new EmbedBuilder()
.setColor(Color.RED)
.setColor(EmbedUI.FAILURE)
.setTitle("Query Failed")
.setDescription("Couldn't find any results for " + option)
.setFooter("Kiafumi - Maintained by oko.moe")
.setDescription("Couldn't find any results.")
.setFooter("Query: " + option)
.setTimestamp(ZonedDateTime.now());
e.getHook().sendMessageEmbeds(eb.build()).queue();
return;
}
EmbedBuilder eb = new EmbedBuilder()
.setColor(Color.PINK)
.setColor(EmbedUI.INFO)
.setTitle(sr.getTitle(), sr.getUrl().toString())
.setDescription(sr.getDescription())
.setFooter("Kiafumi - Maintained by oko.moe")
.setFooter("Query: " + option)
.setTimestamp(ZonedDateTime.now());
e.getHook().sendMessageEmbeds(eb.build()).queue();
return; //unnecessary, but there.
}
}

View file

@ -6,7 +6,7 @@ import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import java.awt.*;
import moe.oko.Kiafumi.util.EmbedUI;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
@ -30,16 +30,16 @@ public class InviteCommand extends CommandClass{
@Override
public void newCommand(String name, SlashCommandInteractionEvent e) {
if(e.getGuild() == null) { return; }
switch (name) {
case "invite":
if ("invite".equals(name)) {
e.deferReply().queue();
EmbedBuilder eb = new EmbedBuilder()
.setColor(Color.PINK)
.setFooter("Kiafumi - Maintained by oko.moe")
.setTimestamp(ZonedDateTime.now())
.setColor(EmbedUI.INFO)
.setAuthor("Kiafumi", "https://oko.moe/kiafumi.htm", Kiafumi.JDA.getSelfUser().getAvatarUrl())
.setTitle("Invite me to your server!", Kiafumi.instance.config.assembleDefaultInvite())
.setDescription("Have a nice day!!!")
.setAuthor("oko.moe", "https://oko.moe", Kiafumi.JDA.getSelfUser().getAvatarUrl());
.setDescription("Alternatively, you can host me yourself!")
.appendDescription("https://fem.mint.lgbt/oko/kiafumi")
.setFooter(EmbedUI.BRAND)
.setTimestamp(ZonedDateTime.now());
e.getHook().sendMessageEmbeds(eb.build()).queue();
}
}
@ -52,7 +52,7 @@ public class InviteCommand extends CommandClass{
@Override
public List<CommandInfo> getSlashCommandInfo() {
List<CommandInfo> cil = new ArrayList<>();
CommandInfo ci = new CommandInfo("invite", "provides an invite for kiafumi.");
CommandInfo ci = new CommandInfo("invite", "Returns an invite for Kiafumi.");
cil.add(ci);
return cil;
}

View file

@ -2,13 +2,16 @@ package moe.oko.Kiafumi.command;
import moe.oko.Kiafumi.Kiafumi;
import moe.oko.Kiafumi.util.CommandInfo;
import moe.oko.Kiafumi.util.EmbedUI;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import java.awt.Color;
import java.util.*;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Random;
public class PingCommand extends CommandClass{
//Always true, ping cmd is EXISTENTIAL
@ -25,33 +28,34 @@ public class PingCommand extends CommandClass{
@Override
public void legacyCommand(String[] args, MessageReceivedEvent e, boolean prefix) {
if(!prefix) { return; }
switch(args[0].toLowerCase()) {
case "ping":
if ("ping".equals(args[0].toLowerCase())) {
long sentMs = e.getMessage().getTimeCreated().toInstant().toEpochMilli();
long recMs = System.currentTimeMillis();
long ping = sentMs - recMs;
EmbedBuilder eb = new EmbedBuilder().setColor(new Color(0x6271c1))
.setFooter("ping pong :)").setTitle(getComedy()).setDescription("Pinged " + ping + "ms");
long ping = recMs - sentMs;
EmbedBuilder eb = new EmbedBuilder()
.setColor(EmbedUI.INFO)
.setTitle(getComedy())
.setDescription("Pong! " + ping + "ms")
.setFooter(EmbedUI.BRAND)
.setTimestamp(ZonedDateTime.now());
e.getChannel().sendMessageEmbeds(eb.build()).queue();
return;
default:
//how
}
}
@Override
public void newCommand(String name, SlashCommandInteractionEvent e) {
switch(name.toLowerCase(Locale.ROOT)) {
case "ping":
if ("ping".equals(name.toLowerCase(Locale.ROOT))) {
e.deferReply().queue();
long sentMs = e.getTimeCreated().toInstant().toEpochMilli();
long recMs = System.currentTimeMillis();
long ping = sentMs - recMs;
EmbedBuilder eb = new EmbedBuilder().setColor(Color.PINK)
.setFooter("ping pong :)").setTitle(getComedy()).setDescription("Pinged " + ping + "ms");
long ping = recMs - sentMs;
EmbedBuilder eb = new EmbedBuilder()
.setColor(EmbedUI.INFO)
.setTitle(getComedy())
.setDescription("Pong! " + ping + "ms")
.setFooter(EmbedUI.BRAND)
.setTimestamp(ZonedDateTime.now());
e.getHook().sendMessageEmbeds(eb.build()).queue();
return;
default:
}
}
@ -68,7 +72,7 @@ public class PingCommand extends CommandClass{
@Override
public List<CommandInfo> getSlashCommandInfo() {
List<CommandInfo> si = new ArrayList<>();
CommandInfo ci = new CommandInfo("ping", "pings the server with a comedic message :)");
CommandInfo ci = new CommandInfo("ping", "Returns bot latency with a twist!");
si.add(ci);
return si;
}

View file

@ -3,12 +3,12 @@ package moe.oko.Kiafumi.command;
import moe.oko.Kiafumi.Kiafumi;
import moe.oko.Kiafumi.model.Server;
import moe.oko.Kiafumi.util.CommandInfo;
import moe.oko.Kiafumi.util.EmbedUI;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import java.awt.Color;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
@ -38,22 +38,22 @@ public class SettingCommand extends CommandClass {
e.deferReply().queue();
//No options, just fire an embed off...
EmbedBuilder eb = new EmbedBuilder()
.setColor(Color.PINK)
.setTitle("Server Settings")
.setFooter("Kiafumi - Maintained by oko.moe")
.setTimestamp(ZonedDateTime.now())
.setDescription(server.getOpts());
.setColor(EmbedUI.INFO)
.setTitle("Kiafumi Settings")
.setDescription(server.getOpts())
.setFooter(EmbedUI.BRAND)
.setTimestamp(ZonedDateTime.now());
e.getHook().sendMessageEmbeds(eb.build()).queue();
return;
case "setting":
e.deferReply().queue();
String opt = e.getOption("setting_name").getAsString();
EmbedBuilder eb1 = new EmbedBuilder()
.setColor(Color.PINK)
.setTitle(opt + " Value")
.setFooter("Kiafumi - Maintained by oko.moe")
.setTimestamp(ZonedDateTime.now())
.setDescription(server.getOptionByString(opt));
.setColor(EmbedUI.INFO)
.setTitle(opt)
.setDescription("Value: `" + server.getOptionByString(opt) + '`')
.setFooter(EmbedUI.BRAND)
.setTimestamp(ZonedDateTime.now());
e.getHook().sendMessageEmbeds(eb1.build()).queue();
return;
case "setting_set":
@ -62,11 +62,11 @@ public class SettingCommand extends CommandClass {
String opt2 = e.getOption("setting_value").getAsString();
String response = server.setOptionByString(opt1, opt2);
EmbedBuilder eb2 = new EmbedBuilder()
.setColor(Color.PINK)
.setTitle("Setting Modification - " + opt1)
.setFooter("Kiafumi - Maintained by oko.moe")
.setTimestamp(ZonedDateTime.now())
.setDescription(response);
.setColor(EmbedUI.SUCCESS)
.setTitle(opt1)
.setDescription(response)
.setFooter(EmbedUI.BRAND)
.setTimestamp(ZonedDateTime.now());
e.getHook().sendMessageEmbeds(eb2.build()).queue();
return;
case "setting_clear":
@ -74,11 +74,11 @@ public class SettingCommand extends CommandClass {
String opt3 = e.getOption("setting_name").getAsString();
String response1 = server.resetOptionByString(opt3);
EmbedBuilder eb3 = new EmbedBuilder()
.setColor(Color.PINK)
.setTitle("Setting Reset - " + opt3)
.setFooter("Kiafumi - Maintained by oko.moe")
.setTimestamp(ZonedDateTime.now())
.setDescription(response1);
.setColor(EmbedUI.SUCCESS)
.setTitle(opt3)
.setDescription(response1)
.setFooter(EmbedUI.BRAND)
.setTimestamp(ZonedDateTime.now());
e.getHook().sendMessageEmbeds(eb3.build()).queue();
return;
}

View file

@ -2,6 +2,7 @@ package moe.oko.Kiafumi.listener;
import moe.oko.Kiafumi.Kiafumi;
import moe.oko.Kiafumi.model.Server;
import moe.oko.Kiafumi.util.EmbedUI;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
@ -15,7 +16,6 @@ import net.dv8tion.jda.api.events.user.update.GenericUserPresenceEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
import java.awt.Color;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@ -57,12 +57,12 @@ public class MainListener extends ListenerAdapter {
public void onMessageReceived(MessageReceivedEvent event) {
if(event.getMessage().getMentionedUsers().contains(Kiafumi.JDA.getSelfUser())) {
EmbedBuilder eb = new EmbedBuilder()
.setColor(Color.PINK)
.setImage(Kiafumi.JDA.getSelfUser().getAvatarUrl())
.setColor(EmbedUI.INFO)
.setTitle("Hi, i'm Kiafumi!")
.setDescription("I was born on October 6th 2017! My goal is to explore the metaverse and help people in it!")
.setDescription("I was summoned on October 6th 2017! My goal is to explore the metaverse and help people in it!")
.setImage(Kiafumi.JDA.getSelfUser().getAvatarUrl())
.setTimestamp(ZonedDateTime.now())
.setFooter("Kiafumi - Maintained by oko.moe");
.setFooter(EmbedUI.BRAND);
event.getChannel().sendMessageEmbeds(eb.build()).queue();
}
}
@ -107,20 +107,23 @@ public class MainListener extends ListenerAdapter {
try {
event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(server.getJoinRole())).queue();
} catch(Exception ex) {
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to apply welcome role to " + event.getMember().getEffectiveName() + ", role did not exist.**").queue();
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to apply welcome role to " + event.getMember().getEffectiveName() + ", as the role does not exist.**").queue();
}
}
if(server.isWelcomeEnabled()) {
TextChannel textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
if(textChannel == null) {
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to send welcome message, welcome channel doesn't exist.**").queue();
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to send welcome message, as the welcome channel does not exist.**").queue();
return;
}
//Ok, now we proceed.
EmbedBuilder embedBuilder = new EmbedBuilder()
.setColor(EmbedUI.SUCCESS)
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
+ event.getMember().getId() + ")", null, event.getMember().getAvatarUrl()).setFooter("User Joined").setTimestamp(OffsetDateTime.now())
.setDescription(event.getMember().getAsMention() + " | **Joined Discord**: " + event.getMember().getTimeCreated()).setColor(Color.GREEN);
+ event.getMember().getId() + ")", null, event.getMember().getEffectiveAvatarUrl())
.setDescription(event.getMember().getAsMention() + " | **Joined Discord**: " + event.getMember().getTimeCreated())
.setFooter("User Joined")
.setTimestamp(OffsetDateTime.now());
textChannel.sendMessageEmbeds(embedBuilder.build()).queue();
}
}
@ -131,15 +134,18 @@ public class MainListener extends ListenerAdapter {
if(server.isWelcomeEnabled()) {
TextChannel textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
if(textChannel == null) {
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to send leave message, welcome channel doesn't exist.**").queue();
event.getGuild().getTextChannels().get(0).sendMessage("**Failed to send leave message, as the welcome channel does not exist.**").queue();
return;
}
//Ok, now we proceed.
DateTimeFormatter dTF = DateTimeFormatter.ofPattern("dd-MM-yyyy");
EmbedBuilder embedBuilder = new EmbedBuilder()
.setColor(EmbedUI.FAILURE)
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
+ event.getMember().getId() + ")", null, event.getMember().getAvatarUrl()).setFooter("User Left").setTimestamp(OffsetDateTime.now())
.setDescription(event.getMember().getAsMention() + " | **Joined Server**: " + event.getMember().getTimeJoined().format(dTF)).setColor(Color.RED);
+ event.getMember().getId() + ")", null, event.getMember().getEffectiveAvatarUrl())
.setDescription(event.getMember().getAsMention() + " | **Joined Server**: " + event.getMember().getTimeJoined().format(dTF))
.setFooter("User Left")
.setTimestamp(OffsetDateTime.now());
textChannel.sendMessageEmbeds(embedBuilder.build()).queue();
}
}

View file

@ -0,0 +1,19 @@
package moe.oko.Kiafumi.util;
import java.awt.Color;
public abstract class EmbedUI {
/**
* Shorthand reference for common EmbedBuilder colors & strings.
* I (oko) chose these colors based on the Pantone Color of the year.
*/
// Strings
public static final String BRAND = "Kiafumi - oko.moe";
// Colors
public static final Color SUCCESS = new Color(136,176,75);
public static final Color FAILURE = new Color(255,111,97);
public static final Color INFO = new Color(123,196,196);
}