Merge branch 'develop'
This commit is contained in:
@@ -13,6 +13,5 @@
|
|||||||
<classpathentry kind="lib" path="lib/slf4j-jdk14-1.7.25.jar"/>
|
<classpathentry kind="lib" path="lib/slf4j-jdk14-1.7.25.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/twitter4j-core-4.0.7-javadoc.jar"/>
|
<classpathentry kind="lib" path="lib/twitter4j-core-4.0.7-javadoc.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/twitter4j-core-4.0.7.jar"/>
|
<classpathentry kind="lib" path="lib/twitter4j-core-4.0.7.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ini4j-0.5.4.jar"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
BSD 3-Clause License
|
BSD 3-Clause License
|
||||||
|
|
||||||
Copyright (c) 2019, AlexStewartCode
|
Copyright (c) 2019, AlexStewartCode and individual contributors.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
@@ -1,2 +1,6 @@
|
|||||||
# KittyBot
|
# KittyBot
|
||||||
Fun and useful Discord bot
|
Fun and useful Discord bot designed to be able searching websites, playing games, compiling code, and much more!
|
||||||
|
|
||||||
|
This repo is an eclipse project, and can be opened in the IDE directly. Authentication keys will need to be placed in a file called `Ref.java` at `src/offline/`. This folder isn't present in this repository by default.
|
||||||
|
|
||||||
|
If you're looking to contribute, feel free to submit a pull request! Take a look at the styleguide to get some pointers on formatting for this repo!
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
# KittyBot Style Guide
|
||||||
|
|
||||||
|
This document represents the reasonable defaults and expectations for this project, and provides some rationale for the style restrictions! There can always be exceptions to the rules, but they may need justifying.
|
||||||
|
|
||||||
|
Code Formatting
|
||||||
|
---
|
||||||
|
|
||||||
|
#### Indenting
|
||||||
|
Tabs are used so that individual developers can configure their own indent width settings that won't be enforced on others working on the project.
|
||||||
|
|
||||||
|
```java
|
||||||
|
// I'm not indented!
|
||||||
|
{
|
||||||
|
// I'm indented with one tab!
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Braces
|
||||||
|
When braces are present, Allman style is used meaning that braces start on the next line. Braces are used to prevent scope confusion. Omitting braces on single-line statements is fine if the situation is clear.
|
||||||
|
|
||||||
|
```java
|
||||||
|
if(foo)
|
||||||
|
{
|
||||||
|
System.out.println("This");
|
||||||
|
System.out.println("has");
|
||||||
|
System.out.println("braces!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bar)
|
||||||
|
System.out.println("No braces!");
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Naming
|
||||||
|
Class names and function names are `PascalCase`. Variable names are `camelCase`.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class MyClass
|
||||||
|
{
|
||||||
|
private Foo myVariable;
|
||||||
|
|
||||||
|
public function MyFuction()
|
||||||
|
{
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Favor a broad to narrow naming scheme to promote autocomplete grouping. For example, use a name like `userDescriptionHeader` instead of `headerUserDescription` because there may be other variables related to a user or description, but there's likely only one header section of a description.
|
||||||
|
|
||||||
|
|
||||||
|
#### Ternary Operator (`?:`)
|
||||||
|
Don't.
|
||||||
|
|
||||||
|
|
||||||
|
Architecture
|
||||||
|
---
|
||||||
|
|
||||||
|
#### Commands
|
||||||
|
All commands get spawned on their own threads, and should be implemented in a thread-safe way. Commands all derive from the Command.java class, and use the custom types defined in KittyBot. In order to make any later changes easier and decouple the command logic from core and routing, no JDA structures should be directly exposed in commands, and instead everything needed should be added to the kitty structures that add space to the system. Commands should override the `HelpText` and `Run` functions. Commands are registered in the ObjectBuilderFactory, and the command registration structure can be used for sub-commands as needed. See the RPG for an example.
|
||||||
|
|
||||||
|
#### Tracked Values
|
||||||
|
Does something need to be tracked in a database? Make sure the class with the data you want inherits from DatabaseTrackedObject, and override the appropriate functions. The object, when marked as dirty, will automatically be written to the database when the next database upkeep tick occurs. Refer to CommandBoop to see an example of a tracked global value, and KittyUser for tracked per-user values.
|
||||||
|
|
||||||
|
#### Tokens, Secrets, etc
|
||||||
|
Things like tokens, private keys, an secrets are kept in the offline package. This file is intentionally excluded from the repo. If it shouldn't be in the repo, put it in the offline package.
|
||||||
Binary file not shown.
+163
-14
@@ -1,21 +1,170 @@
|
|||||||
|
[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=
|
||||||
|
|
||||||
[CommandBeansShow]
|
[CommandBeansShow]
|
||||||
Displays how many beans you have =
|
You have %s beans!=
|
||||||
You have %s beans! =
|
Displays how many beans you have=
|
||||||
|
|
||||||
|
[CommandHelp]
|
||||||
|
Lets you look up specific commands, or get a link to a list of all commands.=
|
||||||
|
You can get help with a specific command by typing `!help command`!\nGeneral Commands: `boop, roll, choose, help, info, vote, results, showpoll, wolfram, cplus, java, beans, role, bet, yeet`=
|
||||||
|
|
||||||
|
[CommandRoll]
|
||||||
|
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=
|
||||||
|
|
||||||
|
[CommandStats]
|
||||||
|
Displays the actively running KittyBot application information=
|
||||||
|
|
||||||
|
[CommandTweet]
|
||||||
|
With an input of x,y,z where x y and z are all choices, kitty will choose one=
|
||||||
|
Tweet command failed!=
|
||||||
|
|
||||||
|
[CommandRole]
|
||||||
|
Please enter `general`, `mod`, or `admin`!=
|
||||||
|
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.=
|
||||||
|
Your role is=
|
||||||
|
Changed %s to role `%s`!=
|
||||||
|
|
||||||
|
[CommandColiru]
|
||||||
|
Will try to compile any c++ code you put in! Supports up to C++14 standard, uses g++.=
|
||||||
|
|
||||||
|
[CommandJDoodle]
|
||||||
|
Will compile any java code you put in! Supports Java 1.8=
|
||||||
|
|
||||||
|
[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!=
|
||||||
|
Indicator changed to `%s`=
|
||||||
|
|
||||||
|
[CommandPerish]
|
||||||
|
Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned=
|
||||||
|
|
||||||
|
[CommandStark]
|
||||||
|
Snaps your icon or the icon of a friend you mentioned=
|
||||||
|
|
||||||
|
[CommandYeet]
|
||||||
|
Yeet yourself or yeet a friend with @!=
|
||||||
|
|
||||||
|
[CommandPollVote]
|
||||||
|
There is no poll running!=
|
||||||
|
You already voted=
|
||||||
|
%s That's not a vaild vote!=
|
||||||
|
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!=
|
||||||
|
You successfully voted for=
|
||||||
|
|
||||||
|
[CommandShutdown]
|
||||||
|
Stops kitty. `-s` or `safe` as an argument attempts to sync off the database before shutdown.=
|
||||||
|
Forced shutdown, database synced before abandoning threads.=
|
||||||
|
Forced immediate shutdown, threads abandoned without sync.=
|
||||||
|
|
||||||
[CommandBetBeans]
|
[CommandBetBeans]
|
||||||
Please bet with at least 50 beans! =
|
That's not a valid bet!=
|
||||||
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 =
|
Please bet with at least 50 beans!=
|
||||||
That's not a valid bet! =
|
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!=
|
||||||
You don't have enough beans! =
|
You don't have enough beans!=
|
||||||
You won %s beans! =
|
You won %s beans!=
|
||||||
|
|
||||||
[CommandBoop]
|
[CommandDoWork]
|
||||||
%s booped %s! =
|
I finished with my work! :D=
|
||||||
Kitty will react with a counter =
|
Occupies a core for a few seconds=
|
||||||
Woah! %s booped me! That's %s total! =
|
|
||||||
%s booped several others - %s! =
|
[CommandRPStart]
|
||||||
|
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=
|
||||||
|
|
||||||
|
[CommandPollResults]
|
||||||
|
Will show current results of a poll and percentages of votes per choice=
|
||||||
|
%s people voted for %s `%s` with `%s%` !\n =
|
||||||
|
|
||||||
|
[CommandRating]
|
||||||
|
Kittybot content set to=
|
||||||
|
Warning: NSFW may slip through, images are only based on tags on their respective sites!=
|
||||||
|
Invalid content rating=
|
||||||
|
|
||||||
|
[CommandGiveBeans]
|
||||||
|
That's not a valid number!=
|
||||||
|
Gave %s %s beans!=
|
||||||
|
Gives beans to the mentioned users!=
|
||||||
|
You didn't mention anyone!=
|
||||||
|
|
||||||
|
[CommandPollShow]
|
||||||
|
There is no poll running!=
|
||||||
|
And the choices are:\n=
|
||||||
|
Will show the current poll running=
|
||||||
|
The current poll is `%s`\n=
|
||||||
|
|
||||||
|
[CommandHelpBuilder]
|
||||||
|
Emit help for all commands as formatted HTML=
|
||||||
|
commands=
|
||||||
|
|
||||||
|
[CommandRPEnd]
|
||||||
|
Here's your file!=
|
||||||
|
You can't end this RP!=
|
||||||
|
Ends RP in channel=
|
||||||
|
|
||||||
|
[CommandRPG]
|
||||||
|
Invalid RPG Command!=
|
||||||
|
Admin+ command only right now - experimental text RPG! Format is !rpg <rpg command>=
|
||||||
|
|
||||||
|
[CommandBoop]
|
||||||
|
%s booped %s!=
|
||||||
|
Kitty will react with a counter=
|
||||||
|
Woah! %s booped me! That's %s total!=
|
||||||
|
%s booped several others - %s!=
|
||||||
|
|
||||||
|
[CommandInfo]
|
||||||
|
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/=
|
||||||
|
|
||||||
|
[CommandPing]
|
||||||
|
Pong!=
|
||||||
|
Will respond with Pong!=
|
||||||
|
|
||||||
|
[CommandChoose]
|
||||||
|
With an input of x,y,z where x y and z are all choices, kitty will choose one=
|
||||||
|
I chooooooose %s!=
|
||||||
|
|
||||||
|
[CommandEightBall]
|
||||||
|
It is certain.=
|
||||||
|
Ask again later.=
|
||||||
|
Cannot predict now.=
|
||||||
|
My sources say no.=
|
||||||
|
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.=
|
||||||
|
Concentrate and ask again.=
|
||||||
|
Signs point to yes.=
|
||||||
|
Don't count on it.=
|
||||||
|
Yes.=
|
||||||
|
My reply is no.=
|
||||||
|
Most likely.=
|
||||||
|
Reply hazy, try again.=
|
||||||
|
Without a doubt.=
|
||||||
|
Yes - definitely.=
|
||||||
|
Very doubtful.=
|
||||||
|
As I see it, yes.=
|
||||||
|
Better not tell you now.=
|
||||||
|
Outlook good.=
|
||||||
|
Outlook not so good.=
|
||||||
|
It is decidedly so.=
|
||||||
|
|
||||||
|
[CommandInvite]
|
||||||
|
Provies a direct invite link for KittyBot=
|
||||||
|
|
||||||
|
[CommandWolfram]
|
||||||
|
Something went wrong!=
|
||||||
|
Will query wolframalpha with your question and give a full image output of the answer=
|
||||||
|
You need to provide some arguments!=
|
||||||
|
|
||||||
|
[CommandMap]
|
||||||
|
Seed=
|
||||||
|
Invalid arguments provided!=
|
||||||
|
Height=
|
||||||
|
Using mapgen v0.1=
|
||||||
|
Width=
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
|
|
||||||
public class CommandChangeIndicator extends Command
|
public class CommandChangeIndicator extends Command
|
||||||
@@ -8,7 +9,7 @@ public class CommandChangeIndicator extends Command
|
|||||||
public CommandChangeIndicator(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandChangeIndicator(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Changes the command indicator to any single character. By default, it's '!'. If more than one character is provided, the first one is used!"; }
|
public String HelpText() { return Localizer.Stub("Changes the command indicator to any single character. By default, it's '!'. If more than one character is provided, the first one is used!"); }
|
||||||
|
|
||||||
@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)
|
||||||
@@ -21,6 +22,6 @@ public class CommandChangeIndicator extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
guild.SetCommandIndicator(arg.substring(0, 1));
|
guild.SetCommandIndicator(arg.substring(0, 1));
|
||||||
res.Call("Indicator changed to `" + guild.GetCommandIndicator() +"`!");
|
res.Call(String.format(Localizer.Stub("Indicator changed to `%s`"), guild.GetCommandIndicator()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class CommandChoose extends Command
|
|||||||
public CommandChoose(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandChoose(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "With an input of x,y,z where x y and z are all choices, kitty will choose one"; }
|
public String HelpText() { return Localizer.Stub("With an input of x,y,z where x y and z are all choices, kitty will choose one"); }
|
||||||
|
|
||||||
@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)
|
||||||
@@ -26,6 +26,6 @@ public class CommandChoose extends Command
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Call("I chooooooose" + choices[(int) (Math.random()*choices.length)] + "!");
|
res.Call(String.format(Localizer.Stub("I chooooooose %s!"), (choices[(int) (Math.random()*choices.length)]).toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
import network.NetworkColiru;
|
import network.NetworkColiru;
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ public class CommandColiru extends Command
|
|||||||
public CommandColiru(KittyRole level, KittyRating rating) { super(level, rating);}
|
public CommandColiru(KittyRole level, KittyRating rating) { super(level, rating);}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Will try to compile any c++ code you put in! Supports up to C++14 standard, uses g++."; }
|
public String HelpText() { return Localizer.Stub("Will try to compile any c++ code you put in! Supports up to C++14 standard, uses g++."); }
|
||||||
|
|
||||||
@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)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class CommandDoWork extends Command
|
|||||||
public CommandDoWork(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandDoWork(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Occupies a core for a few seconds"; }
|
public String HelpText() { return Localizer.Stub("Occupies a core for a few seconds"); }
|
||||||
|
|
||||||
// Called when the command is run!
|
// Called when the command is run!
|
||||||
@Override
|
@Override
|
||||||
@@ -28,6 +28,6 @@ public class CommandDoWork extends Command
|
|||||||
thispieceofshit += Math.log((double)i);
|
thispieceofshit += Math.log((double)i);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Call("I finished with my work! :D");
|
res.Call(Localizer.Stub("I finished with my work! :D"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,41 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
|
|
||||||
public class CommandEightBall extends Command
|
public class CommandEightBall extends Command
|
||||||
{
|
{
|
||||||
String [] answers = {"It is certain.", "It is decidedly so.", "Without a doubt.", "Yes - definitely.", "You may rely on it.", "As I see it, yes.", "Most likely.",
|
String [] answers =
|
||||||
"Outlook good.", "Yes.", "Signs point to yes.", "Reply hazy, try again.", "Ask again later.", "Better not tell you now.", "Cannot predict now.",
|
|
||||||
"Concentrate and ask again.", "Don't count on it.", "My reply is no.", "My sources say no.", "Outlook not so good.", "Very doubtful."};
|
|
||||||
public CommandEightBall(KittyRole level, KittyRating rating)
|
|
||||||
{
|
{
|
||||||
super(level, rating);
|
Localizer.Stub("It is certain.")
|
||||||
}
|
, Localizer.Stub("It is decidedly so.")
|
||||||
|
, Localizer.Stub("Without a doubt.")
|
||||||
|
, Localizer.Stub("Yes - definitely.")
|
||||||
|
, Localizer.Stub("You may rely on it.")
|
||||||
|
, Localizer.Stub("As I see it, yes.")
|
||||||
|
, Localizer.Stub("Most likely.")
|
||||||
|
, Localizer.Stub("Outlook good.")
|
||||||
|
, Localizer.Stub("Yes.")
|
||||||
|
, Localizer.Stub("Signs point to yes.")
|
||||||
|
|
||||||
|
, Localizer.Stub("Reply hazy, try again.")
|
||||||
|
, Localizer.Stub("Ask again later.")
|
||||||
|
, Localizer.Stub("Better not tell you now.")
|
||||||
|
, Localizer.Stub("Cannot predict now.")
|
||||||
|
, Localizer.Stub("Concentrate and ask again.")
|
||||||
|
|
||||||
|
, Localizer.Stub("Don't count on it.")
|
||||||
|
, Localizer.Stub("My reply is no.")
|
||||||
|
, Localizer.Stub("My sources say no.")
|
||||||
|
, Localizer.Stub("Outlook not so good.")
|
||||||
|
, Localizer.Stub("Very doubtful.")
|
||||||
|
};
|
||||||
|
|
||||||
|
public CommandEightBall(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Answers a yes or no question! Warning: Kitty can not actually tell the future,"
|
public String HelpText() { return Localizer.Stub("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."); }
|
||||||
+ " she claims no responsibility for any lion mauling, lack of lottery wins, or felony charges."; }
|
|
||||||
|
|
||||||
@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,6 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
|
|
||||||
public class CommandGiveBeans extends Command
|
public class CommandGiveBeans extends Command
|
||||||
@@ -8,7 +9,7 @@ public class CommandGiveBeans extends Command
|
|||||||
public CommandGiveBeans (KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandGiveBeans (KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Gives beans to the mentioned users!"; }
|
public String HelpText() { return Localizer.Stub("Gives beans to the mentioned users!"); }
|
||||||
|
|
||||||
@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)
|
||||||
@@ -19,20 +20,20 @@ public class CommandGiveBeans extends Command
|
|||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
res.Call("That's not a valid number!");
|
res.Call(Localizer.Stub("That's not a valid number!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(input.mentions == null)
|
if(input.mentions == null)
|
||||||
{
|
{
|
||||||
res.Call("You didn't mention anyone!");
|
res.Call(Localizer.Stub("You didn't mention anyone!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < input.mentions.length; i++)
|
for(int i = 0; i < input.mentions.length; i++)
|
||||||
{
|
{
|
||||||
input.mentions[i].ChangeBeans(beans);
|
input.mentions[i].ChangeBeans(beans);
|
||||||
res.Call("Gave " + input.mentions[i].name + " " + beans + " beans!");
|
res.Call(String.format(Localizer.Stub("Gave %s %s beans!"), input.mentions[i].name, "" + beans));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,13 @@ import dataStructures.KittyUser;
|
|||||||
import dataStructures.Response;
|
import dataStructures.Response;
|
||||||
import dataStructures.UserInput;
|
import dataStructures.UserInput;
|
||||||
|
|
||||||
// TODO: Convert this to a per-command help string! This lets us do all sorts of neat stuff,
|
// Either allows for specifically looking up commands or gets a list of general commands to try out!
|
||||||
// mostly tho it lets us construct this on the fly or by hand for a specific command!
|
|
||||||
public class CommandHelp extends Command
|
public class CommandHelp extends Command
|
||||||
{
|
{
|
||||||
public CommandHelp(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandHelp(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Lets you look up specific commands, or get a link to a list of all commands."; }
|
public String HelpText() { return Localizer.Stub("Lets you look up specific commands, or get a link to a list of all commands."); }
|
||||||
|
|
||||||
@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)
|
||||||
@@ -25,11 +24,7 @@ public class CommandHelp extends Command
|
|||||||
|
|
||||||
if(help == null)
|
if(help == null)
|
||||||
{
|
{
|
||||||
help = "You can get help with a specific command by typing `!help command`!"
|
help = Localizer.Stub("You can get help with a specific command by typing `!help command`!\nGeneral Commands: `boop, roll, choose, help, info, vote, results, showpoll, wolfram, cplus, java, beans, role, bet, yeet`");
|
||||||
+ "\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`";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import core.Stats;
|
import core.Stats;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
@@ -25,7 +26,7 @@ public class CommandHelpBuilder extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Emit help for all commands as formatted HTML"; }
|
public String HelpText() { return Localizer.Stub("Emit help for all commands as formatted HTML"); }
|
||||||
|
|
||||||
@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)
|
||||||
@@ -95,7 +96,7 @@ public class CommandHelpBuilder extends Command {
|
|||||||
roleStr = roleStr.substring(0, 1).toUpperCase() + roleStr.toLowerCase().substring(1);
|
roleStr = roleStr.substring(0, 1).toUpperCase() + roleStr.toLowerCase().substring(1);
|
||||||
|
|
||||||
// Section header
|
// Section header
|
||||||
accumulated += headerStart + roleStr + " commands" + headerEnd;
|
accumulated += headerStart + roleStr + " " + Localizer.Stub("commands") + headerEnd;
|
||||||
accumulated += sectionStart;
|
accumulated += sectionStart;
|
||||||
|
|
||||||
// Section content
|
// Section content
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
import dataStructures.KittyRating;
|
import dataStructures.KittyRating;
|
||||||
@@ -14,13 +15,12 @@ public class CommandInfo extends Command
|
|||||||
public CommandInfo(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandInfo(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Provides author info and a link to Kitty's website"; }
|
public String HelpText() { return Localizer.Stub("Provides author info and a link to Kitty's website"); }
|
||||||
|
|
||||||
@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)
|
||||||
{
|
{
|
||||||
String info = "I'm made by `Rin#8904` and `Reverie Wisp#3703`!\n"
|
String info = Localizer.Stub("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/");
|
||||||
+ "You 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/" ;
|
|
||||||
res.Call(info);
|
res.Call(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
import offline.Ref;
|
import offline.Ref;
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ public class CommandInvite extends Command
|
|||||||
public CommandInvite(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandInvite(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Provies a direct invite link for KittyBot"; }
|
public String HelpText() { return Localizer.Stub("Provies a direct invite link for KittyBot"); }
|
||||||
|
|
||||||
@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,6 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
import network.NetworkJDoodle;
|
import network.NetworkJDoodle;
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ public class CommandJDoodle extends Command
|
|||||||
public CommandJDoodle(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandJDoodle(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Will compile any java code you put in! Supports Java 1.8"; }
|
public String HelpText() { return Localizer.Stub("Will compile any java code you put in! Supports Java 1.8"); }
|
||||||
|
|
||||||
@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)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package commands;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
import dataStructures.KittyRating;
|
import dataStructures.KittyRating;
|
||||||
@@ -22,7 +23,7 @@ public class CommandMap extends Command
|
|||||||
public CommandMap(KittyRole roleLevel, KittyRating contentRating) { super(roleLevel, contentRating); }
|
public CommandMap(KittyRole roleLevel, KittyRating contentRating) { super(roleLevel, contentRating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Generates a map! You can pass additional information if you want with the flags `-s<seed> -w<width> -h<height>`. 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\nDefault seed: Random,\nDefault Width: 35(max "+ MaxWidth + "),\nDefault Height: 25(max " + MaxHeight + ")"; }
|
public String HelpText() { return String.format(Localizer.Stub("Generates a map! You can pass additional information if you want with the flags `-s<seed> -w<width> -h<height>`. 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\nDefault seed: Random,\nDefault Width: 35(max %s),\nDefault Height: 25(max %s)"), "" + MaxWidth, "" + MaxHeight); }
|
||||||
|
|
||||||
@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)
|
||||||
@@ -59,7 +60,7 @@ public class CommandMap extends Command
|
|||||||
}
|
}
|
||||||
catch(NumberFormatException e)
|
catch(NumberFormatException e)
|
||||||
{
|
{
|
||||||
res.Call("Invalid arguments provided!");
|
res.Call(Localizer.Stub("Invalid arguments provided!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,8 +76,10 @@ public class CommandMap extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Response header creation
|
// Response header creation
|
||||||
header += "Using mapgen v0.1\n";
|
header += Localizer.Stub("Using mapgen v0.1") + "\n";
|
||||||
header += "Seed: `" + seed + "`, Width: `"+ width +"`, Height: `"+ height + "`\n";
|
header += Localizer.Stub("Seed") + ": `" + seed + "`, ";
|
||||||
|
header += Localizer.Stub("Width") + "`"+ width +"`, ";
|
||||||
|
header += Localizer.Stub("Height") + ": `"+ height + "`\n";
|
||||||
|
|
||||||
// Response body creation
|
// Response body creation
|
||||||
body += "```\n";
|
body += "```\n";
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.io.IOException;
|
|||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
import dataStructures.KittyRating;
|
import dataStructures.KittyRating;
|
||||||
@@ -22,7 +23,7 @@ public class CommandPerish extends Command
|
|||||||
public CommandPerish(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandPerish(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned"; };
|
public String HelpText() { return Localizer.Stub("Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned"); };
|
||||||
|
|
||||||
private static Long num = 0l;
|
private static Long num = 0l;
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ public class CommandPing extends Command
|
|||||||
public CommandPing(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandPing(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Will respond with Pong!"; }
|
public String HelpText() { return Localizer.Stub("Will respond with Pong!"); }
|
||||||
|
|
||||||
// Called when the command is run!
|
// Called when the command is run!
|
||||||
@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)
|
||||||
{
|
{
|
||||||
res.Call("Pong!");
|
res.Call(Localizer.Stub("Pong!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class CommandPollManage extends Command
|
|||||||
public CommandPollManage(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandPollManage(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "'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"; }
|
public String HelpText() { return Localizer.Stub("'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"); }
|
||||||
|
|
||||||
@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)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class CommandPollResults extends Command
|
|||||||
public CommandPollResults(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandPollResults(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Will show current results of a poll and percentages of votes per choice"; }
|
public String HelpText() { return Localizer.Stub("Will show current results of a poll and percentages of votes per choice"); }
|
||||||
|
|
||||||
@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)
|
||||||
@@ -26,8 +26,7 @@ public class CommandPollResults extends Command
|
|||||||
|
|
||||||
for(int i = 0; i < votes.size(); i++)
|
for(int i = 0; i < votes.size(); i++)
|
||||||
{
|
{
|
||||||
|
results += String.format(Localizer.Stub("%s people voted for %s `%s` with `%s%` !\n "), votes.get(i).votes, votes.get(i).choice, (int)(((double)votes.get(i).votes) / ((double)totalVotes) * 100));
|
||||||
results += votes.get(i).votes + " people voted for `" + votes.get(i).choice + "` with `" + (int)(((double)votes.get(i).votes) / ((double)totalVotes) * 100) + "%`!\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Call(results);
|
res.Call(results);
|
||||||
|
|||||||
@@ -8,18 +8,18 @@ public class CommandPollShow extends Command
|
|||||||
public CommandPollShow(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandPollShow(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Will show the current poll running"; }
|
public String HelpText() { return Localizer.Stub("Will show the current poll running"); }
|
||||||
|
|
||||||
@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)
|
||||||
{
|
{
|
||||||
if(!guild.polling)
|
if(!guild.polling)
|
||||||
{
|
{
|
||||||
res.Call("There is no poll running!");
|
res.Call(Localizer.Stub("There is no poll running!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String poll = "The current poll is `" + guild.poll + "`\n";
|
String poll = String.format(Localizer.Stub("The current poll is `%s`\n"), guild.poll);
|
||||||
poll += "And the choices are:\n";
|
poll += Localizer.Stub("And the choices are:\n");
|
||||||
for(int i = 0; i < guild.choices.size(); i++)
|
for(int i = 0; i < guild.choices.size(); i++)
|
||||||
{
|
{
|
||||||
poll += (i+1) + ": `" + guild.choices.get(i).choice + "`\n";
|
poll += (i+1) + ": `" + guild.choices.get(i).choice + "`\n";
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class CommandPollVote extends Command
|
|||||||
public CommandPollVote(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandPollVote(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "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!"; }
|
public String HelpText() { return Localizer.Stub("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!"); }
|
||||||
|
|
||||||
@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)
|
||||||
@@ -17,7 +17,7 @@ public class CommandPollVote extends Command
|
|||||||
{
|
{
|
||||||
if(guild.hasVoted.contains(user.uniqueID))
|
if(guild.hasVoted.contains(user.uniqueID))
|
||||||
{
|
{
|
||||||
res.Call("You already voted");
|
res.Call(Localizer.Stub("You already voted"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
@@ -25,21 +25,22 @@ public class CommandPollVote extends Command
|
|||||||
int voteNum = Integer.parseInt(input.args)-1;
|
int voteNum = Integer.parseInt(input.args)-1;
|
||||||
if(voteNum >= guild.choices.size() || voteNum < 0)
|
if(voteNum >= guild.choices.size() || voteNum < 0)
|
||||||
{
|
{
|
||||||
res.Call(voteNum + " That's not a vaild vote!");
|
res.Call(String.format(Localizer.Stub("%s That's not a vaild vote!"), voteNum));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
KittyPoll polled = guild.choices.get(voteNum);
|
KittyPoll polled = guild.choices.get(voteNum);
|
||||||
polled.votes++;
|
polled.votes++;
|
||||||
guild.hasVoted.add(user.uniqueID);
|
guild.hasVoted.add(user.uniqueID);
|
||||||
res.Call("You successfully voted for `" + polled.choice + "`!");
|
res.Call(Localizer.Stub("You successfully voted for") + " `" + polled.choice + "`!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
res.Call("That's not a vaild number!");
|
res.Call(Localizer.Stub("That's not a vaild number!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res.Call("There is no poll running!");
|
res.Call(Localizer.Stub("There is no poll running!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import core.RPManager;
|
import core.RPManager;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
|
|
||||||
@@ -13,24 +14,30 @@ public class CommandRPEnd extends Command
|
|||||||
public CommandRPEnd (KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandRPEnd (KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Ends RP in channel"; }
|
public String HelpText() { return Localizer.Stub("Ends RP in channel"); }
|
||||||
|
|
||||||
@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)
|
||||||
{
|
{
|
||||||
File sending = null;
|
File sending = null;
|
||||||
try {
|
|
||||||
|
try
|
||||||
|
{
|
||||||
sending = RPManager.instance.endRP(channel, user);
|
sending = RPManager.instance.endRP(channel, user);
|
||||||
} catch (FileNotFoundException | UnsupportedEncodingException e)
|
}
|
||||||
|
catch (FileNotFoundException | UnsupportedEncodingException e)
|
||||||
{
|
{
|
||||||
System.out.println("I don't know how you got here");
|
System.out.println("I don't know how you got here");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sending != null)
|
if(sending != null)
|
||||||
{
|
{
|
||||||
res.CallFile(sending, "txt");
|
res.CallFile(sending, "txt");
|
||||||
res.Call("Here's your file!");
|
res.Call(Localizer.Stub("Here's your file!"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
res.Call("You can't end this RP!");
|
{
|
||||||
|
res.Call(Localizer.Stub("You can't end this RP!"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import core.rpg.RPGFramework;
|
import core.rpg.RPGFramework;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
@@ -22,7 +23,7 @@ public class CommandRPG extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Admin+ command only right now - experimental text RPG! Format is !rpg <rpg command>"; };
|
public String HelpText() { return Localizer.Stub("Admin+ command only right now - experimental text RPG! Format is !rpg <rpg command>"); };
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -42,7 +43,7 @@ public class CommandRPG extends Command
|
|||||||
|
|
||||||
if(result == null)
|
if(result == null)
|
||||||
{
|
{
|
||||||
res.Call("Invalid RPG Command!");
|
res.Call(Localizer.Stub("Invalid RPG Command!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package commands;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import core.RPManager;
|
import core.RPManager;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
|
|
||||||
@@ -11,7 +12,7 @@ public class CommandRPStart extends Command
|
|||||||
public CommandRPStart (KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandRPStart (KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Starts an rp, add people to it by mentioning them!"; }
|
public String HelpText() { return Localizer.Stub("Starts an rp, add people to it by mentioning them!"); }
|
||||||
|
|
||||||
@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,6 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
import dataStructures.KittyRating;
|
import dataStructures.KittyRating;
|
||||||
@@ -14,7 +15,7 @@ public class CommandRating extends Command
|
|||||||
public CommandRating(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandRating(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "'0' is fully sfw (Derpi and e621 searches are disabled), '1' is filtered (kitty auto appends a sfw tag on any searches), '2' is nsfw (any search will go through). Some other words are supported for setting filter as well."; }
|
public String HelpText() { return Localizer.Stub("'0' is fully sfw (Derpi and e621 searches are disabled), '1' is filtered (kitty auto appends a sfw tag on any searches), '2' is nsfw (any search will go through). Some other words are supported for setting filter as well."); }
|
||||||
|
|
||||||
// Called when the command is run!
|
// Called when the command is run!
|
||||||
@Override
|
@Override
|
||||||
@@ -54,11 +55,11 @@ public class CommandRating extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(newRating != null)
|
if(newRating != null)
|
||||||
res.Call("Kittybot content set to " + newRating);
|
res.Call(Localizer.Stub("Kittybot content set to") + " " + newRating);
|
||||||
else
|
else
|
||||||
res.Call("Invalid content rating `" + input.args + "`");
|
res.Call(Localizer.Stub("Invalid content rating") + " `" + input.args + "`");
|
||||||
|
|
||||||
if(newRating.equals("Filtered"))
|
if(newRating.equals("Filtered"))
|
||||||
res.Call("Warning: NSFW may slip through, images are only based on tags on their respective sites!");
|
res.Call(Localizer.Stub("Warning: NSFW may slip through, images are only based on tags on their respective sites!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
|
|
||||||
public class CommandRole extends Command
|
public class CommandRole extends Command
|
||||||
@@ -8,20 +9,20 @@ public class CommandRole extends Command
|
|||||||
public CommandRole (KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandRole (KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "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."; }
|
public String HelpText() { return Localizer.Stub("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."); }
|
||||||
|
|
||||||
@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)
|
||||||
{
|
{
|
||||||
if(input.args.isEmpty())
|
if(input.args.isEmpty())
|
||||||
{
|
{
|
||||||
res.Call("Your role is " + user.GetRole().name() + "!");
|
res.Call(Localizer.Stub("Your role is") + " " + user.GetRole().name() + "!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(user.GetRole().getValue() < KittyRole.Admin.getValue())
|
if(user.GetRole().getValue() < KittyRole.Admin.getValue())
|
||||||
{
|
{
|
||||||
res.Call("You aren't allowed to do that! You must have the KittyRole '" + KittyRole.Admin.toString() + "' or higher!");
|
res.Call(String.format(Localizer.Stub("You aren't allowed to do that! You must have the KittyRole '%' or higher!"), KittyRole.Admin.toString()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ public class CommandRole extends Command
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
res.Call("Please enter `general`, `mod`, or `admin`!");
|
res.Call(Localizer.Stub("Please enter `general`, `mod`, or `admin`!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String users = "";
|
String users = "";
|
||||||
@@ -55,6 +56,6 @@ public class CommandRole extends Command
|
|||||||
users += input.mentions[i].name + " ";
|
users += input.mentions[i].name + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Call("Changed " + users + " to role `" + newRole.name() + "`!");
|
res.Call(String.format(Localizer.Stub("Changed %s to role `%s`!"), users, newRole.name()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class CommandRoll extends Command
|
|||||||
public CommandRoll(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandRoll(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "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"; }
|
public String HelpText() { return Localizer.Stub("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"); }
|
||||||
|
|
||||||
@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)
|
||||||
@@ -27,7 +27,7 @@ public class CommandRoll extends Command
|
|||||||
}
|
}
|
||||||
catch(Exception e)
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
res.Call("Didn't work ;3;");
|
res.Call(Localizer.Stub("Didn't work ;3;"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package commands;
|
|||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.DatabaseManager;
|
import core.DatabaseManager;
|
||||||
|
import core.Localizer;
|
||||||
import core.Stats;
|
import core.Stats;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
@@ -17,7 +18,7 @@ public class CommandShutdown extends Command
|
|||||||
public CommandShutdown(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandShutdown(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Stops kitty. `-s` or `safe` as an argument attempts to sync off the database before shutdown."; }
|
public String HelpText() { return Localizer.Stub("Stops kitty. `-s` or `safe` as an argument attempts to sync off the database before shutdown."); }
|
||||||
|
|
||||||
// Called when the command is run!
|
// Called when the command is run!
|
||||||
@Override
|
@Override
|
||||||
@@ -41,12 +42,12 @@ public class CommandShutdown extends Command
|
|||||||
if(isSafe)
|
if(isSafe)
|
||||||
{
|
{
|
||||||
DatabaseManager.instance.Upkeep(); // Force upkeep, this works so long as on main thread.
|
DatabaseManager.instance.Upkeep(); // Force upkeep, this works so long as on main thread.
|
||||||
res.CallImmediate("Forced shutdown, database synced before abandoning threads.");
|
res.CallImmediate(Localizer.Stub("Forced shutdown, database synced before abandoning threads."));
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res.CallImmediate("Forced immediate shutdown, threads abandoned without sync.");
|
res.CallImmediate(Localizer.Stub("Forced immediate shutdown, threads abandoned without sync."));
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.io.IOException;
|
|||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
import utils.ImageUtils;
|
import utils.ImageUtils;
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ public class CommandStark extends Command
|
|||||||
public CommandStark(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandStark(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Snaps your icon or the icon of a friend you mentioned"; };
|
public String HelpText() { return Localizer.Stub("Snaps your icon or the icon of a friend you mentioned"); };
|
||||||
|
|
||||||
private static Long num = 0l;
|
private static Long num = 0l;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import core.CommandManager.ThreadData;
|
import core.CommandManager.ThreadData;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
@@ -16,7 +17,7 @@ public class CommandStats extends Command
|
|||||||
public CommandStats(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandStats(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Displays the actively running KittyBot application information"; }
|
public String HelpText() { return Localizer.Stub("Displays the actively running KittyBot application information"); }
|
||||||
|
|
||||||
// Called when the command is run!
|
// Called when the command is run!
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package commands;
|
package commands;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
import network.NetworkTwitter;
|
import network.NetworkTwitter;
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ public class CommandTweet extends Command
|
|||||||
public CommandTweet(KittyRole level, KittyRating rating) { super(level, rating); }
|
public CommandTweet(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "With an input of x,y,z where x y and z are all choices, kitty will choose one"; }
|
public String HelpText() { return Localizer.Stub("With an input of x,y,z where x y and z are all choices, kitty will choose one"); }
|
||||||
|
|
||||||
@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)
|
||||||
@@ -18,7 +19,7 @@ public class CommandTweet extends Command
|
|||||||
try {
|
try {
|
||||||
res.Call(tweet.tweet(input.args));
|
res.Call(tweet.tweet(input.args));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
res.Call("FUCKED UP HARD");
|
res.Call(Localizer.Stub("Tweet command failed!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package commands;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
import network.*;
|
import network.*;
|
||||||
import utils.ImageUtils;
|
import utils.ImageUtils;
|
||||||
@@ -14,13 +15,13 @@ public class CommandWolfram extends Command
|
|||||||
public CommandWolfram(KittyRole level, KittyRating rating) { super(level, rating);}
|
public CommandWolfram(KittyRole level, KittyRating rating) { super(level, rating);}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Will query wolframalpha with your question and give a full image output of the answer"; }
|
public String HelpText() { return Localizer.Stub("Will query wolframalpha with your question and give a full image output of the answer"); }
|
||||||
|
|
||||||
@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)
|
||||||
{
|
{
|
||||||
if(input.args == null || input.args.trim().length() == 0)
|
if(input.args == null || input.args.trim().length() == 0)
|
||||||
res.Call("You need to provide some arguments!");
|
res.Call(Localizer.Stub("You need to provide some arguments!"));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -30,7 +31,7 @@ public class CommandWolfram extends Command
|
|||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
res.Call("Something went wrong!");
|
res.Call(Localizer.Stub("Something went wrong!"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,7 @@ import javax.imageio.stream.FileImageOutputStream;
|
|||||||
import javax.imageio.stream.ImageOutputStream;
|
import javax.imageio.stream.ImageOutputStream;
|
||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
|
import core.Localizer;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
import dataStructures.KittyRating;
|
import dataStructures.KittyRating;
|
||||||
@@ -38,7 +39,7 @@ public class CommandYeet extends Command
|
|||||||
private static Long num = 0l;
|
private static Long num = 0l;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return "Yeet yourself or yeet a friend with @!"; }
|
public String HelpText() { return Localizer.Stub("Yeet yourself or yeet a friend with @!"); }
|
||||||
|
|
||||||
// Called when the command is run!
|
// Called when the command is run!
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package core;
|
package core;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
import dataStructures.KittyRating;
|
import dataStructures.KittyRating;
|
||||||
@@ -42,7 +41,7 @@ public abstract class Command
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO(wisp, rin): ADD CHANNEL CHECK HERE
|
//TODO: ADD CHANNEL CHECK HERE
|
||||||
|
|
||||||
if(user.GetRole().getValue() >= roleLevel.getValue())
|
if(user.GetRole().getValue() >= roleLevel.getValue())
|
||||||
{
|
{
|
||||||
|
|||||||
+41
-52
@@ -3,13 +3,12 @@ package core;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
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.HashMap;
|
import dataStructures.SectionedKeyValueStore;
|
||||||
import org.ini4j.InvalidFileFormatException;
|
|
||||||
import org.ini4j.Profile.Section;
|
|
||||||
import org.ini4j.Wini;
|
|
||||||
|
|
||||||
import utils.FileUtils;
|
import utils.FileUtils;
|
||||||
import utils.GlobalLog;
|
import utils.GlobalLog;
|
||||||
import utils.LogFilter;
|
import utils.LogFilter;
|
||||||
@@ -23,14 +22,15 @@ public class Localizer
|
|||||||
public final static String filename = "localization.config";
|
public final static String filename = "localization.config";
|
||||||
public final static String functionName = "Localizer.Stub";
|
public final static String functionName = "Localizer.Stub";
|
||||||
|
|
||||||
// Local translation
|
// Local translation storage
|
||||||
private static HashMap<String, LocInfo> translated = new HashMap<String, LocInfo>();
|
private static SectionedKeyValueStore stringStore;
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
private static void Log(String str) { GlobalLog.Log(LogFilter.Strings, str); }
|
private static void Log(String str) { GlobalLog.Log(LogFilter.Strings, str); }
|
||||||
private static void Warn(String str) { GlobalLog.Warn(LogFilter.Strings, str); }
|
private static void Warn(String str) { GlobalLog.Warn(LogFilter.Strings, str); }
|
||||||
private static void Error(String str) { GlobalLog.Error(LogFilter.Strings, str); }
|
private static void Error(String str) { GlobalLog.Error(LogFilter.Strings, str); }
|
||||||
|
|
||||||
|
|
||||||
// Structure used for holding a pair of strings and any other info we need
|
// Structure used for holding a pair of strings and any other info we need
|
||||||
// about localized information that is being looked up.
|
// about localized information that is being looked up.
|
||||||
private static class LocInfo
|
private static class LocInfo
|
||||||
@@ -84,17 +84,34 @@ 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(translated.containsKey(input))
|
if(stringStore == null)
|
||||||
{
|
return input;
|
||||||
String value = translated.get(input).phrase;
|
|
||||||
if(value.trim().length() > 0)
|
String value = stringStore.GetKey(input);
|
||||||
|
if(value == null || value.length() < 1)
|
||||||
|
return input;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return input;
|
// Reads a file to string, adapted from https://stackoverflow.com/a/326440/5383198
|
||||||
|
static String ReadFileAsString(String path, Charset encoding)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||||
|
return new String(encoded, encoding);
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
Warn("No file found to read from!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update localization from the disk on file. Creates the file if it doesn't exist.
|
// Update localization from the disk on file. Creates the file if it doesn't exist.
|
||||||
@@ -102,27 +119,20 @@ public class Localizer
|
|||||||
public static void UpdateLocFromDisk()
|
public static void UpdateLocFromDisk()
|
||||||
{
|
{
|
||||||
Log("Attempting to read localization file");
|
Log("Attempting to read localization file");
|
||||||
|
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
String fileContents = ReadFileAsString(filename, Charset.defaultCharset());
|
||||||
|
|
||||||
|
if(fileContents == null)
|
||||||
{
|
{
|
||||||
File file = new File(filename);
|
File file = new File(filename);
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
|
|
||||||
Wini ini = new Wini(file);
|
|
||||||
|
|
||||||
for(String str : ini.keySet())
|
|
||||||
{
|
|
||||||
// Store everything in all .ini sections
|
|
||||||
Section sec = ini.get(str);
|
|
||||||
for(String s : sec.keySet())
|
|
||||||
{
|
|
||||||
if(!translated.containsKey(s))
|
|
||||||
translated.put(s, new LocInfo(sec.getName(), sec.get(s, String.class)));
|
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
}
|
|
||||||
catch(InvalidFileFormatException e)
|
|
||||||
{
|
{
|
||||||
Error("File issue with format during localization file read");
|
stringStore = new SectionedKeyValueStore(fileContents);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(IOException e)
|
catch(IOException e)
|
||||||
{
|
{
|
||||||
@@ -135,27 +145,12 @@ public class Localizer
|
|||||||
public static void SaveLocToDisk()
|
public static void SaveLocToDisk()
|
||||||
{
|
{
|
||||||
Log("Attempting to write updated localization file");
|
Log("Attempting to write updated localization file");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PrintWriter pw = new PrintWriter(filename);
|
PrintWriter pw = new PrintWriter(filename);
|
||||||
|
pw.println(stringStore.toString());
|
||||||
pw.close();
|
pw.close();
|
||||||
|
|
||||||
File file = new File(filename);
|
|
||||||
file.createNewFile();
|
|
||||||
|
|
||||||
Wini ini = new Wini(file);
|
|
||||||
|
|
||||||
for(String s : translated.keySet())
|
|
||||||
{
|
|
||||||
LocInfo toWrite = translated.get(s);
|
|
||||||
ini.put(toWrite.file, s, toWrite.phrase);
|
|
||||||
}
|
|
||||||
|
|
||||||
ini.store();
|
|
||||||
}
|
|
||||||
catch(InvalidFileFormatException e)
|
|
||||||
{
|
|
||||||
Error("File issue with format during localization file write");
|
|
||||||
}
|
}
|
||||||
catch(IOException e)
|
catch(IOException e)
|
||||||
{
|
{
|
||||||
@@ -171,12 +166,6 @@ public class Localizer
|
|||||||
FileUtils.AcquireAllFiles(".\\src").forEach((path) -> StripForContents(path, localizeList));
|
FileUtils.AcquireAllFiles(".\\src").forEach((path) -> StripForContents(path, localizeList));
|
||||||
|
|
||||||
for(LocInfo toStub : localizeList)
|
for(LocInfo toStub : localizeList)
|
||||||
{
|
stringStore.AddKeyValue(toStub.file, toStub.phrase, toStub.phrase);
|
||||||
if(!translated.containsKey(toStub.phrase))
|
|
||||||
{
|
|
||||||
translated.put(toStub.phrase, new LocInfo(toStub.file, ""));
|
|
||||||
Log("Found new stubbed phrase '" + toStub.phrase + "' in " + toStub.file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package dataStructures;
|
||||||
|
|
||||||
|
// A generic class designed to hold two types, as a first and second variable.
|
||||||
|
public class Pair<T1, T2>
|
||||||
|
{
|
||||||
|
public T1 First;
|
||||||
|
public T2 Second;
|
||||||
|
|
||||||
|
public Pair(T1 first, T2 second)
|
||||||
|
{
|
||||||
|
this.First = first;
|
||||||
|
this.Second = second;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
package dataStructures;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
// This is a class designed to parse ini inspired key-value pairs that are sectioned off.
|
||||||
|
// The difference here is that this is more permissive than an ini file, and only accepts
|
||||||
|
// a single split character, not the traditional set an ini does. All of the following are valid:
|
||||||
|
//
|
||||||
|
// [ExampleSection]
|
||||||
|
// Key=Value
|
||||||
|
// Valid Ridiculous Key&\n\t_.:;foo = \tValid Ridiculous Value*&%$()^.[]{}@
|
||||||
|
// EmptyValue=
|
||||||
|
//
|
||||||
|
// Note that the sections are NOT designed to allow for duplicate keys across them.
|
||||||
|
// 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
|
||||||
|
{
|
||||||
|
// Variables
|
||||||
|
public final char SectionStart = '[';
|
||||||
|
public final char SectionEnd = ']';
|
||||||
|
public final char KeyValueLineSeparator = '\n';
|
||||||
|
public final String KeyValueSplit = "=";
|
||||||
|
|
||||||
|
// [Key: SectionName, [Key: KeyString, Value: ValueString]]
|
||||||
|
private HashMap<String, HashMap<String, String>> sectionKeyValue;
|
||||||
|
|
||||||
|
// [Key: KeyString, Value: ValueString]]
|
||||||
|
private HashMap<String, String> keyValue;
|
||||||
|
|
||||||
|
// String constructor that parses the input string into the object
|
||||||
|
public SectionedKeyValueStore(String input)
|
||||||
|
{
|
||||||
|
sectionKeyValue = new HashMap<String, HashMap<String, String>>();
|
||||||
|
keyValue = new HashMap<String, String>();
|
||||||
|
Parse(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calls back on each item in the entire structure. Provides section, then a pair of the keyString and valueString.
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
|
public void ForEach(BiConsumer<? super String, Pair<? super String, ? super String>> action)
|
||||||
|
{
|
||||||
|
Iterator it = sectionKeyValue.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
Map.Entry pair = (Map.Entry)it.next();
|
||||||
|
Iterator internal = ((HashMap<String, String>)pair.getValue()).entrySet().iterator();
|
||||||
|
|
||||||
|
while(internal.hasNext())
|
||||||
|
{
|
||||||
|
Map.Entry internalPair = (Map.Entry)internal.next();
|
||||||
|
action.accept((String)pair.getKey(), new Pair<String, String>((String)internalPair.getKey(), (String)internalPair.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calls back each item in the structure but does not priv
|
||||||
|
@SuppressWarnings({"rawtypes"})
|
||||||
|
public void ForEach(Consumer<Pair<? super String, ? super String>> action)
|
||||||
|
{
|
||||||
|
Iterator it = keyValue.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
Map.Entry pair = (Map.Entry)it.next();
|
||||||
|
action.accept(new Pair<String, String>((String)pair.getKey(), (String)pair.getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parses the internal hashmap as a string then reutrns it, featuring 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"})
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
String out = "";
|
||||||
|
|
||||||
|
// Iterates over the sections and
|
||||||
|
Iterator it = sectionKeyValue.entrySet().iterator();
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
Map.Entry pair = (Map.Entry)it.next();
|
||||||
|
out += ("" + SectionStart + pair.getKey() + SectionEnd + KeyValueLineSeparator);
|
||||||
|
|
||||||
|
Iterator internal = ((HashMap<String, String>)pair.getValue()).entrySet().iterator();
|
||||||
|
while(internal.hasNext())
|
||||||
|
{
|
||||||
|
Map.Entry internalPair = (Map.Entry)internal.next();
|
||||||
|
String key = (String)internalPair.getKey();
|
||||||
|
String value = (String)internalPair.getValue();
|
||||||
|
|
||||||
|
if(key == value)
|
||||||
|
out += (key + KeyValueSplit) + KeyValueLineSeparator;
|
||||||
|
else
|
||||||
|
out += (key + KeyValueSplit + value) + KeyValueLineSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
out += KeyValueLineSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parses out the string passed in into the sectionkeyValue HashMap.
|
||||||
|
// Any character used in a split call is escaped just in case on
|
||||||
|
// account of some characters having specific regex meanings.
|
||||||
|
private void Parse(String input)
|
||||||
|
{
|
||||||
|
String[] sections = input.split("\\" + SectionStart);
|
||||||
|
|
||||||
|
for(int sec = 0; sec < sections.length; ++sec)
|
||||||
|
{
|
||||||
|
// Gather information about the contents of the section, and the header.
|
||||||
|
String section = sections[sec];
|
||||||
|
if(section.length() < 2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int pos = section.indexOf(SectionEnd);
|
||||||
|
if(pos == -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Parse section name. If it already exists, don't bother making it.
|
||||||
|
String sectionName = section.substring(0, pos);
|
||||||
|
AddSection(sectionName);
|
||||||
|
|
||||||
|
// Parse out the pairs within the section, split them all out.
|
||||||
|
String unparsedPairs = section.substring(pos + 1);
|
||||||
|
String[] pairs = unparsedPairs.split("\\" + KeyValueLineSeparator);
|
||||||
|
|
||||||
|
// Parse out valid key-value pairs, and store them in the specified section.
|
||||||
|
// At this point, we can be guarenteed that sectionName is in the Hashmap.
|
||||||
|
for(int pair = 0; pair < pairs.length; ++pair)
|
||||||
|
{
|
||||||
|
String line = pairs[pair];
|
||||||
|
int splitPos = line.indexOf(KeyValueSplit);
|
||||||
|
if(splitPos < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
String key = line.substring(0, splitPos);
|
||||||
|
String value = line.substring(splitPos + KeyValueSplit.length());
|
||||||
|
sectionKeyValue.get(sectionName).putIfAbsent(key, value);
|
||||||
|
keyValue.putIfAbsent(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dumps out a string array
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private void Dump(String[] toPrint)
|
||||||
|
{
|
||||||
|
System.out.println("Length: " + toPrint.length);
|
||||||
|
|
||||||
|
for(int i = 0; i < toPrint.length; ++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;
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
-12
@@ -1,7 +1,6 @@
|
|||||||
package main;
|
package main;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
import javax.security.auth.login.LoginException;
|
||||||
|
|
||||||
import core.*;
|
import core.*;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
@@ -18,8 +17,10 @@ import core.Localizer;
|
|||||||
import utils.GlobalLog;
|
import utils.GlobalLog;
|
||||||
import net.dv8tion.jda.core.*;
|
import net.dv8tion.jda.core.*;
|
||||||
|
|
||||||
// NOTE(wisp): http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation.
|
// http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation.
|
||||||
// NOTE(wisp): Application entry point!
|
// This is the application entry point, and bot startup location!
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class Main extends ListenerAdapter
|
public class Main extends ListenerAdapter
|
||||||
{
|
{
|
||||||
// Variables and stuff
|
// Variables and stuff
|
||||||
@@ -32,17 +33,17 @@ public class Main extends ListenerAdapter
|
|||||||
// Main test location
|
// Main test location
|
||||||
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
||||||
{
|
{
|
||||||
// Facotry startup.
|
// Localizer startup - Potentially integrate with the factory. Needs to happen first tho.
|
||||||
|
Localizer.UpdateLocFromDisk();
|
||||||
|
Localizer.ScrapeAll();
|
||||||
|
Localizer.SaveLocToDisk();
|
||||||
|
|
||||||
|
// Factory startup
|
||||||
databaseManager = ObjectBuilderFactory.ConstructDatabaseManager();
|
databaseManager = ObjectBuilderFactory.ConstructDatabaseManager();
|
||||||
commandManager = ObjectBuilderFactory.ConstructCommandManager();
|
commandManager = ObjectBuilderFactory.ConstructCommandManager();
|
||||||
rpManager = ObjectBuilderFactory.ConstructRPManager();
|
rpManager = ObjectBuilderFactory.ConstructRPManager();
|
||||||
stats = ObjectBuilderFactory.ConstructStats(commandManager);
|
stats = ObjectBuilderFactory.ConstructStats(commandManager);
|
||||||
|
|
||||||
// Localizer startup - Potentially integrate with the factory.
|
|
||||||
Localizer.UpdateLocFromDisk();
|
|
||||||
Localizer.ScrapeAll();
|
|
||||||
Localizer.SaveLocToDisk();
|
|
||||||
|
|
||||||
// Bot startup
|
// Bot startup
|
||||||
kitty = new JDABuilder(AccountType.BOT).setToken(Ref.TestToken).buildBlocking();
|
kitty = new JDABuilder(AccountType.BOT).setToken(Ref.TestToken).buildBlocking();
|
||||||
kitty.getPresence().setGame(Game.playing("with a new build"));
|
kitty.getPresence().setGame(Game.playing("with a new build"));
|
||||||
@@ -56,8 +57,6 @@ public class Main extends ListenerAdapter
|
|||||||
if(!PreProcessSetup(event))
|
if(!PreProcessSetup(event))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GlobalLog.Log("Parseable message recieved!");
|
|
||||||
|
|
||||||
// Factory objects
|
// Factory objects
|
||||||
KittyUser user = ObjectBuilderFactory.ExtractUser(event);
|
KittyUser user = ObjectBuilderFactory.ExtractUser(event);
|
||||||
KittyGuild guild = ObjectBuilderFactory.ExtractGuild(event);
|
KittyGuild guild = ObjectBuilderFactory.ExtractGuild(event);
|
||||||
@@ -74,7 +73,7 @@ public class Main extends ListenerAdapter
|
|||||||
// Track beans!
|
// Track beans!
|
||||||
user.ChangeBeans(1);
|
user.ChangeBeans(1);
|
||||||
|
|
||||||
//RP logging system
|
// RP logging system
|
||||||
RPManager.instance.addLine(channel, user, input);
|
RPManager.instance.addLine(channel, user, input);
|
||||||
|
|
||||||
// Issue the command
|
// Issue the command
|
||||||
@@ -140,6 +139,7 @@ public class Main extends ListenerAdapter
|
|||||||
{
|
{
|
||||||
databaseManager.Upkeep();
|
databaseManager.Upkeep();
|
||||||
RPManager.Upkeep(kitty);
|
RPManager.Upkeep(kitty);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package network;
|
package network;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import core.*;
|
|
||||||
import dataStructures.GenericImage;
|
import dataStructures.GenericImage;
|
||||||
import offline.*;
|
import offline.*;
|
||||||
import utils.*;
|
import utils.*;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package network;
|
package network;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import core.*;
|
|
||||||
import dataStructures.GenericImage;
|
import dataStructures.GenericImage;
|
||||||
|
import offline.Ref;
|
||||||
import utils.*;
|
import utils.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +25,7 @@ public class NetworkE621
|
|||||||
private static final Gson jsonParser_ = new Gson();
|
private static final Gson jsonParser_ = new Gson();
|
||||||
private static final String API_ROOT = "https://e621.net/post/index.json?";
|
private static final String API_ROOT = "https://e621.net/post/index.json?";
|
||||||
private static int maxSearchResults_ = 10;
|
private static int maxSearchResults_ = 10;
|
||||||
private static String[] blacklist = {"theallseeingeye","scat","diaper","cub"};
|
private static String[] blacklist = Ref.e621Blacklist;
|
||||||
private class E621ResponseObject
|
private class E621ResponseObject
|
||||||
{
|
{
|
||||||
// public varaibles matching the case and the type we want for JSON.
|
// public varaibles matching the case and the type we want for JSON.
|
||||||
|
|||||||
Reference in New Issue
Block a user