本文整理汇总了Java中org.telegram.telegrambots.api.objects.Update.hasMessage方法的典型用法代码示例。如果您正苦于以下问题:Java Update.hasMessage方法的具体用法?Java Update.hasMessage怎么用?Java Update.hasMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.telegram.telegrambots.api.objects.Update
的用法示例。
在下文中一共展示了Update.hasMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MessageHandle
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
public static void MessageHandle(TelegramBot tgb, Update msg){
MessageHandle.msg = msg;
MessageHandle.tgb = tgb;
if(msg.hasMessage()){
if(msg.getMessage().hasText()){
switch(msg.getMessage().getText().toUpperCase()){
case "IV":
showIV();
break;
case "GAMEID":
showGameId();
break;
}
}
}
}
示例2: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
public void onUpdateReceived(Update update) {
if (update.hasMessage() && update.getMessage().hasPhoto()) {
Message message = update.getMessage();
long chatId = message.getChatId();
// get the last photo - it seems to be the bigger one
List<PhotoSize> photos = message.getPhoto();
PhotoSize photo = photos.get(photos.size() - 1);
String id = photo.getFileId();
try {
GetFile getFile = new GetFile();
getFile.setFileId(id);
String filePath = getFile(getFile).getFileUrl(getBotToken());
// TODO: cache images?
logger.info("== DOWNLOADING IMAGE " + filePath);
URL url = new URL(filePath);
String caption = Classifier.classify(url.openStream());
logger.info("Caption for image " + filePath + ":\n" + caption);
sendPhotoMessage(chatId, id, caption);
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例3: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的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);
}
}
}
}
示例4: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public synchronized void onUpdateReceived(final Update update) {
if (update.hasMessage()) {
final Message message = update.getMessage();
Thread processThread = new Thread(() -> {
TgContextHolder.setupContext(message);
TgContext tgContext = TgContextHolder.currentContext();
synchronized (tgContext) {
try {
messageHandler.handleMessage(message, tgContext);
}catch (TgBotMessageHandleException e) {
send(tgContext.getChatId(), e.getMessage());
}
}
});
processThread.setName("TgRequest");
processThread.setDaemon(true);
processThread.start();
}
}
示例5: MessageHandle
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
public static void MessageHandle(TelegramBot tgb, Update msg){
MessageHandle.msg = msg;
MessageHandle.tgb = tgb;
if(msg.getMessage().getFrom().getId() == 123078226){
if(msg.hasMessage()){
if(msg.getMessage().hasText()){
String line = msg.getMessage().getText().replace(" ", "");
Pattern r = Pattern.compile("\\-*[0-9]+\\.[0-9]+,\\-*[0-9]+\\.[0-9]+");
if (r.matcher(line).find()) {
String[] pinfo = line.split(",");
try {
double x,y;
NumberFormat df = NumberFormat.getNumberInstance();
df.setMaximumFractionDigits(6);
x = Float.parseFloat(df.format(Float.parseFloat(pinfo[0])));
y = Float.parseFloat(df.format(Float.parseFloat(pinfo[1])));
findMon(Example.go.get(0),x,y);
}catch(Exception ex){}
}
switch(msg.getMessage().getText().toUpperCase()){
case "IV":
showIV();
break;
case "GAMEID":
showGameId();
break;
case "STOP":
Example.go.get(0).setLocation(22.2821181,114.1510632,1);
stop();
break;
}
}
}
}
if(msg.getMessage().hasLocation()){
findMon(Example.go.get(0),msg.getMessage().getLocation().getLatitude(),msg.getMessage().getLocation().getLongitude());
}
}
示例6: MessageHandle
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
public static void MessageHandle(TelegramBot tgb, Update msg){
MessageHandle.msg = msg;
MessageHandle.tgb = tgb;
if(msg.getMessage().getFrom().getId() == 123078226){
if(msg.hasMessage()){
if(msg.getMessage().hasText()){
String line = msg.getMessage().getText().replace(" ", "");
Pattern r = Pattern.compile("\\-*[0-9]+\\.[0-9]+,\\-*[0-9]+\\.[0-9]+");
if (r.matcher(line).find()) {
String[] pinfo = line.split(",");
try {
double x,y;
NumberFormat df = NumberFormat.getNumberInstance();
df.setMaximumFractionDigits(6);
x = Float.parseFloat(df.format(Float.parseFloat(pinfo[0])));
y = Float.parseFloat(df.format(Float.parseFloat(pinfo[1])));
findMon(Example.go.get(0),x,y);
}catch(Exception ex){}
}
switch(msg.getMessage().getText().toUpperCase()){
case "IV":
showIV();
break;
case "GAMEID":
showGameId();
break;
}
}
}
}
if(msg.getMessage().hasLocation()){
findMon(Example.go.get(0),msg.getMessage().getLocation().getLatitude(),msg.getMessage().getLocation().getLongitude());
}
}
示例7: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
System.out.println(update.getMessage());
if(update.hasChannelPost()){
}
if(update.hasMessage()){
MessageHandle.MessageHandle(this,update);
}
}
示例8: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
public void onUpdateReceived(Update update) {
if(update.hasMessage()) {
Message message = update.getMessage();
String[] command = message.getText().split(" ");
if(command[0].startsWith("/") && commandHash.containsKey(command[0])) {
commandHash.get(command[0]).run(update, this);
logger.write(update);
}
else {
SendMessage sm = new SendMessage();
sm.setChatId(update.getMessage().getChatId());
sm.setParseMode(ParseMode.HTML);
sm.setText("Comando Inválido. Digite <b>/ajuda</b> para a lista de comandos.");
try {
sendMessage(sm);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
}
示例9: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
// TODO Auto-generated method stub
System.out.println("Received msg");
if (update.hasMessage() && update.getMessage().hasText()) {
String text = update.getMessage().getText().toLowerCase();
SendMessage message = new SendMessage();
message.setChatId(update.getMessage().getChatId());
//write everything in lowercase in the contains
if(text.equals("/license") || text.equals("/license"+this.getBotUsername())){
message.setText("Welcome!\nThis bot is a program which is available under the MIT license at https://github.com/Bergiu/TelegramEntenBot");
}
else if(text.contains("ente")){
message.setText("*QUACK!*");
// } else if (text.contains("bla")){
// message.setText("*BLUB!*");
// } else if (text.contains("kuh")){
// message.setText("*MUUHH!*");
}
else if(text.contains("foss")){
message.setText("*FOOOOOOOSSSS <3!*");
}else if (text.contains("git") || text.contains("love")){
message.setText("*<3*");
} else {
return;
}
message.setParseMode("markdown");
try {
sendMessage(message); // Call method to send the message
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
示例10: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage()) {
if (update.getMessage().getText().startsWith("/start")) {
startQuiz(update);
} else if (update.getMessage().getText().startsWith("/stop")) {
quizInterface.endGame(update.getMessage().getChatId());
}
} else if (update.hasCallbackQuery()) {
answerQuestion(update);
}
}
示例11: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public final void onUpdateReceived(Update update) {
if (update.hasMessage()) {
Message message = update.getMessage();
if (message.isCommand() && !filter(message)) {
if (commandRegistry.executeCommand(this, message)) {
return;
}
}
}
processNonCommandUpdate(update);
}
示例12: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
if (update.hasMessage()) {
handleMessage(update.getMessage());
} else if (update.hasCallbackQuery()) {
handleCallbackQuery(update.getCallbackQuery());
} else {
log.info("Unsupported update: {}", update.toString());
}
}
示例13: MessageHandle
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
public static void MessageHandle(TelegramBot tgb, Update msg){
MessageHandle.msg = msg;
MessageHandle.tgb = tgb;
if(msg.getMessage().getFrom().getId() == 123078226){
if(msg.hasMessage()){
if(msg.getMessage().hasText()){
String line = msg.getMessage().getText().replace(" ", "");
Pattern r = Pattern.compile("\\-*[0-9]+\\.[0-9]+,\\-*[0-9]+\\.[0-9]+");
if (r.matcher(line).find()) {
String[] pinfo = line.split(",");
try {
double x,y;
NumberFormat df = NumberFormat.getNumberInstance();
df.setMaximumFractionDigits(6);
x = Float.parseFloat(df.format(Float.parseFloat(pinfo[0])));
y = Float.parseFloat(df.format(Float.parseFloat(pinfo[1])));
findMon(Example.go.get(0),x,y);
}catch(Exception ex){}
}
switch(msg.getMessage().getText().toUpperCase()){
case "IV":
showIV();
break;
case "GAMEID":
showGameId();
break;
case "STOP":
Example.go.get(0).setLocation(22.2821181,114.1510632,1);
stop();
break;
case "CATCH":
catchMon(Example.go.get(0),msg);
}
}
}
}
if(msg.getMessage().hasLocation()){
findMon(Example.go.get(0),msg.getMessage().getLocation().getLatitude(),msg.getMessage().getLocation().getLongitude());
}
}
示例14: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
if(update.hasMessage() && update.getMessage().hasText()) {
//TODO
}
}
示例15: onUpdateReceived
import org.telegram.telegrambots.api.objects.Update; //导入方法依赖的package包/类
@Override
public void onUpdateReceived(Update update) {
if(Database.hasStudent(update.getMessage().getFrom().getId()))
try {
sendMessage(new SendMessage().setText("I am your personal school assistant!").setChatId(update.getMessage().getChatId()));
sendMessage(new SendMessage().setText("Say \"Help\" for a list of commands, or just say what you need!").setChatId(update.getMessage().getChatId()));
} catch (TelegramApiException e) {
System.err.println("Error sending welcome message:");
e.printStackTrace();
}
if(update.hasMessage() && update.getMessage().hasText() && update.getMessage().getChat().getUserName() != null /* <-- this bot isn't useful for group chats */) {
String input = update.getMessage().getText();
if(input.startsWith("/")) {
//they want to use commands
} else {
//they want the human-like assistant
}
}
}