Compare commits

...

4 commits

Author SHA1 Message Date
Anya ae092d3440 Add username edit logging 2022-05-21 03:42:11 -07:00
Anya 299622ed30 Clean up config.yml
removed some unnecessary pingResponses & fixed comments.
2022-05-21 01:43:17 -07:00
Anya b8887705ef Reorganize Listeners & Remove GamePrevention
I'm removing gamePrevention as it was out of scope for kya.
Splitting the MainListener should help with expanding kya's capabilities.
The SkynetListener class will provide further info for the logChannel.
2022-05-21 01:37:44 -07:00
Anya 2cdfef9d8a added correct handling for welcomeChannel variable mismatch. 2022-05-20 16:13:55 -07:00
5 changed files with 138 additions and 137 deletions

View file

@ -3,6 +3,7 @@ package moe.oko.Kiafumi;
import moe.oko.Kiafumi.command.CommandClass;
import moe.oko.Kiafumi.command.CommandRegistrar;
import moe.oko.Kiafumi.listener.MainListener;
import moe.oko.Kiafumi.listener.SkynetListener;
import moe.oko.Kiafumi.model.KiafumiDB;
import moe.oko.Kiafumi.model.ServerManager;
import moe.oko.Kiafumi.util.CommandInfo;
@ -168,7 +169,10 @@ public class Kiafumi {
.disableCache(CacheFlag.EMOTE)
.setActivity(Activity.of(Activity.ActivityType.valueOf(config.getActivityType()), config.getActivityMsg()))
.setStatus(OnlineStatus.valueOf(config.getStatusType()))
.addEventListeners(new MainListener()).build().awaitReady();
.addEventListeners(
new MainListener(),
new SkynetListener()
).build().awaitReady();
} catch(Exception ex) {
error("Initialization broke...");
ex.printStackTrace();

View file

@ -35,9 +35,7 @@ public class KiafumiConfig {
private String activityMsg;
private String statusType;
private List<String> pingResponses;
private boolean gamePrevention;
private int gameCheckTime;
private String gameToPrevent;
/*
SQL Variable Section
@ -92,9 +90,7 @@ public class KiafumiConfig {
activityMsg = main.getString("activityMsg");
statusType = main.getString("statusType");
pingResponses = main.getStringList("pingResponses");
gamePrevention = main.getBoolean("gamePrevention");
gameCheckTime = main.getInt("gameCheckTime");
gameToPrevent = main.getString("gameToPrevent");
// SQL loaders
var sql = configuration.getConfigurationSection("sql");
@ -130,12 +126,8 @@ public class KiafumiConfig {
public String getLogChannel() { return logChannel; }
public boolean isGamePreventionEnabled() { return gamePrevention; }
public int getGameCheckTime() { return gameCheckTime; }
public String getGameToPrevent() { return gameToPrevent; }
public List<String> getPingResponses() { return pingResponses; }
public KiafumiDB createDb() { return new KiafumiDB(username, password, host, port, database); }

View file

@ -3,30 +3,19 @@ package moe.oko.Kiafumi.listener;
import moe.oko.Kiafumi.Kiafumi;
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;
import net.dv8tion.jda.api.events.ReadyEvent;
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.events.user.update.GenericUserPresenceEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Timer;
import java.util.TimerTask;
import static moe.oko.Kiafumi.Kiafumi.info;
import static moe.oko.Kiafumi.Kiafumi.debug;
import static moe.oko.Kiafumi.Kiafumi.error;
/**
* Main Listener
* Used for all utility garbage like guild handling and persistence. (Also LOL prevention).
* Used for all essential utility listeners, such as guild handling and persistence.
* @author Kay, oko, Tiddy
*/
public class MainListener extends ListenerAdapter {
@ -72,91 +61,4 @@ public class MainListener extends ListenerAdapter {
event.getChannel().sendMessageEmbeds(eb.build()).queue();
}
}
/**
* Game Prevention, is a global mechanic :^)
* @param event - GenericUserPresenceEvent event to be used.
*/
@Deprecated
@Override
public void onGenericUserPresence(@NotNull GenericUserPresenceEvent event) {
if(Kiafumi.instance.config.isGamePreventionEnabled()) {
// Proceed.
if(event.getMember().getActivities().contains(Activity.playing(Kiafumi.instance.config.getGameToPrevent()))) {
// THEY ARE PLAYING THE BIG BAD GAME!!!! WARN THE MIMMEDIATELYOYUITHTHHT
event.getMember().getUser().openPrivateChannel().complete().sendMessage("**YOU ARE PLAYING THE BIG BAD GAME STOP STOP STOP** " +
"(in " + Kiafumi.instance.config.getGameCheckTime() + " minutes i wll EVAPORATE you from every server i am IN.").queue();
var timer = new Timer();
int timeInMilisToKill = (Kiafumi.instance.config.getGameCheckTime() * 60) * 1000;
timer.schedule(new TimerTask() {
@Override
public void run() {
if(event.getMember().getActivities().contains(Activity.playing(Kiafumi.instance.config.getGameToPrevent()))) {
event.getMember().getUser().openPrivateChannel().complete().sendMessage("**I warned you, NOW SUFFER MY RAGE**").queue();
for(Guild guild : event.getJDA().getGuilds()) {
if(guild.isMember(event.getMember().getUser())) {
guild.ban(guild.getMember(event.getMember().getUser()), 0, "PLAYED A HORRIBLE GAME").queue();
}
}
} else {
event.getMember().getUser().openPrivateChannel().complete().sendMessage("Thank you for not playing that shitty game anymore.").queue();
}
}
}, timeInMilisToKill);
}
}
}
@Override
public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) {
var server = Kiafumi.instance.getServerManager().getOrCreateServer(event.getGuild());
if(server.getJoinRole() != null) {
try {
event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(server.getJoinRole())).queue();
} catch(Exception ex) {
error("Failed to apply welcome role to " + event.getMember().getEffectiveName() + ", as the role does not exist.");
}
}
if(server.isWelcomeEnabled()) {
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] joined guild [" + event.getGuild().getName() + ':' + event.getGuild().getId() + "].");
// Fetch the welcome channel from settings.
var textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
if(textChannel == null) {
error("Failed to send welcome message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
return;
}
var dTF = DateTimeFormatter.ofPattern("MM-dd-yyyy");
// Prepare embed.
var embedBuilder = new EmbedBuilder()
.setColor(EmbedUI.SUCCESS)
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
+ event.getMember().getId() + ")", null, event.getUser().getAvatarUrl()).setFooter("User Joined").setTimestamp(OffsetDateTime.now())
.setDescription(event.getMember().getAsMention() + " | **Joined Discord**: " + event.getMember().getTimeCreated().format(dTF));
textChannel.sendMessageEmbeds(embedBuilder.build()).queue();
debug("Guild join message successfully sent.");
}
}
@Override
public void onGuildMemberRemove(@NotNull GuildMemberRemoveEvent event) {
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] left guild [" + event.getGuild().getName() + ':' + event.getGuild().getId() + "].");
// Fetch the welcome channel from settings.
var server = Kiafumi.instance.getServerManager().getOrCreateServer(event.getGuild());
if(server.isWelcomeEnabled()) {
var textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
if(textChannel == null) {
error("Failed to send leave message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
return;
}
// Prepare embed.
var dTF = DateTimeFormatter.ofPattern("MM-dd-yyyy");
var embedBuilder = new EmbedBuilder()
.setColor(EmbedUI.FAILURE)
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
+ event.getMember().getId() + ")", null, event.getUser().getAvatarUrl()).setFooter("User Left").setTimestamp(OffsetDateTime.now())
.setDescription(event.getMember().getAsMention() + " | **Joined Server**: " + event.getMember().getTimeJoined().format(dTF));
textChannel.sendMessageEmbeds(embedBuilder.build()).queue();
debug("Guild leave message successfully sent.");
}
}
}

