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


Java TelegramBot类代码示例

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


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

示例1: MessageImpl

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private MessageImpl(JSONObject jsonObject, TelegramBot telegramBot) {

        if (!jsonObject.isNull("result")) jsonObject = jsonObject.getJSONObject("result");

        jsonMessage = jsonObject;

        message_id = jsonObject.getInt("message_id");
        from = UserImpl.createUser(jsonObject.optJSONObject("from"));
        date = jsonObject.getLong("date");
        chat = ChatImpl.createChat(jsonObject.getJSONObject("chat"), telegramBot);
        forward_from = UserImpl.createUser(jsonObject.optJSONObject("forward_from"));
        forward_from_chat = ChatImpl.createChat(jsonObject.optJSONObject("forward_from_chat"), telegramBot);
        forward_from_message_id = jsonObject.optInt("forward_from_message_id");
        forward_date = jsonObject.optLong("forward_date");
        reply_to_message = MessageImpl.createMessage(jsonObject.optJSONObject("reply_to_message"), telegramBot);
        edit_date = jsonObject.optLong("edit_date");
        content = ContentImpl.createContent(jsonObject, telegramBot);

        this.telegramBot = telegramBot;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:21,代码来源:MessageImpl.java

示例2: ReddigramBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
ReddigramBot() throws Exception {
    timer = new Timer();
    config = BotConfig.configFromFile(new File("config.json"));
    dataFile = DataFile.load(this);
    client = new RedditClient(UserAgent.of("server", "xyz.mkotb.reddigram", "1.0", config.redditUsername()));
    telegramBot = TelegramBot.login(config.botApiKey());
    liveManager = new LiveManager(this);

    telegramBot.getEventsManager().register(new InlineListener(this));
    telegramBot.getEventsManager().register(new CommandListener(this));
    telegramBot.startUpdates(true);
    log("Successfully logged in");

    timer.scheduleAtFixedRate(new OAuthTask(this), 0L, 3500000L); // every 58 minutes reauth.
    timer.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            if (dataFile != null) {
                dataFile.save();
            }
        }
    }, 0L, 600000L); // every 10m save data file
}
 
开发者ID:mkotb,项目名称:Reddigram,代码行数:24,代码来源:ReddigramBot.java

