Removed unneeded files and updated examples
This commit is contained in:
+23
-10
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
This file is a part of rexy's matrix bot
|
||||
This file is a part of rexy's matrix client
|
||||
Copyright (C) 2019 rexy712
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
@@ -22,28 +22,41 @@
|
||||
#include "raii/static_string.hpp"
|
||||
|
||||
int main(){
|
||||
//auth information needed to initiate a session
|
||||
const char* username = "username";
|
||||
const char* password = "password";
|
||||
const char* useragent = "rexy712s info bot";
|
||||
const char* homeserver = "matrix.org";
|
||||
matrix::auth_data auth{username, password, homeserver};
|
||||
|
||||
matrix::bot matbot(auth, useragent);
|
||||
auto sync_reply = matbot.sync(0); //initial sync
|
||||
|
||||
matrix::auth_data auth{username, password, homeserver, useragent};
|
||||
bool should_quit = false;
|
||||
matbot.set_message_callback([&](const matrix::bot& bot, const matrix::msg_info& msg)->void
|
||||
|
||||
//create an open connection to the homeserver
|
||||
matrix::session ses(auth);
|
||||
|
||||
//access syncer instance to pull from server
|
||||
matrix::syncer& syn = ses.get_syncer();
|
||||
|
||||
//access client instance to send events to the server or query specific data
|
||||
matrix::client& cli = ses.get_client();
|
||||
|
||||
//initial sync to clear backlog
|
||||
auto sync_reply = syn.sync(0);
|
||||
|
||||
//callback on recived message (also processes your own messages!)
|
||||
//uses ref capture lambda to access client instance for message sending
|
||||
syn.set_message_callback([&](const matrix::msg_info& msg)->void
|
||||
{
|
||||
if(msg.body == "!exit"_ss){
|
||||
should_quit = true;
|
||||
bot.send_message(msg.roomid, "[INFO] Shutting down..."_ss);
|
||||
cli.send_message(msg.roomid, "[INFO] Shutting down..."_ss);
|
||||
}else if(msg.body == "!info"_ss){
|
||||
bot.send_message(msg.roomid, "This is an example of a bot which responds to commands!"_ss);
|
||||
cli.send_message(msg.roomid, "This is an example of a bot which responds to commands!"_ss);
|
||||
}
|
||||
});
|
||||
|
||||
//continuously loop syncing operation to always keep up to date with the server state
|
||||
while(!should_quit){
|
||||
sync_reply = matbot.sync(30000);
|
||||
sync_reply = syn.sync(30000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user