Merge branch 'develop'
This commit is contained in:
@@ -44,3 +44,4 @@ catch=1
|
|||||||
guildrolelist=1
|
guildrolelist=1
|
||||||
benchmark, bench=1
|
benchmark, bench=1
|
||||||
bethistory=1
|
bethistory=1
|
||||||
|
crouton=1
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ guildroleallowed=
|
|||||||
help=
|
help=
|
||||||
buildHelp=
|
buildHelp=
|
||||||
fetch=
|
fetch=
|
||||||
|
crouton=
|
||||||
invite=
|
invite=
|
||||||
shutdown=
|
shutdown=
|
||||||
|
|
||||||
|
|||||||
+11
-1
@@ -15,7 +15,7 @@ BetHistoryOutput=Kitty has %s beans!
|
|||||||
BetHistoryInfo=Sees the amount of beans Kitty has earned through your bets!
|
BetHistoryInfo=Sees the amount of beans Kitty has earned through your bets!
|
||||||
|
|
||||||
[CommandCatch]
|
[CommandCatch]
|
||||||
CatchInfo=
|
CatchInfo=Play catch with yourself or with a friend with @!
|
||||||
|
|
||||||
[CommandBeansShow]
|
[CommandBeansShow]
|
||||||
BeansShowDisplay=You have %s beans!
|
BeansShowDisplay=You have %s beans!
|
||||||
@@ -95,6 +95,9 @@ ShutdownSafe=Shutting down, but first syncing database and finishing current thr
|
|||||||
ShutdownUnsafe=Shutting down and immediately and abandoning all threads without sync.
|
ShutdownUnsafe=Shutting down and immediately and abandoning all threads without sync.
|
||||||
ShutdownInfo=Stops kitty. `-s` or `safe` as an argument attempts to sync off the database before shutdown.
|
ShutdownInfo=Stops kitty. `-s` or `safe` as an argument attempts to sync off the database before shutdown.
|
||||||
|
|
||||||
|
[CommandCrouton]
|
||||||
|
CroutonInfo=Crouton
|
||||||
|
|
||||||
[CommandTeey]
|
[CommandTeey]
|
||||||
TeeyInfo=Teey yourself back into existance, or teey a friend with @!
|
TeeyInfo=Teey yourself back into existance, or teey a friend with @!
|
||||||
|
|
||||||
@@ -225,4 +228,11 @@ MapVersion=Using mapgen v0.1
|
|||||||
MapWidth=Width
|
MapWidth=Width
|
||||||
MapHeight=Height
|
MapHeight=Height
|
||||||
|
|
||||||
|
[CommandTradeBeans]
|
||||||
|
TradeBeansInfo=Gives another person some of your beans! Use is `tradebeans amount @person`!
|
||||||
|
TradeBeansNoTargetError=You have to give *someone* your beans!
|
||||||
|
TradeBeansIntParseError=That's not a real number!
|
||||||
|
TradeBeansNotEnoughError=You don't have enough beans!
|
||||||
|
TradeBeanseStealingBeans=Stealing is wrong! *Steals 10 beans from %s*
|
||||||
|
TradeBeansSuccess=%s gave %s %s of their beans!
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package commands;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
import core.Command;
|
||||||
|
import core.LocStrings;
|
||||||
|
import dataStructures.KittyChannel;
|
||||||
|
import dataStructures.KittyEmbed;
|
||||||
|
import dataStructures.KittyGuild;
|
||||||
|
import dataStructures.KittyRating;
|
||||||
|
import dataStructures.KittyRole;
|
||||||
|
import dataStructures.KittyUser;
|
||||||
|
import dataStructures.Response;
|
||||||
|
import dataStructures.UserInput;
|
||||||
|
|
||||||
|
public class CommandCrouton extends Command
|
||||||
|
{
|
||||||
|
public CommandCrouton(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String HelpText() { return LocStrings.Stub("CroutonInfo"); };
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||||
|
{
|
||||||
|
KittyEmbed embed = new KittyEmbed();
|
||||||
|
embed.authorImage = "https://crouton.net/crouton.png";
|
||||||
|
embed.authorLink = "https://crouton.net/";
|
||||||
|
embed.authorText = "Crouton";
|
||||||
|
embed.color = new Color(255f / 255, 153f / 255, 51f / 255); // Crouton
|
||||||
|
embed.descriptionText = "Crouton";
|
||||||
|
embed.footerText = "Crouton";
|
||||||
|
embed.title = "Crouton";
|
||||||
|
|
||||||
|
embed.imageURL = "https://crouton.net/crouton.png";
|
||||||
|
|
||||||
|
res.CallEmbed(embed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package commands;
|
||||||
|
|
||||||
|
import core.Command;
|
||||||
|
import core.LocStrings;
|
||||||
|
import dataStructures.KittyChannel;
|
||||||
|
import dataStructures.KittyGuild;
|
||||||
|
import dataStructures.KittyRating;
|
||||||
|
import dataStructures.KittyRole;
|
||||||
|
import dataStructures.KittyUser;
|
||||||
|
import dataStructures.Response;
|
||||||
|
import dataStructures.UserInput;
|
||||||
|
|
||||||
|
public class CommandTradeBeans extends Command
|
||||||
|
{
|
||||||
|
public CommandTradeBeans(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String HelpText() { return LocStrings.Stub("TradeBeansInfo"); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||||
|
{
|
||||||
|
if(input.mentions == null)
|
||||||
|
{
|
||||||
|
res.Call(LocStrings.Stub("TradeBeansNoTargetError"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int beans = 0;
|
||||||
|
try {
|
||||||
|
beans = Integer.parseInt(input.args.split(" ")[0]);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e)
|
||||||
|
{
|
||||||
|
res.Call(LocStrings.Stub("TradeBeansIntParseError"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(user.GetBeans() < beans)
|
||||||
|
{
|
||||||
|
res.Call(LocStrings.Stub("TradeBeansNotEnoughError"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(beans < 0)
|
||||||
|
{
|
||||||
|
res.Call(String.format(LocStrings.Stub("TradeBeansStealingBeans"), user.name));
|
||||||
|
user.ChangeBeans(-10);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
input.mentions[0].ChangeBeans(beans);
|
||||||
|
user.ChangeBeans(-beans);
|
||||||
|
res.Call(String.format(LocStrings.Stub("TradeBeansSuccess"), user.name, input.mentions[0].name, beans));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -374,6 +374,7 @@ public class ObjectBuilderFactory
|
|||||||
manager.Register(LocCommands.Stub("catch"), new CommandCatch(KittyRole.General, KittyRating.Safe));
|
manager.Register(LocCommands.Stub("catch"), new CommandCatch(KittyRole.General, KittyRating.Safe));
|
||||||
manager.Register(LocCommands.Stub("guildrolelist"), new CommandGuildRoleList(KittyRole.General, KittyRating.Safe));
|
manager.Register(LocCommands.Stub("guildrolelist"), new CommandGuildRoleList(KittyRole.General, KittyRating.Safe));
|
||||||
manager.Register(LocCommands.Stub("bethistory"), new CommandBetHistory(KittyRole.General, KittyRating.Safe));
|
manager.Register(LocCommands.Stub("bethistory"), new CommandBetHistory(KittyRole.General, KittyRating.Safe));
|
||||||
|
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("benchmark, bench"), new CommandBenchmark(KittyRole.General, KittyRating.Safe));
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ public class KittyEmbed
|
|||||||
public String authorLink = null;
|
public String authorLink = null;
|
||||||
public String authorImage = null;
|
public String authorImage = null;
|
||||||
public String descriptionText = null;
|
public String descriptionText = null;
|
||||||
|
public String bodyImageURL = null;
|
||||||
|
public String imageURL = null;
|
||||||
|
|
||||||
|
|
||||||
public KittyEmbed()
|
public KittyEmbed()
|
||||||
{
|
{
|
||||||
this.title = "Untitled";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ public class Response
|
|||||||
if(embedInfo.authorImage != null || embedInfo.authorLink != null || embedInfo.authorText != null)
|
if(embedInfo.authorImage != null || embedInfo.authorLink != null || embedInfo.authorText != null)
|
||||||
embed.setAuthor(embedInfo.authorText, embedInfo.authorLink, embedInfo.authorImage);
|
embed.setAuthor(embedInfo.authorText, embedInfo.authorLink, embedInfo.authorImage);
|
||||||
|
|
||||||
|
if(embedInfo.imageURL != null)
|
||||||
|
embed.setImage(embedInfo.imageURL);
|
||||||
|
|
||||||
event.getChannel().sendMessage(embed.build()).queue();
|
event.getChannel().sendMessage(embed.build()).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-81
@@ -26,7 +26,7 @@ import net.dv8tion.jda.core.*;
|
|||||||
public class Main extends ListenerAdapter
|
public class Main extends ListenerAdapter
|
||||||
{
|
{
|
||||||
// Variables and bot specific objects
|
// Variables and bot specific objects
|
||||||
private static JDA kitty;
|
private static JDA kitty; // TODO: Wrap
|
||||||
private static DatabaseManager databaseManager;
|
private static DatabaseManager databaseManager;
|
||||||
private static CommandEnabler commandEnabler;
|
private static CommandEnabler commandEnabler;
|
||||||
private static CommandManager commandManager;
|
private static CommandManager commandManager;
|
||||||
@@ -34,7 +34,7 @@ public class Main extends ListenerAdapter
|
|||||||
private static RPManager rpManager;
|
private static RPManager rpManager;
|
||||||
private static PluginManager pluginManager;
|
private static PluginManager pluginManager;
|
||||||
|
|
||||||
// Main test location
|
// Initialization and setup
|
||||||
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
||||||
{
|
{
|
||||||
// Factory startup. The ordering is intentional.
|
// Factory startup. The ordering is intentional.
|
||||||
@@ -52,11 +52,12 @@ public class Main extends ListenerAdapter
|
|||||||
kitty.addEventListener(new Main());
|
kitty.addEventListener(new Main());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When a message is sent in a server that kitty is in, this is what's called.
|
||||||
@Override
|
@Override
|
||||||
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
|
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
|
||||||
{
|
{
|
||||||
// Tweak the event as necessary
|
// Tweak the event as necessary
|
||||||
if(!PreProcessSetup(event))
|
if(!Superintendent.PreProcessSetup(event, stats))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Factory objects
|
// Factory objects
|
||||||
@@ -69,7 +70,7 @@ public class Main extends ListenerAdapter
|
|||||||
UserInput input = new UserInput(event, guild);
|
UserInput input = new UserInput(event, guild);
|
||||||
|
|
||||||
// Tweak object construction as necessary
|
// Tweak object construction as necessary
|
||||||
if(!PostProcessSetup(event, user, guild, channel, response, input))
|
if(!Superintendent.PostProcessSetup(event, user, guild, channel, response, input))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Track beans!
|
// Track beans!
|
||||||
@@ -79,7 +80,7 @@ public class Main extends ListenerAdapter
|
|||||||
RPManager.instance.addLine(channel, user, input);
|
RPManager.instance.addLine(channel, user, input);
|
||||||
|
|
||||||
// Run any pre-emptive upkeep we need to
|
// Run any pre-emptive upkeep we need to
|
||||||
PerCommandUpkeepPre();
|
Superintendent.PerCommandUpkeepPre();
|
||||||
|
|
||||||
// Attempt to spin up a command. If the command doesn't exist.
|
// Attempt to spin up a command. If the command doesn't exist.
|
||||||
// Run plugins right before invoking the commands but after all other setup.
|
// Run plugins right before invoking the commands but after all other setup.
|
||||||
@@ -92,81 +93,6 @@ public class Main extends ListenerAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run any upkeep in post we need to
|
// Run any upkeep in post we need to
|
||||||
PerCommandUpkeepPost();
|
Superintendent.PerCommandUpkeepPost(kitty, databaseManager);
|
||||||
}
|
|
||||||
|
|
||||||
// This is run on the JDA GuildMessageReceivedEvent before anything else happens.
|
|
||||||
public static boolean PreProcessSetup(GuildMessageReceivedEvent event)
|
|
||||||
{
|
|
||||||
// Verify we have an event
|
|
||||||
if(event == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Track number of messages seen
|
|
||||||
stats.NoteMessageEvent();
|
|
||||||
|
|
||||||
// If we're mid-shutdown, no more commands.
|
|
||||||
if(stats.GetIsShuttingDown())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Swat down highest ban level immediately before even hitting command parsing.
|
|
||||||
for(int i = 0; i < Ref.alwaysIgnore.length; ++i)
|
|
||||||
{
|
|
||||||
String id = event.getAuthor().getId();
|
|
||||||
if(id.equals(Ref.alwaysIgnore[i]))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This runs after all the objects have been constructed!
|
|
||||||
// Modifications to objects here stick!
|
|
||||||
public static boolean PostProcessSetup(GuildMessageReceivedEvent event, KittyUser user, KittyGuild guild, KittyChannel channel, Response res, UserInput input)
|
|
||||||
{
|
|
||||||
// Verify we have everything. From here out, we promise we have that all.
|
|
||||||
if(event == null || user == null || guild == null || channel == null || res == null || input == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// If the guild member is the owner, give them admin role by default.
|
|
||||||
if(event.getMember().isOwner())
|
|
||||||
user.ChangeRole(KittyRole.Admin);
|
|
||||||
|
|
||||||
// Give devs the dev role
|
|
||||||
for(int i = 0; i < Ref.devIDs.length; ++i)
|
|
||||||
{
|
|
||||||
if(event.getAuthor().getId().equals(Ref.devIDs[i]))
|
|
||||||
{
|
|
||||||
user.ChangeRole(KittyRole.Dev);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is for stuff that we need to do on a regular basis, but don't
|
|
||||||
// necessarily want running at all points in time.
|
|
||||||
// Happens just after the command / plugin runs.
|
|
||||||
private static boolean PerCommandUpkeepPost()
|
|
||||||
{
|
|
||||||
// Upkeep database
|
|
||||||
databaseManager.Upkeep();
|
|
||||||
|
|
||||||
// Update command-specific
|
|
||||||
RPManager.Upkeep(kitty);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only called once per command. Good for lazily updating.
|
|
||||||
// Happens just before the command / plugin runs.
|
|
||||||
private static boolean PerCommandUpkeepPre()
|
|
||||||
{
|
|
||||||
// Upkeep localization system's file monitoring
|
|
||||||
LocStrings.Upkeep();
|
|
||||||
LocCommands.Upkeep();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package main;
|
||||||
|
|
||||||
|
import core.DatabaseManager;
|
||||||
|
import core.LocCommands;
|
||||||
|
import core.LocStrings;
|
||||||
|
import core.RPManager;
|
||||||
|
import core.Stats;
|
||||||
|
import dataStructures.KittyChannel;
|
||||||
|
import dataStructures.KittyGuild;
|
||||||
|
import dataStructures.KittyRole;
|
||||||
|
import dataStructures.KittyUser;
|
||||||
|
import dataStructures.Response;
|
||||||
|
import dataStructures.UserInput;
|
||||||
|
import net.dv8tion.jda.core.JDA;
|
||||||
|
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
import offline.Ref;
|
||||||
|
|
||||||
|
// Manages the fiddly bits and upkeep of the bot - while not
|
||||||
|
public class Superintendent
|
||||||
|
{
|
||||||
|
// This is run on the JDA GuildMessageReceivedEvent before anything else happens.
|
||||||
|
public static boolean PreProcessSetup(GuildMessageReceivedEvent event, Stats stats)
|
||||||
|
{
|
||||||
|
// Verify we have an event
|
||||||
|
if(event == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Track number of messages seen
|
||||||
|
stats.NoteMessageEvent();
|
||||||
|
|
||||||
|
// If we're mid-shutdown, no more commands.
|
||||||
|
if(stats.GetIsShuttingDown())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Swat down highest ban level immediately before even hitting command parsing.
|
||||||
|
for(int i = 0; i < Ref.alwaysIgnore.length; ++i)
|
||||||
|
{
|
||||||
|
String id = event.getAuthor().getId();
|
||||||
|
if(id.equals(Ref.alwaysIgnore[i]))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This runs after all the objects have been constructed!
|
||||||
|
// Modifications to objects here stick!
|
||||||
|
public static boolean PostProcessSetup(GuildMessageReceivedEvent event, KittyUser user, KittyGuild guild, KittyChannel channel, Response res, UserInput input)
|
||||||
|
{
|
||||||
|
// Verify we have everything. From here out, we promise we have that all.
|
||||||
|
if(event == null || user == null || guild == null || channel == null || res == null || input == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// If the guild member is the owner, give them admin role by default.
|
||||||
|
if(event.getMember().isOwner())
|
||||||
|
user.ChangeRole(KittyRole.Admin);
|
||||||
|
|
||||||
|
// Give devs the dev role
|
||||||
|
for(int i = 0; i < Ref.devIDs.length; ++i)
|
||||||
|
{
|
||||||
|
if(event.getAuthor().getId().equals(Ref.devIDs[i]))
|
||||||
|
{
|
||||||
|
user.ChangeRole(KittyRole.Dev);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is for stuff that we need to do on a regular basis, but don't
|
||||||
|
// necessarily want running at all points in time.
|
||||||
|
// Happens just after the command / plugin runs.
|
||||||
|
public static boolean PerCommandUpkeepPost(JDA bot, DatabaseManager databaseManager)
|
||||||
|
{
|
||||||
|
// Upkeep database
|
||||||
|
databaseManager.Upkeep();
|
||||||
|
|
||||||
|
// Update command-specific
|
||||||
|
RPManager.Upkeep(bot);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only called once per command. Good for lazily updating.
|
||||||
|
// Happens just before the command / plugin runs.
|
||||||
|
public static boolean PerCommandUpkeepPre()
|
||||||
|
{
|
||||||
|
// Upkeep localization system's file monitoring
|
||||||
|
LocStrings.Upkeep();
|
||||||
|
LocCommands.Upkeep();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user