Cppgram  1.0.0
Easy and modern C++14 Telegram Bot API wrapper
message_entity.hpp
1 #ifndef CPPGRAM_MESSAGEENTITY_HPP
2 #define CPPGRAM_MESSAGEENTITY_HPP
3 
4 #include <cstring>
5 #include <experimental/optional>
6 #include <string>
7 
8 #include <json/json.h>
9 
10 #include "enums.hpp"
11 #include "user.hpp"
12 
13 namespace cppgram
14 {
15 namespace types
16 {
25 {
28  public:
31 
33  int offset,
34 
36  length;
37 
40  std::experimental::optional<std::string> url;
41 
43  std::experimental::optional<User> user;
44 
45  MessageEntity( Json::Value &json_message_entity )
46  : offset( json_message_entity["offset"].asInt() )
47  , length( json_message_entity["length"].asInt() )
48  {
49  std::vector<std::string> entity_strings = {"mention",
50  "hashtag",
51  "bot_command",
52  "url",
53  "email",
54  "bold",
55  "italic",
56  "code",
57  "pre",
58  "text_link",
59  "text_mention"};
60  int i = 10; // entity_strings.size() - 1
61 
62  std::string entity_type = json_message_entity["type"].asString();
63  while ( i > 0 && entity_type.compare( entity_strings[i] ) != 0 )
64  {
65  i--;
66  }
67 
68  type = static_cast<EMessageEntity>( i );
69 
70  if ( !json_message_entity["url"].isNull() )
71  {
72  url.emplace( json_message_entity["url"].asString() );
73  }
74 
75  if ( !json_message_entity["user"].isNull() )
76  {
77  user.emplace( User( json_message_entity["user"] ) );
78  }
79  }
80 
81  MessageEntity( const MessageEntity &prev )
82  {
83  user = prev.user;
84 
85  type = prev.type;
86 
87  url = prev.url;
88  offset = prev.offset;
89  length = prev.length;
90  }
91 };
92 }
93 }
94 
95 #endif
std::experimental::optional< User > user
Optional. For “text_mention” only, the mentioned user
Definition: message_entity.hpp:43
int offset
Offset in UTF-16 code units to the start of the entity.
Definition: message_entity.hpp:33
EMessageEntity type
Type of the entity.
Definition: message_entity.hpp:30
Entity in the message.
Definition: message_entity.hpp:24
int length
Length of the entity in UTF-16 code units.
Definition: message_entity.hpp:33
EMessageEntity
Type of the entity.
Definition: enums.hpp:28
main namespace for Cppgram
std::experimental::optional< std::string > url
Optional. For “text_link” only, url that will be opened after user taps on the text ...
Definition: message_entity.hpp:40
User object.
Definition: user.hpp:20