mirror of
https://github.com/UltraCoderRU/telebotxx.git
synced 2026-01-28 04:05:13 +00:00
Source code reformated.
This commit is contained in:
parent
81bb25f4fe
commit
592751a50c
23 changed files with 1118 additions and 1069 deletions
|
|
@ -6,212 +6,213 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace telebotxx
|
||||
namespace telebotxx {
|
||||
|
||||
class Attachment
|
||||
{
|
||||
class Attachment
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
Audio,
|
||||
Document,
|
||||
Game,
|
||||
PhotoSizeArray,
|
||||
Sticker,
|
||||
Video,
|
||||
Voice,
|
||||
Contact,
|
||||
Location,
|
||||
Venue
|
||||
};
|
||||
|
||||
Attachment(Type type);
|
||||
Attachment(const Attachment&);
|
||||
Attachment(Attachment&&);
|
||||
virtual ~Attachment() = 0;
|
||||
|
||||
Type getType() const;
|
||||
|
||||
void swap(Attachment& other) noexcept;
|
||||
|
||||
private:
|
||||
Type attachmentType_;
|
||||
Audio,
|
||||
Document,
|
||||
Game,
|
||||
PhotoSizeArray,
|
||||
Sticker,
|
||||
Video,
|
||||
Voice,
|
||||
Contact,
|
||||
Location,
|
||||
Venue
|
||||
};
|
||||
|
||||
using AttachmentPtr = std::shared_ptr<Attachment>;
|
||||
Attachment(Type type);
|
||||
Attachment(const Attachment&);
|
||||
Attachment(Attachment&&);
|
||||
virtual ~Attachment() = 0;
|
||||
|
||||
class PhotoSize
|
||||
{
|
||||
public:
|
||||
PhotoSize();
|
||||
PhotoSize(const PhotoSize&);
|
||||
PhotoSize(PhotoSize&&);
|
||||
~PhotoSize();
|
||||
Type getType() const;
|
||||
|
||||
const std::string& getFileId() const;
|
||||
void setFileId(const std::string& fileId);
|
||||
void swap(Attachment& other) noexcept;
|
||||
|
||||
int getWidth() const;
|
||||
void setWidth(int width);
|
||||
private:
|
||||
Type attachmentType_;
|
||||
};
|
||||
|
||||
int getHeight() const;
|
||||
void setHeight(int height);
|
||||
using AttachmentPtr = std::shared_ptr<Attachment>;
|
||||
|
||||
int getFileSize() const;
|
||||
void setFileSize(int fileSize);
|
||||
class PhotoSize
|
||||
{
|
||||
public:
|
||||
PhotoSize();
|
||||
PhotoSize(const PhotoSize&);
|
||||
PhotoSize(PhotoSize&&);
|
||||
~PhotoSize();
|
||||
|
||||
void swap(PhotoSize& other) noexcept;
|
||||
const std::string& getFileId() const;
|
||||
void setFileId(const std::string& fileId);
|
||||
|
||||
const PhotoSize& operator=(PhotoSize other) noexcept;
|
||||
int getWidth() const;
|
||||
void setWidth(int width);
|
||||
|
||||
private:
|
||||
std::string fileId_;
|
||||
int width_;
|
||||
int height_;
|
||||
int fileSize_;
|
||||
};
|
||||
int getHeight() const;
|
||||
void setHeight(int height);
|
||||
|
||||
using PhotoSizePtr = std::shared_ptr<PhotoSize>;
|
||||
int getFileSize() const;
|
||||
void setFileSize(int fileSize);
|
||||
|
||||
class PhotoSizeArray : public Attachment
|
||||
{
|
||||
public:
|
||||
PhotoSizeArray();
|
||||
PhotoSizeArray(const PhotoSizeArray&);
|
||||
PhotoSizeArray(PhotoSizeArray&&);
|
||||
~PhotoSizeArray();
|
||||
void swap(PhotoSize& other) noexcept;
|
||||
|
||||
const std::vector<PhotoSize>& getArray() const;
|
||||
void setArray(const std::vector<PhotoSize>& array);
|
||||
const PhotoSize& operator=(PhotoSize other) noexcept;
|
||||
|
||||
void swap(PhotoSizeArray& other) noexcept;
|
||||
private:
|
||||
std::string fileId_;
|
||||
int width_;
|
||||
int height_;
|
||||
int fileSize_;
|
||||
};
|
||||
|
||||
const PhotoSizeArray& operator=(PhotoSizeArray other) noexcept;
|
||||
using PhotoSizePtr = std::shared_ptr<PhotoSize>;
|
||||
|
||||
private:
|
||||
std::vector<PhotoSize> array_;
|
||||
};
|
||||
class PhotoSizeArray : public Attachment
|
||||
{
|
||||
public:
|
||||
PhotoSizeArray();
|
||||
PhotoSizeArray(const PhotoSizeArray&);
|
||||
PhotoSizeArray(PhotoSizeArray&&);
|
||||
~PhotoSizeArray();
|
||||
|
||||
using PhotoSizeArrayPtr = std::shared_ptr<PhotoSizeArray>;
|
||||
const std::vector<PhotoSize>& getArray() const;
|
||||
void setArray(const std::vector<PhotoSize>& array);
|
||||
|
||||
class Audio : public Attachment
|
||||
{
|
||||
public:
|
||||
Audio();
|
||||
Audio(const Audio&);
|
||||
Audio(Audio&&);
|
||||
~Audio();
|
||||
void swap(PhotoSizeArray& other) noexcept;
|
||||
|
||||
const std::string& getFileId() const;
|
||||
void setFileId(const std::string& fileId);
|
||||
const PhotoSizeArray& operator=(PhotoSizeArray other) noexcept;
|
||||
|
||||
int getDuration() const;
|
||||
void setDuration(int duration);
|
||||
private:
|
||||
std::vector<PhotoSize> array_;
|
||||
};
|
||||
|
||||
const std::string& getPerformer() const;
|
||||
void setPerformer(const std::string& performer);
|
||||
using PhotoSizeArrayPtr = std::shared_ptr<PhotoSizeArray>;
|
||||
|
||||
const std::string& getTitle() const;
|
||||
void setTitle(const std::string& title);
|
||||
class Audio : public Attachment
|
||||
{
|
||||
public:
|
||||
Audio();
|
||||
Audio(const Audio&);
|
||||
Audio(Audio&&);
|
||||
~Audio();
|
||||
|
||||
const std::string& getMimeType() const;
|
||||
void setMimeType(const std::string& mimeType);
|
||||
const std::string& getFileId() const;
|
||||
void setFileId(const std::string& fileId);
|
||||
|
||||
int getFileSize() const;
|
||||
void setFileSize(int fileSize);
|
||||
int getDuration() const;
|
||||
void setDuration(int duration);
|
||||
|
||||
void swap(Audio& other) noexcept;
|
||||
const std::string& getPerformer() const;
|
||||
void setPerformer(const std::string& performer);
|
||||
|
||||
const Audio& operator=(Audio other) noexcept;
|
||||
const std::string& getTitle() const;
|
||||
void setTitle(const std::string& title);
|
||||
|
||||
private:
|
||||
std::string fileId_;
|
||||
int duration_;
|
||||
std::string performer_;
|
||||
std::string title_;
|
||||
std::string mimeType_;
|
||||
int fileSize_;
|
||||
};
|
||||
const std::string& getMimeType() const;
|
||||
void setMimeType(const std::string& mimeType);
|
||||
|
||||
class Document : public Attachment
|
||||
{
|
||||
public:
|
||||
Document();
|
||||
Document(const Document&);
|
||||
Document(Document&&);
|
||||
~Document();
|
||||
int getFileSize() const;
|
||||
void setFileSize(int fileSize);
|
||||
|
||||
const std::string& getFileId() const;
|
||||
void setFileId(const std::string& fileId);
|
||||
void swap(Audio& other) noexcept;
|
||||
|
||||
const PhotoSizePtr getThumb() const;
|
||||
void setThumb(const PhotoSizePtr& thumb);
|
||||
const Audio& operator=(Audio other) noexcept;
|
||||
|
||||
const std::string& getFileName() const;
|
||||
void setFileName(const std::string& fileName);
|
||||
private:
|
||||
std::string fileId_;
|
||||
int duration_;
|
||||
std::string performer_;
|
||||
std::string title_;
|
||||
std::string mimeType_;
|
||||
int fileSize_;
|
||||
};
|
||||
|
||||
const std::string& getMimeType() const;
|
||||
void setMimeType(const std::string& mimeType);
|
||||
class Document : public Attachment
|
||||
{
|
||||
public:
|
||||
Document();
|
||||
Document(const Document&);
|
||||
Document(Document&&);
|
||||
~Document();
|
||||
|
||||
int getFileSize() const;
|
||||
void setFileSize(int fileSize);
|
||||
const std::string& getFileId() const;
|
||||
void setFileId(const std::string& fileId);
|
||||
|
||||
void swap(Document& other) noexcept;
|
||||
const PhotoSizePtr getThumb() const;
|
||||
void setThumb(const PhotoSizePtr& thumb);
|
||||
|
||||
const Document& operator=(Document other) noexcept;
|
||||
const std::string& getFileName() const;
|
||||
void setFileName(const std::string& fileName);
|
||||
|
||||
private:
|
||||
std::string fileId_;
|
||||
PhotoSizePtr thumb_;
|
||||
std::string fileName_;
|
||||
std::string mimeType_;
|
||||
int fileSize_;
|
||||
};
|
||||
const std::string& getMimeType() const;
|
||||
void setMimeType(const std::string& mimeType);
|
||||
|
||||
class Sticker : public Attachment
|
||||
{
|
||||
public:
|
||||
Sticker();
|
||||
Sticker(const Sticker&);
|
||||
Sticker(Sticker&&);
|
||||
~Sticker();
|
||||
int getFileSize() const;
|
||||
void setFileSize(int fileSize);
|
||||
|
||||
const std::string& getFileId() const;
|
||||
void setFileId(const std::string& fileId);
|
||||
void swap(Document& other) noexcept;
|
||||
|
||||
int getWidth() const;
|
||||
void setWidth(int width);
|
||||
const Document& operator=(Document other) noexcept;
|
||||
|
||||
int getHeight() const;
|
||||
void setHeight(int height);
|
||||
private:
|
||||
std::string fileId_;
|
||||
PhotoSizePtr thumb_;
|
||||
std::string fileName_;
|
||||
std::string mimeType_;
|
||||
int fileSize_;
|
||||
};
|
||||
|
||||
const PhotoSizePtr getThumb() const;
|
||||
void setThumb(const PhotoSizePtr& thumb);
|
||||
class Sticker : public Attachment
|
||||
{
|
||||
public:
|
||||
Sticker();
|
||||
Sticker(const Sticker&);
|
||||
Sticker(Sticker&&);
|
||||
~Sticker();
|
||||
|
||||
const std::string& getEmoji() const;
|
||||
void setEmoji(const std::string& emoji);
|
||||
const std::string& getFileId() const;
|
||||
void setFileId(const std::string& fileId);
|
||||
|
||||
int getFileSize() const;
|
||||
void setFileSize(int fileSize);
|
||||
int getWidth() const;
|
||||
void setWidth(int width);
|
||||
|
||||
void swap(Sticker& other) noexcept;
|
||||
int getHeight() const;
|
||||
void setHeight(int height);
|
||||
|
||||
const Sticker& operator=(Sticker other) noexcept;
|
||||
const PhotoSizePtr getThumb() const;
|
||||
void setThumb(const PhotoSizePtr& thumb);
|
||||
|
||||
private:
|
||||
std::string fileId_;
|
||||
int width_;
|
||||
int height_;
|
||||
PhotoSizePtr thumb_;
|
||||
std::string emoji_;
|
||||
int fileSize_;
|
||||
};
|
||||
const std::string& getEmoji() const;
|
||||
void setEmoji(const std::string& emoji);
|
||||
|
||||
int getFileSize() const;
|
||||
void setFileSize(int fileSize);
|
||||
|
||||
void swap(Sticker& other) noexcept;
|
||||
|
||||
const Sticker& operator=(Sticker other) noexcept;
|
||||
|
||||
private:
|
||||
std::string fileId_;
|
||||
int width_;
|
||||
int height_;
|
||||
PhotoSizePtr thumb_;
|
||||
std::string emoji_;
|
||||
int fileSize_;
|
||||
};
|
||||
|
||||
void swap(PhotoSize& lhs, PhotoSize& rhs);
|
||||
void swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs);
|
||||
void swap(Audio& lhs, Audio& rhs);
|
||||
void swap(Document& lhs, Document& rhs);
|
||||
void swap(Sticker& lhs, Sticker& rhs);
|
||||
|
||||
void swap(PhotoSize& lhs, PhotoSize& rhs);
|
||||
void swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs);
|
||||
void swap(Audio& lhs, Audio& rhs);
|
||||
void swap(Document& lhs, Document& rhs);
|
||||
void swap(Sticker& lhs, Sticker& rhs);
|
||||
}
|
||||
|
||||
#endif // TELEBOTXX_ATTACHMENT_HPP
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef TELEBOTXX_BOTAPI_H
|
||||
#define TELEBOTXX_BOTAPI_H
|
||||
#ifndef TELEBOTXX_BOTAPI_HPP
|
||||
#define TELEBOTXX_BOTAPI_HPP
|
||||
|
||||
#include "User.hpp"
|
||||
#include "Message.hpp"
|
||||
|
|
@ -10,85 +10,86 @@
|
|||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace telebotxx
|
||||
namespace telebotxx {
|
||||
|
||||
template <typename RequestType, typename T>
|
||||
void setRequestOption(RequestType& request, T t)
|
||||
{
|
||||
template <typename RequestType, typename T>
|
||||
void setRequestOption(RequestType& request, T t)
|
||||
{
|
||||
request.setOption(t);
|
||||
}
|
||||
|
||||
template <typename RequestType, typename T, typename... Ts>
|
||||
void setRequestOption(RequestType& request, T&& t, Ts&&... ts)
|
||||
{
|
||||
setRequestOption(request, std::forward<T>(t));
|
||||
setRequestOption(request, std::forward<Ts>(ts)...);
|
||||
};
|
||||
|
||||
class BotApi
|
||||
{
|
||||
public:
|
||||
|
||||
/// \param [in] token bot's secret token
|
||||
BotApi(const std::string& token);
|
||||
|
||||
~BotApi();
|
||||
|
||||
/// \brief Get basic information about the bot
|
||||
/// \return User object with information about the bot
|
||||
User getMe();
|
||||
|
||||
/// \brief Send text message
|
||||
/// \param chatId chat identifier
|
||||
/// \param text text
|
||||
/// \return Message object, recieved from the server
|
||||
Message sendMessage(ChatId&& chatId, Text&& text);
|
||||
|
||||
/// \brief Send text message
|
||||
/// \param chatId chat identifier
|
||||
/// \param text text
|
||||
/// \param args parameters
|
||||
/// \return Message object, recieved from the server
|
||||
template<typename... Ts>
|
||||
Message sendMessage(ChatId&& chatId, Text&& text, Ts&&... args)
|
||||
{
|
||||
SendMessageRequest request(getTelegramMainUrl(), std::forward<ChatId>(chatId), std::forward<Text>(text));
|
||||
setRequestOption(request, std::forward<Ts>(args)...);
|
||||
return request.execute();
|
||||
}
|
||||
|
||||
/// \brief Send image
|
||||
/// \param [in] chatId chat identifier
|
||||
/// \param [in] photo photo
|
||||
/// \return Message object, recieved from the server
|
||||
Message sendPhoto(ChatId&& chatId, Photo&& photo);
|
||||
|
||||
/// \brief Send image
|
||||
/// \param [in] chatId chat identifier
|
||||
/// \param [in] photo photo
|
||||
/// \param [in] args parameters
|
||||
/// \return Message object, recieved from the server
|
||||
template<typename... Ts>
|
||||
Message sendPhoto(ChatId&& chatId, Photo&& photo, Ts&&... args)
|
||||
{
|
||||
SendPhotoRequest request(getTelegramMainUrl(), std::forward<ChatId>(chatId), std::forward<Photo>(photo));
|
||||
setRequestOption(request, std::forward<Ts>(args)...);
|
||||
return request.execute();
|
||||
}
|
||||
|
||||
/// \brief Get updates using long polling
|
||||
/// \param offset identifier of the first update to be returned
|
||||
/// \param limit maximum number of updates to be retrieved
|
||||
/// \param timeout timeout in seconds for long polling
|
||||
/// \return Updates (vector of Update)
|
||||
Updates getUpdates(int offset = 0, unsigned short limit = 0, unsigned timeout = 0);
|
||||
|
||||
private:
|
||||
std::string getTelegramMainUrl() const;
|
||||
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
request.setOption(t);
|
||||
}
|
||||
|
||||
#endif // TELEBOTXX_BOTAPI_H
|
||||
template <typename RequestType, typename T, typename... Ts>
|
||||
void setRequestOption(RequestType& request, T&& t, Ts&&... ts)
|
||||
{
|
||||
setRequestOption(request, std::forward<T>(t));
|
||||
setRequestOption(request, std::forward<Ts>(ts)...);
|
||||
};
|
||||
|
||||
class BotApi
|
||||
{
|
||||
public:
|
||||
|
||||
/// \param [in] token bot's secret token
|
||||
BotApi(const std::string& token);
|
||||
|
||||
~BotApi();
|
||||
|
||||
/// \brief Get basic information about the bot
|
||||
/// \return User object with information about the bot
|
||||
User getMe();
|
||||
|
||||
/// \brief Send text message
|
||||
/// \param chatId chat identifier
|
||||
/// \param text text
|
||||
/// \return Message object, recieved from the server
|
||||
Message sendMessage(ChatId&& chatId, Text&& text);
|
||||
|
||||
/// \brief Send text message
|
||||
/// \param chatId chat identifier
|
||||
/// \param text text
|
||||
/// \param args parameters
|
||||
/// \return Message object, recieved from the server
|
||||
template <typename... Ts>
|
||||
Message sendMessage(ChatId&& chatId, Text&& text, Ts&&... args)
|
||||
{
|
||||
SendMessageRequest request(getTelegramMainUrl(), std::forward<ChatId>(chatId), std::forward<Text>(text));
|
||||
setRequestOption(request, std::forward<Ts>(args)...);
|
||||
return request.execute();
|
||||
}
|
||||
|
||||
/// \brief Send image
|
||||
/// \param [in] chatId chat identifier
|
||||
/// \param [in] photo photo
|
||||
/// \return Message object, recieved from the server
|
||||
Message sendPhoto(ChatId&& chatId, Photo&& photo);
|
||||
|
||||
/// \brief Send image
|
||||
/// \param [in] chatId chat identifier
|
||||
/// \param [in] photo photo
|
||||
/// \param [in] args parameters
|
||||
/// \return Message object, recieved from the server
|
||||
template <typename... Ts>
|
||||
Message sendPhoto(ChatId&& chatId, Photo&& photo, Ts&&... args)
|
||||
{
|
||||
SendPhotoRequest request(getTelegramMainUrl(), std::forward<ChatId>(chatId), std::forward<Photo>(photo));
|
||||
setRequestOption(request, std::forward<Ts>(args)...);
|
||||
return request.execute();
|
||||
}
|
||||
|
||||
/// \brief Get updates using long polling
|
||||
/// \param offset identifier of the first update to be returned
|
||||
/// \param limit maximum number of updates to be retrieved
|
||||
/// \param timeout timeout in seconds for long polling
|
||||
/// \return Updates (vector of Update)
|
||||
Updates getUpdates(int offset = 0, unsigned short limit = 0, unsigned timeout = 0);
|
||||
|
||||
private:
|
||||
std::string getTelegramMainUrl() const;
|
||||
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TELEBOTXX_BOTAPI_HPP
|
||||
|
|
|
|||
|
|
@ -5,64 +5,65 @@
|
|||
#include <memory>
|
||||
#include <cstdint>
|
||||
|
||||
namespace telebotxx
|
||||
namespace telebotxx {
|
||||
|
||||
class Chat
|
||||
{
|
||||
class Chat
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
Private,
|
||||
Group,
|
||||
Supergroup,
|
||||
Channel
|
||||
};
|
||||
|
||||
Chat();
|
||||
Chat(const Chat&);
|
||||
Chat(Chat&&);
|
||||
~Chat();
|
||||
|
||||
std::int64_t getId() const;
|
||||
void setId(std::int64_t id);
|
||||
|
||||
Type getType() const;
|
||||
void setType(Type type);
|
||||
|
||||
const std::string& getTitle() const;
|
||||
void setTitle(const std::string& title);
|
||||
|
||||
const std::string& getUsername() const;
|
||||
void setUsername(const std::string& username);
|
||||
|
||||
const std::string& getFirstName() const;
|
||||
void setFirstName(const std::string& firstName);
|
||||
|
||||
const std::string& getLastName() const;
|
||||
void setLastName(const std::string& lastName);
|
||||
|
||||
bool isAllAdmins() const;
|
||||
void setAllAdmins(bool allAdmins);
|
||||
|
||||
void swap(Chat& other) noexcept;
|
||||
|
||||
const Chat& operator=(Chat other) noexcept;
|
||||
|
||||
private:
|
||||
std::int64_t id_;
|
||||
Type type_;
|
||||
std::string title_;
|
||||
std::string username_;
|
||||
std::string firstName_;
|
||||
std::string lastName_;
|
||||
bool allAdmins_;
|
||||
Private,
|
||||
Group,
|
||||
Supergroup,
|
||||
Channel
|
||||
};
|
||||
|
||||
using ChatPtr = std::shared_ptr<Chat>;
|
||||
Chat();
|
||||
Chat(const Chat&);
|
||||
Chat(Chat&&);
|
||||
~Chat();
|
||||
|
||||
void swap(Chat& lhs, Chat& rhs);
|
||||
std::int64_t getId() const;
|
||||
void setId(std::int64_t id);
|
||||
|
||||
Type getType() const;
|
||||
void setType(Type type);
|
||||
|
||||
const std::string& getTitle() const;
|
||||
void setTitle(const std::string& title);
|
||||
|
||||
const std::string& getUsername() const;
|
||||
void setUsername(const std::string& username);
|
||||
|
||||
const std::string& getFirstName() const;
|
||||
void setFirstName(const std::string& firstName);
|
||||
|
||||
const std::string& getLastName() const;
|
||||
void setLastName(const std::string& lastName);
|
||||
|
||||
bool isAllAdmins() const;
|
||||
void setAllAdmins(bool allAdmins);
|
||||
|
||||
void swap(Chat& other) noexcept;
|
||||
|
||||
const Chat& operator=(Chat other) noexcept;
|
||||
|
||||
private:
|
||||
std::int64_t id_;
|
||||
Type type_;
|
||||
std::string title_;
|
||||
std::string username_;
|
||||
std::string firstName_;
|
||||
std::string lastName_;
|
||||
bool allAdmins_;
|
||||
};
|
||||
|
||||
using ChatPtr = std::shared_ptr<Chat>;
|
||||
|
||||
void swap(Chat& lhs, Chat& rhs);
|
||||
|
||||
Chat::Type chatTypeFromString(const std::string& str);
|
||||
|
||||
Chat::Type chatTypeFromString(const std::string& str);
|
||||
}
|
||||
|
||||
#endif // TELEBOTXX_CHAT_HPP
|
||||
|
|
|
|||
|
|
@ -3,33 +3,33 @@
|
|||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace telebotxx
|
||||
namespace telebotxx {
|
||||
|
||||
class ParseError : public std::invalid_argument
|
||||
{
|
||||
class ParseError : public std::invalid_argument
|
||||
public:
|
||||
ParseError(const std::string& message)
|
||||
: std::invalid_argument(message)
|
||||
{
|
||||
public:
|
||||
ParseError(const std::string& message)
|
||||
: std::invalid_argument(message)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
class ApiError : public std::runtime_error
|
||||
class ApiError : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
ApiError(int code, const std::string& message)
|
||||
: std::runtime_error(message), code_(code)
|
||||
{
|
||||
public:
|
||||
ApiError(int code, const std::string& message)
|
||||
: std::runtime_error(message), code_(code)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
int getCode() const
|
||||
{
|
||||
return code_;
|
||||
}
|
||||
int getCode() const
|
||||
{
|
||||
return code_;
|
||||
}
|
||||
|
||||
protected:
|
||||
int code_;
|
||||
};
|
||||
protected:
|
||||
int code_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
#ifndef TELEBOTXX_LOGGING_HPP
|
||||
#define TELEBOTXX_LOGGING_HPP
|
||||
|
||||
namespace telebotxx
|
||||
{
|
||||
extern bool debugMode;
|
||||
namespace telebotxx {
|
||||
|
||||
extern bool debugMode;
|
||||
|
||||
/// \brief Enable/disable debug output
|
||||
void setDebugMode(bool enabled);
|
||||
|
||||
/// \brief Enable/disable debug output
|
||||
void setDebugMode(bool enabled);
|
||||
}
|
||||
|
||||
#endif // TELEBOTXX_LOGGING_HPP
|
||||
|
|
|
|||
|
|
@ -9,177 +9,178 @@
|
|||
#include <ctime>
|
||||
#include <memory>
|
||||
|
||||
namespace telebotxx
|
||||
namespace telebotxx {
|
||||
|
||||
class MessageEntity
|
||||
{
|
||||
class MessageEntity
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
Mention,
|
||||
Hashtag,
|
||||
BotCommand,
|
||||
Url,
|
||||
Email,
|
||||
Bold,
|
||||
Italic,
|
||||
Code,
|
||||
Pre,
|
||||
TextLink,
|
||||
TextMention
|
||||
};
|
||||
|
||||
MessageEntity();
|
||||
MessageEntity(const MessageEntity&);
|
||||
MessageEntity(MessageEntity&&);
|
||||
~MessageEntity();
|
||||
|
||||
Type getType() const;
|
||||
void setType(Type type);
|
||||
|
||||
int getOffset() const;
|
||||
void setOffset(int offset);
|
||||
|
||||
size_t getLength() const;
|
||||
void setLength(size_t length);
|
||||
|
||||
const std::string& getUrl() const;
|
||||
void setUrl(const std::string& url);
|
||||
|
||||
const User& getUser() const;
|
||||
void setUser(const User& user);
|
||||
|
||||
void swap(MessageEntity& other) noexcept;
|
||||
|
||||
const MessageEntity& operator=(MessageEntity other);
|
||||
|
||||
private:
|
||||
Type type_;
|
||||
int offset_;
|
||||
std::size_t length_;
|
||||
std::string url_;
|
||||
User user_;
|
||||
Mention,
|
||||
Hashtag,
|
||||
BotCommand,
|
||||
Url,
|
||||
Email,
|
||||
Bold,
|
||||
Italic,
|
||||
Code,
|
||||
Pre,
|
||||
TextLink,
|
||||
TextMention
|
||||
};
|
||||
|
||||
MessageEntity::Type messageEntityTypeFromString(const std::string& str);
|
||||
MessageEntity();
|
||||
MessageEntity(const MessageEntity&);
|
||||
MessageEntity(MessageEntity&&);
|
||||
~MessageEntity();
|
||||
|
||||
using MessageEntities = std::vector<MessageEntity>;
|
||||
Type getType() const;
|
||||
void setType(Type type);
|
||||
|
||||
class Message;
|
||||
using MessagePtr = std::shared_ptr<Message>;
|
||||
int getOffset() const;
|
||||
void setOffset(int offset);
|
||||
|
||||
class Message
|
||||
{
|
||||
public:
|
||||
Message();
|
||||
Message(const Message&);
|
||||
Message(Message&&);
|
||||
~Message();
|
||||
size_t getLength() const;
|
||||
void setLength(size_t length);
|
||||
|
||||
int getId() const;
|
||||
void setId(int id);
|
||||
const std::string& getUrl() const;
|
||||
void setUrl(const std::string& url);
|
||||
|
||||
const UserPtr getFrom() const;
|
||||
void setFrom(UserPtr from);
|
||||
const User& getUser() const;
|
||||
void setUser(const User& user);
|
||||
|
||||
time_t getDate() const;
|
||||
void setDate(time_t date);
|
||||
void swap(MessageEntity& other) noexcept;
|
||||
|
||||
const Chat& getChat() const;
|
||||
void setChat(const Chat& chat);
|
||||
const MessageEntity& operator=(MessageEntity other);
|
||||
|
||||
const UserPtr getForwardFrom() const;
|
||||
void setForwardFrom(UserPtr forwardFrom);
|
||||
private:
|
||||
Type type_;
|
||||
int offset_;
|
||||
std::size_t length_;
|
||||
std::string url_;
|
||||
User user_;
|
||||
};
|
||||
|
||||
const ChatPtr getForwardFromChat() const;
|
||||
void setForwardFromChat(ChatPtr forwardFromChat);
|
||||
MessageEntity::Type messageEntityTypeFromString(const std::string& str);
|
||||
|
||||
time_t getForwardDate() const;
|
||||
void setForwardDate(time_t forwardDate);
|
||||
using MessageEntities = std::vector<MessageEntity>;
|
||||
|
||||
const MessagePtr getReplyToMessage() const;
|
||||
void setReplyToMessage(MessagePtr replyToMessage);
|
||||
class Message;
|
||||
using MessagePtr = std::shared_ptr<Message>;
|
||||
|
||||
time_t getEditDate() const;
|
||||
void setEditDate(time_t editDate);
|
||||
class Message
|
||||
{
|
||||
public:
|
||||
Message();
|
||||
Message(const Message&);
|
||||
Message(Message&&);
|
||||
~Message();
|
||||
|
||||
const std::string& getText() const;
|
||||
void setText(const std::string& text);
|
||||
int getId() const;
|
||||
void setId(int id);
|
||||
|
||||
const MessageEntities& getEntities() const;
|
||||
void setEntities(MessageEntities&& entities);
|
||||
const UserPtr getFrom() const;
|
||||
void setFrom(UserPtr from);
|
||||
|
||||
const AttachmentPtr getAttachment() const;
|
||||
void setAttachment(AttachmentPtr attachment);
|
||||
time_t getDate() const;
|
||||
void setDate(time_t date);
|
||||
|
||||
const std::string& getCaption() const;
|
||||
void setCaption(const std::string& caption);
|
||||
const Chat& getChat() const;
|
||||
void setChat(const Chat& chat);
|
||||
|
||||
const UserPtr getNewChatMember() const;
|
||||
void setNewChatMember(UserPtr newChatMember);
|
||||
const UserPtr getForwardFrom() const;
|
||||
void setForwardFrom(UserPtr forwardFrom);
|
||||
|
||||
const UserPtr getLeftChatMember() const;
|
||||
void setLeftChatMember(UserPtr leftChatMember);
|
||||
const ChatPtr getForwardFromChat() const;
|
||||
void setForwardFromChat(ChatPtr forwardFromChat);
|
||||
|
||||
const std::string& getNewChatTitle() const;
|
||||
void setNewChatTitle(const std::string& newChatTitle);
|
||||
time_t getForwardDate() const;
|
||||
void setForwardDate(time_t forwardDate);
|
||||
|
||||
const PhotoSizeArrayPtr getNewChatPhoto() const;
|
||||
void setNewChatPhoto(PhotoSizeArrayPtr newChatPhoto);
|
||||
const MessagePtr getReplyToMessage() const;
|
||||
void setReplyToMessage(MessagePtr replyToMessage);
|
||||
|
||||
bool isDeleteChatPhoto() const;
|
||||
void setDeleteChatPhoto(bool deleteChatPhoto);
|
||||
time_t getEditDate() const;
|
||||
void setEditDate(time_t editDate);
|
||||
|
||||
bool isGroupChatCreated() const;
|
||||
void setGroupChatCreated(bool groupChatCreated);
|
||||
const std::string& getText() const;
|
||||
void setText(const std::string& text);
|
||||
|
||||
bool isSuperGroupChatCreated() const;
|
||||
void setSuperGroupChatCreated(bool superGroupChatCreated);
|
||||
const MessageEntities& getEntities() const;
|
||||
void setEntities(MessageEntities&& entities);
|
||||
|
||||
bool isChannelChatCreated() const;
|
||||
void setChannelChatCreated(bool channelChatCreated);
|
||||
const AttachmentPtr getAttachment() const;
|
||||
void setAttachment(AttachmentPtr attachment);
|
||||
|
||||
std::int64_t getMigrateToChatId() const;
|
||||
void setMigrateToChatId(std::int64_t migrateToChatId);
|
||||
const std::string& getCaption() const;
|
||||
void setCaption(const std::string& caption);
|
||||
|
||||
std::int64_t getMigrateFromChatId() const;
|
||||
void setMigrateFromChatId(std::int64_t migrateFromChatId);
|
||||
const UserPtr getNewChatMember() const;
|
||||
void setNewChatMember(UserPtr newChatMember);
|
||||
|
||||
const MessagePtr getPinnedMessage() const;
|
||||
void setPinnedMessage(MessagePtr pinnedMessage);
|
||||
const UserPtr getLeftChatMember() const;
|
||||
void setLeftChatMember(UserPtr leftChatMember);
|
||||
|
||||
void swap(Message& other) noexcept;
|
||||
const std::string& getNewChatTitle() const;
|
||||
void setNewChatTitle(const std::string& newChatTitle);
|
||||
|
||||
const Message& operator=(Message other) noexcept;
|
||||
const PhotoSizeArrayPtr getNewChatPhoto() const;
|
||||
void setNewChatPhoto(PhotoSizeArrayPtr newChatPhoto);
|
||||
|
||||
private:
|
||||
int id_;
|
||||
UserPtr from_;
|
||||
std::time_t date_;
|
||||
Chat chat_;
|
||||
UserPtr forwardFrom_;
|
||||
ChatPtr forwardFromChat_;
|
||||
std::time_t forwardDate_;
|
||||
MessagePtr replyToMessage_;
|
||||
std::time_t editDate_;
|
||||
std::string text_;
|
||||
MessageEntities entities_;
|
||||
AttachmentPtr attachment_;
|
||||
std::string caption_;
|
||||
UserPtr newChatMember_;
|
||||
UserPtr leftChatMember_;
|
||||
std::string newChatTitle_;
|
||||
PhotoSizeArrayPtr newChatPhoto_;
|
||||
bool deleteChatPhoto_;
|
||||
bool groupChatCreated_;
|
||||
bool superGroupChatCreated_;
|
||||
bool channelChatCreated_;
|
||||
std::int64_t migrateToChatId_;
|
||||
std::int64_t migrateFromChatId_;
|
||||
MessagePtr pinnedMessage_;
|
||||
};
|
||||
bool isDeleteChatPhoto() const;
|
||||
void setDeleteChatPhoto(bool deleteChatPhoto);
|
||||
|
||||
bool isGroupChatCreated() const;
|
||||
void setGroupChatCreated(bool groupChatCreated);
|
||||
|
||||
bool isSuperGroupChatCreated() const;
|
||||
void setSuperGroupChatCreated(bool superGroupChatCreated);
|
||||
|
||||
bool isChannelChatCreated() const;
|
||||
void setChannelChatCreated(bool channelChatCreated);
|
||||
|
||||
std::int64_t getMigrateToChatId() const;
|
||||
void setMigrateToChatId(std::int64_t migrateToChatId);
|
||||
|
||||
std::int64_t getMigrateFromChatId() const;
|
||||
void setMigrateFromChatId(std::int64_t migrateFromChatId);
|
||||
|
||||
const MessagePtr getPinnedMessage() const;
|
||||
void setPinnedMessage(MessagePtr pinnedMessage);
|
||||
|
||||
void swap(Message& other) noexcept;
|
||||
|
||||
const Message& operator=(Message other) noexcept;
|
||||
|
||||
private:
|
||||
int id_;
|
||||
UserPtr from_;
|
||||
std::time_t date_;
|
||||
Chat chat_;
|
||||
UserPtr forwardFrom_;
|
||||
ChatPtr forwardFromChat_;
|
||||
std::time_t forwardDate_;
|
||||
MessagePtr replyToMessage_;
|
||||
std::time_t editDate_;
|
||||
std::string text_;
|
||||
MessageEntities entities_;
|
||||
AttachmentPtr attachment_;
|
||||
std::string caption_;
|
||||
UserPtr newChatMember_;
|
||||
UserPtr leftChatMember_;
|
||||
std::string newChatTitle_;
|
||||
PhotoSizeArrayPtr newChatPhoto_;
|
||||
bool deleteChatPhoto_;
|
||||
bool groupChatCreated_;
|
||||
bool superGroupChatCreated_;
|
||||
bool channelChatCreated_;
|
||||
std::int64_t migrateToChatId_;
|
||||
std::int64_t migrateFromChatId_;
|
||||
MessagePtr pinnedMessage_;
|
||||
};
|
||||
|
||||
void swap(Message& lhs, Message& rhs);
|
||||
|
||||
void swap(Message& lhs, Message& rhs);
|
||||
}
|
||||
|
||||
#endif // TELEBOTXX_MESSAGE_HPP
|
||||
|
|
|
|||
|
|
@ -4,128 +4,129 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace telebotxx
|
||||
namespace telebotxx {
|
||||
|
||||
class ChatId
|
||||
{
|
||||
class ChatId
|
||||
public:
|
||||
ChatId(int);
|
||||
ChatId(const std::string&);
|
||||
ChatId(const ChatId&);
|
||||
ChatId(ChatId&&);
|
||||
~ChatId();
|
||||
|
||||
enum class Type { Id, Username };
|
||||
Type getType() const;
|
||||
const int getId() const;
|
||||
const std::string getUsername() const;
|
||||
private:
|
||||
Type type_;
|
||||
union
|
||||
{
|
||||
public:
|
||||
ChatId(int);
|
||||
ChatId(const std::string&);
|
||||
ChatId(const ChatId&);
|
||||
ChatId(ChatId&&);
|
||||
~ChatId();
|
||||
|
||||
enum class Type { Id, Username };
|
||||
Type getType() const;
|
||||
const int getId() const;
|
||||
const std::string getUsername() const;
|
||||
private:
|
||||
Type type_;
|
||||
union
|
||||
{
|
||||
int id_;
|
||||
std::string username_;
|
||||
};
|
||||
};
|
||||
|
||||
using Text = std::string;
|
||||
using Caption = std::string;
|
||||
|
||||
enum class ParseMode
|
||||
{
|
||||
Plain,
|
||||
Markdown,
|
||||
Html
|
||||
};
|
||||
|
||||
class DisableWebPagePreview
|
||||
{
|
||||
public:
|
||||
DisableWebPagePreview(bool disabled = true);
|
||||
bool value() const;
|
||||
private:
|
||||
bool disable_;
|
||||
};
|
||||
|
||||
class DisableNotification
|
||||
{
|
||||
public:
|
||||
DisableNotification(bool disabled = true);
|
||||
bool value() const;
|
||||
private:
|
||||
bool disable_;
|
||||
};
|
||||
|
||||
class ReplyTo
|
||||
{
|
||||
public:
|
||||
explicit ReplyTo(int id);
|
||||
int value() const;
|
||||
private:
|
||||
int id_;
|
||||
std::string username_;
|
||||
};
|
||||
};
|
||||
|
||||
class Buffer
|
||||
using Text = std::string;
|
||||
using Caption = std::string;
|
||||
|
||||
enum class ParseMode
|
||||
{
|
||||
Plain,
|
||||
Markdown,
|
||||
Html
|
||||
};
|
||||
|
||||
class DisableWebPagePreview
|
||||
{
|
||||
public:
|
||||
DisableWebPagePreview(bool disabled = true);
|
||||
bool value() const;
|
||||
private:
|
||||
bool disable_;
|
||||
};
|
||||
|
||||
class DisableNotification
|
||||
{
|
||||
public:
|
||||
DisableNotification(bool disabled = true);
|
||||
bool value() const;
|
||||
private:
|
||||
bool disable_;
|
||||
};
|
||||
|
||||
class ReplyTo
|
||||
{
|
||||
public:
|
||||
explicit ReplyTo(int id);
|
||||
int value() const;
|
||||
private:
|
||||
int id_;
|
||||
};
|
||||
|
||||
class Buffer
|
||||
{
|
||||
public:
|
||||
Buffer(const char *buffer, std::size_t size, const std::string& filename);
|
||||
explicit Buffer(const std::vector<char>& data, const std::string& filename);
|
||||
const char *data() const;
|
||||
const std::size_t size() const;
|
||||
const std::string filename() const;
|
||||
private:
|
||||
const char *data_;
|
||||
std::size_t size_;
|
||||
std::string filename_;
|
||||
};
|
||||
|
||||
class File
|
||||
{
|
||||
public:
|
||||
explicit File(const std::string& filename);
|
||||
const std::string& getFilename() const;
|
||||
private:
|
||||
std::string filename_;
|
||||
};
|
||||
|
||||
class Url
|
||||
{
|
||||
public:
|
||||
explicit Url(const std::string& url);
|
||||
const std::string& getUrl() const;
|
||||
private:
|
||||
std::string url_;
|
||||
};
|
||||
|
||||
class Photo
|
||||
{
|
||||
public:
|
||||
explicit Photo(int id);
|
||||
explicit Photo(const Buffer&);
|
||||
explicit Photo(const File&);
|
||||
explicit Photo(const Url&);
|
||||
Photo(const Photo&);
|
||||
Photo(Photo&&);
|
||||
~Photo();
|
||||
|
||||
enum class Type { Id, Buffer, File, Url };
|
||||
Type getType() const;
|
||||
|
||||
int getId() const;
|
||||
const Buffer& getBuffer() const;
|
||||
const File& getFile() const;
|
||||
const Url& getUrl() const;
|
||||
|
||||
private:
|
||||
Type type_;
|
||||
union
|
||||
{
|
||||
public:
|
||||
Buffer(const char* buffer, std::size_t size, const std::string& filename);
|
||||
explicit Buffer(const std::vector<char>& data, const std::string& filename);
|
||||
const char* data() const;
|
||||
const std::size_t size() const;
|
||||
const std::string filename() const;
|
||||
private:
|
||||
const char* data_;
|
||||
std::size_t size_;
|
||||
std::string filename_;
|
||||
int id_;
|
||||
Buffer buffer_;
|
||||
File file_;
|
||||
Url url_;
|
||||
};
|
||||
};
|
||||
|
||||
class File
|
||||
{
|
||||
public:
|
||||
explicit File(const std::string& filename);
|
||||
const std::string& getFilename() const;
|
||||
private:
|
||||
std::string filename_;
|
||||
};
|
||||
|
||||
class Url
|
||||
{
|
||||
public:
|
||||
explicit Url(const std::string& url);
|
||||
const std::string& getUrl() const;
|
||||
private:
|
||||
std::string url_;
|
||||
};
|
||||
|
||||
class Photo
|
||||
{
|
||||
public:
|
||||
explicit Photo(int id);
|
||||
explicit Photo(const Buffer&);
|
||||
explicit Photo(const File&);
|
||||
explicit Photo(const Url&);
|
||||
Photo(const Photo&);
|
||||
Photo(Photo&&);
|
||||
~Photo();
|
||||
|
||||
enum class Type { Id, Buffer, File, Url};
|
||||
Type getType() const;
|
||||
|
||||
int getId() const;
|
||||
const Buffer& getBuffer() const;
|
||||
const File& getFile() const;
|
||||
const Url& getUrl() const;
|
||||
|
||||
private:
|
||||
Type type_;
|
||||
union
|
||||
{
|
||||
int id_;
|
||||
Buffer buffer_;
|
||||
File file_;
|
||||
Url url_;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TELEBOTXX_REQUEST_OPTIONS_HPP
|
||||
|
|
|
|||
|
|
@ -4,35 +4,34 @@
|
|||
#include <telebotxx/RequestOptions.hpp>
|
||||
#include <telebotxx/Message.hpp>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace telebotxx
|
||||
namespace telebotxx {
|
||||
|
||||
class SendMessageRequest
|
||||
{
|
||||
class SendMessageRequest
|
||||
{
|
||||
public:
|
||||
SendMessageRequest(const std::string& telegramMainUrl, const ChatId& chat, const Text& text);
|
||||
~SendMessageRequest();
|
||||
public:
|
||||
SendMessageRequest(const std::string& telegramMainUrl, const ChatId& chat, const Text& text);
|
||||
~SendMessageRequest();
|
||||
|
||||
void setParseMode(ParseMode mode);
|
||||
void setDisableWebPagePreview(const DisableWebPagePreview& disableWebPagePreview);
|
||||
void setDisableNotification(const DisableNotification& disableNotification);
|
||||
void setReplyToMessageId(const ReplyTo& replyToMessageId);
|
||||
void setParseMode(ParseMode mode);
|
||||
void setDisableWebPagePreview(const DisableWebPagePreview& disableWebPagePreview);
|
||||
void setDisableNotification(const DisableNotification& disableNotification);
|
||||
void setReplyToMessageId(const ReplyTo& replyToMessageId);
|
||||
|
||||
void setOption(ParseMode mode);
|
||||
void setOption(const DisableWebPagePreview& disableWebPagePreview);
|
||||
void setOption(const DisableNotification& disableNotification);
|
||||
void setOption(const ReplyTo& replyToMessageId);
|
||||
void setOption(ParseMode mode);
|
||||
void setOption(const DisableWebPagePreview& disableWebPagePreview);
|
||||
void setOption(const DisableNotification& disableNotification);
|
||||
void setOption(const ReplyTo& replyToMessageId);
|
||||
|
||||
Message execute();
|
||||
Message execute();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TELEBOTXX_SEND_MESSAGE_REQUEST_HPP
|
||||
|
|
|
|||
|
|
@ -4,32 +4,32 @@
|
|||
#include <telebotxx/RequestOptions.hpp>
|
||||
#include <telebotxx/Message.hpp>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace telebotxx
|
||||
namespace telebotxx {
|
||||
|
||||
class SendPhotoRequest
|
||||
{
|
||||
class SendPhotoRequest
|
||||
{
|
||||
public:
|
||||
SendPhotoRequest(const std::string& telegramMainUrl, const ChatId& chat, const Photo& photo);
|
||||
~SendPhotoRequest();
|
||||
public:
|
||||
SendPhotoRequest(const std::string& telegramMainUrl, const ChatId& chat, const Photo& photo);
|
||||
~SendPhotoRequest();
|
||||
|
||||
void setCaption(const Caption& caption);
|
||||
void setDisableNotification(const DisableNotification& disableNotification);
|
||||
void setReplyToMessageId(const ReplyTo& replyToMessageId);
|
||||
void setOption(const Caption& caption);
|
||||
void setOption(const DisableNotification& disableNotification);
|
||||
void setOption(const ReplyTo& replyToMessageId);
|
||||
void setCaption(const Caption& caption);
|
||||
void setDisableNotification(const DisableNotification& disableNotification);
|
||||
void setReplyToMessageId(const ReplyTo& replyToMessageId);
|
||||
|
||||
Message execute();
|
||||
void setOption(const Caption& caption);
|
||||
void setOption(const DisableNotification& disableNotification);
|
||||
void setOption(const ReplyTo& replyToMessageId);
|
||||
|
||||
Message execute();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // TELEBOTXX_SEND_PHOTO_REQUEST_HPP
|
||||
|
|
|
|||
|
|
@ -6,68 +6,68 @@
|
|||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace telebotxx
|
||||
namespace telebotxx {
|
||||
|
||||
class Update
|
||||
{
|
||||
class Update
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
Message,
|
||||
EditedMessage,
|
||||
InlineQuery,
|
||||
ChosenInlineResult,
|
||||
CallbackQuery
|
||||
};
|
||||
|
||||
Update(int id, Type type);
|
||||
Update(const Update&);
|
||||
Update(Update&&);
|
||||
virtual ~Update() = 0;
|
||||
|
||||
int getId() const;
|
||||
Type getType() const;
|
||||
|
||||
void swap(Update& other) noexcept;
|
||||
|
||||
private:
|
||||
int id_;
|
||||
Type updateType_;
|
||||
Message,
|
||||
EditedMessage,
|
||||
InlineQuery,
|
||||
ChosenInlineResult,
|
||||
CallbackQuery
|
||||
};
|
||||
|
||||
using UpdatePtr = std::shared_ptr<Update>;
|
||||
using Updates = std::vector<UpdatePtr>;
|
||||
Update(int id, Type type);
|
||||
Update(const Update&);
|
||||
Update(Update&&);
|
||||
virtual ~Update() = 0;
|
||||
|
||||
class MessageUpdate : public Update
|
||||
{
|
||||
public:
|
||||
MessageUpdate(int id, const Message& message);
|
||||
MessageUpdate(const MessageUpdate&);
|
||||
MessageUpdate(MessageUpdate&&);
|
||||
~MessageUpdate();
|
||||
int getId() const;
|
||||
Type getType() const;
|
||||
|
||||
const Message& getMessage() const;
|
||||
void swap(Update& other) noexcept;
|
||||
|
||||
void swap(MessageUpdate& other) noexcept;
|
||||
private:
|
||||
int id_;
|
||||
Type updateType_;
|
||||
};
|
||||
|
||||
const MessageUpdate& operator=(MessageUpdate other);
|
||||
using UpdatePtr = std::shared_ptr<Update>;
|
||||
using Updates = std::vector<UpdatePtr>;
|
||||
|
||||
private:
|
||||
Message message_;
|
||||
};
|
||||
class MessageUpdate : public Update
|
||||
{
|
||||
public:
|
||||
MessageUpdate(int id, const Message& message);
|
||||
MessageUpdate(const MessageUpdate&);
|
||||
MessageUpdate(MessageUpdate&&);
|
||||
~MessageUpdate();
|
||||
|
||||
class EditedMessageUpdate: public MessageUpdate
|
||||
{
|
||||
public:
|
||||
EditedMessageUpdate(int id, const Message& message);
|
||||
EditedMessageUpdate(const EditedMessageUpdate&);
|
||||
EditedMessageUpdate(EditedMessageUpdate&&);
|
||||
~EditedMessageUpdate();
|
||||
const Message& getMessage() const;
|
||||
|
||||
void swap(EditedMessageUpdate& other) noexcept;
|
||||
void swap(MessageUpdate& other) noexcept;
|
||||
|
||||
const EditedMessageUpdate& operator=(EditedMessageUpdate other);
|
||||
};
|
||||
const MessageUpdate& operator=(MessageUpdate other);
|
||||
|
||||
private:
|
||||
Message message_;
|
||||
};
|
||||
|
||||
class EditedMessageUpdate : public MessageUpdate
|
||||
{
|
||||
public:
|
||||
EditedMessageUpdate(int id, const Message& message);
|
||||
EditedMessageUpdate(const EditedMessageUpdate&);
|
||||
EditedMessageUpdate(EditedMessageUpdate&&);
|
||||
~EditedMessageUpdate();
|
||||
|
||||
void swap(EditedMessageUpdate& other) noexcept;
|
||||
|
||||
const EditedMessageUpdate& operator=(EditedMessageUpdate other);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,57 +4,58 @@
|
|||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
namespace telebotxx
|
||||
namespace telebotxx {
|
||||
|
||||
class User
|
||||
{
|
||||
class User
|
||||
{
|
||||
public:
|
||||
User();
|
||||
User(const User&);
|
||||
User(User&&);
|
||||
~User();
|
||||
public:
|
||||
User();
|
||||
User(const User&);
|
||||
User(User&&);
|
||||
~User();
|
||||
|
||||
/// \brief Get id
|
||||
int getId() const;
|
||||
/// \brief Get id
|
||||
int getId() const;
|
||||
|
||||
/// \brief Set id
|
||||
void setId(int id);
|
||||
/// \brief Set id
|
||||
void setId(int id);
|
||||
|
||||
/// \brief Get first name
|
||||
const std::string& getFirstName() const;
|
||||
/// \brief Get first name
|
||||
const std::string& getFirstName() const;
|
||||
|
||||
/// \brief Set first name
|
||||
void setFirstName(const std::string& firstName);
|
||||
/// \brief Set first name
|
||||
void setFirstName(const std::string& firstName);
|
||||
|
||||
/// \brief Get last name
|
||||
const std::string& getLastName() const;
|
||||
/// \brief Get last name
|
||||
const std::string& getLastName() const;
|
||||
|
||||
/// \brief Set last name
|
||||
void setLastName(const std::string& lastName);
|
||||
/// \brief Set last name
|
||||
void setLastName(const std::string& lastName);
|
||||
|
||||
/// \brief Get username
|
||||
const std::string& getUsername() const;
|
||||
/// \brief Get username
|
||||
const std::string& getUsername() const;
|
||||
|
||||
/// \brief Set username
|
||||
void setUsername(const std::string& username);
|
||||
/// \brief Set username
|
||||
void setUsername(const std::string& username);
|
||||
|
||||
/// \brief Get string representation of user
|
||||
const std::string toString() const;
|
||||
/// \brief Get string representation of user
|
||||
const std::string toString() const;
|
||||
|
||||
void swap(User&) noexcept;
|
||||
void swap(User&) noexcept;
|
||||
|
||||
const User& operator=(User other);
|
||||
const User& operator=(User other);
|
||||
|
||||
private:
|
||||
int id_;
|
||||
std::string firstName_;
|
||||
std::string lastName_;
|
||||
std::string username_;
|
||||
};
|
||||
private:
|
||||
int id_;
|
||||
std::string firstName_;
|
||||
std::string lastName_;
|
||||
std::string username_;
|
||||
};
|
||||
|
||||
using UserPtr = std::shared_ptr<User>;
|
||||
using UserPtr = std::shared_ptr<User>;
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const User& user);
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const User& user);
|
||||
}
|
||||
|
||||
#endif // TELEBOTXX_USER_H
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
#include <telebotxx/Attachment.hpp>
|
||||
|
||||
using namespace telebotxx;
|
||||
namespace telebotxx {
|
||||
|
||||
Attachment::Attachment(Type type)
|
||||
: attachmentType_(type)
|
||||
: attachmentType_(type)
|
||||
{
|
||||
}
|
||||
|
||||
Attachment::Attachment(const Attachment&) = default;
|
||||
|
||||
Attachment::Attachment(Attachment&&) = default;
|
||||
|
||||
Attachment::~Attachment() = default;
|
||||
|
||||
Attachment::Type Attachment::getType() const
|
||||
|
|
@ -24,14 +26,16 @@ void Attachment::swap(Attachment& other) noexcept
|
|||
////////////////////////////////////////////////////////////////
|
||||
|
||||
PhotoSize::PhotoSize()
|
||||
: width_(-1),
|
||||
height_(-1),
|
||||
fileSize_(-1)
|
||||
: width_(-1),
|
||||
height_(-1),
|
||||
fileSize_(-1)
|
||||
{
|
||||
}
|
||||
|
||||
PhotoSize::PhotoSize(const PhotoSize&) = default;
|
||||
|
||||
PhotoSize::PhotoSize(PhotoSize&&) = default;
|
||||
|
||||
PhotoSize::~PhotoSize() = default;
|
||||
|
||||
const std::string& PhotoSize::getFileId() const
|
||||
|
|
@ -97,7 +101,9 @@ PhotoSizeArray::PhotoSizeArray()
|
|||
}
|
||||
|
||||
PhotoSizeArray::PhotoSizeArray(const PhotoSizeArray&) = default;
|
||||
|
||||
PhotoSizeArray::PhotoSizeArray(PhotoSizeArray&&) = default;
|
||||
|
||||
PhotoSizeArray::~PhotoSizeArray() = default;
|
||||
|
||||
const std::vector<PhotoSize>& PhotoSizeArray::getArray() const
|
||||
|
|
@ -125,14 +131,16 @@ const PhotoSizeArray& PhotoSizeArray::operator=(PhotoSizeArray other) noexcept
|
|||
////////////////////////////////////////////////////////////////
|
||||
|
||||
Audio::Audio()
|
||||
: Attachment(Type::Audio),
|
||||
duration_(-1),
|
||||
fileSize_(-1)
|
||||
: Attachment(Type::Audio),
|
||||
duration_(-1),
|
||||
fileSize_(-1)
|
||||
{
|
||||
}
|
||||
|
||||
Audio::Audio(const Audio&) = default;
|
||||
|
||||
Audio::Audio(Audio&&) = default;
|
||||
|
||||
Audio::~Audio() = default;
|
||||
|
||||
const std::string& Audio::getFileId() const
|
||||
|
|
@ -216,13 +224,15 @@ const Audio& Audio::operator=(Audio other) noexcept
|
|||
////////////////////////////////////////////////////////////////
|
||||
|
||||
Document::Document()
|
||||
: Attachment(Type::Document),
|
||||
fileSize_(-1)
|
||||
: Attachment(Type::Document),
|
||||
fileSize_(-1)
|
||||
{
|
||||
}
|
||||
|
||||
Document::Document(const Document&) = default;
|
||||
|
||||
Document::Document(Document&&) = default;
|
||||
|
||||
Document::~Document() = default;
|
||||
|
||||
const std::string& Document::getFileId() const
|
||||
|
|
@ -295,13 +305,15 @@ const Document& Document::operator=(Document other) noexcept
|
|||
////////////////////////////////////////////////////////////////
|
||||
|
||||
Sticker::Sticker()
|
||||
: Attachment(Type::Sticker),
|
||||
fileSize_(-1)
|
||||
: Attachment(Type::Sticker),
|
||||
fileSize_(-1)
|
||||
{
|
||||
}
|
||||
|
||||
Sticker::Sticker(const Sticker&) = default;
|
||||
|
||||
Sticker::Sticker(Sticker&&) = default;
|
||||
|
||||
Sticker::~Sticker() = default;
|
||||
|
||||
const std::string& Sticker::getFileId() const
|
||||
|
|
@ -384,27 +396,29 @@ const Sticker& Sticker::operator=(Sticker other) noexcept
|
|||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
void telebotxx::swap(PhotoSize& lhs, PhotoSize& rhs)
|
||||
void swap(PhotoSize& lhs, PhotoSize& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
void telebotxx::swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs)
|
||||
void swap(PhotoSizeArray& lhs, PhotoSizeArray& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
void telebotxx::swap(Audio& lhs, Audio& rhs)
|
||||
void swap(Audio& lhs, Audio& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
void telebotxx::swap(Document& lhs, Document& rhs)
|
||||
void swap(Document& lhs, Document& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
void telebotxx::swap(Sticker& lhs, Sticker& rhs)
|
||||
void swap(Sticker& lhs, Sticker& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <cpr/cpr.h>
|
||||
|
||||
using namespace telebotxx;
|
||||
namespace telebotxx {
|
||||
|
||||
class BotApi::Impl
|
||||
{
|
||||
|
|
@ -41,7 +41,7 @@ public:
|
|||
{
|
||||
auto r = cpr::Post(cpr::Url{telegramMainUrl_ + "/sendPhoto"},
|
||||
cpr::Multipart{{"chat_id", chat},
|
||||
{"photo", cpr::File{filename}},
|
||||
{"photo", cpr::File{filename}},
|
||||
{"caption", caption}
|
||||
}
|
||||
);
|
||||
|
|
@ -181,3 +181,5 @@ std::string BotApi::getTelegramMainUrl() const
|
|||
{
|
||||
return impl_->getTelegramMainUrl();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
10
src/Chat.cpp
10
src/Chat.cpp
|
|
@ -1,7 +1,7 @@
|
|||
#include <telebotxx/Chat.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace telebotxx;
|
||||
namespace telebotxx {
|
||||
|
||||
Chat::Chat()
|
||||
: id_(-1),
|
||||
|
|
@ -11,7 +11,9 @@ Chat::Chat()
|
|||
}
|
||||
|
||||
Chat::Chat(const Chat&) = default;
|
||||
|
||||
Chat::Chat(Chat&&) = default;
|
||||
|
||||
Chat::~Chat() = default;
|
||||
|
||||
std::int64_t Chat::getId() const
|
||||
|
|
@ -102,12 +104,12 @@ const Chat& Chat::operator=(Chat other) noexcept
|
|||
return *this;
|
||||
}
|
||||
|
||||
void telebotxx::swap(Chat& lhs, Chat& rhs)
|
||||
void swap(Chat& lhs, Chat& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
Chat::Type telebotxx::chatTypeFromString(const std::string& str)
|
||||
Chat::Type chatTypeFromString(const std::string& str)
|
||||
{
|
||||
if (str == "private")
|
||||
return Chat::Type::Private;
|
||||
|
|
@ -120,3 +122,5 @@ Chat::Type telebotxx::chatTypeFromString(const std::string& str)
|
|||
else
|
||||
throw std::invalid_argument("Unknown chat type");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,313 +3,314 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
namespace telebotxx
|
||||
namespace telebotxx {
|
||||
namespace impl {
|
||||
|
||||
template<typename T> bool is(const rapidjson::Value& obj);
|
||||
template<> bool is<int>(const rapidjson::Value& obj) { return obj.IsInt(); }
|
||||
template<> bool is<std::int64_t>(const rapidjson::Value& obj) { return obj.IsInt64(); }
|
||||
template<> bool is<bool>(const rapidjson::Value& obj) { return obj.IsBool(); }
|
||||
template<> bool is<std::string>(const rapidjson::Value& obj) { return obj.IsString(); }
|
||||
|
||||
template<typename T> const T get(const rapidjson::Value& obj);
|
||||
template<> const int get(const rapidjson::Value& obj) { return obj.GetInt(); }
|
||||
template<> const std::int64_t get(const rapidjson::Value& obj) { return obj.GetInt64(); }
|
||||
template<> const bool get(const rapidjson::Value& obj) { return obj.GetBool(); }
|
||||
template<> const std::string get(const rapidjson::Value& obj) { return obj.GetString(); }
|
||||
|
||||
template<typename T> const T null();
|
||||
template<> const int null() { return 0; }
|
||||
template<> const std::int64_t null() { return 0; }
|
||||
template<> const bool null() { return false; }
|
||||
template<> const std::string null() { return ""; }
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T parse(const rapidjson::Value& obj, const char* name, bool required)
|
||||
{
|
||||
namespace impl
|
||||
if (obj.HasMember(name))
|
||||
{
|
||||
template<typename T> bool is(const rapidjson::Value& obj);
|
||||
template<> bool is<int>(const rapidjson::Value& obj) { return obj.IsInt(); }
|
||||
template<> bool is<std::int64_t>(const rapidjson::Value& obj) { return obj.IsInt64(); }
|
||||
template<> bool is<bool>(const rapidjson::Value& obj) { return obj.IsBool(); }
|
||||
template<> bool is<std::string>(const rapidjson::Value& obj) { return obj.IsString(); }
|
||||
|
||||
template<typename T> const T get(const rapidjson::Value& obj);
|
||||
template<> const int get(const rapidjson::Value& obj) { return obj.GetInt(); }
|
||||
template<> const std::int64_t get(const rapidjson::Value& obj) { return obj.GetInt64(); }
|
||||
template<> const bool get(const rapidjson::Value& obj) { return obj.GetBool(); }
|
||||
template<> const std::string get(const rapidjson::Value& obj) { return obj.GetString(); }
|
||||
|
||||
template<typename T> const T null();
|
||||
template<> const int null() { return 0; }
|
||||
template<> const std::int64_t null() { return 0; }
|
||||
template<> const bool null() { return false; }
|
||||
template<> const std::string null() { return ""; }
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
const T parse(const rapidjson::Value& obj, const char* name, bool required)
|
||||
{
|
||||
if (obj.HasMember(name))
|
||||
{
|
||||
if (impl::is<T>(obj[name]))
|
||||
return impl::get<T>(obj[name]);
|
||||
else
|
||||
throw ParseError(std::string("Field '")+ name + "' has invalid type");
|
||||
}
|
||||
else if (required)
|
||||
throw ParseError(std::string("Field '")+ name + "' not found");
|
||||
if (impl::is<T>(obj[name]))
|
||||
return impl::get<T>(obj[name]);
|
||||
else
|
||||
return impl::null<T>();
|
||||
throw ParseError(std::string("Field '") + name + "' has invalid type");
|
||||
}
|
||||
else if (required)
|
||||
throw ParseError(std::string("Field '") + name + "' not found");
|
||||
else
|
||||
return impl::null<T>();
|
||||
}
|
||||
|
||||
const rapidjson::Value& parseObject(const rapidjson::Value& parent, const char* name, bool required, bool& found)
|
||||
const rapidjson::Value& parseObject(const rapidjson::Value& parent, const char* name, bool required, bool& found)
|
||||
{
|
||||
if (parent.HasMember(name))
|
||||
{
|
||||
if (parent.HasMember(name))
|
||||
if (parent[name].IsObject())
|
||||
{
|
||||
if (parent[name].IsObject())
|
||||
{
|
||||
found = true;
|
||||
return parent[name];
|
||||
}
|
||||
else
|
||||
throw ParseError(std::string("Field '")+ name + "' has invalid type");
|
||||
}
|
||||
else if (required)
|
||||
throw ParseError(std::string("Field '")+ name + "' not found");
|
||||
else
|
||||
{
|
||||
found = false;
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
const rapidjson::Value& parseArray(const rapidjson::Value& parent, const char* name, bool required, bool& found)
|
||||
{
|
||||
if (parent.HasMember(name))
|
||||
{
|
||||
if (parent[name].IsArray())
|
||||
{
|
||||
found = true;
|
||||
return parent[name];
|
||||
}
|
||||
else
|
||||
throw ParseError(std::string("Field '")+ name + "' has invalid type");
|
||||
}
|
||||
else if (required)
|
||||
throw ParseError(std::string("Field '")+ name + "' not found");
|
||||
else
|
||||
{
|
||||
found = false;
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& obj)
|
||||
{
|
||||
auto photo = std::make_unique<PhotoSize>();
|
||||
photo->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
|
||||
photo->setWidth(parse<int>(obj, "width", REQUIRED));
|
||||
photo->setHeight(parse<int>(obj, "height", REQUIRED));
|
||||
photo->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
|
||||
return photo;
|
||||
}
|
||||
|
||||
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
return parsePhotoSize(obj);
|
||||
found = true;
|
||||
return parent[name];
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
throw ParseError(std::string("Field '") + name + "' has invalid type");
|
||||
}
|
||||
|
||||
std::unique_ptr<PhotoSizeArray> parsePhotoSizeArray(const rapidjson::Value& parent, const char* name, bool required)
|
||||
else if (required)
|
||||
throw ParseError(std::string("Field '") + name + "' not found");
|
||||
else
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseArray(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
std::vector<PhotoSize> photos;
|
||||
for (auto& elem : obj.GetArray())
|
||||
{
|
||||
auto photo = parsePhotoSize(elem);
|
||||
photos.push_back(std::move(*photo));
|
||||
}
|
||||
auto result = std::make_unique<PhotoSizeArray>();
|
||||
result->setArray(photos);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Audio> parseAudio(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto audio = std::make_unique<Audio>();
|
||||
audio->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
|
||||
audio->setDuration(parse<int>(obj, "duration", REQUIRED));
|
||||
audio->setPerformer(parse<std::string>(obj, "performer", OPTIONAL));
|
||||
audio->setTitle(parse<std::string>(obj, "title", OPTIONAL));
|
||||
audio->setMimeType(parse<std::string>(obj, "mime_type", OPTIONAL));
|
||||
audio->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
|
||||
return audio;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Document> parseDocument(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto document = std::make_unique<Document>();
|
||||
document->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
|
||||
document->setThumb(parsePhotoSize(obj, "thumb", OPTIONAL));
|
||||
document->setFileName(parse<std::string>(obj, "file_name", OPTIONAL));
|
||||
document->setMimeType(parse<std::string>(obj, "mime_type", OPTIONAL));
|
||||
document->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
|
||||
return document;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Sticker> parseSticker(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto sticker = std::make_unique<Sticker>();
|
||||
sticker->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
|
||||
sticker->setWidth(parse<int>(obj, "width", REQUIRED));
|
||||
sticker->setHeight(parse<int>(obj, "height", REQUIRED));
|
||||
sticker->setThumb(parsePhotoSize(obj, "thumb", OPTIONAL));
|
||||
sticker->setEmoji(parse<std::string>(obj, "emoji", OPTIONAL));
|
||||
sticker->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
|
||||
return sticker;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto message = std::make_unique<Message>();
|
||||
|
||||
message->setId(parse<int>(obj, "message_id", REQUIRED));
|
||||
message->setFrom(parseUser(obj, "from", OPTIONAL));
|
||||
message->setDate(parse<int>(obj, "date", REQUIRED));
|
||||
message->setChat(*parseChat(obj, "chat", REQUIRED));
|
||||
message->setForwardFrom(parseUser(obj, "forward_from", OPTIONAL));
|
||||
message->setForwardFromChat(parseChat(obj, "forward_from_chat", OPTIONAL));
|
||||
message->setForwardDate(parse<int>(obj, "forward_date", OPTIONAL));
|
||||
message->setReplyToMessage(parseMessage(obj, "reply_to_message", OPTIONAL));
|
||||
message->setEditDate(parse<int>(obj, "edit_date", OPTIONAL));
|
||||
message->setText(parse<std::string>(obj, "text", OPTIONAL));
|
||||
//message->setEntities(parseEntities(obj, "entities", OPTIONAL));
|
||||
|
||||
/// \todo: Parse one of the possible attachments
|
||||
std::shared_ptr<Attachment> attachment;
|
||||
if (!(attachment = parsePhotoSizeArray(obj, "photo", OPTIONAL)))
|
||||
if (!(attachment = parseAudio(obj, "audio", OPTIONAL)))
|
||||
if (!(attachment = parseDocument(obj, "document", OPTIONAL)))
|
||||
attachment = parseSticker(obj, "sticker", OPTIONAL);
|
||||
message->setAttachment(attachment);
|
||||
|
||||
message->setCaption(parse<std::string>(obj, "caption", OPTIONAL));
|
||||
message->setNewChatMember(parseUser(obj, "new_chat_member", OPTIONAL));
|
||||
message->setLeftChatMember(parseUser(obj, "left_chat_member", OPTIONAL));
|
||||
message->setNewChatTitle(parse<std::string>(obj, "new_chat_title", OPTIONAL));
|
||||
message->setNewChatPhoto(parsePhotoSizeArray(obj, "new_chat_photo", OPTIONAL));
|
||||
message->setDeleteChatPhoto(parse<bool>(obj, "delete_chat_photo", OPTIONAL));
|
||||
message->setGroupChatCreated(parse<bool>(obj, "group_chat_created", OPTIONAL));
|
||||
message->setSuperGroupChatCreated(parse<bool>(obj, "supergroup_chat_created", OPTIONAL));
|
||||
message->setChannelChatCreated(parse<bool>(obj, "channel_chat_created", OPTIONAL));
|
||||
message->setMigrateToChatId(parse<std::int64_t>(obj, "migrate_to_chat_id", OPTIONAL));
|
||||
message->setMigrateFromChatId(parse<std::int64_t>(obj, "migrate_from_chat_id", OPTIONAL));
|
||||
message->setPinnedMessage(parseMessage(obj, "pinned_message", OPTIONAL));
|
||||
|
||||
return message;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto chat = std::make_unique<Chat>();
|
||||
chat->setId(parse<std::int64_t>(obj, "id", REQUIRED));
|
||||
chat->setType(chatTypeFromString(parse<std::string>(obj, "type", REQUIRED)));
|
||||
chat->setTitle(parse<std::string>(obj, "title", OPTIONAL));
|
||||
chat->setUsername(parse<std::string>(obj, "username", OPTIONAL));
|
||||
chat->setFirstName(parse<std::string>(obj, "first_name", OPTIONAL));
|
||||
chat->setLastName(parse<std::string>(obj, "last_name", OPTIONAL));
|
||||
chat->setAllAdmins(parse<bool>(obj, "all_members_are_administrators", OPTIONAL));
|
||||
return chat;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Update> parseUpdate(const rapidjson::Value& obj)
|
||||
{
|
||||
int id = parse<int>(obj, "update_id", REQUIRED);
|
||||
|
||||
std::unique_ptr<Message> message;
|
||||
if ((message = parseMessage(obj, "message", OPTIONAL)))
|
||||
return std::make_unique<MessageUpdate>(id, *message);
|
||||
else if ((message = parseMessage(obj, "edited_message", OPTIONAL)))
|
||||
return std::make_unique<EditedMessageUpdate>(id, *message);
|
||||
/// \todo: other updates
|
||||
else
|
||||
throw ParseError("Unknown update type");
|
||||
}
|
||||
|
||||
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseArray(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
std::vector<UpdatePtr> updates;
|
||||
for (auto& elem : obj.GetArray())
|
||||
{
|
||||
auto update = parseUpdate(elem);
|
||||
updates.emplace_back(std::move(update));
|
||||
}
|
||||
return std::make_unique<Updates>(std::move(updates));
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto user = std::make_unique<User>();
|
||||
user->setId(parse<int>(obj, "id", REQUIRED));
|
||||
user->setFirstName(parse<std::string>(obj, "first_name", REQUIRED));
|
||||
user->setLastName(parse<std::string>(obj, "last_name", OPTIONAL));
|
||||
user->setUsername(parse<std::string>(obj, "username", OPTIONAL));
|
||||
return user;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void checkResponse(const rapidjson::Document& doc)
|
||||
{
|
||||
if (!doc.IsObject())
|
||||
throw ParseError("Object expected");
|
||||
|
||||
// Get status
|
||||
bool ok = parse<bool>(doc, "ok", REQUIRED);
|
||||
if (!ok)
|
||||
{
|
||||
int code = parse<int>(doc, "error_code", REQUIRED);
|
||||
std::string description(parse<std::string>(doc, "description", REQUIRED));
|
||||
throw ApiError(code, description);
|
||||
}
|
||||
found = false;
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
const rapidjson::Value& parseArray(const rapidjson::Value& parent, const char* name, bool required, bool& found)
|
||||
{
|
||||
if (parent.HasMember(name))
|
||||
{
|
||||
if (parent[name].IsArray())
|
||||
{
|
||||
found = true;
|
||||
return parent[name];
|
||||
}
|
||||
else
|
||||
throw ParseError(std::string("Field '") + name + "' has invalid type");
|
||||
}
|
||||
else if (required)
|
||||
throw ParseError(std::string("Field '") + name + "' not found");
|
||||
else
|
||||
{
|
||||
found = false;
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& obj)
|
||||
{
|
||||
auto photo = std::make_unique<PhotoSize>();
|
||||
photo->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
|
||||
photo->setWidth(parse<int>(obj, "width", REQUIRED));
|
||||
photo->setHeight(parse<int>(obj, "height", REQUIRED));
|
||||
photo->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
|
||||
return photo;
|
||||
}
|
||||
|
||||
std::unique_ptr<PhotoSize> parsePhotoSize(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
return parsePhotoSize(obj);
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<PhotoSizeArray> parsePhotoSizeArray(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseArray(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
std::vector<PhotoSize> photos;
|
||||
for (auto& elem : obj.GetArray())
|
||||
{
|
||||
auto photo = parsePhotoSize(elem);
|
||||
photos.push_back(std::move(*photo));
|
||||
}
|
||||
auto result = std::make_unique<PhotoSizeArray>();
|
||||
result->setArray(photos);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Audio> parseAudio(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto audio = std::make_unique<Audio>();
|
||||
audio->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
|
||||
audio->setDuration(parse<int>(obj, "duration", REQUIRED));
|
||||
audio->setPerformer(parse<std::string>(obj, "performer", OPTIONAL));
|
||||
audio->setTitle(parse<std::string>(obj, "title", OPTIONAL));
|
||||
audio->setMimeType(parse<std::string>(obj, "mime_type", OPTIONAL));
|
||||
audio->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
|
||||
return audio;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Document> parseDocument(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto document = std::make_unique<Document>();
|
||||
document->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
|
||||
document->setThumb(parsePhotoSize(obj, "thumb", OPTIONAL));
|
||||
document->setFileName(parse<std::string>(obj, "file_name", OPTIONAL));
|
||||
document->setMimeType(parse<std::string>(obj, "mime_type", OPTIONAL));
|
||||
document->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
|
||||
return document;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Sticker> parseSticker(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto sticker = std::make_unique<Sticker>();
|
||||
sticker->setFileId(parse<std::string>(obj, "file_id", REQUIRED));
|
||||
sticker->setWidth(parse<int>(obj, "width", REQUIRED));
|
||||
sticker->setHeight(parse<int>(obj, "height", REQUIRED));
|
||||
sticker->setThumb(parsePhotoSize(obj, "thumb", OPTIONAL));
|
||||
sticker->setEmoji(parse<std::string>(obj, "emoji", OPTIONAL));
|
||||
sticker->setFileSize(parse<int>(obj, "file_size", OPTIONAL));
|
||||
return sticker;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto message = std::make_unique<Message>();
|
||||
|
||||
message->setId(parse<int>(obj, "message_id", REQUIRED));
|
||||
message->setFrom(parseUser(obj, "from", OPTIONAL));
|
||||
message->setDate(parse<int>(obj, "date", REQUIRED));
|
||||
message->setChat(*parseChat(obj, "chat", REQUIRED));
|
||||
message->setForwardFrom(parseUser(obj, "forward_from", OPTIONAL));
|
||||
message->setForwardFromChat(parseChat(obj, "forward_from_chat", OPTIONAL));
|
||||
message->setForwardDate(parse<int>(obj, "forward_date", OPTIONAL));
|
||||
message->setReplyToMessage(parseMessage(obj, "reply_to_message", OPTIONAL));
|
||||
message->setEditDate(parse<int>(obj, "edit_date", OPTIONAL));
|
||||
message->setText(parse<std::string>(obj, "text", OPTIONAL));
|
||||
//message->setEntities(parseEntities(obj, "entities", OPTIONAL));
|
||||
|
||||
/// \todo: Parse one of the possible attachments
|
||||
std::shared_ptr<Attachment> attachment;
|
||||
if (!(attachment = parsePhotoSizeArray(obj, "photo", OPTIONAL)))
|
||||
if (!(attachment = parseAudio(obj, "audio", OPTIONAL)))
|
||||
if (!(attachment = parseDocument(obj, "document", OPTIONAL)))
|
||||
attachment = parseSticker(obj, "sticker", OPTIONAL);
|
||||
message->setAttachment(attachment);
|
||||
|
||||
message->setCaption(parse<std::string>(obj, "caption", OPTIONAL));
|
||||
message->setNewChatMember(parseUser(obj, "new_chat_member", OPTIONAL));
|
||||
message->setLeftChatMember(parseUser(obj, "left_chat_member", OPTIONAL));
|
||||
message->setNewChatTitle(parse<std::string>(obj, "new_chat_title", OPTIONAL));
|
||||
message->setNewChatPhoto(parsePhotoSizeArray(obj, "new_chat_photo", OPTIONAL));
|
||||
message->setDeleteChatPhoto(parse<bool>(obj, "delete_chat_photo", OPTIONAL));
|
||||
message->setGroupChatCreated(parse<bool>(obj, "group_chat_created", OPTIONAL));
|
||||
message->setSuperGroupChatCreated(parse<bool>(obj, "supergroup_chat_created", OPTIONAL));
|
||||
message->setChannelChatCreated(parse<bool>(obj, "channel_chat_created", OPTIONAL));
|
||||
message->setMigrateToChatId(parse<std::int64_t>(obj, "migrate_to_chat_id", OPTIONAL));
|
||||
message->setMigrateFromChatId(parse<std::int64_t>(obj, "migrate_from_chat_id", OPTIONAL));
|
||||
message->setPinnedMessage(parseMessage(obj, "pinned_message", OPTIONAL));
|
||||
|
||||
return message;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto chat = std::make_unique<Chat>();
|
||||
chat->setId(parse<std::int64_t>(obj, "id", REQUIRED));
|
||||
chat->setType(chatTypeFromString(parse<std::string>(obj, "type", REQUIRED)));
|
||||
chat->setTitle(parse<std::string>(obj, "title", OPTIONAL));
|
||||
chat->setUsername(parse<std::string>(obj, "username", OPTIONAL));
|
||||
chat->setFirstName(parse<std::string>(obj, "first_name", OPTIONAL));
|
||||
chat->setLastName(parse<std::string>(obj, "last_name", OPTIONAL));
|
||||
chat->setAllAdmins(parse<bool>(obj, "all_members_are_administrators", OPTIONAL));
|
||||
return chat;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Update> parseUpdate(const rapidjson::Value& obj)
|
||||
{
|
||||
int id = parse<int>(obj, "update_id", REQUIRED);
|
||||
|
||||
std::unique_ptr<Message> message;
|
||||
if ((message = parseMessage(obj, "message", OPTIONAL)))
|
||||
return std::make_unique<MessageUpdate>(id, *message);
|
||||
else if ((message = parseMessage(obj, "edited_message", OPTIONAL)))
|
||||
return std::make_unique<EditedMessageUpdate>(id, *message);
|
||||
/// \todo: other updates
|
||||
else
|
||||
throw ParseError("Unknown update type");
|
||||
}
|
||||
|
||||
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseArray(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
std::vector<UpdatePtr> updates;
|
||||
for (auto& elem : obj.GetArray())
|
||||
{
|
||||
auto update = parseUpdate(elem);
|
||||
updates.emplace_back(std::move(update));
|
||||
}
|
||||
return std::make_unique<Updates>(std::move(updates));
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required)
|
||||
{
|
||||
bool found;
|
||||
auto& obj = parseObject(parent, name, required, found);
|
||||
if (found)
|
||||
{
|
||||
auto user = std::make_unique<User>();
|
||||
user->setId(parse<int>(obj, "id", REQUIRED));
|
||||
user->setFirstName(parse<std::string>(obj, "first_name", REQUIRED));
|
||||
user->setLastName(parse<std::string>(obj, "last_name", OPTIONAL));
|
||||
user->setUsername(parse<std::string>(obj, "username", OPTIONAL));
|
||||
return user;
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void checkResponse(const rapidjson::Document& doc)
|
||||
{
|
||||
if (!doc.IsObject())
|
||||
throw ParseError("Object expected");
|
||||
|
||||
// Get status
|
||||
bool ok = parse<bool>(doc, "ok", REQUIRED);
|
||||
if (!ok)
|
||||
{
|
||||
int code = parse<int>(doc, "error_code", REQUIRED);
|
||||
std::string description(parse<std::string>(doc, "description", REQUIRED));
|
||||
throw ApiError(code, description);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,44 +10,45 @@
|
|||
|
||||
#include <rapidjson/document.h>
|
||||
|
||||
namespace telebotxx
|
||||
{
|
||||
const bool REQUIRED = true;
|
||||
const bool OPTIONAL = false;
|
||||
namespace telebotxx {
|
||||
|
||||
/// \brief Parse JSON object to Chat
|
||||
/// \param parent reference to parent JSON object
|
||||
/// \param name field with Chat object
|
||||
/// \param required REQUIRED or OPTIONAL
|
||||
/// \return pointer to Chat
|
||||
std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required);
|
||||
const bool REQUIRED = true;
|
||||
const bool OPTIONAL = false;
|
||||
|
||||
/// \brief Parse JSON object to User
|
||||
/// \param parent reference to parent JSON object
|
||||
/// \param name field with Document object
|
||||
/// \param required REQUIRED or OPTIONAL
|
||||
/// \return pointer to User
|
||||
std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required);
|
||||
/// \brief Parse JSON object to Chat
|
||||
/// \param parent reference to parent JSON object
|
||||
/// \param name field with Chat object
|
||||
/// \param required REQUIRED or OPTIONAL
|
||||
/// \return pointer to Chat
|
||||
std::unique_ptr<Chat> parseChat(const rapidjson::Value& parent, const char* name, bool required);
|
||||
|
||||
/// \brief Parse JSON object to Message
|
||||
/// \param parent reference to parent JSON object
|
||||
/// \param name field with Message object
|
||||
/// \param required REQUIRED or OPTIONAL
|
||||
/// \return pointer to Message
|
||||
std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required);
|
||||
/// \brief Parse JSON object to User
|
||||
/// \param parent reference to parent JSON object
|
||||
/// \param name field with Document object
|
||||
/// \param required REQUIRED or OPTIONAL
|
||||
/// \return pointer to User
|
||||
std::unique_ptr<User> parseUser(const rapidjson::Value& parent, const char* name, bool required);
|
||||
|
||||
/// \brief Parse JSON array of Update
|
||||
/// \param parent reference to parent JSON object
|
||||
/// \param name field with array of Update objects
|
||||
/// \param required REQUIRED or OPTIONAL
|
||||
/// \return Updates (vector of UpdatePtr>
|
||||
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required);
|
||||
/// \brief Parse JSON object to Message
|
||||
/// \param parent reference to parent JSON object
|
||||
/// \param name field with Message object
|
||||
/// \param required REQUIRED or OPTIONAL
|
||||
/// \return pointer to Message
|
||||
std::unique_ptr<Message> parseMessage(const rapidjson::Value& parent, const char* name, bool required);
|
||||
|
||||
/// \brief Parse JSON array of Update
|
||||
/// \param parent reference to parent JSON object
|
||||
/// \param name field with array of Update objects
|
||||
/// \param required REQUIRED or OPTIONAL
|
||||
/// \return Updates (vector of UpdatePtr>
|
||||
std::unique_ptr<Updates> parseUpdates(const rapidjson::Value& parent, const char* name, bool required);
|
||||
|
||||
/// \brief Check JSON response
|
||||
///
|
||||
/// Throws an exception if error code recieved.
|
||||
/// \param doc reference to JSON document
|
||||
void checkResponse(const rapidjson::Document& doc);
|
||||
|
||||
/// \brief Check JSON response
|
||||
///
|
||||
/// Throws an exception if error code recieved.
|
||||
/// \param doc reference to JSON document
|
||||
void checkResponse(const rapidjson::Document& doc);
|
||||
}
|
||||
|
||||
#endif // TELEBOTXX_JSON_OBJECTS_HPP
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
#include <telebotxx/Logging.hpp>
|
||||
|
||||
namespace telebotxx
|
||||
{
|
||||
bool debugMode = false;
|
||||
namespace telebotxx {
|
||||
|
||||
bool debugMode = false;
|
||||
|
||||
void setDebugMode(bool enabled)
|
||||
{
|
||||
debugMode = enabled;
|
||||
}
|
||||
|
||||
void setDebugMode(bool enabled)
|
||||
{
|
||||
debugMode = enabled;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,18 @@
|
|||
#include <telebotxx/Message.hpp>
|
||||
|
||||
using namespace telebotxx;
|
||||
namespace telebotxx {
|
||||
|
||||
MessageEntity::MessageEntity()
|
||||
: type_(Type::Mention),
|
||||
offset_(-1),
|
||||
length_(0)
|
||||
: type_(Type::Mention),
|
||||
offset_(-1),
|
||||
length_(0)
|
||||
{
|
||||
}
|
||||
|
||||
MessageEntity::MessageEntity(const MessageEntity&) = default;
|
||||
|
||||
MessageEntity::MessageEntity(MessageEntity&&) = default;
|
||||
|
||||
MessageEntity::~MessageEntity() = default;
|
||||
|
||||
MessageEntity::Type MessageEntity::getType() const
|
||||
|
|
@ -79,7 +81,7 @@ const MessageEntity& MessageEntity::operator=(MessageEntity other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
MessageEntity::Type telebotxx::messageEntityTypeFromString(const std::string& str)
|
||||
MessageEntity::Type messageEntityTypeFromString(const std::string& str)
|
||||
{
|
||||
if (str == "mention")
|
||||
return MessageEntity::Type::Mention;
|
||||
|
|
@ -108,12 +110,14 @@ MessageEntity::Type telebotxx::messageEntityTypeFromString(const std::string& st
|
|||
}
|
||||
|
||||
Message::Message()
|
||||
: id_(-1)
|
||||
: id_(-1)
|
||||
{
|
||||
}
|
||||
|
||||
Message::Message(const Message&) = default;
|
||||
|
||||
Message::Message(Message&&) = default;
|
||||
|
||||
Message::~Message() = default;
|
||||
|
||||
int Message::getId() const
|
||||
|
|
@ -391,7 +395,9 @@ const Message& Message::operator=(Message other) noexcept
|
|||
return *this;
|
||||
}
|
||||
|
||||
void telebotxx::swap(Message& lhs, Message& rhs)
|
||||
void swap(Message& lhs, Message& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <telebotxx/RequestOptions.hpp>
|
||||
|
||||
using namespace telebotxx;
|
||||
namespace telebotxx {
|
||||
|
||||
ChatId::ChatId(int id)
|
||||
: type_(Type::Id), id_(id)
|
||||
|
|
@ -95,7 +95,7 @@ int ReplyTo::value() const
|
|||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
Buffer::Buffer(const char *buffer, std::size_t size, const std::string& filename)
|
||||
Buffer::Buffer(const char* buffer, std::size_t size, const std::string& filename)
|
||||
: data_(buffer), size_(size), filename_(filename)
|
||||
{
|
||||
}
|
||||
|
|
@ -140,7 +140,7 @@ const std::string& Url::getUrl() const
|
|||
}
|
||||
|
||||
Url::Url(const std::string& url)
|
||||
: url_(url)
|
||||
: url_(url)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ Photo::~Photo()
|
|||
{
|
||||
if (type_ == Type::File)
|
||||
file_.~File();
|
||||
else if(type_ == Type::Url)
|
||||
else if (type_ == Type::Url)
|
||||
url_.~Url();
|
||||
}
|
||||
|
||||
|
|
@ -235,3 +235,5 @@ const Url& Photo::getUrl() const
|
|||
{
|
||||
return url_;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@
|
|||
#include <rapidjson/writer.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
using namespace telebotxx;
|
||||
namespace telebotxx {
|
||||
|
||||
class SendMessageRequest::Impl
|
||||
{
|
||||
|
|
@ -61,7 +62,8 @@ public:
|
|||
if (parseMode_)
|
||||
{
|
||||
writer.String("parse_mode");
|
||||
writer.String((parseMode_ == ParseMode::Markdown) ? "Markdown" : (parseMode_ == ParseMode::Html) ? "HTML" : "Plain");
|
||||
writer.String(
|
||||
(parseMode_ == ParseMode::Markdown) ? "Markdown" : (parseMode_ == ParseMode::Html) ? "HTML" : "Plain");
|
||||
}
|
||||
|
||||
// Add disable_web_page_preview
|
||||
|
|
@ -173,3 +175,5 @@ Message SendMessageRequest::execute()
|
|||
{
|
||||
return impl_->execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include <telebotxx/SendPhotoRequest.hpp>
|
||||
|
||||
#include <telebotxx/Logging.hpp>
|
||||
#include "JsonObjects.hpp"
|
||||
|
||||
|
|
@ -8,8 +7,9 @@
|
|||
#include <rapidjson/writer.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
using namespace telebotxx;
|
||||
namespace telebotxx {
|
||||
|
||||
class SendPhotoRequest::Impl
|
||||
{
|
||||
|
|
@ -137,3 +137,5 @@ Message SendPhotoRequest::execute()
|
|||
{
|
||||
return impl_->execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <telebotxx/Update.hpp>
|
||||
|
||||
using namespace telebotxx;
|
||||
namespace telebotxx {
|
||||
|
||||
Update::Update(int id, Type type)
|
||||
: id_(id),
|
||||
|
|
@ -80,3 +80,5 @@ const EditedMessageUpdate& EditedMessageUpdate::operator=(EditedMessageUpdate ot
|
|||
swap(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <telebotxx/User.hpp>
|
||||
#include <sstream>
|
||||
|
||||
using namespace telebotxx;
|
||||
namespace telebotxx {
|
||||
|
||||
User::User()
|
||||
: id_(-1)
|
||||
|
|
@ -9,7 +9,9 @@ User::User()
|
|||
}
|
||||
|
||||
User::User(const User&) = default;
|
||||
|
||||
User::User(User&&) = default;
|
||||
|
||||
User::~User() = default;
|
||||
|
||||
int User::getId() const
|
||||
|
|
@ -73,8 +75,10 @@ const User& User::operator=(User other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
std::ostream& telebotxx::operator<<(std::ostream& os, const User& user)
|
||||
std::ostream& operator<<(std::ostream& os, const User& user)
|
||||
{
|
||||
os << user.toString();
|
||||
return os;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue