Skip to content
This repository has been archived by the owner on Apr 8, 2020. It is now read-only.

Commit

Permalink
Fixed merge conflict, patch for null pointer usage
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarlopro committed Mar 27, 2018
2 parents b74badf + 7ac21f4 commit 47b8eb2
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 795 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ build-vs/
build-vs17/
x64/
structure
.vscode/
.vscode/
scripts/*.rst
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ project(FramebotFramework)

find_package(OpenSSL REQUIRED)

set(curl /usr/local/lib/libcurl.so)

add_subdirectory(src)
add_subdirectory(test)
Expand Down
8 changes: 7 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@ project(ExampleBots)

include_directories (${PROJECT_SOURCE_DIR}/../include)

add_definitions("-g")


add_executable(echo echo.c)
target_link_libraries(echo jansson ${curl} framebot)
target_link_libraries(echo jansson libcurl.so framebot)

add_executable(inline inline_bot.c)
target_link_libraries(inline jansson libcurl.so framebot)
53 changes: 53 additions & 0 deletions examples/inline_bot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <framebot/framebot.h>

#include <stdio.h>
#include <stdlib.h>

#ifdef _WIN32
#include <Windows.h>
#define custom_sleep(mili) Sleep(mili)
#else
#include <unistd.h>
#define custom_sleep(mili) sleep(mili/1000)
#endif

int main (int argc, char **argv) {
if (argc < 2) {
printf("Usage: ./inline BOT_TOKEN\n");
exit(-1);
}
framebot_init();

char *result = alloc_string("[{\"type\":\"sticker\",\"id\":\"1\",\"sticker_file_id\":\"CAADAQADHAADDf4xFY94M8CVYwIeAg\"}]");
Bot *inbot = framebot(argv[1]);
if(!inbot)
return -1;

Framebot *updates = get_updates(inbot, NULL, 0, 100, 0, NULL);
Update *queries = NULL;

long int last_update = 0;

while (1) {
if (updates->inline_query) {
queries = updates->inline_query;

while (queries) {
if (answer_inline_query(inbot, queries->inline_query->id, result, 0, 0, NULL, NULL, NULL)) {
printf("Answered %s!\n", queries->inline_query->from->username);
}

last_update = queries->update_id;
queries = queries->next;
}
}
custom_sleep(3000);
get_updates(inbot, updates, last_update, 100, 0, NULL);
}

bot_free(inbot);
free(result);
framebot_free(updates);

return 0;
}
4 changes: 3 additions & 1 deletion include/framebot/framebot.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@
#define HEIGHT(p) (p > 0 ? api_ltoa(p) : NULL)
#define LENGTH(p) (p > 0 ? api_ltoa(p) : NULL)

#define IF_STRING_NULL(p) (p == NULL?"null":p)

#define UPDATE_ID_LAST(x, y) (x->update_id > y->update_id ? x->update_id : y->update_id)

#include <stdlib.h>
Expand Down Expand Up @@ -488,7 +490,7 @@ Message *edit_message_reply_markup(Bot *bot, char *chat_id, long int message_id,
Message *edit_message_reply_markup_chat(Bot *bot, long int chat_id, long int message_id,
char *inline_message_id, char *reply_markup);

bool answerInlineQuery( Bot *bot, char *inline_query_id, char *results, long int cache_time, bool is_personal,
bool answer_inline_query( Bot *bot, char *inline_query_id, char *results, long int cache_time, bool is_personal,
char *next_offset, char *switch_pm_text, char *switch_pm_parameter);

#endif

0 comments on commit 47b8eb2

Please sign in to comment.