initial commit
This commit is contained in:
commit
c67f973227
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build/
|
34
CMakeLists.txt
Normal file
34
CMakeLists.txt
Normal file
|
@ -0,0 +1,34 @@
|
|||
cmake_minimum_required (VERSION 3.7)
|
||||
project (whyblocked
|
||||
VERSION 0.1.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -g -Og")
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/src)
|
||||
include_directories(${PROJECT_BINARY_DIR})
|
||||
|
||||
include_directories(${LIBXDG_BASEDIR_INCLUDE_DIRS})
|
||||
|
||||
link_directories(${LIBXDG_BASEDIR_LIBRARY_DIRS})
|
||||
|
||||
# Write version in header
|
||||
configure_file (
|
||||
"${PROJECT_SOURCE_DIR}/src/version.hpp.in"
|
||||
"${PROJECT_BINARY_DIR}/version.hpp"
|
||||
)
|
||||
|
||||
file(GLOB sources src/*.cpp)
|
||||
add_executable(whyblocked ${sources})
|
||||
target_link_libraries(whyblocked
|
||||
${LIBXDG_BASEDIR_LIBRARIES} vsqlitepp stdc++fs)
|
||||
install(TARGETS whyblocked DESTINATION ${CMAKE_INSTALL_BINDIR})
|
4
README.md
Normal file
4
README.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
**whyblocked** reminds you why you blocked someone. It is developed with
|
||||
Mastodon in mind, but can be used for other contexts, of course.
|
||||
|
||||
It has a text interface and uses a SQLite-database.
|
9
src/version.hpp.in
Normal file
9
src/version.hpp.in
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef VERSION_HPP
|
||||
#define VERSION_HPP
|
||||
|
||||
namespace global
|
||||
{
|
||||
static constexpr char version[] = "@PROJECT_VERSION@";
|
||||
}
|
||||
|
||||
#endif // VERSION_HPP
|
146
src/whyblock.cpp
Normal file
146
src/whyblock.cpp
Normal file
|
@ -0,0 +1,146 @@
|
|||
// CC-0, tastytea
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <experimental/filesystem>
|
||||
#include <basedir.h>
|
||||
#include <sqlite/connection.hpp>
|
||||
#include <sqlite/execute.hpp>
|
||||
#include <sqlite/query.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <version.hpp>
|
||||
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::cin;
|
||||
namespace fs = std::experimental::filesystem;
|
||||
|
||||
string get_filepath()
|
||||
{
|
||||
string filepath;
|
||||
xdgHandle xdg;
|
||||
xdgInitHandle(&xdg);
|
||||
filepath = xdgDataHome(&xdg);
|
||||
xdgWipeHandle(&xdg);
|
||||
|
||||
filepath += "/whyblock";
|
||||
if (!fs::exists(filepath))
|
||||
{
|
||||
fs::create_directory(filepath);
|
||||
}
|
||||
filepath += "/database.sqlite";
|
||||
if (!fs::exists(filepath))
|
||||
{
|
||||
sqlite::connection con(filepath);
|
||||
sqlite::execute(con, "CREATE TABLE blocks(user TEXT PRIMARY KEY, blocked INTEGER, reason TEXT);", true);
|
||||
sqlite::execute(con, "CREATE TABLE urls(user TEXT, url TEXT);", true);
|
||||
}
|
||||
|
||||
return filepath;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
sqlite::connection con(get_filepath());
|
||||
string answer;
|
||||
|
||||
cout << "Would you like to add, remove or view records?\n";
|
||||
cout << "Or do you want to get the details of a record?\n";
|
||||
cout << "Type add, remove, view or details. Or just the first letter\n";
|
||||
cout << ": ";
|
||||
cin >> answer;
|
||||
switch (answer[0])
|
||||
{
|
||||
case 'a':
|
||||
case 'A':
|
||||
{
|
||||
cout << "ADD\n";
|
||||
break;
|
||||
}
|
||||
case 'r':
|
||||
case 'R':
|
||||
{
|
||||
cout << "REMOVE\n";
|
||||
break;
|
||||
}
|
||||
case 'v':
|
||||
case 'V':
|
||||
{
|
||||
sqlite::query q(con, "SELECT * FROM blocks;");
|
||||
boost::shared_ptr<sqlite::result> result = q.get_result();
|
||||
while(result->next_row())
|
||||
{
|
||||
if (result->get_int(1) == 1)
|
||||
{
|
||||
cout << " Blocked: ";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Silenced: ";
|
||||
}
|
||||
cout << result->get_string(0) << " because: ";
|
||||
cout << result->get_string(2) << '\n';
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'd':
|
||||
case 'D':
|
||||
{
|
||||
cout << "Which user?\n";
|
||||
cin >> answer;
|
||||
{
|
||||
sqlite::query q(con, "SELECT * FROM blocks WHERE user = \'" + answer + "\';");
|
||||
boost::shared_ptr<sqlite::result> result = q.get_result();
|
||||
result->next_row();
|
||||
cout << answer << " is ";
|
||||
if (result->get_row_count() == 0)
|
||||
{
|
||||
cout << "not in the database.\n";
|
||||
break;
|
||||
}
|
||||
if (result->get_int(1) == 1)
|
||||
{
|
||||
cout << "blocked, because: ";
|
||||
}
|
||||
else if (result->get_int(1) == 0)
|
||||
{
|
||||
cout << "silenced, because: ";
|
||||
}
|
||||
cout << result->get_string(2) << '\n';
|
||||
}
|
||||
{
|
||||
sqlite::query q(con, "SELECT * FROM urls WHERE user = \'" + answer + "\';");
|
||||
boost::shared_ptr<sqlite::result> result = q.get_result();
|
||||
while(result->next_row())
|
||||
{
|
||||
cout << result->get_string(1) << '\n';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
cout << "Response not understood.\n";
|
||||
}
|
||||
// sqlite::execute ins(con, "INSERT INTO TEST VALUES(?, ?, ?);");
|
||||
// ins % sqlite::nil % "Hello";
|
||||
// ins();
|
||||
|
||||
// sqlite::query q(con, "SELECT * FROM blocks;");
|
||||
// boost::shared_ptr<sqlite::result> result = q.get_result();
|
||||
// while(result->next_row())
|
||||
// {
|
||||
// std::cout << "ID: " << result->get_int(0) << "\n"
|
||||
// << "Name: " << result->get_string(1) << std::endl;
|
||||
// }
|
||||
}
|
||||
catch(const std::exception &e)
|
||||
{
|
||||
cerr << "An error occurred: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user