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

Java User类代码示例

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

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



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

示例1: onUpdateReceived

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
    if (update.hasMessage()) {
        Message message = update.getMessage();
        System.out.println(message);
        List<User> newUsers = update.getMessage().getNewChatMembers();
        if (newUsers != null) {
            String welcomeMessage = "Bienvenido al grupo Java Studio: ";

            for (User newUser : newUsers) {
                String user = newUser.getUserName().equals("null") ? newUser.getFirstName()
                        : "@" + newUser.getUserName();
                welcomeMessage += user + " ";
            }
            SendMessage welcomeSendMessage = new SendMessage()
                    .setChatId(message.getChatId())
                    .setText(welcomeMessage);
            try {
                sendMessage(welcomeSendMessage);
            } catch (TelegramApiException ex) {
                Logger.getLogger(CoffeeAndyBot.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }
}
 
开发者ID:Java-Studio-Telegram-Group,项目名称:Coffee_AndyBot,代码行数:27,代码来源:CoffeeAndyBot.java


示例2: setupContext

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
public static void setupContext(Message message) {
	User user = message.getFrom();
	Chat chat = message.getChat();
	Long chatId = chat.getId();

	if (!tgUserContexts.containsKey(chatId)) {
		TgContext value = new TgContext();
		value.setUser(user);
		value.setChat(chat);
		tgUserContexts.put(chatId, value);
	}

	TgContext tgContext = tgUserContexts.get(chatId);

	tgContextThreadLocal.set(tgContext);
}
 
开发者ID:enoy19,项目名称:spring-tg,代码行数:17,代码来源:TgContextHolder.java


示例3: getUser

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
/**
 * Fetches the user who caused the update.
 *
 * @param update a Telegram {@link Update}
 * @return the originating user
 * @throws IllegalStateException if the user could not be found
 */
public static User getUser(Update update) {
  if (MESSAGE.test(update)) {
    return update.getMessage().getFrom();
  } else if (CALLBACK_QUERY.test(update)) {
    return update.getCallbackQuery().getFrom();
  } else if (INLINE_QUERY.test(update)) {
    return update.getInlineQuery().getFrom();
  } else if (CHANNEL_POST.test(update)) {
    return update.getChannelPost().getFrom();
  } else if (EDITED_CHANNEL_POST.test(update)) {
    return update.getEditedChannelPost().getFrom();
  } else if (EDITED_MESSAGE.test(update)) {
    return update.getEditedMessage().getFrom();
  } else if (CHOSEN_INLINE_QUERY.test(update)) {
    return update.getChosenInlineQuery().getFrom();
  } else {
    throw new IllegalStateException("Could not retrieve originating user from update");
  }
}
 
开发者ID:addo37,项目名称:AbilityBots,代码行数:27,代码来源:AbilityUtils.java


示例4: execute

import org.telegram.telegrambots.api.objects.User; //导入依赖的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


示例5: execute

import org.telegram.telegrambots.api.objects.User; //导入依赖的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


示例6: execute

import org.telegram.telegrambots.api.objects.User; //导入依赖的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


示例7: execute

import org.telegram.telegrambots.api.objects.User; //导入依赖的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


示例8: deserializeResponse

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
@Override
public User deserializeResponse(String answer) throws TelegramApiRequestException {
    try {
        ApiResponse<User> result = OBJECT_MAPPER.readValue(answer,
                new TypeReference<ApiResponse<User>>() {
                });
        if (result.getOk()) {
            return result.getResult();
        } else {
            throw new TelegramApiRequestException("Error getting me", result);
        }
    } catch (IOException e2) {
        throw new TelegramApiRequestException("Unable to deserialize response", e2);
    }
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:16,代码来源:GetMe.java


示例9: assertFromUser

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
private void assertFromUser(User from) {
    Assert.assertNotNull(from);
    Assert.assertEquals((Integer) 1111111, from.getId());
    Assert.assertEquals("Test Lastname", from.getLastName());
    Assert.assertEquals("Test Firstname", from.getFirstName());
    Assert.assertEquals("Testusername", from.getUserName());
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:8,代码来源:TestDeserialization.java


示例10: getMeAsync

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
public void getMeAsync(SentCallback<User> sentCallback) throws TelegramApiException {
    if (sentCallback == null) {
        throw new TelegramApiException("Parameter sentCallback can not be null");
    }

    GetMe getMe = new GetMe();
    sendApiMethodAsync(getMe, sentCallback);
}
 
开发者ID:gomgomdev,项目名称:telegram-bot_misebot,代码行数:9,代码来源:AbsSender.java


示例11: ChosenInlineQuery

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
public ChosenInlineQuery(JSONObject jsonObject) {
    super();
    this.resultId = jsonObject.getString(RESULTID_FIELD);
    this.from = new User(jsonObject.getJSONObject(FROM_FIELD));
    if (jsonObject.has(LOCATION_FIELD)) {
        location = new Location(jsonObject.getJSONObject(LOCATION_FIELD));
    }
    if (jsonObject.has(INLINE_MESSAGE_ID_FIELD)) {
        inlineMessageId = jsonObject.getString(INLINE_MESSAGE_ID_FIELD);
    }
    this.query = jsonObject.getString(QUERY_FIELD);
}
 
开发者ID:gomgomdev,项目名称:telegram-bot_misebot,代码行数:13,代码来源:ChosenInlineQuery.java


示例12: InlineQuery

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
public InlineQuery(JSONObject jsonObject) {
    super();
    this.id = jsonObject.getString(ID_FIELD);
    this.from = new User(jsonObject.getJSONObject(FROM_FIELD));
    if (jsonObject.has(LOCATION_FIELD)) {
        location = new Location(jsonObject.getJSONObject(LOCATION_FIELD));
    }
    this.query = jsonObject.getString(QUERY_FIELD);
    this.offset = jsonObject.getString(OFFSET_FIELD);
}
 
开发者ID:gomgomdev,项目名称:telegram-bot_misebot,代码行数:11,代码来源:InlineQuery.java


示例13: deserializeResponse

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
@Override
public User deserializeResponse(JSONObject answer) {
    if (answer.getBoolean(Constants.RESPONSEFIELDOK)) {
        return new User(answer.getJSONObject(Constants.RESPONSEFIELDRESULT));
    }
    return null;
}
 
开发者ID:gomgomdev,项目名称:telegram-bot_misebot,代码行数:8,代码来源:GetMe.java


示例14: execute

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

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

    String userName = chat.getUserName();
    if (userName == null || userName.isEmpty()) {
        userName = user.getFirstName() + " " + user.getLastName();
    }

    StringBuilder messageTextBuilder = new StringBuilder("Hello ").append(userName);
    if (arguments != null && arguments.length > 0) {
        messageTextBuilder.append("\n");
        messageTextBuilder.append("Thank you so much for your kind words:\n");
        messageTextBuilder.append(String.join(" ", arguments));
    }

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

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


示例15: setUser

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
public void setUser(User user) {
	this.user = user;
	this.userId = user.getId();
}
 
开发者ID:enoy19,项目名称:spring-tg,代码行数:5,代码来源:TgContext.java


示例16: getUser

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
public User getUser() {
	return user;
}
 
开发者ID:enoy19,项目名称:spring-tg,代码行数:4,代码来源:TgContext.java


示例17: getFrom

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
public User getFrom() {
    return from;
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:4,代码来源:PreCheckoutQuery.java


示例18: getUser

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
public User getUser() {
    return user;
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:4,代码来源:GameHighScore.java


示例19: assertForwardFrom

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
private void assertForwardFrom(User forwardFrom) {
    Assert.assertNotNull(forwardFrom);
    Assert.assertEquals("ForwardLastname", forwardFrom.getLastName());
    Assert.assertEquals("ForwardFirstname", forwardFrom.getFirstName());
    Assert.assertEquals(Integer.valueOf(222222), forwardFrom.getId());
}
 
开发者ID:samurayrj,项目名称:rubenlagus-TelegramBots,代码行数:7,代码来源:TestDeserialization.java


示例20: TGSessionKey

import org.telegram.telegrambots.api.objects.User; //导入依赖的package包/类
public TGSessionKey(final User user, final Long chatId) {
    this.user = user;
    this.chatId = chatId;
}
 
开发者ID:SammyVimes,项目名称:gopstopbot,代码行数:5,代码来源:TGSessionKey.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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