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

Commit

Permalink
change Framebot struct
Browse files Browse the repository at this point in the history
  • Loading branch information
h4child committed Mar 5, 2018
1 parent 25a0470 commit cfd023d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 59 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->message;
message = frame_update->update_message;
temp = message;

while (temp) {
Expand Down
21 changes: 10 additions & 11 deletions include/framebot/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,20 +272,19 @@ typedef struct _update{
ShippingQuery *shipping_query;
PreCheckoutQuery *pre_checkout_query;
struct _update *next;
} Update, UPMessage, UPIQuery, UPIResult, UPCQuery,
UPSQuery, UPPCQuery;
} Update;

typedef struct {
long int update_id;
UPMessage *message;
UPMessage *edited_message;
UPMessage *channel_post;
UPMessage *edited_channel_post;
UPIQuery *inline_query;
UPIResult *chosen_inline_result;
UPCQuery *callback_query;
UPSQuery *shipping_query;
UPPCQuery *pre_checkout_query;
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;
} Framebot;

typedef struct _chat_member {
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->message)
framebot->message = update;
if(!framebot->update_message)
framebot->update_message = update;
else
update_add(framebot->message, update);
update_add(framebot->update_message, update);
}


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


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


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


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


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


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


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


else if( update->pre_checkout_query ) {
if(!framebot->pre_checkout_query)
framebot->pre_checkout_query = update;
if(!framebot->update_pre_checkout_query)
framebot->update_pre_checkout_query = update;
else
update_add(framebot->pre_checkout_query, update);
update_add(framebot->update_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->message) {
update_free(framebot->message);
if(framebot->update_message) {
update_free(framebot->update_message);
}
else if(framebot->edited_message) {
update_free(framebot->edited_message);
else if(framebot->update_edited_message) {
update_free(framebot->update_edited_message);
}
else if(framebot->channel_post) {
update_free(framebot->channel_post);
else if(framebot->update_channel_post) {
update_free(framebot->update_channel_post);
}
else if(framebot->edited_channel_post) {
update_free(framebot->edited_channel_post);
else if(framebot->update_edited_channel_post) {
update_free(framebot->update_edited_channel_post);
}
else if(framebot->inline_query) {
update_free(framebot->inline_query);
else if(framebot->update_inline_query) {
update_free(framebot->update_inline_query);
}
else if(framebot->chosen_inline_result) {
update_free(framebot->chosen_inline_result);
else if(framebot->update_chosen_inline_result) {
update_free(framebot->update_chosen_inline_result);
}
else if(framebot->callback_query) {
update_free(framebot->callback_query);
else if(framebot->update_callback_query) {
update_free(framebot->update_callback_query);
}
else if(framebot->shipping_query) {
update_free(framebot->shipping_query);
else if(framebot->update_shipping_query) {
update_free(framebot->update_shipping_query);
}
else if(framebot->pre_checkout_query) {
update_free(framebot->pre_checkout_query);
else if(framebot->update_pre_checkout_query) {
update_free(framebot->update_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->message;
update = fbot->update_message;

update_length = update_len(update);

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

Framebot *fbot = get_updates(bot, NULL, 0, 0, 0, NULL);
update = fbot->message;
update = fbot->update_message;
update_length = update_len(update);
printf(BLUE"length = %lu"COLOR_RESET, update_length);

Expand Down

0 comments on commit cfd023d

Please sign in to comment.