示例3: EchoBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public EchoBot() {

        //This returns a logged in TelegramBot instance or null if the API key was invalid.
        telegramBot = TelegramBot.login(API_KEY);
        //This registers the EchoListener Listener to this bot.
        telegramBot.getEventsManager().register(new EchoListener(telegramBot));
        //This method starts the retrieval of updates.
        //The boolean it accepts is to specify whether to retrieve messages
        //which were sent before the bot was started but after the bot was last turned off.
        telegramBot.startUpdates(false);

        //The following while(true) loop is simply for keeping the java application alive.
        //You can do this however you like, but none of the above methods are blocking and
        //so without this code the bot would simply boot then exit.
        while (true) {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API-Examples,代码行数:23,代码来源:EchoBot.java

示例4: InlineTranslationBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public InlineTranslationBot() {

        //This returns a logged in TelegramBot instance or null if the API key was invalid.
        telegramBot = TelegramBot.login(API_KEY);
        //This registers the FormattingListener Listener to this bot.
        telegramBot.getEventsManager().register(new InlineTranslationListener(telegramBot));
        //This method starts the retrieval of updates.
        //The boolean it accepts is to specify whether to retrieve messages
        //which were sent before the bot was started but after the bot was last turned off.
        telegramBot.startUpdates(false);

        //The following while(true) loop is simply for keeping the java application alive.
        //You can do this however you like, but none of the above methods are blocking and
        //so without this code the bot would simply boot then exit.
        while (true) {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API-Examples,代码行数:23,代码来源:InlineTranslationBot.java

示例5: InlineSpoilerBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public InlineSpoilerBot() {

        instance = this;

        //This returns a logged in TelegramBot instance or null if the API key was invalid.
        telegramBot = TelegramBot.login(API_KEY);
        //This registers the SpoilerListener Listener to this bot.
        initSpoilerManager();
        telegramBot.getEventsManager().register(listener);
        //This method starts the retrieval of updates.
        //The boolean it accepts is to specify whether to retrieve messages
        //which were sent before the bot was started but after the bot was last turned off.
        telegramBot.startUpdates(false);

        //The following while(true) loop is simply for keeping the java application alive.
        //You can do this however you like, but none of the above methods are blocking and
        //so without this code the bot would simply boot then exit.
        while (true) {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API-Examples,代码行数:26,代码来源:InlineSpoilerBot.java

示例6: FormattingBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public FormattingBot() {

        //This returns a logged in TelegramBot instance or null if the API key was invalid.
        telegramBot = TelegramBot.login(API_KEY);
        //This registers the FormattingListener Listener to this bot.
        telegramBot.getEventsManager().register(new FormattingListener(telegramBot));
        //This method starts the retrieval of updates.
        //The boolean it accepts is to specify whether to retrieve messages
        //which were sent before the bot was started but after the bot was last turned off.
        telegramBot.startUpdates(false);

        //The following while(true) loop is simply for keeping the java application alive.
        //You can do this however you like, but none of the above methods are blocking and
        //so without this code the bot would simply boot then exit.
        while (true) {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API-Examples,代码行数:23,代码来源:FormattingBot.java

示例7: processReplyContent

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
/**
 * This does generic processing of ReplyingOptions objects when sending a request to the API
 *
 * @param multipartBody     The MultipartBody that the ReplyingOptions content should be appended to
 * @param replyingOptions   The ReplyingOptions that were used in this request
 */
public static void processReplyContent(MultipartBody multipartBody, ReplyingOptions replyingOptions) {

    if (replyingOptions.getReplyTo() != 0)
        multipartBody.field("reply_to_message_id", String.valueOf(replyingOptions.getReplyTo()), "application/json; charset=utf8;");
    if (replyingOptions.getReplyMarkup() != null) {

        switch (replyingOptions.getReplyMarkup().getType()) {

            case FORCE_REPLY:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ForceReply.class), "application/json; charset=utf8;");
                break;
            case KEYBOARD_HIDE:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardHide.class), "application/json; charset=utf8;");
                break;
            case KEYBOARD_REMOVE:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardRemove.class), "application/json; charset=utf8;");
                break;
            case KEYBOARD_MARKUP:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), ReplyKeyboardMarkup.class), "application/json; charset=utf8;");
                break;
            case INLINE_KEYBOARD_MARKUP:
                multipartBody.field("reply_markup", TelegramBot.GSON.toJson(replyingOptions.getReplyMarkup(), InlineKeyboardMarkup.class), "application/json; charset=utf8;");
                break;
        }
    }
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:33,代码来源:Utils.java

示例8: createChat

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public static Chat createChat(JSONObject jsonObject, TelegramBot telegramBot) {

        if(jsonObject != null) {

            String chatType = jsonObject.getString("type");

            switch (chatType) {

                case "private":
                    return IndividualChatImpl.createIndividualChat(jsonObject, telegramBot);
                case "group":
                    return GroupChatImpl.createGroupChat(jsonObject, telegramBot);
                case "channel":
                    return ChannelChatImpl.createChannelChat(jsonObject, telegramBot);
                case "supergroup":
                    return SuperGroupChatImpl.createSuperGroupChat(jsonObject, telegramBot);
                default:
                    System.err.println("An invalid chat type was provided when creating a chat object. Chat type " + chatType + " was provided. Report this to @zackpollard.");
            }
        }

        return null;
    }
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:24,代码来源:ChatImpl.java

示例9: getFileDownloadLink

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
/**
 * Gets the download link for this file
 *
 * @param telegramBot The TelegramBot instance that relates to this file
 *
 * @return The URL to download the file in String form
 */
