Merge branch 'develop'

This commit is contained in:
Alex
2019-07-06 00:21:03 -04:00
43 changed files with 671 additions and 525 deletions
+8 -4
View File
@@ -8,6 +8,7 @@
"Localized Commands","buildHelp","" "Localized Commands","buildHelp",""
"Localized Commands","c++, g++, cplus, cpp","" "Localized Commands","c++, g++, cplus, cpp",""
"Localized Commands","catch","" "Localized Commands","catch",""
"Localized Commands","character",""
"Localized Commands","charactercreate","" "Localized Commands","charactercreate",""
"Localized Commands","charactereditbio","" "Localized Commands","charactereditbio",""
"Localized Commands","charactereditname","" "Localized Commands","charactereditname",""
@@ -39,6 +40,7 @@
"Localized Commands","perish, thenperish","" "Localized Commands","perish, thenperish",""
"Localized Commands","ping","" "Localized Commands","ping",""
"Localized Commands","poll","" "Localized Commands","poll",""
"Localized Commands","raffle",""
"Localized Commands","raffleend","" "Localized Commands","raffleend",""
"Localized Commands","rafflejoin","" "Localized Commands","rafflejoin",""
"Localized Commands","rafflespin","" "Localized Commands","rafflespin",""
@@ -80,7 +82,7 @@
"Localized Strings","BoopInfo","Kitty will react with a counter" "Localized Strings","BoopInfo","Kitty will react with a counter"
"Localized Strings","BoopMultiple","%s booped several others - %s!" "Localized Strings","BoopMultiple","%s booped several others - %s!"
"Localized Strings","BoopPerson","%s booped %s!" "Localized Strings","BoopPerson","%s booped %s!"
"Localized Strings","BoopStandard","Woah! %s booped me! That's %s total!" "Localized Strings","BoopStandard","Woah! %s booped me! That's %s total! "
"Localized Strings","CatchInfo","Play catch with yourself or with a friend with @!" "Localized Strings","CatchInfo","Play catch with yourself or with a friend with @!"
"Localized Strings","ChangeIndicatorChanged","Indicator changed to `%s`" "Localized Strings","ChangeIndicatorChanged","Indicator changed to `%s`"
"Localized Strings","ChangeIndicatorError","Please specify a letter or symbol to use!" "Localized Strings","ChangeIndicatorError","Please specify a letter or symbol to use!"
@@ -183,7 +185,7 @@
"Localized Strings","LeaderboardInfo","Shows you the 10 users with the most beans on the server" "Localized Strings","LeaderboardInfo","Shows you the 10 users with the most beans on the server"
"Localized Strings","LeaderboardTitle","Server Leaderboard" "Localized Strings","LeaderboardTitle","Server Leaderboard"
"Localized Strings","MapHeight","" "Localized Strings","MapHeight",""
"Localized Strings","MapInfo","Generates a map! You can pass additional information if you want with the flags `-s<seed>`. If one of the fields isn't provided, its default will be used. Note that adjusting the width and height impacts the map outcomes.nn**Defaults**nDefault Seed: Random,nDefault Width: 35(max %s),nDefault Height: 25(max %s)nn**Key**nLand: ~nMountain: nBeach: " "Localized Strings","MapInfo","Generates a map! You can pass additional information if you want with the flags `-s<seed>`. If one of the fields isn't provided, its default will be used. Note that adjusting the width and height impacts the map outcomes.\n\n**Defaults**\nDefault Seed: Random,\nDefault Width: 35(max %s),\nDefault Height: 25(max %s)\n\n**Key**\nLand: ~\nMountain: \u25B2\nBeach: =\nTrees: \u00A5\nVolcano: #"
"Localized Strings","MapInvalid","Invalid arguments provided!" "Localized Strings","MapInvalid","Invalid arguments provided!"
"Localized Strings","MapSeed","Seed" "Localized Strings","MapSeed","Seed"
"Localized Strings","MapVersion","Using mapgen v0.1" "Localized Strings","MapVersion","Using mapgen v0.1"
@@ -193,11 +195,11 @@
"Localized Strings","PingResponse","Pong!" "Localized Strings","PingResponse","Pong!"
"Localized Strings","PollManageInfo","'start' will start a new poll with the query of the line you put after, 'choice' will add a choice to the poll, 'stop' will end the poll" "Localized Strings","PollManageInfo","'start' will start a new poll with the query of the line you put after, 'choice' will add a choice to the poll, 'stop' will end the poll"
"Localized Strings","PollResultsInfo","Will show current results of a poll and percentages of votes per choice" "Localized Strings","PollResultsInfo","Will show current results of a poll and percentages of votes per choice"
"Localized Strings","PollResultsResponse","%s people voted for %s `%s` with `%s%` !n" "Localized Strings","PollResultsResponse","%s people voted for `%s` with `%s%%` "
"Localized Strings","PollShowChoices","And the choices are:n" "Localized Strings","PollShowChoices","And the choices are:n"
"Localized Strings","PollShowInfo","Will show the current poll running" "Localized Strings","PollShowInfo","Will show the current poll running"
"Localized Strings","PollShowNoPoll","There is no poll running!" "Localized Strings","PollShowNoPoll","There is no poll running!"
"Localized Strings","PollShowPoll","The current poll is `%s`n" "Localized Strings","PollShowPoll","The current poll is `%s`"
"Localized Strings","PollVoteAlreadyVoted","You already voted" "Localized Strings","PollVoteAlreadyVoted","You already voted"
"Localized Strings","PollVoteInfo","Vote in a poll with the choice number, won't work if no poll is running, you can't change your vote once you have cast it! Be careful!" "Localized Strings","PollVoteInfo","Vote in a poll with the choice number, won't work if no poll is running, you can't change your vote once you have cast it! Be careful!"
"Localized Strings","PollVoteNoPoll","There is no poll running!" "Localized Strings","PollVoteNoPoll","There is no poll running!"
@@ -263,6 +265,7 @@
"Command Enabler","buildhelp","1" "Command Enabler","buildhelp","1"
"Command Enabler","c++, g++, cplus, cpp","1" "Command Enabler","c++, g++, cplus, cpp","1"
"Command Enabler","catch","1" "Command Enabler","catch","1"
"Command Enabler","character","1"
"Command Enabler","charactercreate","1" "Command Enabler","charactercreate","1"
"Command Enabler","charactereditbio","1" "Command Enabler","charactereditbio","1"
"Command Enabler","charactereditname","1" "Command Enabler","charactereditname","1"
@@ -294,6 +297,7 @@
"Command Enabler","perish, thenperish","1" "Command Enabler","perish, thenperish","1"
"Command Enabler","ping","1" "Command Enabler","ping","1"
"Command Enabler","poll","1" "Command Enabler","poll","1"
"Command Enabler","raffle","1"
"Command Enabler","raffleend","1" "Command Enabler","raffleend","1"
"Command Enabler","rafflejoin","1" "Command Enabler","rafflejoin","1"
"Command Enabler","rafflespin","1" "Command Enabler","rafflespin","1"
1 Type Key Value
8 Localized Commands buildHelp
9 Localized Commands c++, g++, cplus, cpp
10 Localized Commands catch
11 Localized Commands character
12 Localized Commands charactercreate
13 Localized Commands charactereditbio
14 Localized Commands charactereditname
40 Localized Commands perish, thenperish
41 Localized Commands ping
42 Localized Commands poll
43 Localized Commands raffle
44 Localized Commands raffleend
45 Localized Commands rafflejoin
46 Localized Commands rafflespin
82 Localized Strings BoopInfo Kitty will react with a counter
83 Localized Strings BoopMultiple %s booped several others - %s!
84 Localized Strings BoopPerson %s booped %s!
85 Localized Strings BoopStandard Woah! %s booped me! That's %s total! Woah! %s booped me! That's %s total!
86 Localized Strings CatchInfo Play catch with yourself or with a friend with @!
87 Localized Strings ChangeIndicatorChanged Indicator changed to `%s`
88 Localized Strings ChangeIndicatorError Please specify a letter or symbol to use!
185 Localized Strings LeaderboardInfo Shows you the 10 users with the most beans on the server
186 Localized Strings LeaderboardTitle Server Leaderboard
187 Localized Strings MapHeight
188 Localized Strings MapInfo Generates a map! You can pass additional information if you want with the flags `-s<seed>`. If one of the fields isn't provided, its default will be used. Note that adjusting the width and height impacts the map outcomes.nn**Defaults**nDefault Seed: Random,nDefault Width: 35(max %s),nDefault Height: 25(max %s)nn**Key**nLand: ~nMountain: ▲nBeach: Generates a map! You can pass additional information if you want with the flags `-s<seed>`. If one of the fields isn't provided, its default will be used. Note that adjusting the width and height impacts the map outcomes.\n\n**Defaults**\nDefault Seed: Random,\nDefault Width: 35(max %s),\nDefault Height: 25(max %s)\n\n**Key**\nLand: ~\nMountain: \u25B2\nBeach: =\nTrees: \u00A5\nVolcano: #
189 Localized Strings MapInvalid Invalid arguments provided!
190 Localized Strings MapSeed Seed
191 Localized Strings MapVersion Using mapgen v0.1
195 Localized Strings PingResponse Pong!
196 Localized Strings PollManageInfo 'start' will start a new poll with the query of the line you put after, 'choice' will add a choice to the poll, 'stop' will end the poll
197 Localized Strings PollResultsInfo Will show current results of a poll and percentages of votes per choice
198 Localized Strings PollResultsResponse %s people voted for %s `%s` with `%s%` !n %s people voted for `%s` with `%s%%`
199 Localized Strings PollShowChoices And the choices are:n
200 Localized Strings PollShowInfo Will show the current poll running
201 Localized Strings PollShowNoPoll There is no poll running!
202 Localized Strings PollShowPoll The current poll is `%s`n The current poll is `%s`
203 Localized Strings PollVoteAlreadyVoted You already voted
204 Localized Strings PollVoteInfo Vote in a poll with the choice number, won't work if no poll is running, you can't change your vote once you have cast it! Be careful!
205 Localized Strings PollVoteNoPoll There is no poll running!
265 Command Enabler buildhelp 1
266 Command Enabler c++, g++, cplus, cpp 1
267 Command Enabler catch 1
268 Command Enabler character 1
269 Command Enabler charactercreate 1
270 Command Enabler charactereditbio 1
271 Command Enabler charactereditname 1
297 Command Enabler perish, thenperish 1
298 Command Enabler ping 1
299 Command Enabler poll 1
300 Command Enabler raffle 1
301 Command Enabler raffleend 1
302 Command Enabler rafflejoin 1
303 Command Enabler rafflespin 1
+1
View File
@@ -8,6 +8,7 @@ function plugin(message, user)
hours = ((timedif / (60*60)) % 24); hours = ((timedif / (60*60)) % 24);
mins = ((timedif / (60)) % 60); mins = ((timedif / (60)) % 60);
secs = timedif % 60; secs = timedif % 60;
return "*GASP!!!* \n" .. user.name .. " said **THE** word! It's been " .. round(days) .. " days, " .. round(hours) .. " hours, " .. round(mins) .. " minutes, and " .. round(secs) .. " seconds since the last time!"; return "*GASP!!!* \n" .. user.name .. " said **THE** word! It's been " .. round(days) .. " days, " .. round(hours) .. " hours, " .. round(mins) .. " minutes, and " .. round(secs) .. " seconds since the last time!";
end end
@@ -1,38 +0,0 @@
package commands.characters;
import core.CharacterManager;
import core.Command;
import core.LocStrings;
import dataStructures.*;
public class CommandCharacterEditBio extends Command
{
public CommandCharacterEditBio(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String getHelpText() { return LocStrings.stub("CharacterEditBioInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
try
{
Long.parseLong(input.args.split(" ")[0]);
}
catch(Exception e)
{
res.send(LocStrings.stub("CharacterEditBioNotValid"));
return;
}
KittyCharacter character = CharacterManager.instance.searchCharacter(input.args.split(" ")[0]).get(0);
if(character.getOwner().equals(user))
{
CharacterManager.instance.editBio(character, input.args.substring(input.args.indexOf(' ')));
res.send(LocStrings.stub("CharacterEditBioSuccess"));
}
else
{
res.send(LocStrings.stub("CharacterEditBioNotAuth"));
}
}
}
@@ -1,38 +0,0 @@
package commands.characters;
import core.CharacterManager;
import core.Command;
import core.LocStrings;
import dataStructures.*;
public class CommandCharacterEditName extends Command
{
public CommandCharacterEditName(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String getHelpText() { return LocStrings.stub("CharacterEditNameInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
try
{
Long.parseLong(input.args.split(" ")[0]);
}
catch(Exception e)
{
res.send(LocStrings.stub("CharacterEditNameNotValid"));
return;
}
KittyCharacter character = CharacterManager.instance.searchCharacter(input.args.split(" ")[0]).get(0);
if(character.getOwner().equals(user))
{
CharacterManager.instance.editName(character, input.args.substring(input.args.indexOf(' ')));
res.send(LocStrings.stub("CharacterEditNameSuccess"));
}
else
{
res.send(LocStrings.stub("CharacterEditNameNotAuth"));
}
}
}
@@ -1,38 +0,0 @@
package commands.characters;
import core.CharacterManager;
import core.Command;
import core.LocStrings;
import dataStructures.*;
public class CommandCharacterEditURL extends Command
{
public CommandCharacterEditURL(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String getHelpText() { return LocStrings.stub("CharacterEditURLInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
try
{
Long.parseLong(input.args.split(" ")[0]);
}
catch(Exception e)
{
res.send(LocStrings.stub("CharacterEditURLNotValid"));
return;
}
KittyCharacter character = CharacterManager.instance.searchCharacter(input.args.split(" ")[0]).get(0);
if(character.getOwner().equals(user))
{
CharacterManager.instance.editRefImage(character, input.args.substring(input.args.indexOf(' ')));
res.send(LocStrings.stub("CharacterEditURLSuccess"));
}
else
{
res.send(LocStrings.stub("CharacterEditURLNotAuth"));
}
}
}
@@ -1,15 +1,10 @@
package commands.characters; package commands.characters;
import commands.guildrole.*;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
import core.SubCommandFramework; import core.SubCommandFramework;
import dataStructures.KittyChannel; import dataStructures.*;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
public class CommandCharacterMain extends Command public class CommandCharacterMain extends Command
{ {
@@ -17,14 +12,16 @@ public class CommandCharacterMain extends Command
public CommandCharacterMain(KittyRole level, KittyRating rating) public CommandCharacterMain(KittyRole level, KittyRating rating)
{ {
super(level, rating); super(level, rating);
framework.addCommand("add", new SubCommandAdd(KittyRole.General, KittyRating.Safe));
framework.addCommand("editbio", new SubCommandEditBio(KittyRole.General, KittyRating.Safe));
framework.addCommand("editname", new SubCommandEditName(KittyRole.General, KittyRating.Safe));
framework.addCommand("editurl", new SubCommandEditURL(KittyRole.General, KittyRating.Safe));
framework.addCommand("search", new SubCommandSearch(KittyRole.General, KittyRating.Safe));
} }
@Override @Override
public String getHelpText() { return LocStrings.stub("CharacterInfo"); } public String getHelpText() { return LocStrings.stub("CharacterInfo"); }
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
@@ -1,40 +0,0 @@
package commands.characters;
import java.util.ArrayList;
import core.CharacterManager;
import core.Command;
import core.LocStrings;
import dataStructures.*;
public class CommandCharacterSearch extends Command
{
public CommandCharacterSearch(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String getHelpText() { return LocStrings.stub("CharacterSearchInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
ArrayList <KittyCharacter> characters = CharacterManager.instance.searchCharacter(input.args);
if(characters.size() < 1)
{
res.send(LocStrings.stub("CharacterSearchNoCharacterFound"));
return;
}
if(characters.size() > 1)
{
res.send(LocStrings.stub("CharacterSearchMultipleCharacterHeader"));
for(KittyCharacter character:characters)
{
res.send(String.format(LocStrings.stub("CharacterSearchMultipleCharacter"), character.getName(), character.getOwner().name, character.getUID()));
}
return;
}
else
{
res.send(String.format(LocStrings.stub("CharacterSearchOneCharacter"), characters.get(0).getOwner().name, characters.get(0).getName(), characters.get(0).getBio(), characters.get(0).getRefImage(), characters.get(0).getUID()));
}
}
}
@@ -6,9 +6,9 @@ import core.SubCommand;
import core.SubCommandFormattable; import core.SubCommandFormattable;
import dataStructures.*; import dataStructures.*;
public class CommandCharacterCreate extends SubCommand public class SubCommandCreate extends SubCommand
{ {
public CommandCharacterCreate(KittyRole level, KittyRating rating) { super(level, rating); } public SubCommandCreate(KittyRole level, KittyRating rating) { super(level, rating); }
@Override @Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input) public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
@@ -0,0 +1,40 @@
package commands.characters;
import core.CharacterManager;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyCharacter;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
public class SubCommandEditBio extends SubCommand
{
public SubCommandEditBio(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
try
{
Long.parseLong(input.split(" ")[0]);
}
catch(Exception e)
{
return new SubCommandFormattable (LocStrings.stub("CharacterEditBioNotValid"));
}
KittyCharacter character = CharacterManager.instance.searchCharacter(input.split(" ")[0]).get(0);
if(character.getOwner().equals(user))
{
CharacterManager.instance.editBio(character, input.substring(input.indexOf(' ')));
return new SubCommandFormattable (LocStrings.stub("CharacterEditBioSuccess"));
}
else
{
return new SubCommandFormattable (LocStrings.stub("CharacterEditBioNotAuth"));
}
}
}
@@ -0,0 +1,40 @@
package commands.characters;
import core.CharacterManager;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyCharacter;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
public class SubCommandEditName extends SubCommand
{
public SubCommandEditName(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
try
{
Long.parseLong(input.split(" ")[0]);
}
catch(Exception e)
{
return new SubCommandFormattable (LocStrings.stub("CharacterEditNameNotValid"));
}
KittyCharacter character = CharacterManager.instance.searchCharacter(input.split(" ")[0]).get(0);
if(character.getOwner().equals(user))
{
CharacterManager.instance.editName(character, input.substring(input.indexOf(' ')));
return new SubCommandFormattable (LocStrings.stub("CharacterEditNameSuccess"));
}
else
{
return new SubCommandFormattable (LocStrings.stub("CharacterEditNameNotAuth"));
}
}
}
@@ -0,0 +1,40 @@
package commands.characters;
import core.CharacterManager;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyCharacter;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
public class SubCommandEditURL extends SubCommand
{
public SubCommandEditURL(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
try
{
Long.parseLong(input.split(" ")[0]);
}
catch(Exception e)
{
return new SubCommandFormattable (LocStrings.stub("CharacterEditURLNotValid"));
}
KittyCharacter character = CharacterManager.instance.searchCharacter(input.split(" ")[0]).get(0);
if(character.getOwner().equals(user))
{
CharacterManager.instance.editRefImage(character, input.substring(input.indexOf(' ')));
return new SubCommandFormattable (LocStrings.stub("CharacterEditURLSuccess"));
}
else
{
return new SubCommandFormattable (LocStrings.stub("CharacterEditURLNotAuth"));
}
}
}
@@ -0,0 +1,43 @@
package commands.characters;
import java.util.ArrayList;
import core.CharacterManager;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyCharacter;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
public class SubCommandSearch extends SubCommand
{
public SubCommandSearch(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
ArrayList <KittyCharacter> characters = CharacterManager.instance.searchCharacter(input);
if(characters.size() < 1)
{
return new SubCommandFormattable (LocStrings.stub("CharacterSearchNoCharacterFound"));
}
String formatted = "";
if(characters.size() > 1)
{
formatted += (LocStrings.stub("CharacterSearchMultipleCharacterHeader"));
for(KittyCharacter character:characters)
{
formatted += "\n" + (String.format(LocStrings.stub("CharacterSearchMultipleCharacter"), character.getName(), character.getOwner().name, character.getUID()));
}
return new SubCommandFormattable(formatted);
}
else
{
return new SubCommandFormattable (String.format(LocStrings.stub("CharacterSearchOneCharacter"), characters.get(0).getOwner().name, characters.get(0).getName(), characters.get(0).getBio(), characters.get(0).getRefImage(), characters.get(0).getUID()));
}
}
}
@@ -1,40 +0,0 @@
package commands.general;
import core.*;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
public class CommandPollManage extends Command
{
public CommandPollManage(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String getHelpText() { return LocStrings.stub("PollManageInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
switch(input.args.split(" ")[0].toLowerCase())
{
case "start":
res.send(guild.startPoll(input.args.substring(input.args.indexOf(' ')).trim()));
break;
case "choice":
res.send(guild.addChoiceToPoll(input.args.substring(input.args.indexOf(' ')).trim()));
break;
case "stop":
res.send(guild.endPoll());
break;
default:
break;
}
}
}
-30
View File
@@ -1,30 +0,0 @@
package commands.general;
import core.*;
import dataStructures.*;
public class CommandPollShow extends Command
{
public CommandPollShow(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String getHelpText() { return LocStrings.stub("PollShowInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
if(!guild.polling)
{
res.send(LocStrings.stub("PollShowNoPoll"));
return;
}
String poll = String.format(LocStrings.stub("PollShowPoll"), guild.poll);
poll += LocStrings.stub("PollShowChoices");
for(int i = 0; i < guild.choices.size(); i++)
{
poll += (i+1) + ": `" + guild.choices.get(i).choice + "`\n";
}
res.send(poll);
}
}
-47
View File
@@ -1,47 +0,0 @@
package commands.general;
import core.*;
import dataStructures.*;
public class CommandPollVote extends Command
{
public CommandPollVote(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String getHelpText() { return LocStrings.stub("PollVoteInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
if(guild.polling)
{
if(guild.hasVoted.contains(user.uniqueID))
{
res.send(LocStrings.stub("PollVoteAlreadyVoted"));
return;
}
try
{
int voteNum = Integer.parseInt(input.args)-1;
if(voteNum >= guild.choices.size() || voteNum < 0)
{
res.send(String.format(LocStrings.stub("PollVoteNotValidVote"), voteNum));
return;
}
KittyPoll polled = guild.choices.get(voteNum);
polled.votes++;
guild.hasVoted.add(user.uniqueID);
res.send(LocStrings.stub("PollVoteSuccess") + " `" + polled.choice + "`!");
return;
}
catch (NumberFormatException e)
{
res.send(LocStrings.stub("PollVoteNotValidNumber"));
return;
}
}
res.send(LocStrings.stub("PollVoteNoPoll"));
}
}
@@ -1,32 +0,0 @@
package commands.general;
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 CommandRaffleEnd extends Command
{
public CommandRaffleEnd(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String getHelpText() { return LocStrings.stub("RaffleEndInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
if(guild.endRaffle())
{
res.send(LocStrings.stub("RaffleEndSuccess"));
}
else
{
res.send(LocStrings.stub("RaffleEndFailure"));
}
}
}
@@ -1,32 +0,0 @@
package commands.general;
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 CommandRaffleJoin extends Command
{
public CommandRaffleJoin(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String getHelpText() { return LocStrings.stub("RaffleJoinInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
if(guild.joinRaffle(user))
{
res.send(LocStrings.stub("RaffleJoinSuccess"));
}
else
{
res.send(LocStrings.stub("RaffleJoinFailure"));
}
}
}
@@ -1,32 +0,0 @@
package commands.general;
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 CommandRaffleSpin extends Command
{
public CommandRaffleSpin(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String getHelpText() { return LocStrings.stub("RaffleSpinInfo"); }
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
try
{
res.send(String.format(LocStrings.stub("RaffleSpinSuccess"), guild.chooseRaffleWinner().name));
}
catch(Exception e)
{
res.send(LocStrings.stub("RaffleSpinFailure"));
}
}
}
@@ -1,43 +0,0 @@
package commands.general;
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 CommandRaffleStart extends Command
{
public CommandRaffleStart(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String getHelpText() { return LocStrings.stub("RaffleStartInfo"); }
public int beanCost;
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
try
{
beanCost = Integer.parseInt(input.args);
}
catch(Exception e)
{
beanCost = 100;
}
if(guild.startRaffle(beanCost))
{
res.send(String.format(LocStrings.stub("RaffleStartSuccess"), beanCost));
}
else
{
res.send(LocStrings.stub("RaffleStartFailure"));
}
}
}
@@ -19,6 +19,7 @@ public class CommandGuildRoleMain extends Command
super(level, rating); super(level, rating);
framework.addCommand("add", new SubCommandAdd (KittyRole.General, KittyRating.Safe)); framework.addCommand("add", new SubCommandAdd (KittyRole.General, KittyRating.Safe));
framework.addCommand("remove", new SubCommandRemove(KittyRole.General, KittyRating.Safe)); framework.addCommand("remove", new SubCommandRemove(KittyRole.General, KittyRating.Safe));
framework.addCommand("list", new SubCommandList(KittyRole.General, KittyRating.Safe));
framework.addCommand("allowed", new SubCommandAllowed(KittyRole.Admin, KittyRating.Safe)); framework.addCommand("allowed", new SubCommandAllowed(KittyRole.Admin, KittyRating.Safe));
framework.addCommand("unallowed", new SubCommandNotAllowed(KittyRole.Admin, KittyRating.Safe)); framework.addCommand("unallowed", new SubCommandNotAllowed(KittyRole.Admin, KittyRating.Safe));
} }
+34
View File
@@ -0,0 +1,34 @@
package commands.poll;
import core.Command;
import core.SubCommandFramework;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
public class CommandPollMain extends Command
{
SubCommandFramework framework = new SubCommandFramework();
public CommandPollMain(KittyRole level, KittyRating rating)
{
super(level, rating);
framework.addCommand("start", new SubCommandStart(KittyRole.Mod, KittyRating.Safe));
framework.addCommand("addoption", new SubCommandAddOption(KittyRole.Mod, KittyRating.Safe));
framework.addCommand("end", new SubCommandEnd(KittyRole.Mod, KittyRating.Safe));
framework.addCommand("show", new SubCommandShow(KittyRole.General, KittyRating.Safe));
framework.addCommand("results", new SubCommandResults(KittyRole.General, KittyRating.Safe));
framework.addCommand("vote", new SubCommandVote(KittyRole.General, KittyRating.Safe));
}
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
framework.run(guild, channel, user, input.args).Call(res);
}
}
@@ -0,0 +1,22 @@
package commands.poll;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
public class SubCommandAddOption extends SubCommand
{
public SubCommandAddOption(KittyRole roleLevel, KittyRating contentRating) {super(roleLevel, contentRating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
return new SubCommandFormattable (guild.addChoiceToPoll(input));
}
}
+22
View File
@@ -0,0 +1,22 @@
package commands.poll;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
public class SubCommandEnd extends SubCommand
{
public SubCommandEnd(KittyRole roleLevel, KittyRating contentRating) {super(roleLevel, contentRating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
return new SubCommandFormattable (guild.endPoll());
}
}
@@ -1,19 +1,16 @@
package commands.general; package commands.poll;
import java.util.ArrayList; import java.util.ArrayList;
import core.*; import core.*;
import dataStructures.*; import dataStructures.*;
public class CommandPollResults extends Command public class SubCommandResults extends SubCommand
{ {
public CommandPollResults(KittyRole level, KittyRating rating) { super(level, rating); } public SubCommandResults(KittyRole level, KittyRating rating) { super(level, rating); }
@Override @Override
public String getHelpText() { return LocStrings.stub("PollResultsInfo"); } public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
String results = ""; String results = "";
int totalVotes = 0; int totalVotes = 0;
@@ -28,9 +25,9 @@ public class CommandPollResults extends Command
for(int i = 0; i < votes.size(); i++) for(int i = 0; i < votes.size(); i++)
{ {
results += String.format(LocStrings.stub("PollResultsResponse"), votes.get(i).votes, votes.get(i).choice, (int)(((double)votes.get(i).votes) / ((double)totalVotes) * 100)); results += String.format(LocStrings.stub("PollResultsResponse"), votes.get(i).votes, votes.get(i).choice, (int)(((double)votes.get(i).votes) / ((double)totalVotes) * 100)) + "\n";
} }
res.send(results); return new SubCommandFormattable (results);
} }
} }
+33
View File
@@ -0,0 +1,33 @@
package commands.poll;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
public class SubCommandShow extends SubCommand
{
public SubCommandShow(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
if(!guild.polling)
{
return new SubCommandFormattable (LocStrings.stub("PollShowNoPoll"));
}
String poll = String.format(LocStrings.stub("PollShowPoll"), guild.poll);
poll += LocStrings.stub("PollShowChoices");
for(int i = 0; i < guild.choices.size(); i++)
{
poll += (i+1) + ": `" + guild.choices.get(i).choice + "`\n";
}
return new SubCommandFormattable (poll);
}
}
+22
View File
@@ -0,0 +1,22 @@
package commands.poll;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
public class SubCommandStart extends SubCommand
{
public SubCommandStart(KittyRole roleLevel, KittyRating contentRating) {super(roleLevel, contentRating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
return new SubCommandFormattable (guild.startPoll(input));
}
}
+47
View File
@@ -0,0 +1,47 @@
package commands.poll;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyPoll;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
public class SubCommandVote extends SubCommand
{
public SubCommandVote(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
if(guild.polling)
{
if(guild.hasVoted.contains(user.uniqueID))
{
return new SubCommandFormattable (LocStrings.stub("PollVoteAlreadyVoted"));
}
try
{
int voteNum = Integer.parseInt(input.substring(input.indexOf(" ")).trim())-1;
if(voteNum >= guild.choices.size() || voteNum < 0)
{
return new SubCommandFormattable (String.format(LocStrings.stub("PollVoteNotValidVote"), voteNum));
}
KittyPoll polled = guild.choices.get(voteNum);
polled.votes++;
guild.hasVoted.add(user.uniqueID);
return new SubCommandFormattable (LocStrings.stub("PollVoteSuccess") + " `" + polled.choice + "`!");
}
catch (NumberFormatException e)
{
return new SubCommandFormattable (LocStrings.stub("PollVoteNotValidNumber"));
}
}
return new SubCommandFormattable (LocStrings.stub("PollVoteNoPoll"));
}
}
@@ -0,0 +1,24 @@
package commands.raffle;
import core.Command;
import core.SubCommandFramework;
import dataStructures.*;
public class CommandRaffleMain extends Command
{
SubCommandFramework framework = new SubCommandFramework();
public CommandRaffleMain(KittyRole level, KittyRating rating)
{
super(level, rating);
framework.addCommand("start", new SubCommandStart(KittyRole.Mod, KittyRating.Safe));
framework.addCommand("spin", new SubCommandSpin(KittyRole.Mod, KittyRating.Safe));
framework.addCommand("end", new SubCommandEnd(KittyRole.Mod, KittyRating.Safe));
framework.addCommand("join", new SubCommandJoin(KittyRole.General, KittyRating.Safe));
}
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
framework.run(guild, channel, user, input.args).Call(res);
}
}
+28
View File
@@ -0,0 +1,28 @@
package commands.raffle;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
public class SubCommandEnd extends SubCommand
{
public SubCommandEnd(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
if(guild.endRaffle())
{
return new SubCommandFormattable (LocStrings.stub("RaffleEndSuccess"));
}
else
{
return new SubCommandFormattable (LocStrings.stub("RaffleEndFailure"));
}
}
}
+24
View File
@@ -0,0 +1,24 @@
package commands.raffle;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.*;
public class SubCommandJoin extends SubCommand
{
public SubCommandJoin(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
if(guild.joinRaffle(user))
{
return new SubCommandFormattable (LocStrings.stub("RaffleJoinSuccess"));
}
else
{
return new SubCommandFormattable (LocStrings.stub("RaffleJoinFailure"));
}
}
}
+28
View File
@@ -0,0 +1,28 @@
package commands.raffle;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
public class SubCommandSpin extends SubCommand
{
public SubCommandSpin(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
try
{
return new SubCommandFormattable (String.format(LocStrings.stub("RaffleSpinSuccess"), guild.chooseRaffleWinner().name));
}
catch(Exception e)
{
return new SubCommandFormattable (LocStrings.stub("RaffleSpinFailure"));
}
}
}
+35
View File
@@ -0,0 +1,35 @@
package commands.raffle;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.*;
public class SubCommandStart extends SubCommand
{
public SubCommandStart(KittyRole level, KittyRating rating) { super(level, rating); }
public int beanCost;
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{
try
{
beanCost = Integer.parseInt(input);
}
catch(Exception e)
{
beanCost = 100;
}
if(guild.startRaffle(beanCost))
{
return new SubCommandFormattable (String.format(LocStrings.stub("RaffleStartSuccess"), beanCost));
}
else
{
return new SubCommandFormattable (LocStrings.stub("RaffleStartFailure"));
}
}
}
+50 -18
View File
@@ -1,14 +1,54 @@
package core; package core;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import commands.characters.CommandCharacterEditBio; import commands.characters.CommandCharacterMain;
import commands.characters.CommandCharacterEditName; import commands.general.CommandBeansShow;
import commands.characters.CommandCharacterEditURL; import commands.general.CommandBenchmark;
import commands.characters.CommandCharacterSearch; import commands.general.CommandBetBeans;
import commands.general.*; import commands.general.CommandBetHistory;
import commands.general.CommandBlurry;
import commands.general.CommandBoop;
import commands.general.CommandCatch;
import commands.general.CommandChangeIndicator;
import commands.general.CommandChoose;
import commands.general.CommandColiru;
import commands.general.CommandColor;
import commands.general.CommandCrouton;
import commands.general.CommandDBFlush;
import commands.general.CommandDBStats;
import commands.general.CommandDoWork;
import commands.general.CommandEightBall;
import commands.general.CommandFetch;
import commands.general.CommandGiveBeans;
import commands.general.CommandHelp;
import commands.general.CommandHelpBuilder;
import commands.general.CommandInfo;
import commands.general.CommandInvite;
import commands.general.CommandJDoodle;
import commands.general.CommandLeaderboard;
import commands.general.CommandMap;
import commands.general.CommandPerish;
import commands.general.CommandPing;
import commands.general.CommandRPEnd;
import commands.general.CommandRPG;
import commands.general.CommandRPStart;
import commands.general.CommandRating;
import commands.general.CommandRemind;
import commands.general.CommandRole;
import commands.general.CommandRoll;
import commands.general.CommandShutdown;
import commands.general.CommandStark;
import commands.general.CommandStats;
import commands.general.CommandTeey;
import commands.general.CommandTweet;
import commands.general.CommandWolfram;
import commands.general.CommandYeet;
import commands.guildrole.CommandGuildRoleMain; import commands.guildrole.CommandGuildRoleMain;
import commands.poll.CommandPollMain;
import commands.raffle.CommandRaffleMain;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
@@ -73,12 +113,8 @@ public class CommandManager
this.register(LocCommands.stub("indicator"), new CommandChangeIndicator(KittyRole.Admin, KittyRating.Safe)); this.register(LocCommands.stub("indicator"), new CommandChangeIndicator(KittyRole.Admin, KittyRating.Safe));
// Mod // Mod
this.register(LocCommands.stub("poll"), new CommandPollManage(KittyRole.Mod, KittyRating.Safe));
this.register(LocCommands.stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe)); this.register(LocCommands.stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe));
this.register(LocCommands.stub("rpg"), new CommandRPG(KittyRole.Mod, KittyRating.Safe)); this.register(LocCommands.stub("rpg"), new CommandRPG(KittyRole.Mod, KittyRating.Safe));
this.register(LocCommands.stub("rafflestart"), new CommandRaffleStart(KittyRole.Mod, KittyRating.Safe));
this.register(LocCommands.stub("rafflespin"), new CommandRaffleSpin(KittyRole.Mod, KittyRating.Safe));
this.register(LocCommands.stub("raffleend"), new CommandRaffleEnd(KittyRole.Mod, KittyRating.Safe));
// General // General
this.register(LocCommands.stub("fetch"), new CommandFetch(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("fetch"), new CommandFetch(KittyRole.General, KittyRating.Safe));
@@ -91,9 +127,6 @@ public class CommandManager
this.register(LocCommands.stub("choose"), new CommandChoose(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("choose"), new CommandChoose(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("help"), new CommandHelp(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("help"), new CommandHelp(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("info, about"), new CommandInfo(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("info, about"), new CommandInfo(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("vote"), new CommandPollVote(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("results"), new CommandPollResults(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("showpoll"), new CommandPollShow(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("wolfram"), new CommandWolfram(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("wolfram"), new CommandWolfram(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("c++, g++, cplus, cpp"), new CommandColiru(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("c++, g++, cplus, cpp"), new CommandColiru(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("java, jdoodle"), new CommandJDoodle(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("java, jdoodle"), new CommandJDoodle(KittyRole.General, KittyRating.Safe));
@@ -110,15 +143,14 @@ public class CommandManager
this.register(LocCommands.stub("bethistory"), new CommandBetHistory(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("bethistory"), new CommandBetHistory(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("crouton"), new CommandCrouton(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("crouton"), new CommandCrouton(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("benchmark, bench"), new CommandBenchmark(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("benchmark, bench"), new CommandBenchmark(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("rafflejoin"), new CommandRaffleJoin(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("searchcharacter"), new CommandCharacterSearch(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("charactereditbio"), new CommandCharacterEditBio(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("charactereditname"), new CommandCharacterEditName(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("charactereditURL"), new CommandCharacterEditURL(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("leaderboard"), new CommandLeaderboard(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("leaderboard"), new CommandLeaderboard(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("color, colour"), new CommandColor(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("color, colour"), new CommandColor(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("remind"), new CommandRemind(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("remind"), new CommandRemind(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("role"), new CommandGuildRoleMain(KittyRole.General, KittyRating.Safe)); this.register(LocCommands.stub("role"), new CommandGuildRoleMain(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("character"), new CommandCharacterMain(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("raffle"), new CommandRaffleMain(KittyRole.General, KittyRating.Safe));
this.register(LocCommands.stub("poll"), new CommandPollMain(KittyRole.General, KittyRating.Safe));
} }
// Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands) // Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands)
+5 -3
View File
@@ -14,8 +14,10 @@ import java.util.Vector;
import com.opencsv.CSVReader; import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder; import com.opencsv.CSVReaderBuilder;
import com.opencsv.CSVWriter; import com.opencsv.CSVWriter;
import com.opencsv.RFC4180ParserBuilder;
import utils.GlobalLog; import utils.GlobalLog;
import utils.StringUtils;
public class ConfigCSV public class ConfigCSV
{ {
@@ -41,7 +43,7 @@ public class ConfigCSV
return new CSVWriter(writer, return new CSVWriter(writer,
CSVWriter.DEFAULT_SEPARATOR, CSVWriter.DEFAULT_SEPARATOR,
CSVWriter.DEFAULT_QUOTE_CHARACTER, CSVWriter.DEFAULT_QUOTE_CHARACTER,
'\\', CSVWriter.DEFAULT_ESCAPE_CHARACTER,
CSVWriter.DEFAULT_LINE_END); CSVWriter.DEFAULT_LINE_END);
} }
@@ -60,7 +62,7 @@ public class ConfigCSV
} }
Reader reader = Files.newBufferedReader(Paths.get(filepath)); Reader reader = Files.newBufferedReader(Paths.get(filepath));
CSVReader csvReader = new CSVReaderBuilder(reader).withSkipLines(1).build(); CSVReader csvReader = new CSVReaderBuilder(reader).withSkipLines(1).withCSVParser(new RFC4180ParserBuilder().build()).build();
fileContents.clear(); fileContents.clear();
// Read contents. As for the line number, we not only start counting at 1, we also skip the header. // Read contents. As for the line number, we not only start counting at 1, we also skip the header.
@@ -74,7 +76,7 @@ public class ConfigCSV
continue; continue;
} }
ConfigItem parsedLine = new ConfigItem(record[0], record[1], record[2]); ConfigItem parsedLine = new ConfigItem(StringUtils.unEscape(record[0]), StringUtils.unEscape(record[1]), StringUtils.unEscape(record[2]));
fileContents.add(parsedLine); fileContents.add(parsedLine);
++line; ++line;
} }
+3 -1
View File
@@ -1,5 +1,7 @@
package core; package core;
import utils.StringUtils;
// Everything in here must be a string type. This class does not // Everything in here must be a string type. This class does not
// perform any parsing past naming columns, and just holds the raw data. // perform any parsing past naming columns, and just holds the raw data.
public class ConfigItem public class ConfigItem
@@ -30,7 +32,7 @@ public class ConfigItem
public String[] getAll() public String[] getAll()
{ {
return new String[] {type, key, value}; return new String[] {StringUtils.reEscape(type), StringUtils.reEscape(key), StringUtils.reEscape(value) };
} }
public String toString() public String toString()
-3
View File
@@ -7,9 +7,6 @@ import java.util.concurrent.Semaphore;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import commands.characters.*;
import commands.general.*;
import commands.guildrole.CommandGuildRoleMain;
import core.lua.PluginManager; import core.lua.PluginManager;
import dataStructures.*; import dataStructures.*;
import main.Main; import main.Main;
+3 -3
View File
@@ -42,12 +42,12 @@ public abstract class SubCommand
// Called by the Command manager - this will run the command // Called by the Command manager - this will run the command
// if the issuing user has the permission to do so! // if the issuing user has the permission to do so!
protected final void Invoke(KittyGuild guild, KittyChannel channel, KittyUser user, String input) protected final SubCommandFormattable Invoke(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{ {
if(!CanCall(guild, channel, user)) if(!CanCall(guild, channel, user))
return; return null;
OnRun(guild, channel, user, input); return OnRun(guild, channel, user, input);
} }
public KittyRating Rating() public KittyRating Rating()
+10 -2
View File
@@ -27,8 +27,16 @@ public class SubCommandFramework
public SubCommandFormattable run(KittyGuild guild, KittyChannel channel, KittyUser user, String input) public SubCommandFormattable run(KittyGuild guild, KittyChannel channel, KittyUser user, String input)
{ {
System.out.print(input); SubCommandFormattable res = null;
SubCommandFormattable res = commands.get(input.split(" ")[0].toLowerCase()).OnRun(guild, channel, user, input.substring(input.indexOf(" "))); try
{
res = commands.get(input.split(" ")[0].toLowerCase()).Invoke(guild, channel, user, input.substring(input.indexOf(" ")));
}
catch(Exception e)
{
res = commands.get(input.split(" ")[0].toLowerCase()).Invoke(guild, channel, user, "");
}
return res; return res;
} }
} }
+5 -3
View File
@@ -26,12 +26,14 @@ public class Plugin
public Plugin(Path filepath) public Plugin(Path filepath)
{ {
this.filepath = filepath; this.filepath = filepath;
reRead();
}
public void reRead()
StringBuilder contentBuilder = new StringBuilder(); {
try try
{ {
StringBuilder contentBuilder = new StringBuilder();
Stream<String> stream = Files.lines(filepath, StandardCharsets.UTF_8); Stream<String> stream = Files.lines(filepath, StandardCharsets.UTF_8);
stream.forEach(str -> contentBuilder.append(str).append("\n")); stream.forEach(str -> contentBuilder.append(str).append("\n"));
stream.close(); stream.close();
+46 -9
View File
@@ -1,33 +1,31 @@
package core.lua; package core.lua;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import utils.GlobalLog;
import utils.LogFilter;
import utils.io.DirectoryMonitor;
// Reads in, handles, and manipulates plugins. Plugins are loaded in the order they appear in the folder. // Reads in, handles, and manipulates plugins. Plugins are loaded in the order they appear in the folder.
public class PluginManager public class PluginManager
{ {
// Variables // Variables
public final String pluginFolder;
public ArrayList<Plugin> plugins; public ArrayList<Plugin> plugins;
public DirectoryMonitor directoryMonitor;
// Constructor // Constructor
public PluginManager(String folder) public PluginManager(String folder)
{ {
this.pluginFolder = folder; this.directoryMonitor = new DirectoryMonitor(folder);
plugins = new ArrayList<Plugin>(); plugins = new ArrayList<Plugin>();
try try
{ {
try (Stream<Path> paths = Files.walk(Paths.get(this.pluginFolder))) directoryMonitor.getCurrentFiles().forEach((file) -> addPlugin(file.path));
{
paths.filter(Files::isRegularFile).forEach((path)->{ addPlugin(path); });
}
} }
catch(Exception e) catch(Exception e)
{ {
@@ -35,6 +33,43 @@ public class PluginManager
} }
} }
public void update()
{
directoryMonitor.update(
(addedFile) ->
{
addPlugin(addedFile.path);
GlobalLog.log(LogFilter.Plugin, "Found new plugin at " + addedFile.path);
},
(updatedFile) ->
{
for(Plugin plugin : plugins)
{
if(plugin.filepath.toString().equalsIgnoreCase(updatedFile.path.toString()))
{
plugin.reRead();
break;
}
}
GlobalLog.log(LogFilter.Plugin, "A plugin was updated " + updatedFile.path);
},
(deletedFile) ->
{
for(int i = plugins.size() - 1; i >= 0; i--)
{
Plugin plugin = plugins.get(i);
if(plugin.filepath.toString().equalsIgnoreCase(deletedFile.path.toString()))
plugins.remove(i);
}
GlobalLog.log(LogFilter.Plugin, "Plugin deleted at " + deletedFile.path);
});
}
// Registers a plugin based on the path
public void addPlugin(Path path) public void addPlugin(Path path)
{ {
plugins.add(new Plugin(path)); plugins.add(new Plugin(path));
@@ -66,6 +101,8 @@ public class PluginManager
public void printAll() public void printAll()
{ {
for(int i = 0; i < plugins.size(); ++i) for(int i = 0; i < plugins.size(); ++i)
{
PluginLog.log(plugins.get(i).contents.toString()); PluginLog.log(plugins.get(i).contents.toString());
}
} }
} }
+4 -2
View File
@@ -86,7 +86,8 @@ 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
Superintendent.perCommandUpkeepPre(); if(!Superintendent.perCommandUpkeepPre(pluginManager))
return;
// 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.
@@ -111,6 +112,7 @@ public class Main extends ListenerAdapter
} }
// Run any upkeep in post we need to // Run any upkeep in post we need to
Superintendent.perCommandUpkeepPost(kittyCore, databaseManager); if(!Superintendent.perCommandUpkeepPost(kittyCore, databaseManager))
return;
} }
} }
+4 -1
View File
@@ -6,6 +6,7 @@ import core.Config;
import core.DatabaseManager; import core.DatabaseManager;
import core.RPManager; import core.RPManager;
import core.Stats; import core.Stats;
import core.lua.PluginManager;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyCore; import dataStructures.KittyCore;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
@@ -71,11 +72,13 @@ public class Superintendent
// Only called once per command. Good for lazily updating. // Only called once per command. Good for lazily updating.
// Happens just before the command / plugin runs. // Happens just before the command / plugin runs.
public static boolean perCommandUpkeepPre() public static boolean perCommandUpkeepPre(PluginManager pluginManager)
{ {
// Upkeep the config file monitoring // Upkeep the config file monitoring
Config.instance.upkeep(); Config.instance.upkeep();
pluginManager.update();
// Return if we succeeded or not. At this time, we always succeed.
return true; return true;
} }
+5 -16
View File
@@ -1,29 +1,18 @@
package utils; package utils;
import org.apache.commons.lang3.StringEscapeUtils;
@SuppressWarnings("deprecation")
public class StringUtils public class StringUtils
{ {
public static String unEscape(String str) public static String unEscape(String str)
{ {
str = str.replaceAll("\\\\b", "\b"); return StringEscapeUtils.unescapeJava(str);
str = str.replaceAll("\\\\n", "\n");
str = str.replaceAll("\\\\t", "\t");
str = str.replaceAll("\\\\r", "\r");
str = str.replaceAll("\\\\f", "\f");
str = str.replaceAll("\\\\\"", "\"");
str = str.replaceAll("\\\\\\\\\\\\", "\\\\");
return str;
} }
public static String reEscape(String str) public static String reEscape(String str)
{ {
str = str.replaceAll("\\\b", "\\\\\\b"); return StringEscapeUtils.escapeJava(str);
str = str.replaceAll("\\\n", "\\\\\\n");
str = str.replaceAll("\\\t", "\\\\\\t");
str = str.replaceAll("\\\r", "\\\\\\r");
str = str.replaceAll("\\\f", "\\\\\\f");
return str;
} }
// Finds first whitespace in the string // Finds first whitespace in the string