当前位置: 首页>>代码示例>>Java>>正文


Java BotLogger类代码示例

本文整理汇总了Java中org.telegram.telegrambots.logging.BotLogger的典型用法代码示例。如果您正苦于以下问题:Java BotLogger类的具体用法?Java BotLogger怎么用?Java BotLogger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BotLogger类属于org.telegram.telegrambots.logging包,在下文中一共展示了BotLogger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateReceived

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
@POST
@Path("/{botPath}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateReceived(@PathParam("botPath") String botPath, Update update) {
    if (callbacks.containsKey(botPath)) {
        try {
            BotApiMethod response = callbacks.get(botPath).onWebhookUpdateReceived(update);
            if (response != null) {
                response.validate();
            }
            return Response.ok(response).build();
        } catch (TelegramApiValidationException e) {
            BotLogger.severe("RESTAPI", e);
            return Response.serverError().build();
        }
    }

    return Response.status(Response.Status.NOT_FOUND).build();
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:21,代码来源:RestApi.java

示例2: Ability

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
private Ability(String name, String info, Locality locality, Privacy privacy, int argNum, Consumer<MessageContext> action, Consumer<MessageContext> postAction, List<Reply> replies, Predicate<Update>... flags) {
  checkArgument(!isEmpty(name), "Method name cannot be empty");
  checkArgument(!containsWhitespace(name), "Method name cannot contain spaces");
  checkArgument(isAlphanumeric(name), "Method name can only be alpha-numeric", name);
  this.name = name;
  this.info = info;

  this.locality = checkNotNull(locality, "Please specify a valid locality setting. Use the Locality enum class");
  this.privacy = checkNotNull(privacy, "Please specify a valid privacy setting. Use the Privacy enum class");

  checkArgument(argNum >= 0, "The number of arguments the method can handle CANNOT be negative. " +
      "Use the number 0 if the method ignores the arguments OR uses as many as appended");
  this.argNum = argNum;

  this.action = checkNotNull(action, "Method action can't be empty. Please assign a function by using .action() method");
  if (postAction == null)
    BotLogger.info(TAG, format("No post action was detected for method with name [%s]", name));

  this.flags = ofNullable(flags).map(Arrays::asList).orElse(newArrayList());

  this.postAction = postAction;
  this.replies = replies;
}
 
开发者ID:addo37,项目名称:AbilityBots,代码行数:24,代码来源:Ability.java

示例3: recover

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
@Override
public boolean recover(Object backup) {
  Map<String, Object> snapshot = localCopy();

  try {
    Map<String, Object> backupData = objectMapper.readValue(backup.toString(), new TypeReference<HashMap<String, Object>>() {
    });
    doRecover(backupData);
    return true;
  } catch (IOException e) {
    BotLogger.error(format("Could not recover DB data from file with String representation %s", backup), TAG, e);
    // Attempt to fallback to data snapshot before recovery
    doRecover(snapshot);
    return false;
  }
}
 
开发者ID:addo37,项目名称:AbilityBots,代码行数:17,代码来源:MapDBContext.java

示例4: onUpdateReceived

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
/**
 * This method contains the stream of actions that are applied on any update.
 * <p>
 * It will correctly handle addition of users into the DB and the execution of abilities and replies.
 *
 * @param update the update received by Telegram's API
 */
@Override
public void onUpdateReceived(Update update) {
  BotLogger.info(format("New update [%s] received at %s", update.getUpdateId(), now()), format("%s - %s", TAG, botUsername));
  BotLogger.info(update.toString(), TAG);
  long millisStarted = System.currentTimeMillis();

  Stream.of(update)
      .filter(this::checkGlobalFlags)
      .filter(this::checkBlacklist)
      .map(this::addUser)
      .filter(this::filterReply)
      .map(this::getAbility)
      .filter(this::validateAbility)
      .filter(this::checkPrivacy)
      .filter(this::checkLocality)
      .filter(this::checkInput)
      .filter(this::checkMessageFlags)
      .map(this::getContext)
      .map(this::consumeUpdate)
      .forEach(this::postConsumption);

  long processingTime = System.currentTimeMillis() - millisStarted;
  BotLogger.info(format("Processing of update [%s] ended at %s%n---> Processing time: [%d ms] <---%n", update.getUpdateId(), now(), processingTime), format("%s - %s", TAG, botUsername));
}
 
开发者ID:addo37,项目名称:AbilityBots,代码行数:32,代码来源:AbilityBot.java

示例5: registerAbilities

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
/**
 * Registers the declared abilities using method reflection. Also, replies are accumulated using the built abilities and standalone methods that return a Reply.
 * <p>
 * <b>Only abilities and replies with the <u>public</u> accessor are registered!</b>
 */
private void registerAbilities() {
  try {
    abilities = stream(this.getClass().getMethods())
        .filter(method -> method.getReturnType().equals(Ability.class))
        .map(this::returnAbility)
        .collect(toMap(Ability::name, identity()));

    Stream<Reply> methodReplies = stream(this.getClass().getMethods())
        .filter(method -> method.getReturnType().equals(Reply.class))
        .map(this::returnReply);

    Stream<Reply> abilityReplies = abilities.values().stream()
        .flatMap(ability -> ability.replies().stream());

    replies = Stream.concat(methodReplies, abilityReplies).collect(toList());
  } catch (IllegalStateException e) {
    BotLogger.error(TAG, "Duplicate names found while registering abilities. Make sure that the abilities declared don't clash with the reserved ones.", e);
    throw propagate(e);
  }

}
 
开发者ID:addo37,项目名称:AbilityBots,代码行数:27,代码来源:AbilityBot.java

示例6: Ability

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
@SafeVarargs
private Ability(String name, String info, Locality locality, Privacy privacy, int argNum, Consumer<MessageContext> action, Consumer<MessageContext> postAction, List<Reply> replies, Predicate<Update>... flags) {
  checkArgument(!isEmpty(name), "Method name cannot be empty");
  checkArgument(!containsWhitespace(name), "Method name cannot contain spaces");
  checkArgument(isAlphanumeric(name), "Method name can only be alpha-numeric", name);
  this.name = name;
  this.info = info;

  this.locality = checkNotNull(locality, "Please specify a valid locality setting. Use the Locality enum class");
  this.privacy = checkNotNull(privacy, "Please specify a valid privacy setting. Use the Privacy enum class");

  checkArgument(argNum >= 0, "The number of arguments the method can handle CANNOT be negative. " +
      "Use the number 0 if the method ignores the arguments OR uses as many as appended");
  this.argNum = argNum;

  this.action = checkNotNull(action, "Method action can't be empty. Please assign a function by using .action() method");
  if (postAction == null)
    BotLogger.info(TAG, format("No post action was detected for method with name [%s]", name));

  this.flags = ofNullable(flags).map(Arrays::asList).orElse(newArrayList());

  this.postAction = postAction;
  this.replies = replies;
}
 
开发者ID:rubenlagus,项目名称:TelegramBots,代码行数:25,代码来源:Ability.java

示例7: execute

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
@Override
public void execute(AbsSender absSender, User user, Chat chat, String[] strings) {
    DatabaseManager databseManager = DatabaseManager.getInstance();
    StringBuilder messageBuilder = new StringBuilder();

    String userName = user.getFirstName() + " " + user.getLastName();

    if (databseManager.getUserStateForCommandsBot(user.getId())) {
        messageBuilder.append("Hi ").append(userName).append("\n");
        messageBuilder.append("i think we know each other already!");
    } else {
        databseManager.setUserStateForCommandsBot(user.getId(), true);
        messageBuilder.append("Welcome ").append(userName).append("\n");
        messageBuilder.append("this bot will demonstrate you the command feature of the Java TelegramBots API!");
    }

    SendMessage answer = new SendMessage();
    answer.setChatId(chat.getId().toString());
    answer.setText(messageBuilder.toString());

    try {
        absSender.sendMessage(answer);
    } catch (TelegramApiException e) {
        BotLogger.error(LOGTAG, e);
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:27,代码来源:StartCommand.java

示例8: execute

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
@Override
public void execute(AbsSender absSender, User user, Chat chat, String[] arguments) {
    DatabaseManager dbManager = DatabaseManager.getInstance();

    if (dbManager.getUserStateForCommandsBot(user.getId())) {
        dbManager.setUserStateForCommandsBot(user.getId(), false);
        String userName = user.getFirstName() + " " + user.getLastName();

        SendMessage answer = new SendMessage();
        answer.setChatId(chat.getId().toString());
        answer.setText("Good bye " + userName + "\n" + "Hope to see you soon!");

        try {
            absSender.sendMessage(answer);
        } catch (TelegramApiException e) {
            BotLogger.error(LOGTAG, e);
        }
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:20,代码来源:StopCommand.java

示例9: execute

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
@Override
public void execute(AbsSender absSender, User user, Chat chat, String[] strings) {

    if (!DatabaseManager.getInstance().getUserStateForCommandsBot(user.getId())) {
        return;
    }

    StringBuilder helpMessageBuilder = new StringBuilder("<b>Help</b>\n");
    helpMessageBuilder.append("These are the registered commands for this Bot:\n\n");

    for (BotCommand botCommand : commandRegistry.getRegisteredCommands()) {
        helpMessageBuilder.append(botCommand.toString()).append("\n\n");
    }

    SendMessage helpMessage = new SendMessage();
    helpMessage.setChatId(chat.getId().toString());
    helpMessage.enableHtml(true);
    helpMessage.setText(helpMessageBuilder.toString());

    try {
        absSender.sendMessage(helpMessage);
    } catch (TelegramApiException e) {
        BotLogger.error(LOGTAG, e);
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:26,代码来源:HelpCommand.java

示例10: CommandsHandler

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
/**
 * Constructor.
 */
public CommandsHandler() {
    register(new HelloCommand());
    register(new StartCommand());
    register(new StopCommand());
    HelpCommand helpCommand = new HelpCommand(this);
    register(helpCommand);

    registerDefaultAction((absSender, message) -> {
        SendMessage commandUnknownMessage = new SendMessage();
        commandUnknownMessage.setChatId(message.getChatId());
        commandUnknownMessage.setText("The command '" + message.getText() + "' is not known by this bot. Here comes some help " + Emoji.AMBULANCE);
        try {
            absSender.sendMessage(commandUnknownMessage);
        } catch (TelegramApiException e) {
            BotLogger.error(LOGTAG, e);
        }
        helpCommand.execute(absSender, message.getFrom(), message.getChat(), new String[] {});
    });
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:23,代码来源:CommandsHandler.java

示例11: processNonCommandUpdate

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
@Override
public void processNonCommandUpdate(Update update) {

    if (update.hasMessage()) {
        Message message = update.getMessage();

        if (!DatabaseManager.getInstance().getUserStateForCommandsBot(message.getFrom().getId())) {
            return;
        }

        if (message.hasText()) {
            SendMessage echoMessage = new SendMessage();
            echoMessage.setChatId(message.getChatId());
            echoMessage.setText("Hey heres your message:\n" + message.getText());

            try {
                sendMessage(echoMessage);
            } catch (TelegramApiException e) {
                BotLogger.error(LOGTAG, e);
            }
        }
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:24,代码来源:CommandsHandler.java

示例12: onWaitingChannelMessage

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
private void onWaitingChannelMessage(Message message) throws InvalidObjectException {
    try {
        if (message.getText().equals(CANCEL_COMMAND)) {
            userState.remove(message.getFrom().getId());
            sendHelpMessage(message.getChatId(), message.getMessageId(), null);
        } else {
            if (message.getText().startsWith("@") && !message.getText().trim().contains(" ")) {
                sendMessage(getMessageToChannelSent(message));
                sendMessageToChannel(message.getText(), message);
                userState.remove(message.getFrom().getId());
            } else {
                sendMessage(getWrongUsernameMessage(message));
            }
        }
    } catch (TelegramApiException e) {
        BotLogger.error(LOGTAG, e);
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:19,代码来源:ChannelHandlers.java

示例13: sendHelpMessage

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
private void sendHelpMessage(Long chatId, Integer messageId, ReplyKeyboardMarkup replyKeyboardMarkup) {
    SendMessage sendMessage = new SendMessage();
    sendMessage.enableMarkdown(true);
    sendMessage.setChatId(chatId);
    sendMessage.setReplyToMessageId(messageId);
    if (replyKeyboardMarkup != null) {
        sendMessage.setReplyMarkup(replyKeyboardMarkup);
    }

    sendMessage.setText(HELP_TEXT);
    try {
        sendMessage(sendMessage);
    } catch (TelegramApiException e) {
        BotLogger.error(LOGTAG, e);
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:17,代码来源:ChannelHandlers.java

示例14: onSetLanguageCommand

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
private void onSetLanguageCommand(Message message, String language) throws InvalidObjectException {
    SendMessage sendMessageRequest = new SendMessage();
    sendMessageRequest.setChatId(message.getChatId());
    ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
    List<LocalisationService.Language> languages = LocalisationService.getSupportedLanguages();
    List<KeyboardRow> commands = new ArrayList<>();
    for (LocalisationService.Language languageItem : languages) {
        KeyboardRow commandRow = new KeyboardRow();
        commandRow.add(languageItem.getCode() + " --> " + languageItem.getName());
        commands.add(commandRow);
    }
    replyKeyboardMarkup.setResizeKeyboard(true);
    replyKeyboardMarkup.setOneTimeKeyboard(true);
    replyKeyboardMarkup.setKeyboard(commands);
    replyKeyboardMarkup.setSelective(true);
    sendMessageRequest.setReplyMarkup(replyKeyboardMarkup);
    sendMessageRequest.setText(LocalisationService.getString("chooselanguage", language));
    try {
        sendMessage(sendMessageRequest);
        languageMessages.add(message.getFrom().getId());
    } catch (TelegramApiException e) {
        BotLogger.error(LOGTAG, e);
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:25,代码来源:DirectionsHandlers.java

示例15: onLanguageSelected

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
private void onLanguageSelected(Message message) throws InvalidObjectException {
    String[] parts = message.getText().split("-->", 2);
    SendMessage sendMessageRequest = new SendMessage();
    sendMessageRequest.setChatId(message.getChatId());
    if (LocalisationService.getLanguageByCode(parts[0].trim()) != null) {
        DatabaseManager.getInstance().putUserLanguage(message.getFrom().getId(), parts[0].trim());
        sendMessageRequest.setText(LocalisationService.getString("languageModified", parts[0].trim()));
    } else {
        sendMessageRequest.setText(LocalisationService.getString("errorLanguage"));
    }
    sendMessageRequest.setReplyToMessageId(message.getMessageId());
    ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove();
    replyKeyboardRemove.setSelective(true);
    sendMessageRequest.setReplyMarkup(replyKeyboardRemove);
    try {
        sendMessage(sendMessageRequest);
        languageMessages.remove(message.getFrom().getId());
    } catch (TelegramApiException e) {
        BotLogger.error(LOGTAG, e);
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:22,代码来源:DirectionsHandlers.java


注:本文中的org.telegram.telegrambots.logging.BotLogger类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。