+ Added first-pass leaderboard command and all requirements
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package core;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
public final class Config
|
||||
{
|
||||
public static final Color ColorDefault = new Color(7*16, 8*16, 9*16); // A slate-grey
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package core;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import network.JDBCDriver;
|
||||
import network.JDBCDriverSQLite;
|
||||
@@ -72,7 +74,7 @@ public class DatabaseDriverKeyValue
|
||||
// Creates a key. The key will be created if it doesn't exist, and the default value returned.
|
||||
public String CreateGetKey(String key)
|
||||
{
|
||||
GlobalLog.Log(LogFilter.Database, "CreateGeyKey: key-" + key);
|
||||
GlobalLog.Log(LogFilter.Database, "CreateGetKey: " + key);
|
||||
|
||||
if(HasKey(key))
|
||||
{
|
||||
@@ -119,6 +121,30 @@ public class DatabaseDriverKeyValue
|
||||
GlobalLog.Log(LogFilter.Database, "CreateKey status: " + status);
|
||||
}
|
||||
|
||||
// Get all keys containing a substring
|
||||
public List<String> GetKeysWith(String keySubstring)
|
||||
{
|
||||
String command = "SELECT * FROM " + tableName + " WHERE " + keyColumnName + " like ?";
|
||||
ResultSet result = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { "%" + keySubstring + "%" });
|
||||
|
||||
List<String> keys = new ArrayList<String>();
|
||||
|
||||
try
|
||||
{
|
||||
while(result.next())
|
||||
{
|
||||
String key = (String) result.getObject(1);
|
||||
keys.add(key);
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
// Transforms a result into a string if possible.
|
||||
private String ResultAsString(ResultSet rs, String key)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package core;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
@@ -128,6 +129,10 @@ public class DatabaseManager
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> scrapeGlobalForString(String substring)
|
||||
{
|
||||
return globalDataDriver.GetKeysWith(substring);
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// Global Data //
|
||||
@@ -141,7 +146,8 @@ public class DatabaseManager
|
||||
}
|
||||
}
|
||||
|
||||
private String globalGetRemoteValue(String key)
|
||||
// You can get values, but not modify them.
|
||||
public String globalGetRemoteValue(String key)
|
||||
{
|
||||
synchronized(globalDataDriver)
|
||||
{
|
||||
@@ -170,7 +176,8 @@ public class DatabaseManager
|
||||
}
|
||||
}
|
||||
|
||||
private String characterGetRemoteValue(String key)
|
||||
// You can get values, but not modify them.
|
||||
public String characterGetRemoteValue(String key)
|
||||
{
|
||||
synchronized(characterDataDriver)
|
||||
{
|
||||
|
||||
@@ -4,12 +4,23 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import commands.*;
|
||||
import core.lua.PluginManager;
|
||||
import dataStructures.*;
|
||||
import main.Main;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.JDABuilder;
|
||||
import net.dv8tion.jda.core.entities.Emote;
|
||||
import net.dv8tion.jda.core.entities.Game;
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
import net.dv8tion.jda.core.entities.Member;
|
||||
import net.dv8tion.jda.core.entities.User;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import offline.Ref;
|
||||
import utils.AdminControl;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
@@ -53,6 +64,7 @@ public class ObjectBuilderFactory
|
||||
// TODO: Investigate using 'synchronized' instead potentially
|
||||
private static boolean hasInitialized;
|
||||
private static Semaphore initMutex = new Semaphore(1);
|
||||
private static JDA kitty;
|
||||
|
||||
// This is it, this is how the lazy init starts!
|
||||
private static void LazyInit()
|
||||
@@ -264,6 +276,7 @@ public class ObjectBuilderFactory
|
||||
return user;
|
||||
}
|
||||
|
||||
// TODO: Cleanup
|
||||
public static KittyUser ExtractUserByJDAUser(String guildID, String name, String userID, String avatarID, String discordID)
|
||||
{
|
||||
LazyInit();
|
||||
@@ -293,7 +306,9 @@ public class ObjectBuilderFactory
|
||||
return user;
|
||||
}
|
||||
|
||||
public static KittyUser getCachedUser(String guildID, String userID)
|
||||
// There is some redundant lookup occurring. If the user isn't cached yet, then we construct them and cache them.
|
||||
// The assumption is made that the user does, in fact, exist.
|
||||
public static KittyUser getKittyUser(String guildID, String userID)
|
||||
{
|
||||
String uid = guildID + userID;
|
||||
KittyUser user = null;
|
||||
@@ -301,6 +316,17 @@ public class ObjectBuilderFactory
|
||||
{
|
||||
user = userCache.get(uid);
|
||||
}
|
||||
|
||||
if(user == null)
|
||||
{
|
||||
Guild jdaGuild = kitty.getGuildById(guildID);
|
||||
Member jdaMember = jdaGuild.getMemberById(userID);
|
||||
User jdaUser = jdaMember.getUser();
|
||||
|
||||
user = ExtractUserByJDAUser(guildID, jdaMember.getNickname(), jdaUser.getId(), jdaUser.getAvatarUrl(), jdaUser.getId());
|
||||
updateUser(user, jdaMember);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -318,6 +344,17 @@ public class ObjectBuilderFactory
|
||||
// Construction Methods //
|
||||
//////////////////////////
|
||||
|
||||
public static KittyCore ConstructKittyCore() throws LoginException, InterruptedException
|
||||
{
|
||||
LazyInit();
|
||||
|
||||
kitty = new JDABuilder(AccountType.BOT).setToken(Ref.TestToken).buildBlocking();
|
||||
kitty.getPresence().setGame(Game.playing("with digital yarn"));
|
||||
kitty.addEventListener(new Main());
|
||||
|
||||
return new KittyCore(kitty);
|
||||
}
|
||||
|
||||
// Default construction of the command manager. In order to remotely resolve command enabling
|
||||
// and disabling, what we do is construct the commands with a localized pair that is checked against
|
||||
// the CommandEnabler object passed in. In theory, we could have multiple CommandManagers, tho we can
|
||||
@@ -386,6 +423,7 @@ public class ObjectBuilderFactory
|
||||
manager.Register(LocCommands.Stub("crouton"), new CommandCrouton(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("benchmark, bench"), new CommandBenchmark(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("rafflejoin"), new CommandRaffleJoin(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.Stub("leaderboard"), new CommandLeaderboard(KittyRole.General, KittyRating.Safe));
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import dataStructures.*;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
@@ -57,7 +55,7 @@ public class RPManager
|
||||
return log;
|
||||
}
|
||||
|
||||
public static void Upkeep(JDA kitty)
|
||||
public static void Upkeep(KittyCore kitty)
|
||||
{
|
||||
Response res = new Response(null, kitty);
|
||||
String reminder = "";
|
||||
|
||||
Reference in New Issue
Block a user