コード例 #1
0
 @Override
 public void onParticipantJoinGroupChat(ParticipantJoinGroupChatEvent event) {
   if (event.getParticipant().getId() == TelegramHook.getBot().getBotID()) {
     event
         .getChat()
         .sendMessage(
             SendableTextMessage.builder()
                 .message(
                     "*Hello!*\n\nThis is a quick message to let you know that @RedditLiveBot is set to monitor all chat messages. We *do not* store or log any user messages, as this feature is for admin controls only.\n\nIf you have any issues, feel free to contact @stuntguy3000 or view the source from /source.")
                 .parseMode(ParseMode.MARKDOWN)
                 .disableWebPagePreview(true)
                 .build());
   }
 }
コード例 #2
0
  @Override
  public void onCallbackQueryReceivedEvent(CallbackQueryReceivedEvent event) {
    String ID = event.getCallbackQuery().getData();
    long userID = event.getCallbackQuery().getFrom().getId();

    RedditHandler redditHandler = instance.getRedditHandler();

    // Standard admin functionality with the prefix # representing a chat
    if (ID.contains("#")) {
      if (!instance.getConfigHandler().getBotSettings().getTelegramAdmins().contains(userID)) {
        event.getCallbackQuery().answer("You are not authorized to do this.", true);
        return;
      }

      String command = ID.split("#")[0];
      Chat chat = TelegramHook.getBot().getChat(ID.split("#")[1]);

      if (command.equals(AdminInlineCommandType.START_FOLLOW.getCommandID())) {
        /** Start following a live feed */
        Message message =
            chat.sendMessage(
                SendableTextMessage.builder()
                    .message(
                        "*Please reply to this message with the live feed you would like to follow.*\n\n"
                            + "Syntax: `<ID> [title]`")
                    .parseMode(ParseMode.MARKDOWN)
                    .build());

        instance
            .getAdminControlHandler()
            .addReplyMessage(message, AdminInlineCommandType.START_FOLLOW);
      } else if (command.equals(AdminInlineCommandType.STOP_FOLLOW.getCommandID())) {
        /** Stop following */
        redditHandler.unfollowLiveThread(true);

        chat.sendMessage(
            SendableTextMessage.builder()
                .message("*Silently stopped following any current live threads.*")
                .parseMode(ParseMode.MARKDOWN)
                .build());
      } else if (command.equals(AdminInlineCommandType.SHOW_SUBS.getCommandID())) {
        /** Show all subscribers */
        ArrayList<Subscriber> subscriptions =
            RedditLiveBot.instance.getSubscriptionHandler().getSubscriptions();

        List<String> subList = new ArrayList<>();

        for (Subscriber subscriber : subscriptions) {
          subList.add(subscriber.getUserID() + " - " + subscriber.getUsername());
        }

        PaginatedMessage paginatedMessage =
            RedditLiveBot.instance.getPaginationHandler().createPaginatedMessage(subList, 15);

        paginatedMessage.setMessage(
            chat.sendMessage(
                SendableTextMessage.builder()
                    .message(paginatedMessage.getPaginatedList().getCurrentPageContent())
                    .replyMarkup(paginatedMessage.getButtons())
                    .parseMode(ParseMode.NONE)
                    .disableWebPagePreview(true)
                    .build()));
      } else if (command.equals(AdminInlineCommandType.ENABLE_DEBUG.getCommandID())) {
        /** Enable debug mode */
        RedditLiveBot.DEBUG = true;
        RedditLiveBot.instance.getConfigHandler().saveConfigs();

        chat.sendMessage(
            SendableTextMessage.builder()
                .message("*Enabled debug mode.*")
                .parseMode(ParseMode.MARKDOWN)
                .build());
      } else if (command.equals(AdminInlineCommandType.DISABLE_DEBUG.getCommandID())) {
        /** Disable debug mode */
        RedditLiveBot.DEBUG = false;
        RedditLiveBot.instance.getConfigHandler().saveConfigs();

        chat.sendMessage(
            SendableTextMessage.builder()
                .message("*Disabled debug mode.*")
                .parseMode(ParseMode.MARKDOWN)
                .build());
      } else if (command.equals(AdminInlineCommandType.BROADCAST.getCommandID())) {
        /** Broadcast a message to all subscribers and the channel */
        Message message =
            chat.sendMessage(
                SendableTextMessage.builder()
                    .message(
                        "*Please reply to this message with the content you would like to Broadcast.*")
                    .parseMode(ParseMode.MARKDOWN)
                    .build());

        instance
            .getAdminControlHandler()
            .addReplyMessage(message, AdminInlineCommandType.BROADCAST);
      } else if (command.equals(AdminInlineCommandType.RESTART.getCommandID())) {
        /** Restart the bot */
        chat.sendMessage(
            SendableTextMessage.builder()
                .message("*Restarting...*")
                .parseMode(ParseMode.MARKDOWN)
                .build());

        instance.shutdown();
      }

      event.getCallbackQuery().answer("", false);
      return;
    } else if (ID.startsWith("f,") || ID.startsWith("fS,")) {
      /** Feed Following */
      if (!instance.getConfigHandler().getBotSettings().getTelegramAdmins().contains(userID)) {
        event.getCallbackQuery().answer("You are not authorized to do this.", true);
        return;
      }

      boolean silent = ID.startsWith("fS,");

      /** Manually follow a feed */
      String threadID = ID.split(",")[1];
      Message sentMessage = instance.getAdminControlHandler().getUpdateMessages().get(threadID);

      Lang.sendDebug(sentMessage.getChat().getId() + " | CHATNAME");

      redditHandler.followLiveThread(threadID, silent);

      String threadInformation =
          "*Reddit Live Thread*\n\n"
              + "*Thread ID:* "
              + threadID
              + "\n"
              + "*Thread URL:* https://reddit.com/live/"
              + threadID
              + "\n"
              + "*Now following this live feed.*";

      TelegramHook.getBot()
          .editMessageText(sentMessage, threadInformation, ParseMode.MARKDOWN, true, null);

      event.getCallbackQuery().answer("", false);
      return;
    } else if (ID.startsWith("usrSubscribe:")) {
      /** User Subscriptions */
      String userToSubscribe = ID.split(":")[1];
      Chat chat = TelegramHook.getBot().getChat(userToSubscribe);

      RedditLiveBot.instance.getSubscriptionHandler().subscribeChat(chat);
      event.getCallbackQuery().answer("You have subscribed to @RedditLiveBot", false);
    } else {
      /** Pagination via UUID */
      String action;
      UUID uuid;

      try {
        uuid = UUID.fromString(ID.split("\\|")[0]);
        action = ID.split("\\|")[1];

        PaginatedMessage paginatedMessage =
            RedditLiveBot.instance.getPaginationHandler().getMessage(uuid);

        if (paginatedMessage != null) {
          String content;
          switch (action) {
            case "next":
              {
                content = paginatedMessage.getPaginatedList().switchToNextPage();
                break;
              }
            case "prev":
              {
                content = paginatedMessage.getPaginatedList().switchToPreviousPage();
                break;
              }
            case "ignore":
              {
                event.getCallbackQuery().answer("Use Next or Previous to navigate.", true);
                return;
              }
            default:
              {
                event.getCallbackQuery().answer("Unable to continue! Contact @stuntguy3000", true);
                return;
              }
          }

          TelegramHook.getBot()
              .editMessageText(
                  paginatedMessage.getMessage(),
                  content,
                  ParseMode.NONE,
                  false,
                  paginatedMessage.getButtons());
          return;
        }
      } catch (Exception ignore) {

      }
    }

    event.getCallbackQuery().answer("Unknown action! Button ID: " + ID, true);
  }