From d74906c3351bc2150c508341ca74d547d619edb3 Mon Sep 17 00:00:00 2001 From: Rodgger Bruno Date: Wed, 6 Jun 2018 02:13:47 -0400 Subject: [PATCH] authentic Framebot to framebot_init framrbot_init(token) --- examples/echo.c | 4 +--- examples/inline_bot.c | 3 +-- include/framebot/framebot.h | 3 +-- src/framebot.c | 12 +++++++----- test/test_chat.c | 3 +-- test/test_file.c | 3 +-- test/test_payments.c | 3 +-- test/test_sendaudio.c | 3 +-- test/test_senddocument.c | 3 +-- test/test_sendmessage.c | 3 +-- test/test_sendphotos.c | 3 +-- test/test_sendvideo.c | 3 +-- test/test_sendvideonote.c | 3 +-- test/test_sendvoice.c | 3 +-- test/test_update.c | 4 +--- test/test_userprofilephotos.c | 3 +-- 16 files changed, 22 insertions(+), 37 deletions(-) diff --git a/examples/echo.c b/examples/echo.c index 19ba40d..1e4ee38 100644 --- a/examples/echo.c +++ b/examples/echo.c @@ -12,9 +12,7 @@ int main (int argc, char **argv) { Framebot *frame_update; Update *message, *temp; - framebot_init(); - - echo = framebot(argv[1]); + echo = framebot_init(argv[1]); frame_update = get_updates(echo, NULL, last_offset, 100, 0, NULL); diff --git a/examples/inline_bot.c b/examples/inline_bot.c index 5b0534a..c58951c 100644 --- a/examples/inline_bot.c +++ b/examples/inline_bot.c @@ -16,10 +16,9 @@ int main (int argc, char **argv) { 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]); + Bot *inbot = framebot_init(argv[1]); if(!inbot) return -1; diff --git a/include/framebot/framebot.h b/include/framebot/framebot.h index e6e08d6..2839417 100644 --- a/include/framebot/framebot.h +++ b/include/framebot/framebot.h @@ -313,8 +313,7 @@ typedef int32_t bool; #include -void framebot_init(); -Bot * framebot(const char *token); +Bot * framebot_init(const char *token); refjson *generic_method_call (const char *token, char *formats, ...); Error * show_error(); diff --git a/src/framebot.c b/src/framebot.c index 6d9e06c..60db484 100644 --- a/src/framebot.c +++ b/src/framebot.c @@ -33,17 +33,19 @@ char *parse_mode[3] = "" }; -void framebot_init () { - network_init(); -} - /** * Authentic bot token */ -Bot * framebot (const char *token) { +Bot * framebot_init (const char *token) { + static bool net = 0; Bot *obot = bot(token, NULL); + if(net == 0){ + network_init(); + net = 1; + } + User *bot_user = get_me(obot); if (bot_user) { diff --git a/test/test_chat.c b/test/test_chat.c index 8ed409d..cf5b558 100644 --- a/test/test_chat.c +++ b/test/test_chat.c @@ -191,14 +191,13 @@ int _func(){ } int main(int argc, char *argv[]){ - framebot_init(); if(argc < 4){ fprintf(stderr, "sendvideonote "); exit(-1); } - _bot = framebot(argv[1]); + _bot = framebot_init(argv[1]); if(!_bot){ fprintf(stderr, "ERROR authentic"); exit(-1); diff --git a/test/test_file.c b/test/test_file.c index cdd8b50..725bf28 100644 --- a/test/test_file.c +++ b/test/test_file.c @@ -46,14 +46,13 @@ int _file(){ int main(int argc, char *argv[]){ - framebot_init(); if(argc < 4){ fprintf(stderr, "file "); exit(-1); } - _bot = framebot(argv[1]); + _bot = framebot_init(argv[1]); if(!_bot){ fprintf(stderr, "ERROR authentic"); exit(-1); diff --git a/test/test_payments.c b/test/test_payments.c index 5c7f47f..ab2fc62 100644 --- a/test/test_payments.c +++ b/test/test_payments.c @@ -267,14 +267,13 @@ void test_invoice(){ int main(int argc, char *argv[]){ - framebot_init(); if(argc < 4){ fprintf(stderr, "payments "); exit(-1); } - _bot = framebot(argv[1]); + _bot = framebot_init(argv[1]); if(!_bot){ fprintf(stderr, "ERROR authentic"); exit(-1); diff --git a/test/test_sendaudio.c b/test/test_sendaudio.c index 71f615e..1dcf20d 100644 --- a/test/test_sendaudio.c +++ b/test/test_sendaudio.c @@ -146,14 +146,13 @@ int _audio(){ int main(int argc, char *argv[]){ - framebot_init(); if(argc < 4){ fprintf(stderr, "sendaudio "); exit(-1); } - _bot = framebot(argv[1]); + _bot = framebot_init(argv[1]); if(!_bot){ fprintf(stderr, "ERROR authentic"); exit(-1); diff --git a/test/test_senddocument.c b/test/test_senddocument.c index 3cf8dc3..dd33e14 100644 --- a/test/test_senddocument.c +++ b/test/test_senddocument.c @@ -118,14 +118,13 @@ void _free(Framebot *update){ int main(int argc, char *argv[]){ - framebot_init(); if(argc < 4){ fprintf(stderr, "sendvideonote "); exit(-1); } - _bot = framebot(argv[1]); + _bot = framebot_init(argv[1]); if(!_bot){ fprintf(stderr, "ERROR authentic"); exit(-1); diff --git a/test/test_sendmessage.c b/test/test_sendmessage.c index b4a4149..e6e3e23 100644 --- a/test/test_sendmessage.c +++ b/test/test_sendmessage.c @@ -119,14 +119,13 @@ int _message(){ } int main(int argc, char *argv[]){ - framebot_init(); if(argc < 4){ fprintf(stderr, "sendphoto "); exit(-1); } - _bot = framebot(argv[1]); + _bot = framebot_init(argv[1]); if(!_bot){ fprintf(stderr, "ERROR authentic"); exit(-1); diff --git a/test/test_sendphotos.c b/test/test_sendphotos.c index 472594a..cfde69a 100644 --- a/test/test_sendphotos.c +++ b/test/test_sendphotos.c @@ -96,14 +96,13 @@ int _photo(){ } int main(int argc, char *argv[]){ - framebot_init(); if(argc < 4){ fprintf(stderr, "sendphoto "); exit(-1); } - _bot = framebot(argv[1]); + _bot = framebot_init(argv[1]); if(!_bot){ fprintf(stderr, "ERROR authentic"); exit(-1); diff --git a/test/test_sendvideo.c b/test/test_sendvideo.c index 824231b..8cf1d5f 100644 --- a/test/test_sendvideo.c +++ b/test/test_sendvideo.c @@ -179,14 +179,13 @@ int _video(){ } int main(int argc, char *argv[]){ - framebot_init(); if(argc < 4){ fprintf(stderr, "sendvideonote "); exit(-1); } - _bot = framebot(argv[1]); + _bot = framebot_init(argv[1]); if(!_bot){ fprintf(stderr, "ERROR authentic"); exit(-1); diff --git a/test/test_sendvideonote.c b/test/test_sendvideonote.c index 4d7406b..a8ae8a5 100644 --- a/test/test_sendvideonote.c +++ b/test/test_sendvideonote.c @@ -114,14 +114,13 @@ int _videonote(){ } int main(int argc, char *argv[]){ - framebot_init(); if(argc < 4){ fprintf(stderr, "sendvideonote "); exit(-1); } - _bot = framebot(argv[1]); + _bot = framebot_init(argv[1]); if(!_bot){ fprintf(stderr, "ERROR authentic"); exit(-1); diff --git a/test/test_sendvoice.c b/test/test_sendvoice.c index be52f62..2414cff 100644 --- a/test/test_sendvoice.c +++ b/test/test_sendvoice.c @@ -117,14 +117,13 @@ int _voice(){ int main(int argc, char *argv[]){ - framebot_init(); if(argc < 4){ fprintf(stderr, "sendphoto "); exit(-1); } - _bot = framebot(argv[1]); + _bot = framebot_init(argv[1]); if(!_bot){ fprintf(stderr, "ERROR authentic"); exit(-1); diff --git a/test/test_update.c b/test/test_update.c index 47d31a2..0b0e229 100644 --- a/test/test_update.c +++ b/test/test_update.c @@ -26,13 +26,11 @@ int main(int argc, char **argv){ *inline_query, *chosen_inline_result, *callback_query, *shipping_query, *pre_checkout_query; Error *error = NULL; - framebot_init(); - if(argc < 2) fprintf(stderr, "update "); - Bot *bot = framebot(argv[1]); + Bot *bot = framebot_init(argv[1]); if(!bot){ error = get_error(); if(error) diff --git a/test/test_userprofilephotos.c b/test/test_userprofilephotos.c index b828946..90a9376 100644 --- a/test/test_userprofilephotos.c +++ b/test/test_userprofilephotos.c @@ -23,12 +23,11 @@ void upp(UserProfilePhotos * oupp){ int main(int argc, char *argv[]){ - framebot_init(); if(argc < 3) fprintf(stderr, "update "); - _bot = framebot(argv[1]); + _bot = framebot_init(argv[1]); if(!_bot){ fprintf(stderr, "Error Authentic"); exit(-1);