Режим выбора пирожков
This commit is contained in:
parent
27e2312eed
commit
e8c78323b1
@ -1,6 +1,7 @@
|
|||||||
package holdfast.samobot.commands;
|
package holdfast.samobot.commands;
|
||||||
|
|
||||||
import holdfast.samobot.IOUtil;
|
import holdfast.samobot.IOUtil;
|
||||||
|
import holdfast.samobot.Util;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -9,10 +10,14 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class Pirozhki extends Command {
|
public class Pirozhki extends Command {
|
||||||
|
|
||||||
private static final String URL = "http://perashki.ru/Piro/Random/";
|
private static final String RANDOM_URL = "http://perashki.ru/Piro/Random/";
|
||||||
|
private static final String BEST_URL = "http://perashki.ru/Piro/Best/?page=";
|
||||||
|
private static final int BEST_LAST_PAGE = 66;
|
||||||
private static final String TAG_BEGIN = "<div class=\"Text\">";
|
private static final String TAG_BEGIN = "<div class=\"Text\">";
|
||||||
private static final String TAG_END = "</div>";
|
private static final String TAG_END = "</div>";
|
||||||
|
|
||||||
|
private static boolean random = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String[] command() {
|
protected String[] command() {
|
||||||
return new String[] { "пирожки" };
|
return new String[] { "пирожки" };
|
||||||
@ -20,7 +25,14 @@ public class Pirozhki extends Command {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(String message, String userName) throws IOException {
|
protected boolean execute(String message, String userName) throws IOException {
|
||||||
String rawHtml = IOUtil.get(URL);
|
if (message.toLowerCase().contains("режим") || message.toLowerCase().contains("mode")) {
|
||||||
|
random = !random;
|
||||||
|
send("Отныне пирожки будут у нас " + (random ? "случайные :)" : "отборные :)"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
String url = random ? RANDOM_URL : (BEST_URL + Util.random(1, BEST_LAST_PAGE));
|
||||||
|
String rawHtml = IOUtil.get(url);
|
||||||
|
|
||||||
int startIndex = rawHtml.indexOf(TAG_BEGIN) + TAG_BEGIN.length();
|
int startIndex = rawHtml.indexOf(TAG_BEGIN) + TAG_BEGIN.length();
|
||||||
int endIndex = rawHtml.indexOf(TAG_END, startIndex);
|
int endIndex = rawHtml.indexOf(TAG_END, startIndex);
|
||||||
|
Loading…
Reference in New Issue
Block a user