Initial commit

This commit is contained in:
Hauke Zühl
2016-04-29 19:38:14 +02:00
parent 64072aef1b
commit d487bce0e4
41 changed files with 1125 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
#ifndef _TG_AUDIO_H_
#define _TG_AUDIO_H_
#include <json/json.h>
#include <string>
namespace Telegram {
class Audio {
public:
Audio(Json::Value);
private:
std::string file_id;
Json::Int64 duration;
std::string performer;
std::string title;
std::string mime_type;
Json::Int64 file_size;
};
}
#endif
+26
View File
@@ -0,0 +1,26 @@
#ifndef _TG_CHAT_H_
#define _TG_CHAT_H_
#include <json/json.h>
#include <string>
namespace Telegram {
class Chat {
public:
Chat(Json::Value);
Json::Int64 getId();
std::string getUsername();
private:
Json::Int64 id;
std::string type;
std::string title;
std::string username;
std::string first_name;
std::string last_name;
};
}
#endif
+21
View File
@@ -0,0 +1,21 @@
#ifndef _TG_CONTACT_H_
#define _TG_CONTACT_H_
#include <json/json.h>
#include <string>
namespace Telegram {
class Contact {
public:
Contact(Json::Value);
private:
std::string phone_number;
std::string first_name;
std::string last_name;
Json::Int64 user_id;
};
}
#endif
+24
View File
@@ -0,0 +1,24 @@
#ifndef _TG_DOCUMENT_H_
#define _TG_DOCUMENT_H_
#include <json/json.h>
#include <string>
#include "PhotoSize.h"
namespace Telegram {
class Document {
public:
Document(Json::Value);
private:
std::string file_id;
PhotoSize *thumb;
std::string file_name;
std::string mime_type;
Json::Int64 file_size;
};
}
#endif
+18
View File
@@ -0,0 +1,18 @@
#ifndef __TG_LOCATION_H_
#define __TG_LOCATION_H_
#include <json/json.h>
namespace Telegram {
class Location {
public:
Location(Json::Value);
private:
float longitude;
float latitude;
};
}
#endif
+78
View File
@@ -0,0 +1,78 @@
#ifndef _TG_MESSAGE_H_
#define _TG_MESSAGE_H_
#include <json/json.h>
#include <string>
#include <vector>
#include "Audio.h"
#include "Chat.h"
#include "Contact.h"
#include "Document.h"
#include "Location.h"
#include "MessageEntity.h"
#include "PhotoSize.h"
#include "Sticker.h"
#include "User.h"
#include "Venue.h"
#include "Video.h"
#include "Voice.h"
namespace Telegram {
/**
* See https://core.telegram.org/bots/api#message
*/
class Message {
public:
// Constructors
Message(void);
Message(Json::Value);
Message(std::string);
void setEntities(Json::Value);
std::vector<PhotoSize*> setPhotos(Json::Value);
Telegram::Chat *getChat();
std::string getText();
Telegram::TMessageEntities getEntities();
private:
Json::UInt64 message_id;
User *from;
Json::Int64 date;
Chat *chat;
User *forward_from;
Json::Int64 forward_date;
Message *reply_to_message;
std::string text;
Telegram::TMessageEntities entities;
Audio *audio;
Document *document;
std::vector<PhotoSize*> photo;
Sticker *sticker;
Video *video;
Voice *voice;
std::string caption;
Contact *contact;
Location *location;
Venue *venue;
User *new_chat_member;
User *left_chat_member;
std::string new_chat_title;
std::vector<PhotoSize*> new_chat_photo;
int delete_chat_photo;
int group_chat_created;
int supergroup_chat_created;
Json::Int64 migrate_to_chat_id;
Json::Int64 migrate_from_chat_id;
Message *pinned_message;
// Methods
void init(void);
void init(Json::Value);
};
}
#endif
+27
View File
@@ -0,0 +1,27 @@
#ifndef _TG_MESSAGEENTITY_H_
#define _TG_MESSAGEENTITY_H_
#include <string>
#include <json/json.h>
#include <vector>
namespace Telegram {
class MessageEntity {
public:
MessageEntity(Json::Value);
std::string getType();
private:
std::string type;
Json::Int64 offset;
Json::Int64 length;
std::string url;
};
typedef std::vector<Telegram::MessageEntity*> TMessageEntities;
}
#endif
+21
View File
@@ -0,0 +1,21 @@
#ifndef _TG_PHOTOSIZE_H_
#define _TG_PHOTOSIZE_H_
#include <json/json.h>
#include <string>
namespace Telegram {
class PhotoSize {
public:
PhotoSize(Json::Value);
private:
std::string file_id;
Json::Int64 width;
Json::Int64 height;
Json::Int64 file_size;
};
}
#endif
+24
View File
@@ -0,0 +1,24 @@
#ifndef _TG_STICKER_H_
#define _TG_STICKER_H_
#include <json/json.h>
#include <string>
#include "PhotoSize.h"
namespace Telegram {
class Sticker {
public:
Sticker(Json::Value);
private:
std::string file_id;
Json::Int64 width;
Json::Int64 height;
PhotoSize *thumb;
Json::Int64 file_size;
};
}
#endif
+63
View File
@@ -0,0 +1,63 @@
#ifndef _TELEGRAM_BOT_H_
#define _TELEGRAM_BOT_H_
#include <string>
#include <map>
#include <curl/curl.h>
#include <json/json.h>
#include "Message.h"
namespace Telegram {
class TelegramBot;
// Typedef for callbacks
typedef std::vector<std::string> TCommandLine;
typedef std::string(*CommandCallback)(TelegramBot*, TCommandLine);
typedef struct {
std::string command;
CommandCallback callback;
std::string help_text;
} TCommand;
typedef std::map<std::string, TCommand> TCommandMap;
class TelegramBot {
public:
TelegramBot();
TelegramBot(std::string);
void addCommand(TCommand);
void setWebhook(std::string);
void processMessage(std::string);
void sendMessage(std::string, Json::Int64);
void sendMessage(std::string, std::string);
Telegram::Message *getMessage();
std::map<std::string, TCommand> getCommandMap();
// Callback methods
/*
std::string start(Telegram::TelegramBot, tvCommandLine);
std::string help(tvCommandLine);
std::string whoami(tvCommandLine);
std::string loadavg(tvCommandLine);
std::string proc(tvCommandLine);
*/
private:
std::string api_url;
Telegram::Message *msg;
TCommandMap command_map;
Json::Int64 chat_id;
void init();
void apiRequest(std::string, std::map<std::string, std::string>);
void apiRequestJson(std::string, std::map<std::string, std::string>);
std::string processCommand(std::string);
};
}
#endif
+21
View File
@@ -0,0 +1,21 @@
#ifndef _TG_USER_H_
#define _TG_USER_H_
#include <json/json.h>
#include <string>
namespace Telegram {
class User {
public:
User(Json::Value);
private:
Json::Int64 id;
std::string first_name;
std::string last_name;
std::string username;
};
}
#endif
+22
View File
@@ -0,0 +1,22 @@
#ifndef _TG_VENUE_H_
#define _TG_VENUE_H_
#include <string>
#include "Location.h"
namespace Telegram {
class Venue {
public:
Venue(Json::Value);
private:
Location *location;
std::string title;
std::string address;
std::string foursquare_id;
};
}
#endif
+26
View File
@@ -0,0 +1,26 @@
#ifndef _TG_VIDEO_H_
#define _TG_VIDEO_H_
#include <json/json.h>
#include <string>
#include "PhotoSize.h"
namespace Telegram {
class Video {
public:
Video(Json::Value);
private:
std::string file_id;
Json::Int64 width;
Json::Int64 height;
Json::Int64 duration;
PhotoSize *thumb;
std::string mime_type;
Json::Int64 file_size;
};
}
#endif
+21
View File
@@ -0,0 +1,21 @@
#ifndef _TG_VOICE_H_
#define _TG_VOICE_H_
#include <json/json.h>
#include <string>
namespace Telegram {
class Voice {
public:
Voice(Json::Value);
private:
std::string file_id;
Json::Int64 duration;
std::string mime_type;
Json::Int64 file_size;
};
}
#endif
+8
View File
@@ -0,0 +1,8 @@
#ifndef __EXEC_H__
#define __EXEC_H__
#include <string>
std::string exec(const char*);
#endif
+9
View File
@@ -0,0 +1,9 @@
#ifndef __explode_h__
#define __explode_h__
#include <string>
#include <vector>
std::vector<std::string> explode( const std::string&, const std::string &);
#endif
+9
View File
@@ -0,0 +1,9 @@
#ifndef __HTTP_BUILD_QUERY_H__
#define __HTTP_BUILD_QUERY_H__
#include <map>
#include <string>
std::string http_build_query(std::map<std::string, std::string>);
#endif
+10
View File
@@ -0,0 +1,10 @@
#ifndef __JSON_ENCODE_H__
#define __JSON_ENCODE_H__
#include <map>
#include <string>
#include <json/json.h>
std::string json_encode(std::map<std::string, std::string>);
#endif
+23
View File
@@ -0,0 +1,23 @@
#ifndef __STD_H__
#define __STD_H__
#include <ios>
#include <sstream>
#include <string>
#include <vector>
// Makro(s)
#define SSTR( x ) static_cast< std::ostringstream & >(( std::ostringstream() << std::dec << x ) ).str()
typedef unsigned long long int uint64;
uint64 stoi(std::string);
std::string itos(uint64);
std::string currentDate();
std::vector<std::string> split(const std::string &text, char sep = ' ');
float stof(std::string);
std::string trim(const std::string&);
std::string gethome();
void Log(std::string);
#endif