default String getFileDownloadLink(TelegramBot telegramBot) {

    JSONObject jsonObject = null;

    try {
        jsonObject = Unirest.post(telegramBot.getBotAPIUrl() + "getFile")
                .field("file_id", getFileId(), "application/json; charset=utf8;")
                .asJson().getBody().getObject();
    } catch (UnirestException e) {
        e.printStackTrace();
    }

    if (jsonObject != null) {

        if (jsonObject.getBoolean("ok")) {

            return "https://api.telegram.org/file/bot" + telegramBot.getAuthToken() + "/" + jsonObject.getJSONObject("result").getString("file_path");
        }
    }

    return null;
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:30,代码来源:File.java

示例10: downloadFile

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
/**
 * Downloads the file to a set location on disk
 *
 * @param telegramBot       The TelegramBot instance that relates to this file
 * @param downloadLocation  A File object pointing to the location where you want to download the file
 *
 * @return A File object that points to the downloaded file
 */
default java.io.File downloadFile(TelegramBot telegramBot, java.io.File downloadLocation) {

    String downloadLink = getFileDownloadLink(telegramBot);

    if (downloadLink != null) {

        try {
            FileUtils.copyURLToFile(new URL(downloadLink), downloadLocation);
        } catch (IOException e) {

            System.err.println("The file download failed due to the provided URL being malformed in some way. Provided URL was " + downloadLink);
        }
    }

    return downloadLocation;
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:25,代码来源:File.java

示例11: RemindMeBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private RemindMeBot(String key) {
    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    instance = this;
    this.bot = TelegramBot.login(key);
    bot.getEventsManager().register(new RemindMeBotListener());
    bot.startUpdates(false);
    storageHook = new StorageHook();
    reminderManager = new ReminderManager();

    //Save reminder map on shutdown to ensure persistence of reminders
    Runtime.getRuntime().addShutdownHook(new Thread(storageHook::save));

    this.debug("Bot started!");
}
 
开发者ID:bo0tzz,项目名称:RemindMeBot,代码行数:15,代码来源:RemindMeBot.java

示例12: WhatIsBot

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
public WhatIsBot(String key) {
    System.out.println("Initialising bot");
    bot = TelegramBot.login(key);
    if (bot == null) {
        System.out.println("Failed to login! Faulty API key?");
        System.exit(1);
    }
    System.out.println("Registering events");
    bot.getEventsManager().register(new WhatIsBotListener(this));
    bot.startUpdates(false);
    System.out.println("Bot initialised!");
}
 
开发者ID:bo0tzz,项目名称:WhatIsBot,代码行数:13,代码来源:WhatIsBot.java

示例13: Conversation

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private Conversation(TelegramBot bot, Map<String, Object> sessionData, Chat forWhom, boolean silent,
                    boolean disableGlobalEvents, List<ConversationPrompt> prompts,
                     Predicate<User> userPredicate, boolean repliesOnly,
                     BiConsumer<Conversation, ConversationContext> endCallback,
                     BiPredicate<ConversationContext, Content> endPredicate,
                     long timeout, SendableMessage timeoutMessage) {
    this.forWhom = forWhom;
    this.context = new ConversationContext(this, bot, sessionData);
    this.currentPrompt = prompts.get(promptIndex);
    this.prompts = Collections.unmodifiableList(prompts);
    this.silent = silent;
    this.disableGlobalEvents = disableGlobalEvents;
    this.userPredicate = (userPredicate == null) ? (user) -> true : userPredicate;
    this.repliesOnly = repliesOnly;
    this.endCallback = endCallback;
    this.endPredicate = endPredicate;

    if (timeout > 0) {
        TIMER.schedule(new TimerTask() {
            @Override
            public void run() {
                if (isVirgin()) {
                    if (timeoutMessage != null) {
                        sendMessage(timeoutMessage);
                    }

                    end();
                }
            }
        }, TimeUnit.SECONDS.toMillis(timeout));
    }
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:33,代码来源:Conversation.java

示例14: ConversationRegistryImpl

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private ConversationRegistryImpl(TelegramBot bot) {
    bot.getEventsManager().register(new Listener() {
        @Override
        @Event.Handler(ignoreCancelled = true, priority = Event.Priority.LOWEST)
        public void onMessageReceived(MessageReceivedEvent event) {
            if (processMessage(event.getMessage())) {
                event.setCancelled(true);
            }
        }
    });
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:12,代码来源:ConversationRegistryImpl.java

示例15: InlineMenuRegistryImpl

import pro.zackpollard.telegrambot.api.TelegramBot; //导入依赖的package包/类
private InlineMenuRegistryImpl(TelegramBot bot) {
    bot.getEventsManager().register(new Listener() {
        @Event.Handler(ignoreCancelled = true, priority = Event.Priority.LOWEST)
        @Override
        public void onCallbackQueryReceivedEvent(CallbackQueryReceivedEvent event) {
            if (process(event.getCallbackQuery())) {
                event.setCancelled(true);
            }
        }
    });
}
 
开发者ID:zackpollard,项目名称:JavaTelegramBot-API,代码行数:12,代码来源:InlineMenuRegistryImpl.java


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