MCPcopy Create free account
hub / github.com/antirez/botlib / botMain

Function botMain

botlib.c:842–857  ·  view source on GitHub ↗

This is the bot main loop: we get messages using getUpdates in blocking * mode, but with a timeout. Then we serve requests as needed, and every * time we unblock, we check for completed requests (by the thread that * handles Yahoo Finance API calls). */

Source from the content-addressed store, hash-verified

840 * time we unblock, we check for completed requests (by the thread that
841 * handles Yahoo Finance API calls). */
842void botMain(void) {
843 int64_t nextid = -100; /* Start getting the last 100 messages. */
844 int previd;
845
846 botGetUsername(); // Will cache Bot.username as side effect.
847 while(1) {
848 previd = nextid;
849 nextid = botProcessUpdates(nextid,1);
850 /* We don't want to saturate all the CPU in a busy loop in case
851 * the above call fails and returns immediately (for networking
852 * errors for instance), so wait a bit at every cycle, but only
853 * if we didn't made any progresses with the ID. */
854 if (nextid == previd) usleep(100000);
855 if (Bot.cron_callback) Bot.cron_callback(DbHandle);
856 }
857}
858
859/* Check if a file named 'apikey.txt' exists, if so load the Telegram bot
860 * API key from there. If the function is able to read the API key from

Callers 1

startBotFunction · 0.85

Calls 2

botGetUsernameFunction · 0.85
botProcessUpdatesFunction · 0.85

Tested by

no test coverage detected