added telegram api support to send message on ip update

This commit is contained in:
max mustermann 2019-05-08 19:19:42 +02:00
parent 3b7e78193a
commit 846a32ee7e
7 changed files with 162 additions and 65 deletions

170
.idea/workspace.xml generated
View File

@ -15,8 +15,13 @@
</component>
<component name="ChangeListManager">
<list default="true" id="59c80f39-2468-4db0-9afd-14b8acdbffed" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/api/TelegramAPI.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/api/TelegramAPI.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/API.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/src/API.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/API.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/API.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/API.h" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/API.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/src/main.cpp" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/cmake-build-debug/" />
<ignored path="$PROJECT_DIR$/CMakeFiles/" />
@ -32,28 +37,19 @@
<component name="ExecutionTargetManager" SELECTED_TARGET="CMakeBuildProfile:Debug" />
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/CMakeLists.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="12" selection-start-line="12" selection-end-line="12" />
<state relative-caret-position="330">
<caret line="22" column="8" selection-start-line="22" selection-start-column="8" selection-end-line="22" selection-end-column="8" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/API.h">
<entry file="file://$PROJECT_DIR$/src/api/API.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="210">
<caret line="14" column="36" selection-start-line="14" selection-start-column="36" selection-end-line="14" selection-end-column="36" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/API.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<state relative-caret-position="243">
<caret line="18" selection-start-line="18" selection-end-line="18" />
<folding>
<element signature="e#40#56#0" expanded="true" />
@ -62,6 +58,27 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/api/TelegramAPI.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120">
<caret line="8" column="26" selection-start-line="8" selection-start-column="26" selection-end-line="8" selection-end-column="26" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/api/TelegramAPI.h">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret column="2" lean-forward="true" selection-start-column="2" selection-end-column="2" />
<folding>
<element signature="e#110#127#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/Hashmap.h">
<provider selected="true" editor-type-id="text-editor" />
@ -70,8 +87,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="330">
<caret line="22" selection-start-line="22" selection-end-line="22" />
<state relative-caret-position="528">
<caret line="58" column="27" lean-forward="true" selection-start-line="58" selection-start-column="27" selection-end-line="58" selection-end-column="27" />
<folding>
<element signature="e#0#19#0" expanded="true" />
</folding>
@ -127,18 +144,21 @@
<option value="$PROJECT_DIR$/API.cpp" />
<option value="$PROJECT_DIR$/.gitignore" />
<option value="$PROJECT_DIR$/src/Logger.h" />
<option value="$PROJECT_DIR$/CMakeLists.txt" />
<option value="$PROJECT_DIR$/src/Logger.cpp" />
<option value="$PROJECT_DIR$/src/main.cpp" />
<option value="$PROJECT_DIR$/src/API.cpp" />
<option value="$PROJECT_DIR$/src/api/API.cpp" />
<option value="$PROJECT_DIR$/src/api/TelegramAPI.h" />
<option value="$PROJECT_DIR$/src/api/TelegramAPI.cpp" />
<option value="$PROJECT_DIR$/src/main.cpp" />
<option value="$PROJECT_DIR$/CMakeLists.txt" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="1020" />
<option name="y" value="236" />
<option name="width" value="1914" />
<option name="height" value="1051" />
<option name="x" value="-1" />
<option name="y" value="25" />
<option name="width" value="1922" />
<option name="height" value="1056" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
@ -146,7 +166,6 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
@ -161,17 +180,19 @@
</path>
<path>
<item name="iprefresher" type="b2602c69:ProjectViewProjectNode" />
<item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
<item name="DynuIPRefresher" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="api" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="iprefresher" type="b2602c69:ProjectViewProjectNode" />
<item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
<item name="Header Search Paths" type="70bed36:NamedLibraryElementNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
@ -184,12 +205,13 @@
<property name="settings.editor.selected.configurable" value="CLionExternalConfigurable" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/src/api" />
<recent name="$PROJECT_DIR$/src" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
@ -226,6 +248,7 @@
<workItem from="1557047487321" duration="761000" />
<workItem from="1557061811880" duration="10758000" />
<workItem from="1557135515205" duration="1933000" />
<workItem from="1557335004023" duration="837000" />
</task>
<task id="LOCAL-00001" summary="edited api class and made it to work">
<created>1557063528491</created>
@ -276,11 +299,18 @@
<option name="project" value="LOCAL" />
<updated>1557161378116</updated>
</task>
<option name="localTasksCounter" value="8" />
<task id="LOCAL-00008" summary="some structure updates">
<created>1557171797551</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1557171797551</updated>
</task>
<option name="localTasksCounter" value="9" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="32403000" />
<option name="totallyTimeSpent" value="33265000" />
</component>
<component name="TodoView">
<todo-panel id="selected-file">
@ -292,26 +322,26 @@
</todo-panel>
</component>
<component name="ToolWindowManager">
<frame x="1919" y="0" width="1922" height="1081" extended-state="6" />
<frame x="-1" y="25" width="1922" height="1056" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.26307365" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.26627535" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Inspection Results" weight="0.32916668" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.31770834" />
<window_info anchor="bottom" id="Run" order="2" weight="0.31764707" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" weight="0.32916668" />
<window_info anchor="bottom" id="Database Changes" order="7" />
<window_info anchor="bottom" id="Messages" order="8" visible="true" weight="0.32604167" />
<window_info active="true" anchor="bottom" id="Messages" order="8" visible="true" weight="0.32513368" />
<window_info anchor="bottom" id="Terminal" order="9" weight="0.32916668" />
<window_info anchor="bottom" id="Event Log" order="10" side_tool="true" />
<window_info anchor="bottom" id="Version Control" order="11" weight="0.32916668" />
<window_info anchor="bottom" id="CMake" order="12" weight="0.328125" />
<window_info anchor="bottom" id="Inspection Results" order="13" weight="0.32916668" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@ -328,16 +358,14 @@
<MESSAGE value="log on error" />
<MESSAGE value="syntax update and sperate variable for dynu domain id" />
<MESSAGE value="reformated output of main" />
<option name="LAST_COMMIT_MESSAGE" value="reformated output of main" />
<MESSAGE value="some structure updates" />
<option name="LAST_COMMIT_MESSAGE" value="some structure updates" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/test.cpp" />
<entry file="file://$PROJECT_DIR$/test.h" />
<entry file="file://$PROJECT_DIR$/cmake_install.cmake" />
<entry file="file://$PROJECT_DIR$/iprefresher.cbp" />
<entry file="file://$PROJECT_DIR$/src/Hashmap.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/.gitignore">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="424">
@ -346,13 +374,17 @@
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/cmake-build-debug/out.myfile" />
<entry file="file://$PROJECT_DIR$/src/Logger.h">
<entry file="file://$PROJECT_DIR$/cmake-build-debug/CMakeCache.txt" />
<entry file="file://$PROJECT_DIR$/src/api/API.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120">
<caret line="8" column="14" selection-start-line="8" selection-start-column="14" selection-end-line="8" selection-end-column="14" />
<state relative-caret-position="210">
<caret line="14" column="36" selection-start-line="14" selection-start-column="36" selection-end-line="14" selection-end-column="36" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/Hashmap.h">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/cmake-build-debug/dynurefresher.log">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="195">
@ -363,14 +395,33 @@
<entry file="file://$PROJECT_DIR$/cmake-build-debug/ip.txt">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/src/API.h">
<entry file="file://$PROJECT_DIR$/src/Logger.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="210">
<caret line="14" column="36" selection-start-line="14" selection-start-column="36" selection-end-line="14" selection-end-column="36" />
<state relative-caret-position="120">
<caret line="8" column="14" selection-start-line="8" selection-start-column="14" selection-end-line="8" selection-end-column="14" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/api/TelegramAPI.h">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret column="2" lean-forward="true" selection-start-column="2" selection-end-column="2" />
<folding>
<element signature="e#110#127#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/api/API.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="243">
<caret line="18" selection-start-line="18" selection-end-line="18" />
<folding>
<element signature="e#40#56#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/cmake-build-debug/CMakeCache.txt" />
<entry file="file://$PROJECT_DIR$/src/Logger.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="555">
@ -381,10 +432,17 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/api/TelegramAPI.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120">
<caret line="8" column="26" selection-start-line="8" selection-start-column="26" selection-end-line="8" selection-end-column="26" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="330">
<caret line="22" selection-start-line="22" selection-end-line="22" />
<state relative-caret-position="528">
<caret line="58" column="27" lean-forward="true" selection-start-line="58" selection-start-column="27" selection-end-line="58" selection-end-column="27" />
<folding>
<element signature="e#0#19#0" expanded="true" />
</folding>
@ -393,18 +451,8 @@
</entry>
<entry file="file://$PROJECT_DIR$/CMakeLists.txt">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="12" selection-start-line="12" selection-end-line="12" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/API.cpp">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="18" selection-start-line="18" selection-end-line="18" />
<folding>
<element signature="e#40#56#0" expanded="true" />
</folding>
<state relative-caret-position="330">
<caret line="22" column="8" selection-start-line="22" selection-start-column="8" selection-end-line="22" selection-end-column="8" />
</state>
</provider>
</entry>

