From 976d106de92ca958e99cc13fd711a50b96509f5e Mon Sep 17 00:00:00 2001 From: Eyre_S Date: Mon, 8 Nov 2021 20:17:42 +0800 Subject: [PATCH] =?UTF-8?q?@id=20=E5=91=BD=E4=BB=A4=E6=94=AF=E6=8C=81?= =?UTF-8?q?=EF=BC=88=E7=9B=B8=E5=BD=93=E6=9A=B4=E5=8A=9B=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=EF=BC=89=EF=BC=8C=E9=99=90=E5=88=B6=20@id=EF=BC=88?= =?UTF-8?q?=E4=B8=BA=E4=BA=86=E5=89=8D=E9=9D=A2=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java | 8 ++++++-- .../java/cc/sukazyo/cono/morny/{data => }/MornyHello.java | 2 +- .../cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) rename src/main/java/cc/sukazyo/cono/morny/{data => }/MornyHello.java (99%) diff --git a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java index 1b339ff..26859e4 100644 --- a/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java +++ b/src/main/java/cc/sukazyo/cono/morny/MornyCoeur.java @@ -11,6 +11,7 @@ import static cc.sukazyo.cono.morny.Logger.logger; public class MornyCoeur { private static TelegramBot account; + public static final String USERNAME = "morny_cono_annie_bot"; public static void main (String[] args) { @@ -20,7 +21,7 @@ public class MornyCoeur { logger.info("args key:\n " + args[0]); try { account = login(args[0]); } - catch (Exception e) { logger.error("Cannot login to bot/api."); System.exit(-1); } + catch (Exception e) { logger.error("Cannot login to bot/api. :\n " + e.getMessage()); System.exit(-1); } logger.info("Bot login succeed."); @@ -37,7 +38,10 @@ public class MornyCoeur { for (int i = 1; i < 4; i++) { if (i != 1) logger.info("retrying..."); try { - logger.info("Succeed login to @" + account.execute(new GetMe()).user().username()); + String username = account.execute(new GetMe()).user().username(); + if (!USERNAME.equals(username)) + throw new RuntimeException("Required the bot @"+USERNAME + " but @"+username + "logged in!"); + logger.info("Succeed login to @" + username); return account; } catch (Exception e) { e.printStackTrace(System.out); diff --git a/src/main/java/cc/sukazyo/cono/morny/data/MornyHello.java b/src/main/java/cc/sukazyo/cono/morny/MornyHello.java similarity index 99% rename from src/main/java/cc/sukazyo/cono/morny/data/MornyHello.java rename to src/main/java/cc/sukazyo/cono/morny/MornyHello.java index f8be6e3..4004403 100644 --- a/src/main/java/cc/sukazyo/cono/morny/data/MornyHello.java +++ b/src/main/java/cc/sukazyo/cono/morny/MornyHello.java @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.data; +package cc.sukazyo.cono.morny; @SuppressWarnings("all") public class MornyHello { diff --git a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java index 4f2b9ea..a6653d2 100644 --- a/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java +++ b/src/main/java/cc/sukazyo/cono/morny/bot/event/OnCommandExecute.java @@ -22,13 +22,17 @@ public class OnCommandExecute extends EventListener { } switch (event.message().text()) { case "/o": + case "/o@" + MornyCoeur.USERNAME: onCommandOnExec(event); break; case "/hi": + case "/hi@" + MornyCoeur.USERNAME: case "/hello": + case "/hello@" + MornyCoeur.USERNAME: onCommandHelloExec(event); break; case "/exit": + case "/exit@" + MornyCoeur.USERNAME: onCommandExitExec(event); break; default: