@id 命令支持(相当暴力的实现),限制 @id(为了前面的功能

This commit is contained in:
A.C.Sukazyo Eyre 2021-11-08 20:17:42 +08:00
parent 703ef816c6
commit 976d106de9
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
3 changed files with 11 additions and 3 deletions

View File

@ -11,6 +11,7 @@ import static cc.sukazyo.cono.morny.Logger.logger;
public class MornyCoeur { public class MornyCoeur {
private static TelegramBot account; private static TelegramBot account;
public static final String USERNAME = "morny_cono_annie_bot";
public static void main (String[] args) { public static void main (String[] args) {
@ -20,7 +21,7 @@ public class MornyCoeur {
logger.info("args key:\n " + args[0]); logger.info("args key:\n " + args[0]);
try { account = login(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."); logger.info("Bot login succeed.");
@ -37,7 +38,10 @@ public class MornyCoeur {
for (int i = 1; i < 4; i++) { for (int i = 1; i < 4; i++) {
if (i != 1) logger.info("retrying..."); if (i != 1) logger.info("retrying...");
try { 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; return account;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(System.out); e.printStackTrace(System.out);

View File

@ -1,4 +1,4 @@
package cc.sukazyo.cono.morny.data; package cc.sukazyo.cono.morny;
@SuppressWarnings("all") @SuppressWarnings("all")
public class MornyHello { public class MornyHello {

View File

@ -22,13 +22,17 @@ public class OnCommandExecute extends EventListener {
} }
switch (event.message().text()) { switch (event.message().text()) {
case "/o": case "/o":
case "/o@" + MornyCoeur.USERNAME:
onCommandOnExec(event); onCommandOnExec(event);
break; break;
case "/hi": case "/hi":
case "/hi@" + MornyCoeur.USERNAME:
case "/hello": case "/hello":
case "/hello@" + MornyCoeur.USERNAME:
onCommandHelloExec(event); onCommandHelloExec(event);
break; break;
case "/exit": case "/exit":
case "/exit@" + MornyCoeur.USERNAME:
onCommandExitExec(event); onCommandExitExec(event);
break; break;
default: default: