aegis.cpp
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
messages.hpp
1 //
2 // messages.hpp
3 // ************
4 //
5 // Copyright (c) 2020 Sharon Fox (sharon at xandium dot io)
6 //
7 // Distributed under the MIT License. (See accompanying file LICENSE)
8 //
9 
10 #pragma once
11 
12 #include "aegis/config.hpp"
13 #include "aegis/shards/shard.hpp"
14 #include "aegis/rest/rest_reply.hpp"
15 #include "aegis/gateway/objects/message.hpp"
16 #include <nlohmann/json.hpp>
17 
18 namespace aegis
19 {
20 
21 namespace gateway
22 {
23 
24 namespace objects
25 {
26 
27 class message;
28 
30 inline void from_json(const nlohmann::json& j, objects::messages& m);
31 
32 inline void to_json(nlohmann::json& j, const objects::messages& m);
34 
37 class messages
38 {
39 public:
40 
42 
45  messages(aegis::core * _core) noexcept
46  : _core(_core)
47  {
48  }
49 
51 
55  messages(const std::string& _json, aegis::core* _core) noexcept
56  : _core(_core)
57  {
58  from_json(nlohmann::json::parse(_json), *this);
59  }
60 
62 
66  messages(const nlohmann::json & _json, aegis::core * _core) noexcept
67  : _core(_core)
68  {
69  from_json(_json, *this);
70  }
71 
74 
77  AEGIS_DECL void set_guild(aegis::guild * _guild)
78  {
79  this->_guild = _guild;
80  }
81 
82  messages() = default;
83  messages& operator=(const messages&) = default;
84  messages(const messages&) = default;
85  messages(messages&& msg) = default;
86 
87  std::vector<aegis::gateway::objects::message>::iterator begin()
88  {
89  return _messages.begin();
90  }
91 
92  std::vector<aegis::gateway::objects::message>::iterator end()
93  {
94  return _messages.end();
95  }
96 
97  std::vector<aegis::gateway::objects::message>::reverse_iterator rbegin()
98  {
99  return _messages.rbegin();
100  }
101 
102  std::vector<aegis::gateway::objects::message>::reverse_iterator rend()
103  {
104  return _messages.rend();
105  }
106 
107  std::vector<aegis::gateway::objects::message> _messages;
109 private:
110  friend inline void from_json(const nlohmann::json& j, objects::messages& m);
111  friend inline void to_json(nlohmann::json& j, const objects::messages& m);
112  friend class aegis::core;
113 
114  std::string _content;
115  aegis::channel * _channel = nullptr;
116  aegis::guild * _guild = nullptr;
117 #if !defined(AEGIS_DISABLE_ALL_CACHE)
118  aegis::user * _user = nullptr;
119 #endif
120  aegis::core * _core = nullptr;
121  snowflake _message_id = 0;
122  snowflake _channel_id = 0;
123  snowflake _guild_id = 0;
124  snowflake _author_id = 0;
125 };
126 
128 inline void from_json(const nlohmann::json& j, objects::messages& m)
129 {
130  if (j.size())
131  for (const auto& _message : j)
132  m._messages.push_back(_message);
133 }
134 
135 inline void to_json(nlohmann::json& j, const objects::messages& m)
136 {
137  if (!m._messages.empty())
138  for (const auto& _message : m._messages)
139  j.push_back(_message);
140 }
142 
143 }
144 
145 }
146 
147 }
Stores creation time and extra data specific to Discord for entities.
Definition: snowflake.hpp:21
Definition: messages.hpp:37
void set_guild(aegis::guild *_guild)
Definition: messages.hpp:77
Class for performing actions pertaining to a specified guild.
Definition: guild.hpp:159
std::vector< aegis::gateway::objects::message > _messages
Definition: messages.hpp:107
messages(aegis::core *_core) noexcept
Constructor for the messages array.
Definition: messages.hpp:45
Primary class for managing a bot interface.
Definition: core.hpp:157
Class for performing actions pertaining to a specified channel.
Definition: channel.hpp:170
Stores user-specific and guild-specific attributes of users.
Definition: user.hpp:37
messages(const std::string &_json, aegis::core *_core) noexcept
Constructor for the message object.
Definition: messages.hpp:55
messages(const nlohmann::json &_json, aegis::core *_core) noexcept
Constructor for the messages object.
Definition: messages.hpp:66