• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java BotLogger类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: checkVersion

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
public int checkVersion() {
    int max = 0;
    try {
        final DatabaseMetaData metaData = this.currentConection.getMetaData();
        final ResultSet res = metaData.getTables(null, null, "",
                new String[]{"TABLE"});
        while (res.next()) {
            if (res.getString("TABLE_NAME").compareTo("Versions") == 0) {
                final ResultSet result = runSqlQuery("SELECT Max(Version) FROM Versions");
                while (result.next()) {
                    max = (max > result.getInt(1)) ? max : result.getInt(1);
                }
            }
        }
    } catch (SQLException e) {
        BotLogger.error(LOGTAG, e);
    }
    return max;
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:20,代码来源:ConectionDB.java


示例17: getFileAndroid

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
private String getFileAndroid(String query) {
    String result = null;
    try {
        CloseableHttpClient client = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
        HttpGet request = new HttpGet(BASEURLAndroid.replace("@language", query));
        HttpResponse response = client.execute(request);
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        String line;
        String responseString = "";
        while ((line = rd.readLine()) != null) {
            responseString += line;
        }

        if (response.getStatusLine().getStatusCode() == STATUS200) {
            result = responseString;
        }
    } catch (IOException e) {
        BotLogger.error(LOGTAG, e);
    }
    return result;
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:22,代码来源:TransifexService.java


示例18: startExecutionEveryDayAt

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
/**
 * Add a new CustomTimerTask to be executed
 *
 * @param task       Task to execute
 * @param targetHour Hour to execute it
 * @param targetMin  Minute to execute it
 * @param targetSec  Second to execute it
 */
public void startExecutionEveryDayAt(CustomTimerTask task, int targetHour, int targetMin, int targetSec) {
    BotLogger.warn(LOGTAG, "Posting new task" + task.getTaskName());
    final Runnable taskWrapper = () -> {
        try {
            task.execute();
            task.reduceTimes();
            startExecutionEveryDayAt(task, targetHour, targetMin, targetSec);
        } catch (Exception e) {
            BotLogger.severe(LOGTAG, "Bot threw an unexpected exception at TimerExecutor", e);
        }
    };
    if (task.getTimes() != 0) {
        final long delay = computNextDilay(targetHour, targetMin, targetSec);
        executorService.schedule(taskWrapper, delay, TimeUnit.SECONDS);
    }
}
 
开发者ID:rubenlagus,项目名称:TelegramBotsExample,代码行数:25,代码来源:TimerExecutor.java


示例19: execute

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

    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:comdata,项目名称:HomeAutomation,代码行数:22,代码来源:HelpCommand.java


示例20: CommandsHandler

import org.telegram.telegrambots.logging.BotLogger; //导入依赖的package包/类
/**
 * Constructor.
 */
public CommandsHandler(String user, String token) {
	this.user = user;
	this.token = token;
	register(new AuthenticateCommand());
	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:comdata,项目名称:HomeAutomation,代码行数:25,代码来源:CommandsHandler.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Snippet类代码示例发布时间:2022-05-23
下一篇:
Java NetHandlerHandshakeMemory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap