switched confuig file format from cfg to json
This commit is contained in:
parent
211a255048
commit
b361753f51
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.7)
|
cmake_minimum_required (VERSION 3.7)
|
||||||
project (expandurl-mastodon
|
project (expandurl-mastodon
|
||||||
VERSION 0.3.3
|
VERSION 0.4.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
11
README.md
11
README.md
|
@ -21,6 +21,7 @@ or to [@tastytea@soc.ialis.me](https://soc.ialis.me/@tastytea).
|
||||||
* [cmake](https://cmake.org/) (tested: 3.9.6)
|
* [cmake](https://cmake.org/) (tested: 3.9.6)
|
||||||
* [curlpp](http://www.curlpp.org/) (tested: 0.8.1)
|
* [curlpp](http://www.curlpp.org/) (tested: 0.8.1)
|
||||||
* [mastodon-cpp](https://github.com/tastytea/mastodon-cpp) (at least: 0.13.1)
|
* [mastodon-cpp](https://github.com/tastytea/mastodon-cpp) (at least: 0.13.1)
|
||||||
|
* [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8.4)
|
||||||
|
|
||||||
## Get sourcecode
|
## Get sourcecode
|
||||||
|
|
||||||
|
@ -39,12 +40,16 @@ Install with `make install`.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
|
**The config file has changed from cfg to JSON in 0.4.0.**
|
||||||
|
|
||||||
You will need to generate an access token yourself at the moment. Create a
|
You will need to generate an access token yourself at the moment. Create a
|
||||||
config file with your account and access token in
|
config file with your account and access token in
|
||||||
`${HOME}/.config/expandurl-mastodon.cfg`:
|
`${HOME}/.config/expandurl-mastodon.json`:
|
||||||
|
|
||||||
expandurl@example.social
|
{
|
||||||
abc123
|
"account": "expandurl@example.social",
|
||||||
|
"access_tocken": "abc123"
|
||||||
|
}
|
||||||
|
|
||||||
Now start expandurl-mastodon without parameters.
|
Now start expandurl-mastodon without parameters.
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <mastodon-cpp/mastodon-cpp.hpp>
|
#include <mastodon-cpp/mastodon-cpp.hpp>
|
||||||
#include <mastodon-cpp/easy/all.hpp>
|
#include <mastodon-cpp/easy/all.hpp>
|
||||||
|
#include <jsoncpp/json/json.h>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using Mastodon::API;
|
using Mastodon::API;
|
||||||
|
@ -75,6 +76,7 @@ public:
|
||||||
const void stop();
|
const void stop();
|
||||||
|
|
||||||
std::vector<Easy::Notification> get_new_messages();
|
std::vector<Easy::Notification> get_new_messages();
|
||||||
|
const std::vector<Easy::Notification> catchup();
|
||||||
Easy::Status get_status(const std::uint_fast64_t &id);
|
Easy::Status get_status(const std::uint_fast64_t &id);
|
||||||
const bool send_reply(const Easy::Status &to_status, const string &message);
|
const bool send_reply(const Easy::Status &to_status, const string &message);
|
||||||
const std::uint_fast64_t get_parent_id(Easy::Notification ¬if);
|
const std::uint_fast64_t get_parent_id(Easy::Notification ¬if);
|
||||||
|
@ -89,6 +91,9 @@ private:
|
||||||
std::unique_ptr<API::http> _ptr;
|
std::unique_ptr<API::http> _ptr;
|
||||||
std::thread _thread;
|
std::thread _thread;
|
||||||
bool _running;
|
bool _running;
|
||||||
|
Json::Value _config;
|
||||||
|
|
||||||
|
const bool read_config();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EXPANDURL_MASTODON_HPP
|
#endif // EXPANDURL_MASTODON_HPP
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <cstdlib> // getenv()
|
#include <cstdlib> // getenv()
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <sstream>
|
||||||
#include "version.hpp"
|
#include "version.hpp"
|
||||||
#include "expandurl-mastodon.hpp"
|
#include "expandurl-mastodon.hpp"
|
||||||
|
|
||||||
|
@ -32,28 +33,45 @@ Listener::Listener()
|
||||||
, _ptr(nullptr)
|
, _ptr(nullptr)
|
||||||
, _running(false)
|
, _running(false)
|
||||||
{
|
{
|
||||||
const string filepath = static_cast<const string>(getenv("HOME")) +
|
|
||||||
"/.config/expandurl-mastodon.cfg";
|
|
||||||
std::ifstream file(filepath);
|
|
||||||
|
|
||||||
if (file.is_open())
|
if (read_config())
|
||||||
{
|
{
|
||||||
std::getline(file, _instance);
|
|
||||||
_instance = _instance.substr(_instance.find('@') + 1);
|
|
||||||
std::getline(file, _access_token);
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
_masto = std::make_unique<Easy>(_instance, _access_token);
|
_masto = std::make_unique<Easy>(_instance, _access_token);
|
||||||
_masto->set_useragent(static_cast<const string>("expandurl-mastodon/") +
|
_masto->set_useragent(static_cast<const string>("expandurl-mastodon/") +
|
||||||
global::version);
|
global::version);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cerr << "ERROR: Could not open " << filepath << '\n';
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool Listener::read_config()
|
||||||
|
{
|
||||||
|
const string filepath = static_cast<const string>(getenv("HOME")) +
|
||||||
|
"/.config/expandurl-mastodon.json";
|
||||||
|
std::ifstream file(filepath);
|
||||||
|
|
||||||
|
if (file.is_open())
|
||||||
|
{
|
||||||
|
std::stringstream json;
|
||||||
|
json << file.rdbuf();
|
||||||
|
file.close();
|
||||||
|
json >> _config;
|
||||||
|
|
||||||
|
_instance = _config["account"].asString();
|
||||||
|
_instance = _instance.substr(_instance.find('@') + 1);
|
||||||
|
_access_token = _config["access_token"].asString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cerr << "ERROR: Could not open " << filepath << ".\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
const void Listener::start()
|
const void Listener::start()
|
||||||
{
|
{
|
||||||
_thread = std::thread([=]
|
_thread = std::thread([=]
|
||||||
|
@ -126,6 +144,11 @@ std::vector<Easy::Notification> Listener::get_new_messages()
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<Easy::Notification> Listener::catchup()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
Mastodon::Easy::Status Listener::get_status(const std::uint_fast64_t &id)
|
Mastodon::Easy::Status Listener::get_status(const std::uint_fast64_t &id)
|
||||||
{
|
{
|
||||||
std::uint_fast16_t ret;
|
std::uint_fast16_t ret;
|
||||||
|
|
Loading…
Reference in New Issue