commit 903d0fbb3ae1d5e82e6a63ba9e233bc2b2ae55b9 Author: Balazs Toldi Date: Sun Jan 31 23:02:44 2021 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3fcff76 --- /dev/null +++ b/.gitignore @@ -0,0 +1,192 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +.idea +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ +build/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + + Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..93a902e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/matrix-cpp-sdk"] + path = external/matrix-cpp-sdk + url = https://github.com/Bazsalanszky/matrix-cpp-sdk/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5191162 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.17) +project(matrix_cpp_examplebot) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(matrix_cpp_examplebot main.cpp) +add_subdirectory(external/matrix-cpp-sdk) + +target_link_libraries(matrix_cpp_examplebot matrix-cpp-sdk) +target_include_directories(matrix_cpp_examplebot PRIVATE external/matrix-cpp-sdk/src) +target_link_libraries(matrix_cpp_examplebot jsoncpp_lib) +include_directories(${Jsoncpp_INCLUDE_DIR}) +include_directories(${MATRIX_CPP_INCLUDE_DIR}) \ No newline at end of file diff --git a/external/matrix-cpp-sdk b/external/matrix-cpp-sdk new file mode 160000 index 0000000..15d1ab0 --- /dev/null +++ b/external/matrix-cpp-sdk @@ -0,0 +1 @@ +Subproject commit 15d1ab091fbbcc123041fb735e4cf4b99e474b44 diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..24d672e --- /dev/null +++ b/main.cpp @@ -0,0 +1,27 @@ +#include +#include +#include + +struct BasicEventListener : public Matrix::EventListener{ + BasicEventListener(Matrix::Client*c): Matrix::EventListener(c) {} + virtual void onEvent(const Matrix::Event& event) { + if(event.getType() == "m.room.message" && event.getContent()["body"].asString() == "!ping"){ + Json::Value msg_content; + msg_content["msgtype"] = "m.type"; + msg_content["body"] = "pong!"; + client->send(event.getRoomId(),"m.room.message",msg_content); + } + } +}; + +int main(){ + Matrix::Logger logger; + Matrix::Homeserver server(getenv("HOMESERVER_NAME"),getenv("HOMESERVER_URL")); + Matrix::Client c(&server, getenv("ACCESS_TOKEN")); + + Matrix::EventListener* listener = new BasicEventListener(&c); + c.addEventListener(listener); + c.start_thread(); + delete listener; + return 0; +}