Initial commit

This commit is contained in:
Balazs Toldi 2021-01-31 23:02:44 +01:00
commit 903d0fbb3a
Signed by: Bazsalanszky
GPG key ID: 933820884952BE27
5 changed files with 236 additions and 0 deletions

192
.gitignore vendored Normal file
View file

@ -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

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "external/matrix-cpp-sdk"]
path = external/matrix-cpp-sdk
url = https://github.com/Bazsalanszky/matrix-cpp-sdk/

13
CMakeLists.txt Normal file
View file

@ -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})

1
external/matrix-cpp-sdk vendored Submodule

@ -0,0 +1 @@
Subproject commit 15d1ab091fbbcc123041fb735e4cf4b99e474b44

27
main.cpp Normal file
View file

@ -0,0 +1,27 @@
#include <iostream>
#include <matrix/Client.h>
#include <json/json.h>
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;
}