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

Commit

Permalink
framebot structure member
Browse files Browse the repository at this point in the history
  • Loading branch information
h4child committed Mar 29, 2018
1 parent ce2dc72 commit b18f04b
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 86 deletions.
2 changes: 1 addition & 1 deletion examples/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main (int argc, char **argv) {


frame_update = get_updates(echo, NULL, last_offset, 100, 0, NULL);
message = frame_update->update_message;
message = frame_update->up_message;
temp = message;

while (temp) {
Expand Down
4 changes: 2 additions & 2 deletions examples/inline_bot.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ int main (int argc, char **argv) {
long int last_update = 0;

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

while (queries) {
if (answer_inline_query(inbot, queries->inline_query->id, result, 0, 0, NULL, NULL, NULL)) {
Expand Down
2 changes: 1 addition & 1 deletion include/framebot/framebot.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ typedef int bool;

/* parameter parse_mode */
#define MODE_HTML "HTML"
#define MODE_MARKDOWN "MARKDOWN"
#define MODE_MARKDOWN "Markdown"

#include <curl/curl.h>
#include <jansson.h>
Expand Down
18 changes: 9 additions & 9 deletions include/framebot/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ typedef struct _update{

typedef struct {
long int update_id;
Update *update_message;
Update *update_edited_message;
Update *update_channel_post;
Update *update_edited_channel_post;
Update *update_inline_query;
Update *update_chosen_inline_result;
Update *update_callback_query;
Update *update_shipping_query;
Update *update_pre_checkout_query;
Update *up_message;
Update *up_edited_message;
Update *up_channel_post;
Update *up_edited_channel_post;
Update *up_inline_query;
Update *up_chosen_inline_result;
Update *up_callback_query;
Update *up_shipping_query;
Update *up_pre_checkout_query;
} Framebot;

typedef struct _chat_member {
Expand Down
3 changes: 0 additions & 3 deletions src/framebot.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ Message * send_message (Bot *bot, char * chat_id, char *text, char * parse_mode,

message = message_parse(s_json->content);

if(!s_json)
return NULL;

close_json ( s_json );

return message;
Expand Down
90 changes: 45 additions & 45 deletions src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1368,74 +1368,74 @@ void chat_photo_free(ChatPhoto *ochat_photo){
void framebot_add( Framebot *framebot, Update *update ){

if( update->message ) {
if(!framebot->update_message)
framebot->update_message = update;
if(!framebot->up_message)
framebot->up_message = update;
else
update_add(framebot->update_message, update);
update_add(framebot->up_message, update);
}


else if( update->edited_message ) {
if(!framebot->update_edited_message)
framebot->update_edited_message = update;
if(!framebot->up_edited_message)
framebot->up_edited_message = update;
else
update_add(framebot->update_edited_message, update);
update_add(framebot->up_edited_message, update);
}


else if( update->channel_post ) {
if(!framebot->update_channel_post)
framebot->update_channel_post = update;
if(!framebot->up_channel_post)
framebot->up_channel_post = update;
else
update_add(framebot->update_channel_post, update);
update_add(framebot->up_channel_post, update);
}


else if( update->edited_channel_post ) {
if(!framebot->update_edited_channel_post)
framebot->update_edited_channel_post = update;
if(!framebot->up_edited_channel_post)
framebot->up_edited_channel_post = update;
else
update_add(framebot->update_edited_channel_post, update);
update_add(framebot->up_edited_channel_post, update);
}


else if( update->inline_query ) {
if(!framebot->update_inline_query)
framebot->update_inline_query = update;
if(!framebot->up_inline_query)
framebot->up_inline_query = update;
else
update_add(framebot->update_inline_query, update);
update_add(framebot->up_inline_query, update);
}


else if( update->chosen_inline_result ) {
if(!framebot->update_chosen_inline_result)
framebot->update_chosen_inline_result = update;
if(!framebot->up_chosen_inline_result)
framebot->up_chosen_inline_result = update;
else
update_add(framebot->update_chosen_inline_result, update);
update_add(framebot->up_chosen_inline_result, update);
}


else if( update->callback_query ) {
if(!framebot->update_callback_query)
framebot->update_callback_query = update;
if(!framebot->up_callback_query)
framebot->up_callback_query = update;
else
update_add(framebot->update_callback_query, update);
update_add(framebot->up_callback_query, update);
}


else if( update->shipping_query ) {
if(!framebot->update_shipping_query)
framebot->update_shipping_query = update;
if(!framebot->up_shipping_query)
framebot->up_shipping_query = update;
else
update_add(framebot->update_shipping_query, update);
update_add(framebot->up_shipping_query, update);
}


else if( update->pre_checkout_query ) {
if(!framebot->update_pre_checkout_query)
framebot->update_pre_checkout_query = update;
if(!framebot->up_pre_checkout_query)
framebot->up_pre_checkout_query = update;
else
update_add(framebot->update_pre_checkout_query, update);
update_add(framebot->up_pre_checkout_query, update);
}

framebot->update_id = UPDATE_ID_LAST(framebot, update);
Expand All @@ -1445,32 +1445,32 @@ void framebot_add( Framebot *framebot, Update *update ){

void framebot_free(Framebot *framebot) {

if(framebot->update_message) {
update_free(framebot->update_message);
if(framebot->up_message) {
update_free(framebot->up_message);
}
else if(framebot->update_edited_message) {
update_free(framebot->update_edited_message);
else if(framebot->up_edited_message) {
update_free(framebot->up_edited_message);
}
else if(framebot->update_channel_post) {
update_free(framebot->update_channel_post);
else if(framebot->up_channel_post) {
update_free(framebot->up_channel_post);
}
else if(framebot->update_edited_channel_post) {
update_free(framebot->update_edited_channel_post);
else if(framebot->up_edited_channel_post) {
update_free(framebot->up_edited_channel_post);
}
else if(framebot->update_inline_query) {
update_free(framebot->update_inline_query);
else if(framebot->up_inline_query) {
update_free(framebot->up_inline_query);
}
else if(framebot->update_chosen_inline_result) {
update_free(framebot->update_chosen_inline_result);
else if(framebot->up_chosen_inline_result) {
update_free(framebot->up_chosen_inline_result);
}
else if(framebot->update_callback_query) {
update_free(framebot->update_callback_query);
else if(framebot->up_callback_query) {
update_free(framebot->up_callback_query);
}
else if(framebot->update_shipping_query) {
update_free(framebot->update_shipping_query);
else if(framebot->up_shipping_query) {
update_free(framebot->up_shipping_query);
}
else if(framebot->update_pre_checkout_query) {
update_free(framebot->update_pre_checkout_query);
else if(framebot->up_pre_checkout_query) {
update_free(framebot->up_pre_checkout_query);
}

free(framebot);
Expand Down
2 changes: 1 addition & 1 deletion test/test_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char **argv){

Update * update;
Framebot *fbot = get_updates(_bot, NULL, 0, 0, 0, NULL);
update = fbot->update_message;
update = fbot->up_message;

update_length = update_len(update);

Expand Down
6 changes: 3 additions & 3 deletions test/test_sendaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ int main(int argc, char *argv[]){

update = get_updates(_bot, update, 0, 0, 0, "message");

while(update->message){
if(strcmp(update->message->message->from->username, argv[2]) == 0){
while(update->up_message){
if(strcmp(update->up_message->message->from->username, argv[2]) == 0){
valid_username = 1;
chat_id = update->message->message->from->id;
chat_id = update->up_message->message->from->id;
_audio();
break;
}
Expand Down
89 changes: 78 additions & 11 deletions test/test_sendmessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,83 @@ char *text = NULL;
Message *result = NULL;

int _message(){
printf(WHITE "Send voice ... \n");
printf(WHITE "Send sendmessage ... \n");

/* Bot *bot, long int chat_id, char *text, char *parse_mode,
bool disable_web_page_preview, bool disable_notification, long int reply_to_message_id,
char * reply_markup */
printf(WHITE "Send chat_id ........." COLOR_RESET);
fflush(stdout);
result = send_message_chat(_bot, chat_id, "parameter chat_id", NULL, 0, 0, 0, NULL);
if(result){
printf(BLUE "OK\n" COLOR_RESET);
}
else{
Error *error = get_error();
printf(RED"false\ncode:%ld | description:%s\n"COLOR_RESET, error->error_code, error->description);
exit(-1);
}

printf(WHITE "Send username ........." COLOR_RESET);
fflush(stdout);
result = send_message_chat(_bot, chat_id, "parameter username", NULL, 0, 0, 0, NULL);
if(result){
printf(BLUE "OK\n" COLOR_RESET);
}
else{
Error *error = get_error();
printf(RED"false\ncode:%ld | description:%s\n"COLOR_RESET, error->error_code, error->description);
exit(-1);
}

printf(WHITE "Send parse_mode HTML ........." COLOR_RESET);
fflush(stdout);
result = send_message_chat(_bot, chat_id, "parameter parse_mode = MODE_HTML%0Abold = <b>bold</b>, <strong>bold</strong>%0Aitalic = <i>italic</i>, <em>italic</em>%0Agithub = <a href=\"https://github.com/giancarlopro/framebot\">inline URL</a>", MODE_HTML, 0, 0, 0, NULL);
if(result){
printf(BLUE "OK\n" COLOR_RESET);
}
else{
Error *error = get_error();
printf(RED"false\ncode:%ld | description:%s\n"COLOR_RESET, error->error_code, error->description);
exit(-1);
}

printf(WHITE "Send parse_mode MARKDOWN ........." COLOR_RESET);
fflush(stdout);
result = send_message_chat(_bot, chat_id, "parameter parse_mode = MODE_MARKDOWN%0Abold = *bold text*%0Aitalic = _italic text_%0A[inline URL](https://github.com/giancarlopro/framebot)%0A```block_languagepre-formatted fixed-width code block```", MODE_MARKDOWN, 0, 0, 0, NULL);
if(result){
printf(BLUE "OK\n" COLOR_RESET);
}
else{
Error *error = get_error();
printf(RED"false\ncode:%ld | description:%s\n"COLOR_RESET, error->error_code, error->description);
exit(-1);
}

printf(WHITE "Send disable_web_page_preview (not thumb)........." COLOR_RESET);
fflush(stdout);
result = send_message_chat(_bot, chat_id, "parameter disable_web_page_preview https://github.com/giancarlopro/framebot", NULL, 1, 0, 0, NULL);
if(result){
printf(BLUE "OK\n" COLOR_RESET);
}
else{
Error *error = get_error();
printf(RED"false\ncode:%ld | description:%s\n"COLOR_RESET, error->error_code, error->description);
exit(-1);
}

printf(WHITE "Send disable_notification ........." COLOR_RESET);
fflush(stdout);
result = send_message_chat(_bot, chat_id, "parameter disable_notification", NULL, 1, 1, 0, NULL);
if(result){
printf(BLUE "OK\n" COLOR_RESET);
}
else{
Error *error = get_error();
printf(RED"false\ncode:%ld | description:%s\n"COLOR_RESET, error->error_code, error->description);
exit(-1);
}

printf(WHITE "Send chat_id ........." COLOR_RESET);
printf(WHITE "Send reply_to_message_id ........." COLOR_RESET);
fflush(stdout);
result = send_message_chat(_bot, chat_id, text, NULL, 0, 0, 0, NULL);
Message * forward = send_message_chat(_bot, chat_id, "parameter reply_to_message_id", NULL, 1, 0, result->message_id, NULL);
if(result){
printf(BLUE "OK\n" COLOR_RESET);
}
Expand All @@ -52,7 +120,7 @@ int main(int argc, char *argv[]){
framebot_init();

if(argc < 4){
fprintf(stderr, "sendphoto <token> <username> <message>");
fprintf(stderr, "sendphoto <token> <username>");
exit(-1);
}

Expand All @@ -62,17 +130,16 @@ int main(int argc, char *argv[]){
exit(-1);
}

text = argv[3];
username = argv[2];

Framebot *update = NULL;

update = get_updates(_bot, update, 0, 0, 0, "message");

while(update->message){
if(strcmp(update->message->message->from->username, argv[2]) == 0){
while(update->up_message){
if(strcmp(update->up_message->message->from->username, argv[2]) == 0){
valid_username = 1;
chat_id = update->message->message->from->id;
chat_id = update->up_message->message->from->id;
_message();
break;
}
Expand Down
6 changes: 3 additions & 3 deletions test/test_sendphotos.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ int main(int argc, char *argv[]){

update = get_updates(_bot, update, 0, 0, 0, "message");

while(update->message){
if(strcmp(update->message->message->from->username, argv[2]) == 0){
while(update->up_message){
if(strcmp(update->up_message->message->from->username, argv[2]) == 0){
valid_username = 1;
chat_id = update->message->message->from->id;
chat_id = update->up_message->message->from->id;
_photo();
break;
}
Expand Down
6 changes: 3 additions & 3 deletions test/test_sendvideonote.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ int main(int argc, char *argv[]){

update = get_updates(_bot, update, 0, 0, 0, "message");

while(update->message){
if(strcmp(update->message->message->from->username, argv[2]) == 0){
while(update->up_message){
if(strcmp(update->up_message->message->from->username, argv[2]) == 0){
valid_username = 1;
chat_id = update->message->message->from->id;
chat_id = update->up_message->message->from->id;
_videonote();
break;
}
Expand Down

0 comments on commit b18f04b

Please sign in to comment.