View File

@ -7,7 +7,20 @@ find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR})
set(SOURCE src/main.cpp src/API.h src/API.cpp src/Hashmap.h src/Logger.cpp src/Logger.h)
set(SOURCE
src/main.cpp
src/api/API.h
src/api/API.cpp
src/Hashmap.h
src/Logger.cpp
src/Logger.h
src/api/TelegramAPI.cpp
src/api/TelegramAPI.h
)
add_executable(iprefresher ${SOURCE})

View File

@ -3,7 +3,7 @@
//
#include "API.h"
#include "Hashmap.h"
#include "../Hashmap.h"
#include <string>
#include <iostream>

View File

@ -7,7 +7,7 @@
#include <string>
#include "Hashmap.h"
#include "../Hashmap.h"
class API {
public:

10
src/api/TelegramAPI.cpp Normal file
View File

@ -0,0 +1,10 @@
//
// Created by lukas on 08.05.19.
//
#include "TelegramAPI.h"
void TelegramAPI::sendMessage(std::string text) {
std::string reply = request("https://api.telegram.org/bot"+ apikey + "/sendmessage?chat_id="+chatid+"&text="+text);
std::cout << "[DEBUG] " <<reply << std::endl;
}

22
src/api/TelegramAPI.h Normal file
View File

@ -0,0 +1,22 @@
//
// Created by lukas on 08.05.19.
//
#ifndef IPREFRESHER_TELEGRAMAPI_H
#define IPREFRESHER_TELEGRAMAPI_H
#include <string>
#include "API.h"
class TelegramAPI : API{
public:
void sendMessage(std::string text);
private:
std::string apikey = "717213769:AAHan1nSXhUsxLJAN1Dv8Oc0z8wqwDdYPn4";
std::string chatid = "618154204";
};
#endif //IPREFRESHER_TELEGRAMAPI_H

View File

@ -1,8 +1,9 @@
#include <iostream>
#include <ctime>
#include "API.h"
#include "api/API.h"
#include "Logger.h"
#include "api/TelegramAPI.h"
int main(int argc, char *argv[]) {
@ -57,6 +58,9 @@ int main(int argc, char *argv[]) {
if (dynurepl != "{\"statusCode\":200}") {
logger.logToLogfile(" [ERROR] failed to write ip to dynu api!");
} else{
TelegramAPI tele;
tele.sendMessage(oldip + " moved to " + ip);
}
logger.safeip(ip);