View file

@ -0,0 +1,114 @@
package moe.oko.Kiafumi.listener;
import moe.oko.Kiafumi.Kiafumi;
import moe.oko.Kiafumi.KiafumiConfig;
import moe.oko.Kiafumi.util.EmbedUI;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
import net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent;
import net.dv8tion.jda.api.events.user.update.UserUpdateNameEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import static moe.oko.Kiafumi.Kiafumi.debug;
import static moe.oko.Kiafumi.Kiafumi.info;
import static moe.oko.Kiafumi.Kiafumi.error;
/**
* Skynet Listener
* Handles all event logging (Join/Leaves, Username Change, etc).
* @author oko
*/
public class SkynetListener extends ListenerAdapter {
KiafumiConfig config;
DateTimeFormatter dTF = DateTimeFormatter.ofPattern("MM-dd-yyyy");
/**
* Join/Leave logging
* Requires the server to configure welcomeEnabled & welcomeChannel (optionally joinRole).
*/
@Override
public void onGuildMemberJoin(@NotNull GuildMemberJoinEvent event) {
var server = Kiafumi.instance.getServerManager().getOrCreateServer(event.getGuild());
if(server.getJoinRole() != null) {
try {
event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(server.getJoinRole())).queue();
} catch(Exception ex) {
error("Failed to apply welcome role to " + event.getMember().getEffectiveName() + ", as the role does not exist.");
}
}
if(server.isWelcomeEnabled()) {
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] joined guild [" + event.getGuild().getName() + ':' + event.getGuild().getId() + "].");
// Fetch the welcome channel from settings.
TextChannel textChannel;
try {
textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
} catch (Exception ex) {
error("Failed to send join message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
return;
}
// Prepare embed.
var eb = new EmbedBuilder()
.setColor(EmbedUI.SUCCESS)
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
+ event.getMember().getId() + ")", null, event.getUser().getAvatarUrl())
.setDescription(event.getMember().getAsMention() + " | **Joined Discord**: " + event.getMember().getTimeCreated().format(dTF))
.setFooter("User Joined")
.setTimestamp(OffsetDateTime.now());
textChannel.sendMessageEmbeds(eb.build()).queue();
debug("Guild join message successfully sent.");
}
}
@Override
public void onGuildMemberRemove(@NotNull GuildMemberRemoveEvent event) {
info("User [" + event.getUser().getName() + ":" + event.getUser().getId() + "] left guild [" + event.getGuild().getName() + ':' + event.getGuild().getId() + "].");
var server = Kiafumi.instance.getServerManager().getOrCreateServer(event.getGuild());
if(server.isWelcomeEnabled()) {
// Fetch the welcome channel from settings.
TextChannel textChannel;
try {
textChannel = event.getGuild().getTextChannelById(server.getWelcomeChannel());
} catch (Exception ex) {
error("Failed to send leave message to guild " + event.getGuild().getId() + " as the welcome channel was not found.");
return;
}
// Prepare embed.
var eb = new EmbedBuilder()
.setColor(EmbedUI.FAILURE)
.setAuthor(event.getMember().getEffectiveName() + "#" + event.getMember().getUser().getDiscriminator() + " ("
+ event.getMember().getId() + ")", null, event.getUser().getAvatarUrl())
.setDescription(event.getMember().getAsMention() + " | **Joined Server**: " + event.getMember().getTimeJoined().format(dTF))
.setFooter("User Left")
.setTimestamp(OffsetDateTime.now());
textChannel.sendMessageEmbeds(eb.build()).queue();
debug("Guild leave message successfully sent.");
}
}
/**
* Name change logging
* Sent to the central logChannel.
*/
@Override
public void onUserUpdateName(@NotNull UserUpdateNameEvent event) {
var user = event.getUser();
String name = event.getNewName(), oldName = event.getOldName();
info("User [" + name + ':' + user.getId() + "] changed name from \"" + oldName + "\".");
var logChannel = Kiafumi.JDA.getTextChannelById(config.getLogChannel());
var eb = new EmbedBuilder()
.setColor(EmbedUI.INFO)
.setAuthor(user.getName() + '#' + user.getDiscriminator() + " (" + user.getId() + ')', null, user.getAvatarUrl())
.setDescription('`' + oldName + "` → `" + name + '`')
.setFooter("Username Edited")
.setTimestamp(OffsetDateTime.now());
logChannel.sendMessageEmbeds(eb.build()).queue();
debug("Username edit message successfully sent.");
}
}

