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

Commit

Permalink
test_sendaudio done
Browse files Browse the repository at this point in the history
  • Loading branch information
h4child committed Mar 27, 2018
1 parent 2dd53ff commit 07b1ec0
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 205 deletions.
2 changes: 2 additions & 0 deletions src/framebot.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,8 @@ Message * send_audio(Bot *bot, char * chat_id, char * filename, char * caption,
free(ifile.audio.reply_to_message_id);
mem_store_free(input);

if(!s_json)
return NULL;

message = message_parse(s_json->content);

Expand Down
2 changes: 0 additions & 2 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,6 @@ MemStore * call_method_input_file(const char * token, IFile ifile){
/* then cleanup the form */
curl_mime_free(form);

curl_easy_cleanup(curl);

if(res == CURLE_OK)
return buff;
}
Expand Down
332 changes: 129 additions & 203 deletions test/test_sendaudio.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,238 +19,164 @@
#define LIGHT_CYAN "\033[01;36m"
#define WHITE "\033[01;37m"


Bot * _bot;

void read_message(Message * message){
printf(BLUE"\tmessage_id = %lu\n"COLOR_RESET, message->message_id);
if(message->from){
printf(BLUE"\ttfrom = (type User)\n"COLOR_RESET);
printf(BLUE"\ttfrom->id = %ld\n"COLOR_RESET, message->from->id);
Bot * _bot = NULL;
char *username = NULL;
long int chat_id = 0;
int valid_username = 0;
char *filename = NULL;
Message *result = NULL;

int _audio(){

printf(WHITE "Send audio ... \n");

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

if(message->date)
printf(BLUE"\ttdate = %ld\n"COLOR_RESET, message->date);
else
printf("\ttdate = NULL\n"COLOR_RESET);

if(message->chat)
printf(BLUE"\ttchat = (type Chat)\n"COLOR_RESET);
else
printf("\ttchat = NULL\n"COLOR_RESET);

if(message->forward_from)
printf(BLUE"\ttforward_from = (type User)\n"COLOR_RESET);
else
printf("\ttforward_from = NULL\n"COLOR_RESET);

if(message->forward_from_chat)
printf(BLUE"\ttforward_from_chat = (type Chat)\n"COLOR_RESET);
else
printf("\ttforward_from_chat = NULL\n"COLOR_RESET);

if(message->forward_from_message_id)
printf(BLUE"\tforward_from_message_id = %ld\n"COLOR_RESET, message->forward_from_message_id);
else
printf("\tforward_from_message_id = NULL\n"COLOR_RESET);

if(message->forward_signature)
printf(BLUE"\tforward_signature = %s\n"COLOR_RESET, message->forward_signature);
else
printf("\tforward_signature = NULL\n"COLOR_RESET);

if(message->forward_date)
printf(BLUE"\tforward_date = %ld\n"COLOR_RESET, message->forward_date);
else
printf("\tforward_date = NULL\n"COLOR_RESET);

if(message->reply_to_message)
printf(BLUE"\treply_to_message = (type Message)\n"COLOR_RESET);
else
printf("\treply_to_message = NULL\n"COLOR_RESET);

if(message->edit_date)
printf(BLUE"\tedit_date = %ld\n"COLOR_RESET, message->edit_date);
else
printf("\tedit_date = NULL\n"COLOR_RESET);

if(message->author_signature)
printf(BLUE"\tauthor_signature = %s\n"COLOR_RESET, message->author_signature);
else
printf("\tauthor_signature = NULL\n"COLOR_RESET);

if(message->text)
printf(BLUE"\ttext = %s\n"COLOR_RESET, message->text);
else
printf("\ttext = NULL\n"COLOR_RESET);

if(message->entities)
printf(BLUE"\tentities = (type MessageEntities)\n"COLOR_RESET);
else
printf("\tentities = NULL\n"COLOR_RESET);

if(message->caption_entities)
printf(BLUE"\tcaption_entities = (type MessageEntities)\n"COLOR_RESET);
else
printf("\tcaption_entities = NULL\n"COLOR_RESET);

if(message->audio)
printf(BLUE"\taudio = (type Audio)\n"COLOR_RESET);
else
printf("\taudio = NULL\n"COLOR_RESET);

if(message->document)
printf(BLUE"\tdocument = (type Document)\n"COLOR_RESET);
else
printf("\tdocument = NULL\n"COLOR_RESET);

if(message->game)
printf(BLUE"\tgame = (type Game)\n"COLOR_RESET);
else
printf("\tgame = NULL\n"COLOR_RESET);

if(message->photo)
printf(BLUE"\tphoto = (type PhotoSize)\n"COLOR_RESET);
else
printf("\tphoto = NULL\n"COLOR_RESET);

if(message->sticker)
printf(BLUE"\tsticker = (type Sticker)\n"COLOR_RESET);
else
printf("\tsticker = NULL\n"COLOR_RESET);

if(message->video)
printf(BLUE"\tvideo = (type Video)\n"COLOR_RESET);
else
printf("\tvideo = NULL\n"COLOR_RESET);

if(message->voice)
printf(BLUE"\tvoice = (type Voice)\n"COLOR_RESET);
else
printf("\tvoice = NULL\n"COLOR_RESET);

if(message->video_note)
printf(BLUE"\tvideo_note = (type VideoNote)\n"COLOR_RESET);
else
printf("\tvideo_note = NULL\n"COLOR_RESET);

if(message->caption)
printf(BLUE"\tcaption = %s\n"COLOR_RESET, message->caption);
else
printf("\tcaption = NULL\n"COLOR_RESET);

if(message->contact)
printf(BLUE"\tcontact = (type Contact)\n"COLOR_RESET);
else
printf("\tcontact = NULL\n"COLOR_RESET);

if(message->location)
printf(BLUE"\tlocation = (type Location)\n"COLOR_RESET);
else
printf("\tlocation = NULL\n"COLOR_RESET);

if(message->venue)
printf(BLUE"\tvenue = (type Venue)\n"COLOR_RESET);
else
printf("\tvenue = NULL\n"COLOR_RESET);
printf(WHITE "Send username ......... " COLOR_RESET);
fflush(stdout);
result = send_audio_chat(_bot, chat_id, filename, NULL,
0, NULL, NULL, 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);
}

if(message->new_chat_members)
printf(BLUE"\tnew_chat_members = (type User)\n"COLOR_RESET);
else
printf("\tnew_chat_member = NULL\n"COLOR_RESET);

if(message->left_chat_member)
printf(BLUE"\tleft_chat_member = (type User)\n"COLOR_RESET);
else
printf("\tleft_chat_member = NULL\n"COLOR_RESET);
printf(WHITE "Send caption ......... " COLOR_RESET);
fflush(stdout);
result = send_audio_chat(_bot, chat_id, filename, "caption",
0, NULL, NULL, 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);
}

if(message->new_chat_title)
printf(BLUE"\tnew_chat_title = %s\n"COLOR_RESET, message->new_chat_title);
else
printf("\tnew_chat_title = NULL\n"COLOR_RESET);

if(message->new_chat_photo)
printf(BLUE"\tnew_chat_photo = (type PhotoSize)\n"COLOR_RESET);
else
printf("\tnew_chat_photo = NULL\n"COLOR_RESET);
printf(WHITE "Send duration ......... " COLOR_RESET);
fflush(stdout);
result = send_audio_chat(_bot, chat_id, filename, "caption",
10, NULL, NULL, 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);
}

if(message->delete_chat_photo)
printf(BLUE"\tdelete_chat_photo = %d\n"COLOR_RESET, message->delete_chat_photo);
else
printf("\tdelete_chat_photo = NULL\n"COLOR_RESET);

if(message->group_chat_created)
printf(BLUE"\tgroup_chat_created = %d\n"COLOR_RESET, message->group_chat_created);
else
printf("\tgroup_chat_created = NULL\n"COLOR_RESET);
printf(WHITE "Send performer ......... " COLOR_RESET);
fflush(stdout);
result = send_audio_chat(_bot, chat_id, filename, "caption",
10, "performer", NULL, 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);
}

if(message->supergroup_chat_created)
printf(BLUE"\tsupergroup_chat_created = %d\n"COLOR_RESET, message->supergroup_chat_created);
else
printf("\tsupergroup_chat_created = NULL\n"COLOR_RESET);

if(message->channel_chat_created)
printf(BLUE"\tchannel_chat_created = %d\n"COLOR_RESET, message->channel_chat_created);
else
printf("\tchannel_chat_created = NULL\n"COLOR_RESET);
printf(WHITE "Send title ......... " COLOR_RESET);
fflush(stdout);
result = send_audio_chat(_bot, chat_id, filename, "caption",
10, "performer", "Title", 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);
}

if(message->migrate_to_chat_id)
printf(BLUE"\tmigrate_to_chat_id = %ld\n"COLOR_RESET, message->migrate_to_chat_id);
else
printf("\tmigrate_to_chat_id = NULL\n"COLOR_RESET);

if(message->migrate_from_chat_id)
printf(BLUE"\tmigrate_from_chat_id = %ld\n"COLOR_RESET);
else
printf("\tmigrate_from_chat_id = NULL\n"COLOR_RESET);
printf(WHITE "Send disable_notification ......... " COLOR_RESET);
result = send_audio_chat(_bot, chat_id, filename, "caption",
10, "performer", "Title", 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);
}

if(message->pinned_message)
printf(BLUE"\tpinned_message = (type Message)\n"COLOR_RESET);
else
printf("\tpinned_message = NULL\n"COLOR_RESET);
printf(WHITE "Send forward ......... " COLOR_RESET);
Message * forward = send_audio_chat(_bot, chat_id, filename, "caption",
10, "performer", "Title", 1, result->message_id, NULL);
if(forward){
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);
}

if(message->invoice)
printf(BLUE"\tinvoice = (type Invoice)\n"COLOR_RESET);
else
printf("\tinvoice = NULL\n"COLOR_RESET);
printf(BLUE"unit parameter successful\n" COLOR_RESET);

if(message->successful_payment)
printf(BLUE"\tsuccessful_payment = (type SuccessfulPayment)\n"COLOR_RESET);
else
printf("\tsuccessful_payment = NULL\n"COLOR_RESET);
return 0;
}


int main(int argc, char *argv[]){
framebot_init();

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

_bot = framebot(argv[1]);
_bot = framebot(argv[1]);
if(!_bot){
fprintf(stderr, "ERROR authentic");
exit(-1);
}

if(!_bot){
fprintf(stderr, "ERROR authentic");
exit(-1);
}
filename = argv[3];
username = argv[2];

/* Message * send_photo_chat(Bot * bot, long int chat_id, char * filename,
char * caption, bool disable_notification,
long int reply_to_message_id){
*/
Message * message = send_audio(_bot, argv[2], argv[3], "descrição", 0, NULL, NULL, 0, 0, NULL);
Framebot *update = NULL;

if(message){
read_message(message);
}
else{
Error * error = show_error();
if(error)
printf("error_code=%ld error_descriptio=n%s\n", error->error_code, error->description);
update = get_updates(_bot, update, 0, 0, 0, "message");

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

if(valid_username == 0)
printf("Username not found");


return 0;
}

0 comments on commit 07b1ec0

Please sign in to comment.