From e8c78323b18178e947deb9a86678e23ee1ea743e Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 11 Nov 2015 21:09:27 +0200 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B6=D0=B8=D0=BC=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=B0=20=D0=BF=D0=B8=D1=80=D0=BE=D0=B6=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/holdfast/samobot/commands/Pirozhki.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/holdfast/samobot/commands/Pirozhki.java b/src/holdfast/samobot/commands/Pirozhki.java index 9f2b113..f8b3502 100644 --- a/src/holdfast/samobot/commands/Pirozhki.java +++ b/src/holdfast/samobot/commands/Pirozhki.java @@ -1,6 +1,7 @@ package holdfast.samobot.commands; import holdfast.samobot.IOUtil; +import holdfast.samobot.Util; import java.io.IOException; /** @@ -9,10 +10,14 @@ import java.io.IOException; */ 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 = "
"; private static final String TAG_END = "
"; + private static boolean random = true; + @Override protected String[] command() { return new String[] { "пирожки" }; @@ -20,7 +25,14 @@ public class Pirozhki extends Command { @Override 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 endIndex = rawHtml.indexOf(TAG_END, startIndex);