View file

@ -4,35 +4,35 @@
# ██╔═██╗ ██║██╔══██║██╔══╝ ██║ ██║██║╚██╔╝██║██║
# ██║ ██╗██║██║ ██║██║ ╚██████╔╝██║ ╚═╝ ██║██║
# ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝
#--------------------------------------------------------------
# --------------------------------------------------------------
# KIAFUMI Default Configuration File (With Comments)
#--------------------------------------------------------------
#DISCORD CONFIG STACK
# --------------------------------------------------------------
# DISCORD CONFIG STACK
discord:
#Paste in your bot token here.
# Paste in your bot token here.
token: "DO NOT SHARE"
#The main guild the bot will recognize and do protection actions on. (Use LossPrevention for more in-depth actions!)
# The main guild the bot will recognize and do protection actions on.
mainGuild: ""
#The channel ID the bot will send important logging messages to.
# The channel ID the bot will send important logging messages to.
logChannel: ""
#The user ID of the owner of the bot.
# The user ID of the owner of the bot.
ownerId: ""
#The client ID of the bot (for invite generation)
# The client ID of the bot (for invite generation)
clientId: ""
#Level of permissions for the invite (If you don't know this, use https://discordapi.com/permissions.html)
#If problems occur, you can use 8 (Administrator)
# Level of permissions for the invite (If you don't know this, use https://discordapi.com/permissions.html)
# If problems occur, you can use 8 (Administrator)
invitePermissionLevel: 139855252544
#MAIN CONFIG STACK
# MAIN CONFIG STACK
main:
#Currently, unimplemented, maybe in the future if performance becomes and issue.
# Currently, unimplemented, maybe in the future if performance becomes and issue.
sharded: false
#Activity Type (STREAMING|PLAYING|WATCHING|COMPETING|DEFAULT)
# Activity Type (STREAMING|PLAYING|WATCHING|COMPETING|DEFAULT)
activityType: "PLAYING"
#Activity Message
activityMsg: "https://38.fail"
#Status type (ONLINE|IDLE|DO_NOT_DISTURB|INVISIBLE)
# Activity Message
activityMsg: "https://oko.moe"
# Status type (ONLINE|IDLE|DO_NOT_DISTURB|INVISIBLE)
statusType: "IDLE"
#Responses for the default ping command
# Responses for the default ping command
pingResponses:
- "Pinged the pentagon"
- "Pinged oko's basement"
@ -40,21 +40,10 @@ main:
- "Pinged you're mother"
- "Pinged 142.250.189.238"
- "Pinged cuomo.zone"
- "Pinged my brain (please help)"
- "Pinged <@951782164847001600>"
- "Pinged A33#*$9331@"
- "Pinged a poortea vpn"
- "Pinged 'agoo'"
- "Pinged my brain"
- "Pinged 38.fail"
- "Pinged pong"
- "Pinged the admins"
- "Pinged the guy in your walls"
#Prevents users in the guild from playing a certain game
gamePrevention: true
#Amount of time in minutes to check after a user starts playing the game until you kick them.
gameCheckTime: 30
#The game to be prevented
gameToPrevent: "League Of Legends"
sql:
host: "localhost"
port: 3306