= Revised SectionedKeyValuePair parsing and writing behavior, along with localization stub

This commit is contained in:
Matthew Cech
2019-04-12 21:27:30 -07:00
parent 20e4376891
commit 84009a294d
3 changed files with 157 additions and 144 deletions
+101 -101
View File
@@ -1,170 +1,170 @@
[CommandPollManage] [CommandPollManage]
'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='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 '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=
[CommandBeansShow] [CommandBeansShow]
You have %s beans!=You have %s beans! You have %s beans!=This phrase has been localized. Also, you have %s.
Displays how many beans you have=Displays how many beans you have Displays how many beans you have=
[CommandHelp] [CommandHelp]
You can get help with a specific command by typing `!help command`!\nYou can also look at <https://www.rinsnowmew.com/bot/info/#commands>\nGeneral Commands: `boop, roll, choose, help, info, vote, results, showpoll, wolfram, cplus, java, beans, role, bet, yeet`=You can get help with a specific command by typing `!help command`!\nYou can also look at <https://www.rinsnowmew.com/bot/info/#commands>\nGeneral Commands: `boop, roll, choose, help, info, vote, results, showpoll, wolfram, cplus, java, beans, role, bet, yeet` You can get help with a specific command by typing `!help command`!\nYou can also look at <https://www.rinsnowmew.com/bot/info/#commands>\nGeneral Commands: `boop, roll, choose, help, info, vote, results, showpoll, wolfram, cplus, java, beans, role, bet, yeet`=
Lets you look up specific commands, or get a link to a list of all commands.=Lets you look up specific commands, or get a link to a list of all commands. Lets you look up specific commands, or get a link to a list of all commands.=
[CommandRoll] [CommandRoll]
Didn't work ;3;=Didn't work ;3; Didn't work ;3;=
Based on input of xdy where x is number of dice and y is faces kitty will roll that amount of dice, display the individual rolls and total=Based on input of xdy where x is number of dice and y is faces kitty will roll that amount of dice, display the individual rolls and total Based on input of xdy where x is number of dice and y is faces kitty will roll that amount of dice, display the individual rolls and total=
[CommandStats] [CommandStats]
Displays the actively running KittyBot application information=Displays the actively running KittyBot application information Displays the actively running KittyBot application information=
[CommandTweet] [CommandTweet]
With an input of x,y,z where x y and z are all choices, kitty will choose one=With an input of x,y,z where x y and z are all choices, kitty will choose one With an input of x,y,z where x y and z are all choices, kitty will choose one=
FUCKED UP HARD=FUCKED UP HARD FUCKED UP HARD=
[CommandRole] [CommandRole]
Please enter `general`, `mod`, or `admin`!=Please enter `general`, `mod`, or `admin`! Please enter `general`, `mod`, or `admin`!=
You aren't allowed to do that! You must have the KittyRole '%' or higher!=You aren't allowed to do that! You must have the KittyRole '%' or higher! You aren't allowed to do that! You must have the KittyRole '%' or higher!=
Will show the current role you have, Admins can change others roles with input of 'role x @y' with x being blacklist, general, mod, or admin. Blacklist will not allow the user to interact with kitty anymore, general mod and admin will give the user access to those commands.=Will show the current role you have, Admins can change others roles with input of 'role x @y' with x being blacklist, general, mod, or admin. Blacklist will not allow the user to interact with kitty anymore, general mod and admin will give the user access to those commands. Will show the current role you have, Admins can change others roles with input of 'role x @y' with x being blacklist, general, mod, or admin. Blacklist will not allow the user to interact with kitty anymore, general mod and admin will give the user access to those commands.=
Your role is=Your role is Your role is=
Changed %s to role `%s`!=Changed %s to role `%s`! Changed %s to role `%s`!=
[CommandColiru] [CommandColiru]
Will try to compile any c++ code you put in! Supports up to C++14 standard, uses g++.=Will try to compile any c++ code you put in! Supports up to C++14 standard, uses g++. Will try to compile any c++ code you put in! Supports up to C++14 standard, uses g++.=
[CommandJDoodle] [CommandJDoodle]
Will compile any java code you put in! Supports Java 1.8=Will compile any java code you put in! Supports Java 1.8 Will compile any java code you put in! Supports Java 1.8=
[CommandChangeIndicator] [CommandChangeIndicator]
Changes the command indicator to any single character. By default, it's '!'. If more than one character is provided, the first one is used!=Changes the command indicator to any single character. By default, it's '!'. If more than one character is provided, the first one is used! Changes the command indicator to any single character. By default, it's '!'. If more than one character is provided, the first one is used!=
Indicator changed to `%s`=Indicator changed to `%s` Indicator changed to `%s`=
[CommandPerish] [CommandPerish]
Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned=Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned=
[CommandStark] [CommandStark]
Snaps your icon or the icon of a friend you mentioned=Snaps your icon or the icon of a friend you mentioned Snaps your icon or the icon of a friend you mentioned=
[CommandYeet] [CommandYeet]
Yeet yourself or yeet a friend with @!=Yeet yourself or yeet a friend with @! Yeet yourself or yeet a friend with @!=
[CommandPollVote] [CommandPollVote]
There is no poll running!=There is no poll running! There is no poll running!=
You already voted=You already voted You already voted=
%s That's not a vaild vote!=%s That's not a vaild vote! %s That's not a vaild vote!=
That's not a vaild number!=That's not a vaild number! That's not a vaild number!=
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!=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! 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!=
You successfully voted for=You successfully voted for You successfully voted for=
[CommandShutdown] [CommandShutdown]
Stops kitty. `-s` or `safe` as an argument attempts to sync off the database before shutdown.=Stops kitty. `-s` or `safe` as an argument attempts to sync off the database before shutdown. Stops kitty. `-s` or `safe` as an argument attempts to sync off the database before shutdown.=
Forced shutdown, database synced before abandoning threads.=Forced shutdown, database synced before abandoning threads. Forced shutdown, database synced before abandoning threads.=
Forced immediate shutdown, threads abandoned without sync.=Forced immediate shutdown, threads abandoned without sync. Forced immediate shutdown, threads abandoned without sync.=
[CommandBetBeans] [CommandBetBeans]
That's not a valid bet!=That's not a valid bet! That's not a valid bet!=
Please bet with at least 50 beans!=Please bet with at least 50 beans! Please bet with at least 50 beans!=
Allows you to bet your beans, set your amount after the command! Warning! House always wins!\nSets of 3 will get 5x, 4 will get 10x, and 5 will get 1000x=Allows you to bet your beans, set your amount after the command! Warning! House always wins!\nSets of 3 will get 5x, 4 will get 10x, and 5 will get 1000x Allows you to bet your beans, set your amount after the command! Warning! House always wins!\nSets of 3 will get 5x, 4 will get 10x, and 5 will get 1000x=
Sorry, you didn't win, try again!=Sorry, you didn't win, try again! Sorry, you didn't win, try again!=
You don't have enough beans!=You don't have enough beans! You don't have enough beans!=
You won %s beans!=You won %s beans! You won %s beans!=
[CommandDoWork] [CommandDoWork]
I finished with my work! :D=I finished with my work! :D I finished with my work! :D=
Occupies a core for a few seconds=Occupies a core for a few seconds Occupies a core for a few seconds=
[CommandRPStart] [CommandRPStart]
Starts an rp, add people to it by mentioning them!=Starts an rp, add people to it by mentioning them! Starts an rp, add people to it by mentioning them!=
[CommandBlurry] [CommandBlurry]
Blurs your icon or the icon of a friend you mentioned=Blurs your icon or the icon of a friend you mentioned Blurs your icon or the icon of a friend you mentioned=
[CommandPollResults] [CommandPollResults]
Will show current results of a poll and percentages of votes per choice=Will show current results of a poll and percentages of votes per choice Will show current results of a poll and percentages of votes per choice=
%s people voted for %s `%s` with `%s%` !\n =%s people voted for %s `%s` with `%s%` !\n %s people voted for %s `%s` with `%s%` !\n =
[CommandRating] [CommandRating]
Kittybot content set to=Kittybot content set to Kittybot content set to=
Warning: NSFW may slip through, images are only based on tags on their respective sites!=Warning: NSFW may slip through, images are only based on tags on their respective sites! Warning: NSFW may slip through, images are only based on tags on their respective sites!=
Invalid content rating=Invalid content rating Invalid content rating=
[CommandGiveBeans] [CommandGiveBeans]
That's not a valid number!=That's not a valid number! That's not a valid number!=
Gave %s %s beans!=Gave %s %s beans! Gave %s %s beans!=
Gives beans to the mentioned users!=Gives beans to the mentioned users! Gives beans to the mentioned users!=
You didn't mention anyone!=You didn't mention anyone! You didn't mention anyone!=
[CommandPollShow] [CommandPollShow]
There is no poll running!=There is no poll running! There is no poll running!=
And the choices are:\n=And the choices are:\n And the choices are:\n=
Will show the current poll running=Will show the current poll running Will show the current poll running=
The current poll is `%s`\n=The current poll is `%s`\n The current poll is `%s`\n=
[CommandHelpBuilder] [CommandHelpBuilder]
Emit help for all commands as formatted HTML=Emit help for all commands as formatted HTML Emit help for all commands as formatted HTML=
commands=commands commands=
[CommandRPEnd] [CommandRPEnd]
Here's your file!=Here's your file! Here's your file!=
You can't end this RP!=You can't end this RP! You can't end this RP!=
Ends RP in channel=Ends RP in channel Ends RP in channel=
[CommandRPG] [CommandRPG]
Invalid RPG Command!=Invalid RPG Command! Invalid RPG Command!=
Admin+ command only right now - experimental text RPG! Format is !rpg <rpg command>=Admin+ command only right now - experimental text RPG! Format is !rpg <rpg command> Admin+ command only right now - experimental text RPG! Format is !rpg <rpg command>=
[CommandBoop] [CommandBoop]
%s booped %s!=%s booped %s! %s booped %s!=
Kitty will react with a counter=Kitty will react with a counter Kitty will react with a counter=
Woah! %s booped me! That's %s total!=Woah! %s booped me! That's %s total! Woah! %s booped me! That's %s total!=
%s booped several others - %s!=%s booped several others - %s! %s booped several others - %s!=
[CommandInfo] [CommandInfo]
Provides author info and a link to Kitty's website=Provides author info and a link to Kitty's website Provides author info and a link to Kitty's website=
I'm made by `Rin#8904` and `Reverie Wisp#3703`!\nYou can find more info about me along with a Patreon link to support us and GitHub link for filing bugs https://www.rinsnowmew.com/bot/=I'm made by `Rin#8904` and `Reverie Wisp#3703`!\nYou can find more info about me along with a Patreon link to support us and GitHub link for filing bugs https://www.rinsnowmew.com/bot/ I'm made by `Rin#8904` and `Reverie Wisp#3703`!\nYou can find more info about me along with a Patreon link to support us and GitHub link for filing bugs https://www.rinsnowmew.com/bot/=
[CommandPing] [CommandPing]
Pong!=Pong! Pong!=
Will respond with Pong!=Will respond with Pong! Will respond with Pong!=
[CommandChoose] [CommandChoose]
With an input of x,y,z where x y and z are all choices, kitty will choose one=With an input of x,y,z where x y and z are all choices, kitty will choose one With an input of x,y,z where x y and z are all choices, kitty will choose one=
I chooooooose %s!=I chooooooose %s! I chooooooose %s!=
[CommandEightBall] [CommandEightBall]
It is certain.=It is certain. It is certain.=
Ask again later.=Ask again later. Ask again later.=
Cannot predict now.=Cannot predict now. Cannot predict now.=
My sources say no.=My sources say no. My sources say no.=
You may rely on it.=You may rely on it. You may rely on it.=
Answers a yes or no question! Warning: Kitty can not actually tell the future, she claims no responsibility for any lion mauling, lack of lottery wins, or felony charges.=Answers a yes or no question! Warning: Kitty can not actually tell the future, she claims no responsibility for any lion mauling, lack of lottery wins, or felony charges. Answers a yes or no question! Warning: Kitty can not actually tell the future, she claims no responsibility for any lion mauling, lack of lottery wins, or felony charges.=
Concentrate and ask again.=Concentrate and ask again. Concentrate and ask again.=
Signs point to yes.=Signs point to yes. Signs point to yes.=
Don't count on it.=Don't count on it. Don't count on it.=
Yes.=Yes. Yes.=
My reply is no.=My reply is no. My reply is no.=
Most likely.=Most likely. Most likely.=
Reply hazy, try again.=Reply hazy, try again. Reply hazy, try again.=
Without a doubt.=Without a doubt. Without a doubt.=
Yes - definitely.=Yes - definitely. Yes - definitely.=
Very doubtful.=Very doubtful. Very doubtful.=
As I see it, yes.=As I see it, yes. As I see it, yes.=
Better not tell you now.=Better not tell you now. Better not tell you now.=
Outlook good.=Outlook good. Outlook good.=
Outlook not so good.=Outlook not so good. Outlook not so good.=
It is decidedly so.=It is decidedly so. It is decidedly so.=
[CommandInvite] [CommandInvite]
Provies a direct invite link for KittyBot=Provies a direct invite link for KittyBot Provies a direct invite link for KittyBot=
[CommandWolfram] [CommandWolfram]
Something went wrong!=Something went wrong! Something went wrong!=
Will query wolframalpha with your question and give a full image output of the answer=Will query wolframalpha with your question and give a full image output of the answer Will query wolframalpha with your question and give a full image output of the answer=
You need to provide some arguments!=You need to provide some arguments! You need to provide some arguments!=
[CommandMap] [CommandMap]
Seed=Seed Seed=
Invalid arguments provided!=Invalid arguments provided! Invalid arguments provided!=
Height=Height Height=
Using mapgen v0.1=Using mapgen v0.1 Using mapgen v0.1=
Width=Width Width=
+7 -2
View File
@@ -88,13 +88,18 @@ public class Localizer
} }
// Nothing for now, but in the future will return a parsed and localized version of // Nothing for now, but in the future will return a parsed and localized version of
// the string in question if one can be found. // the string in question if one can be found. If the localized string is empty,
// returns a the key instead which is the default phrase.
public static String Stub(String input) public static String Stub(String input)
{ {
if(stringStore == null) if(stringStore == null)
return input; return input;
return stringStore.GetKey(input); String value = stringStore.GetKey(input);
if(value.length() < 1)
return input;
return value;
} }
// Reads a file to string, adapted from https://stackoverflow.com/a/326440/5383198 // Reads a file to string, adapted from https://stackoverflow.com/a/326440/5383198
+49 -41
View File
@@ -12,11 +12,12 @@ import java.util.function.Consumer;
// //
// [ExampleSection] // [ExampleSection]
// Key=Value // Key=Value
// Valid Ridiculous Key&\n\t_.:;foo =Some Value // Valid Ridiculous Key&\n\t_.:;foo = \tValid Ridiculous Value*&%$()^.[]{}@
// Key= // EmptyValue=
// //
// Note that the sections are NOT designed to allow for duplicate keys across them. This is a restriction // Note that the sections are NOT designed to allow for duplicate keys across them.
// of the structure, but can be changed later potentially. // This is a restriction of the structure, but can be changed later potentially.
// The only value not allowed in a key or value is the KeyValueSplit.
public class SectionedKeyValueStore public class SectionedKeyValueStore
{ {
// Variables // Variables
@@ -39,31 +40,6 @@ public class SectionedKeyValueStore
Parse(input); Parse(input);
} }
// Adds a KeyValue pair to the specified section if it's not already there.
// Also creates the section if it's not already present.
public void AddKeyValue(String sectionName, String key, String value)
{
AddSection(sectionName);
sectionKeyValue.get(sectionName).putIfAbsent(key, value);
keyValue.putIfAbsent(key, value);
}
// Returns a HashMap of Keys to Values for a given section
@SuppressWarnings("unchecked")
public HashMap<String, String> GetSection(String sectionName)
{
return (HashMap<String, String>) sectionKeyValue.get(sectionName).clone();
}
// Look up a global key
public String GetKey(String key)
{
if(keyValue.containsKey(key))
return keyValue.get(key);
return null;
}
// Calls back on each item in the entire structure. Provides section, then a pair of the keyString and valueString. // Calls back on each item in the entire structure. Provides section, then a pair of the keyString and valueString.
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
public void ForEach(BiConsumer<? super String, Pair<? super String, ? super String>> action) public void ForEach(BiConsumer<? super String, Pair<? super String, ? super String>> action)
@@ -94,39 +70,40 @@ public class SectionedKeyValueStore
} }
} }
// Stores the internal hashmap as a string then reutrns it. // Parses the internal hashmap as a string then reutrns it, featuring sections.
// Places 1 newline between the sections. // Iterates over all key/value pairs in the section and print them. Does not print
// the value of a given key if it is the same as the key.
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
public String toString() public String toString()
{ {
String out = ""; String out = "";
// Iterates over the sections and
Iterator it = sectionKeyValue.entrySet().iterator(); Iterator it = sectionKeyValue.entrySet().iterator();
while (it.hasNext()) while (it.hasNext())
{ {
Map.Entry pair = (Map.Entry)it.next(); Map.Entry pair = (Map.Entry)it.next();
out += ("" + SectionStart + pair.getKey() + SectionEnd + "\n"); out += ("" + SectionStart + pair.getKey() + SectionEnd + KeyValueLineSeparator);
Iterator internal = ((HashMap<String, String>)pair.getValue()).entrySet().iterator(); Iterator internal = ((HashMap<String, String>)pair.getValue()).entrySet().iterator();
while(internal.hasNext()) while(internal.hasNext())
{ {
Map.Entry internalPair = (Map.Entry)internal.next(); Map.Entry internalPair = (Map.Entry)internal.next();
out += (internalPair.getKey() + KeyValueSplit + internalPair.getValue()) + KeyValueLineSeparator; String key = (String)internalPair.getKey();
String value = (String)internalPair.getValue();
if(key == value)
out += (key + KeyValueSplit) + KeyValueLineSeparator;
else
out += (key + KeyValueSplit + value) + KeyValueLineSeparator;
} }
out += "\n"; out += KeyValueLineSeparator;
} }
return out; return out;
} }
// Adds a given section to the hashmap if it's not already present
private void AddSection(String sectionName)
{
sectionKeyValue.putIfAbsent(sectionName, new HashMap<String, String>());
}
// Parses out the string passed in into the sectionkeyValue HashMap. // Parses out the string passed in into the sectionkeyValue HashMap.
// Any character used in a split call is escaped just in case on // Any character used in a split call is escaped just in case on
// account of some characters having specific regex meanings. // account of some characters having specific regex meanings.
@@ -179,4 +156,35 @@ public class SectionedKeyValueStore
for(int i = 0; i < toPrint.length; ++i) for(int i = 0; i < toPrint.length; ++i)
System.out.println(toPrint[i]); System.out.println(toPrint[i]);
} }
// Adds a KeyValue pair to the specified section if it's not already there.
// Also creates the section if it's not already present.
public void AddKeyValue(String sectionName, String key, String value)
{
AddSection(sectionName);
sectionKeyValue.get(sectionName).putIfAbsent(key, value);
keyValue.putIfAbsent(key, value);
}
// Adds a given section to the hashmap if it's not already present
public void AddSection(String sectionName)
{
sectionKeyValue.putIfAbsent(sectionName, new HashMap<String, String>());
}
// Returns a HashMap of Keys to Values for a given section
@SuppressWarnings("unchecked")
public HashMap<String, String> GetSection(String sectionName)
{
return (HashMap<String, String>) sectionKeyValue.get(sectionName).clone();
}
// Look up a global key
public String GetKey(String key)
{
if(keyValue.containsKey(key))
return keyValue.get(key);
return null;
}
} }