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). */
| 840 | * time we unblock, we check for completed requests (by the thread that |
| 841 | * handles Yahoo Finance API calls). */ |
| 842 | void 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 |
no test coverage detected