mirror of
https://github.com/UltraCoderRU/telebotxx.git
synced 2026-01-28 04:05:13 +00:00
Class Chat implemented.
This commit is contained in:
parent
ccc54c397a
commit
10dda01a61
3 changed files with 187 additions and 0 deletions
64
include/telebotxx/Chat.hpp
Normal file
64
include/telebotxx/Chat.hpp
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
#ifndef TELEBOTXX_CHAT_HPP
|
||||||
|
#define TELEBOTXX_CHAT_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace telebotxx
|
||||||
|
{
|
||||||
|
class Chat
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum class Type
|
||||||
|
{
|
||||||
|
Private,
|
||||||
|
Group,
|
||||||
|
Supergroup,
|
||||||
|
Channel
|
||||||
|
};
|
||||||
|
|
||||||
|
Chat();
|
||||||
|
Chat(const Chat&);
|
||||||
|
Chat(Chat&&);
|
||||||
|
~Chat();
|
||||||
|
|
||||||
|
int getId() const;
|
||||||
|
void setId(int 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:
|
||||||
|
int id_;
|
||||||
|
Type type_;
|
||||||
|
std::string title_;
|
||||||
|
std::string username_;
|
||||||
|
std::string firstName_;
|
||||||
|
std::string lastName_;
|
||||||
|
bool allAdmins_;
|
||||||
|
};
|
||||||
|
|
||||||
|
void swap(Chat& lhs, Chat& rhs);
|
||||||
|
|
||||||
|
Chat::Type chatTypeFromString(const std::string& str);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TELEBOTXX_CHAT_HPP
|
||||||
|
|
@ -14,6 +14,7 @@ endif(NOT WIN32)
|
||||||
set(LIBRARY_OUTPUT_PATH "../lib")
|
set(LIBRARY_OUTPUT_PATH "../lib")
|
||||||
|
|
||||||
set(SOURCE_FILES BotApi.cpp
|
set(SOURCE_FILES BotApi.cpp
|
||||||
|
Chat.cpp
|
||||||
Logging.cpp
|
Logging.cpp
|
||||||
User.cpp
|
User.cpp
|
||||||
)
|
)
|
||||||
|
|
|
||||||
122
src/Chat.cpp
Normal file
122
src/Chat.cpp
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
#include <telebotxx/Chat.hpp>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
using namespace telebotxx;
|
||||||
|
|
||||||
|
Chat::Chat()
|
||||||
|
: id_(-1),
|
||||||
|
type_(Type::Private),
|
||||||
|
allAdmins_(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Chat::Chat(const Chat&) = default;
|
||||||
|
Chat::Chat(Chat&&) = default;
|
||||||
|
Chat::~Chat() = default;
|
||||||
|
|
||||||
|
int Chat::getId() const
|
||||||
|
{
|
||||||
|
return id_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Chat::setId(int id)
|
||||||
|
{
|
||||||
|
id_ = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
Chat::Type Chat::getType() const
|
||||||
|
{
|
||||||
|
return type_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Chat::setType(Chat::Type type)
|
||||||
|
{
|
||||||
|
type_ = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& Chat::getTitle() const
|
||||||
|
{
|
||||||
|
return title_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Chat::setTitle(const std::string& title)
|
||||||
|
{
|
||||||
|
title_ = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& Chat::getUsername() const
|
||||||
|
{
|
||||||
|
return username_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Chat::setUsername(const std::string& username)
|
||||||
|
{
|
||||||
|
username_ = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& Chat::getFirstName() const
|
||||||
|
{
|
||||||
|
return firstName_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Chat::setFirstName(const std::string& firstName)
|
||||||
|
{
|
||||||
|
firstName_ = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& Chat::getLastName() const
|
||||||
|
{
|
||||||
|
return lastName_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Chat::setLastName(const std::string& lastName)
|
||||||
|
{
|
||||||
|
lastName_ = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Chat::isAllAdmins() const
|
||||||
|
{
|
||||||
|
return allAdmins_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Chat::setAllAdmins(bool allAdmins)
|
||||||
|
{
|
||||||
|
allAdmins_ = allAdmins;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Chat::swap(Chat& other) noexcept
|
||||||
|
{
|
||||||
|
using std::swap;
|
||||||
|
swap(id_, other.id_);
|
||||||
|
swap(type_, other.type_);
|
||||||
|
swap(title_, other.title_);
|
||||||
|
swap(username_, other.username_);
|
||||||
|
swap(firstName_, other.firstName_);
|
||||||
|
swap(lastName_, other.lastName_);
|
||||||
|
swap(allAdmins_, other.allAdmins_);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Chat& Chat::operator=(Chat other) noexcept
|
||||||
|
{
|
||||||
|
swap(other);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void telebotxx::swap(Chat& lhs, Chat& rhs)
|
||||||
|
{
|
||||||
|
lhs.swap(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
Chat::Type telebotxx::chatTypeFromString(const std::string& str)
|
||||||
|
{
|
||||||
|
if (str == "private")
|
||||||
|
return Chat::Type::Private;
|
||||||
|
else if (str == "group")
|
||||||
|
return Chat::Type::Group;
|
||||||
|
else if (str == "supergroup")
|
||||||
|
return Chat::Type::Supergroup;
|
||||||
|
else if (str == "channel")
|
||||||
|
return Chat::Type::Channel;
|
||||||
|
else
|
||||||
|
throw std::invalid_argument("Unknown chat type");
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue