Added stdin function to helper script
This commit is contained in:
parent
eb567f86c1
commit
4abfa99bfe
@ -20,6 +20,9 @@
|
||||
#include "raii/static_string.hpp"
|
||||
|
||||
#include <cstdlib> //exit
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
[[noreturn]] void usage(int status){
|
||||
printf("Usage: matrix-send STRING\n");
|
||||
@ -27,24 +30,35 @@
|
||||
exit(status);
|
||||
}
|
||||
|
||||
void do_stdin(const matrix::roomcxn& room){
|
||||
std::vector<char> data;
|
||||
data.reserve(256);
|
||||
for(int in;(in = fgetc(stdin)) != EOF;){
|
||||
data.push_back(in);
|
||||
}
|
||||
data.push_back(0);
|
||||
room.send_message(raii::static_string(data.data()));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv){
|
||||
const char* username = "username";
|
||||
const char* password = "password";
|
||||
const char* useragent = "rexy712s test bot";
|
||||
const char* homeserver = "matrix.org";
|
||||
const char* roomid = "!roomid:matrix.org";
|
||||
const char* roomid = "!room:matrix.org";
|
||||
matrix::auth_data auth{username, password, homeserver, useragent};
|
||||
|
||||
if(argc < 2)
|
||||
usage(1);
|
||||
|
||||
matrix::session ses(auth);
|
||||
if(!ses.valid()){
|
||||
fprintf(stderr, "Failed to init matrix session!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto client = ses.spawn_client();
|
||||
auto room = client.spawn_room(raii::static_string(roomid));
|
||||
room.send_message(raii::static_string(argv[1]));
|
||||
if(argc < 2 || !strcmp(argv[1], "-")){
|
||||
do_stdin(room);
|
||||
}else{
|
||||
room.send_message(raii::static_string(argv[1]));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user