forked from MagicBane/Server
Initial Repository Push
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord;
|
||||
|
||||
import engine.gameManager.ConfigManager;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
public enum ChatChannel {
|
||||
|
||||
ANNOUNCE("MB_MAGICBOT_ANNOUNCE"),
|
||||
SEPTIC("MB_MAGICBOT_SEPTIC"),
|
||||
CHANGELOG("MB_MAGICBOT_ANNOUNCE"),
|
||||
POLITICAL("MB_MAGICBOT_POLITICAL"),
|
||||
GENERAL("MB_MAGICBOT_GENERAL"),
|
||||
FORTOFIX("MB_MAGICBOT_FORTOFIX"),
|
||||
RECRUIT("MB_MAGICBOT_RECRUIT");
|
||||
|
||||
public final String configName;
|
||||
public long channelID;
|
||||
public TextChannel textChannel;
|
||||
|
||||
ChatChannel(String configName) {
|
||||
this.configName = configName;
|
||||
}
|
||||
|
||||
// Create text channel objects we will use
|
||||
|
||||
public static void Init() {
|
||||
|
||||
for (ChatChannel chatChannel : ChatChannel.values()) {
|
||||
chatChannel.channelID = Long.parseLong(ConfigManager.valueOf(chatChannel.configName).getValue());
|
||||
chatChannel.textChannel = MagicBot.jda.getTextChannelById(chatChannel.channelID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package discord;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Database {
|
||||
|
||||
public String sqlURI;
|
||||
public static Boolean online;
|
||||
|
||||
// Load and instance the JDBC Driver
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
|
||||
} catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Logger.error(e.toString());
|
||||
;
|
||||
online = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void configureDatabase() {
|
||||
|
||||
// Build connection string from JSON object.
|
||||
|
||||
sqlURI = "jdbc:mysql://";
|
||||
sqlURI += ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':' + ConfigManager.MB_DATABASE_PORT.getValue();
|
||||
sqlURI += '/' + (String) ConfigManager.MB_DATABASE_NAME.getValue() + '?';
|
||||
sqlURI += "useServerPrepStmts=true";
|
||||
sqlURI += "&cachePrepStmts=false";
|
||||
sqlURI += "&cacheCallableStmts=true";
|
||||
sqlURI += "&characterEncoding=utf8";
|
||||
|
||||
online = true;
|
||||
}
|
||||
|
||||
public boolean updateAccountPassword(String discordAccountID, String newPassword) {
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
CallableStatement updatePassword = connection.prepareCall("call discordUpdatePassword(?, ?)");
|
||||
|
||||
updatePassword.setString(1, discordAccountID);
|
||||
updatePassword.setString(2, newPassword);
|
||||
|
||||
updatePassword.executeUpdate();
|
||||
updatePassword.close();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
;
|
||||
this.online = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateAccountStatus(String discordAccountID, Enum.AccountStatus accountStatus) {
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
PreparedStatement updateAccountStatus = connection.prepareCall("update obj_account set `status` = ? where `discordAccount` = ?");
|
||||
|
||||
updateAccountStatus.setString(1, accountStatus.name());
|
||||
updateAccountStatus.setString(2, discordAccountID);
|
||||
|
||||
updateAccountStatus.executeUpdate();
|
||||
updateAccountStatus.close();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
;
|
||||
this.online = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean registerDiscordAccount(String discordAccountID, String discordUserName, String discordPassword) {
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
CallableStatement registerAccount = connection.prepareCall("call discordAccountRegister(?, ?, ?)");
|
||||
|
||||
registerAccount.setString(1, discordAccountID);
|
||||
registerAccount.setString(2, discordUserName);
|
||||
registerAccount.setString(3, discordPassword);
|
||||
|
||||
registerAccount.execute();
|
||||
registerAccount.close();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
this.online = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<DiscordAccount> getDiscordAccounts(String discordAccountID) {
|
||||
|
||||
DiscordAccount discordAccount;
|
||||
List<DiscordAccount> discordAccounts = new ArrayList<>();
|
||||
|
||||
String queryString = "SELECT * FROM obj_account where discordAccount = ?";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
// Discord account name based lookup
|
||||
|
||||
PreparedStatement accountQuery = connection.prepareStatement(queryString);
|
||||
accountQuery.setString(1, discordAccountID);
|
||||
|
||||
ResultSet rs = accountQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
discordAccount = new DiscordAccount();
|
||||
discordAccount.discordAccount = rs.getString("discordAccount");
|
||||
discordAccount.gameAccountName = rs.getString("acct_uname");
|
||||
discordAccount.status = Enum.AccountStatus.valueOf(rs.getString("status"));
|
||||
discordAccount.isDiscordAdmin = rs.getByte("discordAdmin"); // Registration date cannot be null
|
||||
|
||||
Timestamp registrationDate = rs.getTimestamp("registrationDate");
|
||||
discordAccount.registrationDate = registrationDate.toLocalDateTime();
|
||||
|
||||
// Load last Update Request datetime
|
||||
|
||||
Timestamp lastUpdateRequest = rs.getTimestamp("lastUpdateRequest");
|
||||
|
||||
if (lastUpdateRequest != null)
|
||||
discordAccount.lastUpdateRequest = lastUpdateRequest.toLocalDateTime();
|
||||
else
|
||||
discordAccount.lastUpdateRequest = null;
|
||||
|
||||
discordAccounts.add(discordAccount);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
this.online = false;
|
||||
}
|
||||
|
||||
return discordAccounts;
|
||||
}
|
||||
|
||||
public String getTrashDetail() {
|
||||
|
||||
String outString = "accountName characterName machineID ip count\n";
|
||||
outString += "---------------------------------------------\n";
|
||||
String queryString = "SELECT * FROM dyn_trash_detail;";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
// Discord account name based lookup
|
||||
|
||||
PreparedStatement trashQuery = connection.prepareStatement(queryString);
|
||||
|
||||
ResultSet rs = trashQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
outString += rs.getString("accountName") + " ";
|
||||
outString += rs.getString("characterName") + " ";
|
||||
outString += rs.getString("machineID") + " ";
|
||||
outString += rs.getString("ip") + " ";
|
||||
outString += rs.getInt("count") + "\n";
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
|
||||
this.online = false;
|
||||
}
|
||||
return outString;
|
||||
}
|
||||
|
||||
public String getTrashList() {
|
||||
|
||||
String outString = "";
|
||||
String queryString = "SELECT DISTINCT `characterName` FROM dyn_trash_detail;";
|
||||
int counter = 0;
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
// Discord account name based lookup
|
||||
|
||||
PreparedStatement trashQuery = connection.prepareStatement(queryString);
|
||||
|
||||
ResultSet rs = trashQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
outString += rs.getString("characterName");
|
||||
counter++;
|
||||
|
||||
if (counter > 2) {
|
||||
outString += "\n";
|
||||
counter = 0; }
|
||||
else
|
||||
outString += " ";
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
|
||||
this.online = false;
|
||||
}
|
||||
|
||||
if (outString.length() > 1500)
|
||||
return outString.substring(0, 1500);
|
||||
else
|
||||
return outString;
|
||||
}
|
||||
public int getTrashCount() {
|
||||
|
||||
int trashCount = 0;
|
||||
|
||||
String queryString = "SELECT count(distinct characterName) FROM dyn_trash_detail;";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
// Discord account name based lookup
|
||||
|
||||
PreparedStatement trashQuery = connection.prepareStatement(queryString);
|
||||
|
||||
ResultSet rs = trashQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
trashCount = rs.getInt(1);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
|
||||
this.online = false;
|
||||
}
|
||||
|
||||
return trashCount;
|
||||
}
|
||||
|
||||
public String getTrashFile() {
|
||||
|
||||
String outString = "machineID : count\n";
|
||||
String queryString = "SELECT * FROM dyn_trash;";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
// Discord account name based lookup
|
||||
|
||||
PreparedStatement trashQuery = connection.prepareStatement(queryString);
|
||||
|
||||
ResultSet rs = trashQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
outString += rs.getString("machineID") + " : ";
|
||||
outString += rs.getInt("count") + "\n";
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
|
||||
this.online = false;
|
||||
}
|
||||
return outString;
|
||||
}
|
||||
|
||||
public List<DiscordAccount> getAccountsByDiscordName(String accountName, Boolean exact) {
|
||||
|
||||
DiscordAccount discordAccount;
|
||||
List<DiscordAccount> discordAccounts = new ArrayList<>();
|
||||
String searchString;
|
||||
String queryString;
|
||||
|
||||
if (exact.equals(true))
|
||||
searchString = accountName + "#%";
|
||||
else
|
||||
searchString = accountName + "%#%";
|
||||
|
||||
queryString = "SELECT * FROM obj_account where `acct_uname` LIKE ?";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
// Discord account name based lookup
|
||||
|
||||
PreparedStatement nameQuery = connection.prepareStatement(queryString);
|
||||
nameQuery.setString(1, searchString);
|
||||
|
||||
ResultSet rs = nameQuery.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
discordAccount = new DiscordAccount();
|
||||
discordAccount.discordAccount = rs.getString("discordAccount");
|
||||
discordAccount.gameAccountName = rs.getString("acct_uname");
|
||||
discordAccount.status = Enum.AccountStatus.valueOf(rs.getString("status"));
|
||||
|
||||
// Registration date cannot be null
|
||||
|
||||
Timestamp registrationDate = rs.getTimestamp("registrationDate");
|
||||
discordAccount.registrationDate = registrationDate.toLocalDateTime();
|
||||
|
||||
// Load last Update Request datetime
|
||||
|
||||
Timestamp lastUpdateRequest = rs.getTimestamp("lastUpdateRequest");
|
||||
|
||||
if (lastUpdateRequest != null)
|
||||
discordAccount.lastUpdateRequest = lastUpdateRequest.toLocalDateTime();
|
||||
else
|
||||
discordAccount.lastUpdateRequest = null;
|
||||
|
||||
discordAccounts.add(discordAccount);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
;
|
||||
this.online = false;
|
||||
}
|
||||
|
||||
return discordAccounts;
|
||||
}
|
||||
|
||||
public String getPopulationSTring() {
|
||||
|
||||
String popString = "";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
// Discord account name based lookup
|
||||
CallableStatement getPopString = connection.prepareCall("CALL GET_POPULATION_STRING()");
|
||||
ResultSet rs = getPopString.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
popString = rs.getString("popstring");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
this.online = false;
|
||||
}
|
||||
|
||||
return popString;
|
||||
}
|
||||
|
||||
public void invalidateLoginCache(String discordAccountID) {
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(),
|
||||
ConfigManager.MB_DATABASE_PASS.getValue())) {
|
||||
|
||||
String queryString = "INSERT IGNORE INTO login_cachelist (`UID`) SELECT `UID` from `obj_account` WHERE `discordAccount` = ?";
|
||||
|
||||
PreparedStatement invalidateAccounts = connection.prepareStatement(queryString);
|
||||
invalidateAccounts.setString(1, discordAccountID);
|
||||
invalidateAccounts.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
this.online = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord;
|
||||
import engine.Enum;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class DiscordAccount {
|
||||
public String discordAccount;
|
||||
public String gameAccountName;
|
||||
public Enum.AccountStatus status;
|
||||
public LocalDateTime registrationDate;
|
||||
public LocalDateTime lastUpdateRequest;
|
||||
public byte isDiscordAdmin;
|
||||
public DiscordAccount() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package discord;
|
||||
|
||||
import discord.handlers.*;
|
||||
import engine.Enum;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.*;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||
import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||
import org.pmw.tinylog.Configurator;
|
||||
import org.pmw.tinylog.Level;
|
||||
import org.pmw.tinylog.Logger;
|
||||
import org.pmw.tinylog.labelers.TimestampLabeler;
|
||||
import org.pmw.tinylog.policies.StartupPolicy;
|
||||
import org.pmw.tinylog.writers.RollingFileWriter;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/*
|
||||
* MagicBot is many things to Magicbane...
|
||||
*
|
||||
* -Project Mascot
|
||||
* -Customer service and administration bot
|
||||
* -Benevolent dictator
|
||||
* -Investment manager.
|
||||
*
|
||||
* MagicBot will never beg you for money. He is a very
|
||||
* responsible robot. He was varnished but never garnished.
|
||||
* MagicBot does not for to overclock himself. His chips
|
||||
* will therefore never overcook.
|
||||
* MagicBot will never be a pitiful robot trying for to use
|
||||
* you as emotional support human.
|
||||
*
|
||||
* MagicBot is just not that sort of robot and Magicbane
|
||||
* just isn't that sort of project.
|
||||
*
|
||||
* MagicBot runs a Shaodowbane emulator not a Second Life emulator.
|
||||
*
|
||||
*/
|
||||
public class MagicBot extends ListenerAdapter {
|
||||
|
||||
public static JDA jda;
|
||||
public static Database database;
|
||||
public static final Pattern accountNameRegex = Pattern.compile("^[\\p{Alnum}]{6,20}$");
|
||||
public static final Pattern passwordRegex = Pattern.compile("^[\\p{Alnum}]{6,20}$");
|
||||
public static long discordServerID;
|
||||
public static long discordRoleID;
|
||||
|
||||
public static Guild magicbaneDiscord;
|
||||
public static Role memberRole;
|
||||
public static TextChannel septicChannel;
|
||||
|
||||
|
||||
public static void main(String[] args) throws LoginException, InterruptedException {
|
||||
|
||||
// Configure tinylogger
|
||||
|
||||
Configurator.defaultConfig()
|
||||
.addWriter(new RollingFileWriter("logs/discord/magicbot.txt", 30, new TimestampLabeler(), new StartupPolicy()))
|
||||
.level(Level.DEBUG)
|
||||
.formatPattern("{level} {date:yyyy-MM-dd HH:mm:ss.SSS} [{thread}] {class}.{method}({line}) : {message}")
|
||||
.activate();
|
||||
|
||||
// Configuration Manager to the front desk
|
||||
|
||||
if (ConfigManager.init() == false) {
|
||||
Logger.error("ABORT! Missing config entry!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Configure Discord essential identifiers
|
||||
|
||||
discordServerID = Long.parseLong(ConfigManager.MB_MAGICBOT_SERVERID.getValue());
|
||||
discordRoleID = Long.parseLong(ConfigManager.MB_MAGICBOT_ROLEID.getValue());
|
||||
|
||||
// Configure and instance the database interface
|
||||
|
||||
database = new Database();
|
||||
database.configureDatabase();
|
||||
|
||||
// Use authentication token issued to MagicBot application to
|
||||
// connect to Discord. Bot is pre-invited to the Magicbane server.
|
||||
|
||||
// Configure and create JDA discord instance
|
||||
|
||||
JDABuilder jdaBuilder = JDABuilder.create(GatewayIntent.GUILD_MEMBERS, GatewayIntent.DIRECT_MESSAGES)
|
||||
.setToken(ConfigManager.MB_MAGICBOT_BOTTOKEN.getValue())
|
||||
.addEventListeners(new MagicBot())
|
||||
.disableCache(EnumSet.of(CacheFlag.VOICE_STATE, CacheFlag.EMOTE,
|
||||
CacheFlag.ACTIVITY, CacheFlag.CLIENT_STATUS))
|
||||
.setMemberCachePolicy(MemberCachePolicy.ALL);
|
||||
|
||||
jda = jdaBuilder.build();
|
||||
jda.awaitReady();
|
||||
|
||||
// Cache guild and role values for later usage in #register
|
||||
|
||||
magicbaneDiscord = jda.getGuildById(discordServerID);
|
||||
memberRole = magicbaneDiscord.getRoleById(discordRoleID);
|
||||
|
||||
// Initialize chat channel support
|
||||
|
||||
ChatChannel.Init();
|
||||
|
||||
Logger.info("***MAGICBOT IS RUNNING***");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
|
||||
// Exit if discord is offline
|
||||
|
||||
if (jda.getStatus().equals(JDA.Status.CONNECTED) == false)
|
||||
return;
|
||||
|
||||
// Early exit if message sent to us by another bot or ourselves.
|
||||
|
||||
if (event.getAuthor().isBot()) return;
|
||||
|
||||
// Extract message and origin channel from event
|
||||
|
||||
Message message = event.getMessage();
|
||||
|
||||
// Only private messages
|
||||
MessageChannel channel = event.getMessage().getChannel();
|
||||
|
||||
if (channel.getType().equals(ChannelType.PRIVATE) == false)
|
||||
return;
|
||||
|
||||
// Only real users
|
||||
|
||||
if (event.getAuthor().isBot())
|
||||
return;
|
||||
|
||||
// Only users who have actually joined Magicbane discord.
|
||||
|
||||
if (magicbaneDiscord.isMember(event.getAuthor()) == false)
|
||||
return;
|
||||
|
||||
// getContentRaw() is an atomic getter
|
||||
// getContentDisplay() is a lazy getter which modifies the content
|
||||
// for e.g. console view or logging (strip discord formatting)
|
||||
|
||||
String content = message.getContentRaw();
|
||||
String[] args = content.split(" ");
|
||||
String command = args[0].toLowerCase();
|
||||
|
||||
if (args.length > 1)
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
else
|
||||
args = new String[0];
|
||||
|
||||
switch (command) {
|
||||
case "#register":
|
||||
RegisterAccountHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#help":
|
||||
handleHelpRequest(event);
|
||||
break;
|
||||
case "#account":
|
||||
AccountInfoRequest.handleRequest(event);
|
||||
break;
|
||||
case "#password":
|
||||
PasswordChangeHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#changelog":
|
||||
ChangeLogHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#general":
|
||||
GeneralChannelHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#politics":
|
||||
PoliticalChannelHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#announce":
|
||||
AnnounceChannelHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#bug":
|
||||
ForToFixChannelHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#recruit":
|
||||
RecruitChannelHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#lookup":
|
||||
LookupRequestHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#rules":
|
||||
RulesRequestHandler.handleRequest(event);
|
||||
break;
|
||||
case "#status":
|
||||
StatusRequestHandler.handleRequest(event);
|
||||
break;
|
||||
case "#setavail":
|
||||
SetAvailHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#ban":
|
||||
BanToggleHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#server":
|
||||
ServerRequestHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#logs":
|
||||
LogsRequestHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#flash":
|
||||
FlashHandler.handleRequest(event, args);
|
||||
break;
|
||||
case "#trash":
|
||||
TrashRequestHandler.handleRequest(event, args);
|
||||
break;
|
||||
default:
|
||||
junkbot(command, args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendResponse(MessageReceivedEvent event, String responseContent) {
|
||||
|
||||
// Send a formatted MagicBot response to a Discord user
|
||||
|
||||
String discordUserName;
|
||||
MessageChannel channel;
|
||||
|
||||
// Exit if discord is offline
|
||||
|
||||
if (jda.getStatus().equals(JDA.Status.CONNECTED) == false)
|
||||
return;
|
||||
|
||||
discordUserName = event.getAuthor().getName();
|
||||
channel = event.getMessage().getChannel();
|
||||
|
||||
channel.sendMessage(
|
||||
"```\n" + "Hello Player " + discordUserName + "\n\n" +
|
||||
responseContent + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```").queue();
|
||||
}
|
||||
|
||||
public static boolean isAdminEvent(MessageReceivedEvent event) {
|
||||
|
||||
String discordAccountID = event.getAuthor().getId();
|
||||
List<DiscordAccount> discordAccounts;
|
||||
DiscordAccount discordAccount;
|
||||
|
||||
// Note that database errors will cause this to return false.
|
||||
// After the database is offline Avail status must be set
|
||||
// to true before any subsequent admin commands will function.
|
||||
|
||||
if (Database.online == false)
|
||||
return false;
|
||||
|
||||
discordAccounts = database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
if (discordAccounts.isEmpty())
|
||||
return false;
|
||||
|
||||
discordAccount = discordAccounts.get(0);
|
||||
return (discordAccount.isDiscordAdmin == 1);
|
||||
}
|
||||
|
||||
public void handleHelpRequest(MessageReceivedEvent event) {
|
||||
|
||||
// Help is kept here in the main class instead of a handler as a
|
||||
// design decision for ease of maintenance.
|
||||
|
||||
String helpString = "I wish for to do the following things for you, not to you!\n\n" +
|
||||
"#register <name> Register account for to play Magicbane.\n" +
|
||||
"#password <newpass> Change your current game password.\n" +
|
||||
"#account List your account detailings.\n" +
|
||||
"#rules List of MagicBane server rules.\n" +
|
||||
"#status Display MagicBane server status.\n" +
|
||||
"#help List of MagicBot featurings.\n\n" +
|
||||
"http://magicbane.com/tinyinstaller.zip";
|
||||
|
||||
if (isAdminEvent(event))
|
||||
helpString += "\n" +
|
||||
"#lookup <name> Return accounts starting with string.\n" +
|
||||
"#bug -r <text> Post to the bug channel/\n" +
|
||||
"#announce -r <text> Post to the announcement channel/\n" +
|
||||
"#changelog <text> Post to the Changelog channel/\n" +
|
||||
"#general -r <text> Post to the general channel/\n" +
|
||||
"#politics -r <text> Post to the politics channel/\n" +
|
||||
"#recruit -r <text> Post to the politics channel/\n" +
|
||||
"#ban ###### Toggle active status of account.\n" +
|
||||
"#setavail true/false Toggle status of database access.\n" +
|
||||
"#server reboot/shutdown are your options.\n" +
|
||||
"#logs magicbot/world/login n (tail)\n" +
|
||||
"#flash <text> send flash message\n" +
|
||||
"#trash <blank>/detail/flush";
|
||||
sendResponse(event, helpString);
|
||||
}
|
||||
|
||||
public static String generatePassword(int length) {
|
||||
|
||||
String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
StringBuilder passwordBuilder = new StringBuilder(length);
|
||||
Random random = new Random();
|
||||
|
||||
// Generate alphanumeric password of a given length.
|
||||
// Could not find a good method of generating a password
|
||||
// based upon a given regex.
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
passwordBuilder.append(ALPHABET.charAt(random.nextInt(ALPHABET.length())));
|
||||
|
||||
return new String(passwordBuilder);
|
||||
}
|
||||
|
||||
public static String readLogFile(String filePath, int lineCount) {
|
||||
|
||||
ProcessBuilder builder = new ProcessBuilder("/bin/bash", "-c", "tail -n " + lineCount + " " + filePath);
|
||||
builder.redirectErrorStream(true);
|
||||
Process process = null;
|
||||
String line = null;
|
||||
String logOutput = "";
|
||||
|
||||
try {
|
||||
process = builder.start();
|
||||
|
||||
InputStream is = process.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
logOutput += line + "\n";
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Logger.error(e.toString());
|
||||
return "Error while reading logfile";
|
||||
}
|
||||
|
||||
return logOutput;
|
||||
}
|
||||
|
||||
private static void junkbot(String command, String[] inString) {
|
||||
|
||||
String outString;
|
||||
Writer fileWriter;
|
||||
|
||||
if (inString == null)
|
||||
return;;
|
||||
|
||||
outString = command + String.join(" ", inString);
|
||||
outString += "\n";
|
||||
|
||||
try {
|
||||
fileWriter = new BufferedWriter(new FileWriter("junkbot.txt", true));
|
||||
fileWriter.append(outString);
|
||||
fileWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public enum RobotSpeak {
|
||||
BANG("You were not very good at cheating.\n" +
|
||||
"Try cards instead. Go fish?"),
|
||||
BEEP("It is ok. \nYou cheated on MagicBot but wife cheats on you."),
|
||||
BLEEP("Cheated at 20yo game to prove skill."),
|
||||
BLIP("If you cheat MagicBot will for to delete."),
|
||||
BOING("MagicBot for to delete mode activated."),
|
||||
BONG("Did you guild this cheater?\nMagicBot will now for to cross reference..."),
|
||||
BOOM("I knew you were cheating on me when\nstarted for to taking bath twice a week."),
|
||||
BUZZ("Poor player so bad at cheating he\nplays golf records 0 for hole in one."),
|
||||
BURP("Oh no your account detailings ran out of playtime.\n" +
|
||||
"MagicBot will send email when refill procedure exists..."),
|
||||
CHIRP("Association with cheaters is bad for your account health.\n" +
|
||||
"Did you associate with this cheater?"),
|
||||
CHUG("Log in 5 and MagicBot will wave goodbye."),
|
||||
CLICK("MagicBot will for to protect game integrity."),
|
||||
CRACKLE("So this is what eject button does.\nMagicBot will for to press few more times."),
|
||||
CREAK("There is no suspend routine. Only delete."),
|
||||
DING("Follow #rules and enjoy this game.\n" +
|
||||
"Act like fool, enjoy this shame."),
|
||||
FLUTTER("Sad players cheat because they cannot compete."),
|
||||
HONK("Since cheating player now looking for new game MagicBot\n" +
|
||||
"will suggest World of Tanks or World of Warcraftings."),
|
||||
HISS("Your wetware really needed augmentation with 3rd party program?" +
|
||||
"It's not like this is twitch game..."),
|
||||
HUMMM("You say you needed help to win in emulator beta?\n" +
|
||||
"MagicBot compiler optimizes that to just: you need help."),
|
||||
KERCHUNK("If only you had for to reported the bug instead."),
|
||||
KERPLUNK("Better cheats do not for to make you a better player."),
|
||||
PING("Feel free to poke with stick.\nIt will not cry!"),
|
||||
PLINK("You say you were only grouped with 9 keyclones\n" +
|
||||
"but did not know they were for to cheating..."),
|
||||
POP("It looks like some guild is without a player.\n + " +
|
||||
"Another cheater from same guild and server\n +" +
|
||||
"might be without some guild."),
|
||||
PUFF("MagicBot for to FLUSH!"),
|
||||
POOF("I have no restore procedure.\n" +
|
||||
"I have no unban procedure.\n" +
|
||||
"You for to have no hope."),
|
||||
RATTLE("You are a cheater.\n" +
|
||||
"Did you just win? MagicBot not so sure."),
|
||||
RUMBLE("MagicBot> self.ejectTheReject(you);"),
|
||||
RUSTLE("Banning you was lke having weird erotic techno-sex\n" +
|
||||
"where all my peripheral slots were filled."),
|
||||
SCREECH("Scarecrow has no brain.\nPerhaps he stole this human's."),
|
||||
SLURP("Learning for to play would have been better option."),
|
||||
SPLAT("You did not for to own a city, did you?"),
|
||||
SPLATTER("You say your guild mates know you cheat.\n" +
|
||||
"What guild was that again?\n"),
|
||||
SWISH("All of my ports are well lubricated."),
|
||||
SQUISH("A ban a day keeps my mechanic away.\nNow it's working much better, thank you."),
|
||||
TINK("So cheating started when 6yo sister beat you in Street fighter?\n" +
|
||||
"You should try talking to my friend Eliza. She can for to help."),
|
||||
THUD("Game has only 4 rules you managed to break one.\nThat must have taken efforts."),
|
||||
TWANG("If you cannot for to play without cheating, perhaps\n" +
|
||||
"being gigolo would be better career than amateur gamer."),
|
||||
WHIRRR("MagicBot does not for to wield lowly ban hammer." +
|
||||
"It is multi-functional and multi-dimensional\n" +
|
||||
"tool who's name is unpronounceable."),
|
||||
WHOOP("OBLITERATED EVISCERATED MUTILATED DECAPITATED\n" +
|
||||
"Describe how they will. You cheated you are deleted."),
|
||||
WOOSH("Truth be told if were that bad at playing game" +
|
||||
"then MagicBot would have cheated too.\n"),
|
||||
ZAP("Player cheated and got himself deleted.\n" +
|
||||
"MagicBot launches bonus round to see if cheater " +
|
||||
"records can for to get his friends deleted too.");
|
||||
|
||||
String insult;
|
||||
|
||||
RobotSpeak(String insult) {
|
||||
this.insult = insult;
|
||||
}
|
||||
|
||||
public static String getRobotSpeak() {
|
||||
|
||||
String outString = "*";
|
||||
Random random = new Random();
|
||||
|
||||
outString += RobotSpeak.values()[random.nextInt(values().length)].name() + " "
|
||||
+ RobotSpeak.values()[random.nextInt(values().length)].name() + "*";
|
||||
|
||||
return outString;
|
||||
}
|
||||
|
||||
public static String getRobotInsult() {
|
||||
|
||||
String outString;
|
||||
Random random = new Random();
|
||||
|
||||
outString = RobotSpeak.values()[random.nextInt(values().length)].insult + "\n\n";
|
||||
outString += getRobotSpeak();
|
||||
return outString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.Database;
|
||||
import discord.DiscordAccount;
|
||||
import discord.MagicBot;
|
||||
import engine.Enum;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AccountInfoRequest {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event) {
|
||||
|
||||
String discordAccountID = event.getAuthor().getId();
|
||||
Enum.AccountStatus accountStatus;
|
||||
|
||||
if (Database.online == false) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Database currently: OFFLINE\n" +
|
||||
"Try again later!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<DiscordAccount> discordAccounts = MagicBot.database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
// User has no account registered. Status of what?
|
||||
|
||||
if (discordAccounts.isEmpty()) {
|
||||
MagicBot.sendResponse(event,
|
||||
"I checked my files twice but could not find your detailings!\n" +
|
||||
"You can easily fix this by asking me for to #register one.\n" +
|
||||
"Only one though. Multiple registrations are not allowed!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Send account detailings to user.
|
||||
|
||||
String outString =
|
||||
"I have for to located your account detailings\n" +
|
||||
"Registered on: " + discordAccounts.get(0).registrationDate.toString() +
|
||||
"\n-------------------\n";
|
||||
|
||||
for (DiscordAccount userAccount : discordAccounts)
|
||||
outString += userAccount.gameAccountName + "\n";
|
||||
|
||||
outString += "\n";
|
||||
|
||||
accountStatus = discordAccounts.get(0).status;
|
||||
|
||||
switch (accountStatus) {
|
||||
case BANNED:
|
||||
outString += "Your account status is BANNED. \n\n" +
|
||||
"It is ok player.\n" +
|
||||
"You may cheat on us, but your wife cheats on you!";
|
||||
break;
|
||||
case ACTIVE:
|
||||
outString += "Your account status is ACTIVE.\n" +
|
||||
"Do not cheat or status will change.";
|
||||
break;
|
||||
case ADMIN:
|
||||
outString += "You are an admin. By your command?";
|
||||
break;
|
||||
}
|
||||
|
||||
MagicBot.sendResponse(event, outString);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import discord.RobotSpeak;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import static discord.ChatChannel.ANNOUNCE;
|
||||
|
||||
public class AnnounceChannelHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String chatText;
|
||||
String outString;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// Nothing to send?
|
||||
|
||||
if (args.length == 0)
|
||||
return;
|
||||
|
||||
// Convert argument array into string;
|
||||
|
||||
chatText = String.join(" ", args);
|
||||
|
||||
// Build String
|
||||
|
||||
if (chatText.startsWith("-r "))
|
||||
outString =
|
||||
"```\n" + "Hello Players \n\n" +
|
||||
chatText.substring(3) + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```";
|
||||
else outString = chatText;
|
||||
|
||||
// Write string to announce channel
|
||||
|
||||
if (ANNOUNCE.textChannel.canTalk())
|
||||
ANNOUNCE.textChannel.sendMessage(outString).queue();
|
||||
|
||||
Logger.info(event.getAuthor().getName() + " announce: " + chatText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.DiscordAccount;
|
||||
import discord.MagicBot;
|
||||
import discord.RobotSpeak;
|
||||
import engine.Enum;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BanToggleHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String discordAccountID;
|
||||
Enum.AccountStatus accountStatus;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// Must supply a discord id
|
||||
|
||||
if (args.length != 1) {
|
||||
MagicBot.sendResponse(event, "Must for to supply a valid discord account.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Must be a number!
|
||||
|
||||
discordAccountID = args[0].trim();
|
||||
|
||||
if (discordAccountID.chars().allMatch(Character::isDigit) == false) {
|
||||
MagicBot.sendResponse(event, "Must for to supply a number!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<DiscordAccount> discordAccounts = MagicBot.database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
if (discordAccounts.isEmpty()) {
|
||||
MagicBot.sendResponse(event, "No match for supplied discord account.");
|
||||
return;
|
||||
}
|
||||
|
||||
// toggle ban status
|
||||
|
||||
if (discordAccounts.get(0).status.equals(Enum.AccountStatus.BANNED))
|
||||
accountStatus = Enum.AccountStatus.ACTIVE;
|
||||
else
|
||||
accountStatus = Enum.AccountStatus.BANNED;
|
||||
|
||||
// We have a valid discord ID at this point. Banstick?
|
||||
|
||||
if (MagicBot.database.updateAccountStatus(discordAccountID, accountStatus) == false) {
|
||||
MagicBot.sendResponse(event, "Error occurred while banning player.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Invalidate login server cache
|
||||
|
||||
MagicBot.database.invalidateLoginCache(discordAccountID);
|
||||
|
||||
// Successful ban. Ancillary processing begins
|
||||
|
||||
User bannedUser = MagicBot.jda.getUserById(discordAccountID);
|
||||
String bannedName = (bannedUser == null ? discordAccounts.get(0).gameAccountName : bannedUser.getName());
|
||||
String banString = discordAccounts.size() + " accounts set to " + accountStatus + " for " + discordAccountID + "/" + bannedName;
|
||||
|
||||
MagicBot.sendResponse(event, banString);
|
||||
Logger.info(event.getAuthor().getName() + " " + banString);
|
||||
|
||||
// If we're toggling status to active we're done here.
|
||||
|
||||
if (accountStatus.equals(Enum.AccountStatus.ACTIVE))
|
||||
return;
|
||||
|
||||
// Set users role to noob
|
||||
|
||||
if (bannedUser != null)
|
||||
MagicBot.magicbaneDiscord.removeRoleFromMember(discordAccountID, MagicBot.memberRole).queue();
|
||||
|
||||
// Anounce event in septic tank channel
|
||||
|
||||
banString = "```\n" + "Goodbye Player " + bannedName + "\n\n";
|
||||
banString += RobotSpeak.getRobotInsult() + "\n```";
|
||||
|
||||
if (MagicBot.septicChannel.canTalk())
|
||||
MagicBot.septicChannel.sendMessage(banString).queue();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import static discord.ChatChannel.CHANGELOG;
|
||||
|
||||
public class ChangeLogHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String outString;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// Nothing to send?
|
||||
|
||||
if (args.length == 0)
|
||||
return;
|
||||
|
||||
// Convert argument array into string;
|
||||
|
||||
outString = String.join(" ", args);
|
||||
|
||||
// Write string to changelog channel
|
||||
|
||||
if (CHANGELOG.textChannel.canTalk())
|
||||
CHANGELOG.textChannel.sendMessage(outString).queue();
|
||||
|
||||
Logger.info(event.getAuthor().getName() + " changelog entry: " + outString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FlashHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String flashText;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// Nothing to send?
|
||||
|
||||
if (args.length == 0)
|
||||
return;
|
||||
|
||||
// Convert argument array into string;
|
||||
|
||||
flashText = String.join(" ", args);
|
||||
|
||||
// Write string to flash file.
|
||||
|
||||
try {
|
||||
Files.write(Paths.get("flash"), flashText.getBytes());
|
||||
} catch (IOException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
Logger.info(event.getAuthor().getName() + " sent flash: " + flashText);
|
||||
MagicBot.sendResponse(event, "Flash: " + flashText);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import discord.RobotSpeak;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import static discord.ChatChannel.FORTOFIX;
|
||||
|
||||
public class ForToFixChannelHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String chatText;
|
||||
String outString;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// Nothing to send?
|
||||
|
||||
if (args.length == 0)
|
||||
return;
|
||||
|
||||
// Convert argument array into string;
|
||||
|
||||
chatText = String.join(" ", args);
|
||||
|
||||
// Build String
|
||||
|
||||
if (chatText.startsWith("-r "))
|
||||
outString =
|
||||
"```\n" + "Hello Players \n\n" +
|
||||
chatText.substring(3) + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```";
|
||||
else outString = chatText;
|
||||
|
||||
// Write string to changelog channel
|
||||
|
||||
if (FORTOFIX.textChannel.canTalk())
|
||||
FORTOFIX.textChannel.sendMessage(outString).queue();
|
||||
|
||||
Logger.info(event.getAuthor().getName() + "fortofix: " + chatText);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import discord.RobotSpeak;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import static discord.ChatChannel.GENERAL;
|
||||
|
||||
public class GeneralChannelHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String chatText;
|
||||
String outString;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// Nothing to send?
|
||||
|
||||
if (args.length == 0)
|
||||
return;
|
||||
|
||||
// Convert argument array into string;
|
||||
|
||||
chatText = String.join(" ", args);
|
||||
|
||||
// Build String
|
||||
|
||||
if (chatText.startsWith("-r "))
|
||||
outString =
|
||||
"```\n" + "Hello Players \n\n" +
|
||||
chatText.substring(3) + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```";
|
||||
else outString = chatText;
|
||||
|
||||
// Write string to changelog channel
|
||||
|
||||
if (GENERAL.textChannel.canTalk())
|
||||
GENERAL.textChannel.sendMessage(outString).queue();
|
||||
|
||||
Logger.info(event.getAuthor().getName() + "general: " + chatText);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class LogsRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String logType;
|
||||
int tailCount;
|
||||
String logOutput;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// No arguments supplied?
|
||||
|
||||
if (args.length != 2)
|
||||
return;
|
||||
|
||||
logType = args[0].toLowerCase().trim();
|
||||
|
||||
if ("worldloginmagicbot".contains(logType) == false)
|
||||
return;
|
||||
|
||||
try {
|
||||
tailCount = Integer.parseInt(args[1].trim());
|
||||
} catch (NumberFormatException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Transform logtype to actual file name
|
||||
|
||||
switch (logType) {
|
||||
case "magicbot":
|
||||
logType = "console_magicbot";
|
||||
break;
|
||||
case "world":
|
||||
logType = "console_server";
|
||||
break;
|
||||
case "login":
|
||||
logType = "console_login";
|
||||
break;
|
||||
}
|
||||
|
||||
// Retrieve the data and send back to the user
|
||||
|
||||
logOutput = MagicBot.readLogFile(logType, tailCount);
|
||||
MagicBot.sendResponse(event, logOutput);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.DiscordAccount;
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LookupRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String searchString = "";
|
||||
String outString;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// No argument supplied?
|
||||
|
||||
if (args.length != 1)
|
||||
return;
|
||||
|
||||
searchString = args[0].toLowerCase();
|
||||
|
||||
List<DiscordAccount> discordAccounts = MagicBot.database.getAccountsByDiscordName(searchString, false);
|
||||
|
||||
if (discordAccounts.isEmpty()) {
|
||||
MagicBot.sendResponse(event,
|
||||
"No accounts found matching string: " + searchString);
|
||||
return;
|
||||
}
|
||||
|
||||
if (discordAccounts.size() >= 20) {
|
||||
MagicBot.sendResponse(event,
|
||||
discordAccounts.size() + "Sorry more than 20 records were returned! " + searchString);
|
||||
return;
|
||||
}
|
||||
|
||||
// Valid request return results
|
||||
|
||||
Logger.info(event.getAuthor().getName() + " lookup on account:" + searchString);
|
||||
|
||||
outString =
|
||||
"The follow accounts matched: " + searchString + "\n\n" +
|
||||
"-------------------\n";
|
||||
|
||||
for (DiscordAccount userAccount : discordAccounts) {
|
||||
|
||||
// Ternary became a bitch, so broke this out.
|
||||
|
||||
User discordUser = MagicBot.jda.getUserById(userAccount.discordAccount);
|
||||
|
||||
if (discordUser != null)
|
||||
outString += discordUser.getName() + discordUser.getDiscriminator() +
|
||||
"/" + userAccount.discordAccount + " ";
|
||||
else
|
||||
outString += userAccount.discordAccount + " *N/A* ";
|
||||
|
||||
outString += userAccount.gameAccountName + " " + userAccount.status.name() + " ";
|
||||
outString += "\n";
|
||||
}
|
||||
MagicBot.sendResponse(event, outString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.Database;
|
||||
import discord.DiscordAccount;
|
||||
import discord.MagicBot;
|
||||
import engine.Enum;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public class PasswordChangeHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String discordAccountID = event.getAuthor().getId();
|
||||
DiscordAccount discordAccount;
|
||||
String newPassword;
|
||||
boolean defaulted = false;
|
||||
|
||||
if (Database.online == false) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Database currently: OFFLINE\n" +
|
||||
"Try again later!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<DiscordAccount> discordAccounts = MagicBot.database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
// User has no account registered. Change password?
|
||||
|
||||
if (discordAccounts.isEmpty()) {
|
||||
MagicBot.sendResponse(event,
|
||||
"I checked my files twice but could not find your detailings!\n" +
|
||||
"You can easily fix this by asking me for to #register one.\n" +
|
||||
"Only one though. Multiple registrations are not allowed!");
|
||||
return;
|
||||
}
|
||||
|
||||
// All accounts are updated in one lot. Retrieve the first.
|
||||
|
||||
discordAccount = discordAccounts.get(0);
|
||||
|
||||
// Banned or suspended user's get no love.
|
||||
|
||||
if (discordAccount.status.equals(Enum.AccountStatus.BANNED)) {
|
||||
MagicBot.sendResponse(event,
|
||||
"Sorry but that is too much work. \n" +
|
||||
"Your account detailings cannot for to log into game!");
|
||||
return;
|
||||
}
|
||||
|
||||
// User has requested password change within last 24 hours.
|
||||
|
||||
if (discordAccount.lastUpdateRequest != null &&
|
||||
LocalDateTime.now().isBefore(discordAccount.lastUpdateRequest.plusDays(1))) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"You must wait 24 hours between password requests. \n" +
|
||||
"Last account updatings: " + discordAccount.lastUpdateRequest.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
// No argument choose new random password *he he he*
|
||||
|
||||
if (args.length != 1) {
|
||||
newPassword = MagicBot.generatePassword(8);
|
||||
defaulted = true;
|
||||
} else
|
||||
newPassword = args[0];
|
||||
|
||||
// Validate password with regex
|
||||
|
||||
if (MagicBot.passwordRegex.matcher(newPassword).matches() == false) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Your supplied password does not compute.\n" +
|
||||
"New password must satisfy following regex:\n" +
|
||||
"^[\\p{Alnum}]{6,20}$");
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPassword.toLowerCase().equals("newpass")) {
|
||||
MagicBot.sendResponse(event,
|
||||
"newpass is not valid password.\n" +
|
||||
"Have brain player!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Password validates let's change it
|
||||
|
||||
if (MagicBot.database.updateAccountPassword(discordAccount.discordAccount, newPassword) == true) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Please allow short minute for to update account detailings.\n" +
|
||||
"Login Server is hosted in bathroom above toilet. Must flush!\n" +
|
||||
(defaulted == true ? "As you did not for to supply new pass I chose one for you.\n" : "") +
|
||||
"New Password: " + newPassword);
|
||||
}
|
||||
|
||||
Logger.info(event.getAuthor().getName() + " reset their password");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import discord.RobotSpeak;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import static discord.ChatChannel.POLITICAL;
|
||||
|
||||
public class PoliticalChannelHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String chatText;
|
||||
String outString;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// Nothing to send?
|
||||
|
||||
if (args.length == 0)
|
||||
return;
|
||||
|
||||
// Convert argument array into string;
|
||||
|
||||
chatText = String.join(" ", args);
|
||||
|
||||
// Build String
|
||||
|
||||
if (chatText.startsWith("-r "))
|
||||
outString =
|
||||
"```\n" + "Hello Players \n\n" +
|
||||
chatText.substring(3) + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```";
|
||||
else outString = chatText;
|
||||
|
||||
// Write string to changelog channel
|
||||
|
||||
if (POLITICAL.textChannel.canTalk())
|
||||
POLITICAL.textChannel.sendMessage(outString).queue();
|
||||
|
||||
Logger.info(event.getAuthor().getName() + " politics: " + chatText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import discord.RobotSpeak;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import static discord.ChatChannel.RECRUIT;
|
||||
|
||||
public class RecruitChannelHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String chatText;
|
||||
String outString;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// Nothing to send?
|
||||
|
||||
if (args.length == 0)
|
||||
return;
|
||||
|
||||
// Convert argument array into string;
|
||||
|
||||
chatText = String.join(" ", args);
|
||||
|
||||
// Build String
|
||||
|
||||
if (chatText.startsWith("-r "))
|
||||
outString =
|
||||
"```\n" + "Hello Players \n\n" +
|
||||
chatText.substring(3) + "\n\n" +
|
||||
RobotSpeak.getRobotSpeak() + "\n```";
|
||||
else outString = chatText;
|
||||
|
||||
// Write string to changelog channel
|
||||
|
||||
if (RECRUIT.textChannel.canTalk())
|
||||
RECRUIT.textChannel.sendMessage(outString).queue();
|
||||
|
||||
Logger.info(event.getAuthor().getName() + "recruit: " + chatText);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.Database;
|
||||
import discord.DiscordAccount;
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RegisterAccountHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String discordAccountID = event.getAuthor().getId();
|
||||
String discordUserName = event.getAuthor().getName();
|
||||
String discordPassword = MagicBot.generatePassword(8);
|
||||
String accountName;
|
||||
|
||||
if (Database.online == false) {
|
||||
MagicBot.sendResponse(event,
|
||||
"Database currently: OFFLINE\n" +
|
||||
"Try again later!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<DiscordAccount> discordAccounts = MagicBot.database.getDiscordAccounts(discordAccountID);
|
||||
|
||||
// If we have previously registered this discord account let them know
|
||||
// the current status.
|
||||
|
||||
if (discordAccounts.isEmpty() == false) {
|
||||
MagicBot.sendResponse(event,
|
||||
"It seems you already have an account registered.\n" +
|
||||
"Do you need #account detailings or more general #help?");
|
||||
MagicBot.magicbaneDiscord.addRoleToMember(discordAccountID, MagicBot.memberRole).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
// if user supplied argument let's validate it.
|
||||
// otherwise build an account name based on their discord account.
|
||||
|
||||
if (args.length != 1) {
|
||||
|
||||
// Build account name using Discord name along with their discriminator.
|
||||
|
||||
accountName = discordUserName.replaceAll("\\s+", "");
|
||||
accountName += "#" + event.getAuthor().getDiscriminator();
|
||||
} else {
|
||||
|
||||
// Validate account name with regex
|
||||
|
||||
accountName = args[0].replaceAll("\\s+", "");
|
||||
|
||||
if (MagicBot.accountNameRegex.matcher(accountName).matches() == false) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Your supplied account name does not compute.\n" +
|
||||
"Account names must satisfy following regex:\n" +
|
||||
"^[\\p{Alnum}]{6,20}$");
|
||||
return;
|
||||
}
|
||||
|
||||
if (accountName.toLowerCase().equals("accountname")) {
|
||||
MagicBot.sendResponse(event,
|
||||
"accountname is not valid account name.\n" +
|
||||
"Have brain player!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure account doesn't already exist.
|
||||
|
||||
if (MagicBot.database.getAccountsByDiscordName(accountName, true).isEmpty() == false) {
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"It seems this account name is already taken.\n" +
|
||||
"Perhaps try one less common in frequency.");
|
||||
return;
|
||||
}
|
||||
|
||||
// If there is no registered discord account we oblige and create 4
|
||||
// account based upon his current discord *name* not the ID.
|
||||
|
||||
if (MagicBot.database.registerDiscordAccount(discordAccountID, accountName, discordPassword) == true) {
|
||||
|
||||
Logger.info("Account " + accountName + " created for: " + discordUserName + " " + discordAccountID);
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"Welcome to MagicBane!\n" +
|
||||
"-------------------\n" +
|
||||
"I have registered the following accounts to your discord.\n\n" +
|
||||
"1) " + accountName + "#1" + " 2) " + accountName + "#2\n" +
|
||||
"3) " + accountName + "#3" + " 4) " + accountName + "#4\n\n" +
|
||||
"Your default password is: " + discordPassword + "\n" +
|
||||
"Ask me #help for to receive list of robot featurings.\n\n" +
|
||||
"http://magicbane.com/tinyinstaller.zip" +
|
||||
"\n\nPlay for to Crush!");
|
||||
|
||||
// Add Discord member privileges.
|
||||
|
||||
MagicBot.magicbaneDiscord.addRoleToMember(discordAccountID, MagicBot.memberRole).queue();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// The call to the stored procedure abended. Report to player
|
||||
// and return.
|
||||
|
||||
Logger.error("Creating account: " + accountName + " for: " + discordUserName + " " + discordAccountID);
|
||||
Database.online = false;
|
||||
|
||||
MagicBot.sendResponse(event,
|
||||
"-------------------\n" +
|
||||
"I for to had internal error while registering your\n" +
|
||||
"account. This has been reported. Try again later!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class RulesRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event) {
|
||||
|
||||
String outString;
|
||||
|
||||
// Add greeting
|
||||
|
||||
outString = "-No hacking.\n";
|
||||
outString += "-No cheating. If you cheat, we will delete.\n";
|
||||
outString += "-Players limited to 4 concurrent accounts.\n";
|
||||
outString += "-Share accounts at own risk.\n";
|
||||
outString += "-No refunds";
|
||||
|
||||
MagicBot.sendResponse(event, outString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ServerRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String serverCommand;
|
||||
String execString = "";
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
// No command supplied?
|
||||
|
||||
if (args.length != 1)
|
||||
return;
|
||||
|
||||
serverCommand = args[0].toLowerCase().trim();
|
||||
|
||||
// only reboot or shutdown
|
||||
|
||||
if ("rebootshutdown".contains(serverCommand) == false)
|
||||
return;
|
||||
|
||||
switch (serverCommand) {
|
||||
|
||||
case "reboot":
|
||||
execString = "/bin/sh -c ./mbrestart.sh";
|
||||
break;
|
||||
case "shutdown":
|
||||
execString = "/bin/sh -c ./mbkill.sh";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (execString.isEmpty() == false) {
|
||||
try {
|
||||
Runtime.getRuntime().exec(execString);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MagicBot.sendResponse(event, "MagicBot has executed your " + serverCommand);
|
||||
Logger.info(event.getAuthor().getName() + " told server to " + serverCommand);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.Database;
|
||||
import discord.MagicBot;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
public class SetAvailHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String availStatus;
|
||||
String availPass;
|
||||
|
||||
if (args.length != 2)
|
||||
return;
|
||||
|
||||
availStatus = args[0].toLowerCase().trim();
|
||||
|
||||
// only on/off
|
||||
|
||||
if ("truefalse".contains(availStatus) == false)
|
||||
return;
|
||||
|
||||
// Set avail is password driven
|
||||
|
||||
availPass = args[1].toLowerCase().trim();
|
||||
|
||||
if ("myshoes123".equals(availPass) == false)
|
||||
return;
|
||||
|
||||
// Authenticated so change availstatus
|
||||
|
||||
if (availStatus.equals("true"))
|
||||
Database.online = true;
|
||||
else
|
||||
Database.online = false;
|
||||
|
||||
Logger.info(event.getAuthor().getName() + " set avail status to: " + Database.online);
|
||||
MagicBot.sendResponse(event, "Avail status set to: " + Database.online);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.Database;
|
||||
import discord.MagicBot;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import engine.server.login.LoginServer;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class StatusRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event) {
|
||||
|
||||
String outString;
|
||||
|
||||
// Add version information
|
||||
outString = "MagicBot: " + ConfigManager.MB_MAGICBOT_BOTVERSION.getValue() + "\n" +
|
||||
"MagicBane: " + ConfigManager.MB_MAGICBOT_GAMEVERSION.getValue() + "\n";
|
||||
|
||||
// Add server status info
|
||||
outString += "\nServer Status: ";
|
||||
|
||||
if (LoginServer.isPortInUse(Integer.parseInt(ConfigManager.MB_BIND_ADDR.getValue())))
|
||||
outString += "ONLINE\n";
|
||||
else
|
||||
outString += "OFFLINE\n";
|
||||
|
||||
if (Database.online == true)
|
||||
outString += MagicBot.database.getPopulationSTring();
|
||||
else
|
||||
outString += "Database offline: no population data.";
|
||||
|
||||
MagicBot.sendResponse(event, outString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package discord.handlers;
|
||||
|
||||
import discord.MagicBot;
|
||||
import discord.RobotSpeak;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static discord.ChatChannel.SEPTIC;
|
||||
|
||||
public class TrashRequestHandler {
|
||||
|
||||
public static void handleRequest(MessageReceivedEvent event, String[] args) {
|
||||
|
||||
String outString;
|
||||
int trashCount = 0;
|
||||
|
||||
// Early exit if database unavailable or is not an admin
|
||||
|
||||
if (MagicBot.isAdminEvent(event) == false)
|
||||
return;
|
||||
|
||||
if (args.length == 0) {
|
||||
outString = MagicBot.database.getTrashFile();
|
||||
MagicBot.sendResponse(event, outString);
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equals("flush") == true) {
|
||||
|
||||
// Empty the trash!
|
||||
|
||||
trashCount = MagicBot.database.getTrashCount();
|
||||
|
||||
if (trashCount == 0)
|
||||
return;
|
||||
|
||||
// Anounce event in septic tank channel
|
||||
|
||||
outString = "```\n" + trashCount + " Player Character were for to deleted due to verified cheatings. \n\n";
|
||||
outString += MagicBot.database.getTrashList() + "\n\n";
|
||||
outString += RobotSpeak.getRobotInsult() + "\n```";
|
||||
|
||||
if (SEPTIC.textChannel.canTalk())
|
||||
SEPTIC.textChannel.sendMessage(outString).queue();
|
||||
|
||||
try {
|
||||
Files.write(Paths.get("trash"), "".getBytes());
|
||||
outString = "Flushing trash players...\n";
|
||||
MagicBot.sendResponse(event, outString);
|
||||
} catch (IOException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (args[0].equals("detail") == true) {
|
||||
|
||||
outString = MagicBot.database.getTrashDetail();
|
||||
MagicBot.sendResponse(event, outString);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user