More command work, shitloads of commentation, and version bump, oh also LEAGUE OF LEGENDS PRENVETION HAHAHAHHAHAHA

This commit is contained in:
unknown 2022-03-27 22:42:03 -07:00
parent d5c6a5c59c
commit 12d3d1e486
8 changed files with 127 additions and 5 deletions

View File

@ -6,7 +6,7 @@
<groupId>moe.oko</groupId>
<artifactId>Kiafumi</artifactId>
<version>0.1</version>
<version>0.3</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -72,7 +72,7 @@ public class Kiafumi {
* Ran on program start. Anything in here can determine whether the program will start.
*/
public void start() {
//All commands to be loaded on startup!
activeCommands = new ArrayList<>();
activeCommands.add(new PingCommand());
@ -166,6 +166,9 @@ public class Kiafumi {
JDA.getTextChannelById(config.getLogChannel()).sendMessageEmbeds(eb.build()).queue();
}
/**
* Quick method to register commands in all servers.
*/
private void registerAllCommands() {
for(Guild guild : JDA.getGuilds()) {
registerForGuild(guild);
@ -176,6 +179,10 @@ public class Kiafumi {
}
}
/**
* Registers all bot commands with the guild provided
* @param guild - guild to have commands provided to
*/
public void registerForGuild(Guild guild) {
info("Registering commands for " + guild.getId());
for(CommandClass cmd : activeCommands) {

View File

@ -37,6 +37,9 @@ 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
@ -70,13 +73,16 @@ public class KiafumiConfig {
info("Invite link - " + assembleDefaultInvite());
prefix = discord.getString("prefix");
info("Prefix - " + prefix);
//Shiki loaders
//Kia loaders
ConfigurationSection main = configuration.getConfigurationSection("main");
sharded = main.getBoolean("sharded");
activityType = main.getString("activityType");
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
ConfigurationSection sql = configuration.getConfigurationSection("sql");
host = sql.getString("host");
@ -111,6 +117,12 @@ 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

@ -1,8 +1,16 @@
package moe.oko.Kiafumi.listener;
import moe.oko.Kiafumi.Kiafumi;
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.user.update.GenericUserPresenceEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
import java.util.Timer;
import java.util.TimerTask;
import static moe.oko.Kiafumi.Kiafumi.info;
@ -17,11 +25,52 @@ public class MainListener extends ListenerAdapter {
* @param event - event to be handled...
*/
@Override
public void onGuildJoin(GuildJoinEvent event) {
public void onGuildJoin(@NotNull GuildJoinEvent event) {
//Automatically create our default information for the server if we don't have it already.
info("Joined a new guild, NAME: " + event.getGuild().getName() + " ID: " + event.getGuild().getId());
Kiafumi.instance.getServerManager().createNewDefaultServer(event.getGuild());
Kiafumi.instance.registerForGuild(event.getGuild());
}
/**
* Shoots a message into console when the bot is defined as "Ready" by Discord.
*/
@Override
public void onReady(@NotNull ReadyEvent event) {
info("Received READY signal from Discord, bot is now logged in." +
" Guilds Active: " + event.getGuildAvailableCount() + " Guilds Unavailable: " + event.getGuildUnavailableCount());
}
/**
* Game Prevention, is a global mechanic :^)
* @param event - GenericUserPresenceEvent event to be used.
*/
@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();
Timer 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);
}
}
}
}

View File

@ -89,6 +89,10 @@ public class KiafumiDB {
}
}
/**
* Loads all the server information from MySQL into memory.
* @return - a list of all servers loaded from MySQL.
*/
public List<Server> loadServerInformation() {
List<Server> servers = new ArrayList<>();
try {

View File

@ -7,14 +7,23 @@ import javax.annotation.Nullable;
* Used for in-memory data storage. Loaded from Database later.
*/
public class Server {
//Guild ID
private String id;
//Whether the welcome feature is enabled (Join/Leave Logs)
private boolean welcomeEnabled;
//If enabled, the channel for logs to be posted to.
private String welcomeChannel;
//The role to be assigned on join, if null ignored.
private String joinRole;
//TODO Whether the server has protections enabled
private boolean serverProtected;
//If the server has been modified in memory, for saving persistently.
private boolean modified;
/**
* Default constructor, used for new servers
* @param id - the guild id to have server constructed for.
*/
public Server(String id) {
this.id = id;
this.welcomeEnabled = false;
@ -40,8 +49,15 @@ public class Server {
this.modified = false;
}
/**
* @return - the guild id the server is assigned to
*/
public String getId() { return id; }
/**
* Checks the modification of the server file in memory
* @return - whether the server settings have been modified
*/
public boolean isModified() {
return modified;
}

View File

@ -9,9 +9,17 @@ import java.util.List;
import static moe.oko.Kiafumi.Kiafumi.error;
import static moe.oko.Kiafumi.Kiafumi.info;
/**
* ServerManager Class
* Permits the access of servers easily
*/
public class ServerManager {
//Server Memory Storage Hashmap, <Server/Guild ID, Server Object>
private HashMap<String, Server> servers = new HashMap<>();
/**
* Constructor, loads servers and initializes the hashmap.
*/
public ServerManager() {
List<Server> loadedServers = Kiafumi.instance.database.loadServerInformation();
if(loadedServers == null) {
@ -27,11 +35,31 @@ public class ServerManager {
servers = serverHashMap;
}
/**
* Fetches the server via the guild id
* @param id - the id to find a server for
* @return - the server, if non-existent a default profile is created for it.
*/
public Server getOrCreateServer(String id) {
if(servers.get(id) == null) { createNewDefaultServer(Kiafumi.JDA.getGuildById(id)); }
return servers.get(id);
}
/**
* Fetches the server via the guild.
* @param guild - the guild to find the server for
* @return - the server, if non-existent a default profile is created for it.
*/
public Server getOrCreateServer(Guild guild) {
if(servers.get(guild.getId()) == null) { createNewDefaultServer(guild); }
return servers.get(guild.getId());
}
/**
* Initializes a persistent profile for the server and creates a new one that is loaded into memory.
* @param guild - the guild to have a default profile created for it.
* @return - whether the function succeeded.
*/
public boolean createNewDefaultServer(Guild guild) {
info("Started default server creation for " + guild.getId());
Server server = new Server(guild.getId());

View File

@ -51,6 +51,12 @@ main:
- "Pinged a poortea vpn"
- "Pinged 'agoo'"
- "Pinged Ayana"
#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