12 #include "aegis/config.hpp"
14 #include "aegis/utility.hpp"
15 #include "aegis/ratelimit/ratelimit.hpp"
16 #include "aegis/permission.hpp"
17 #include "aegis/snowflake.hpp"
18 #include "aegis/gateway/objects/permission_overwrite.hpp"
19 #include "aegis/gateway/objects/channel.hpp"
20 #include <shared_mutex>
21 #include "aegis/futures.hpp"
26 #if (AEGIS_HAS_STD_SHARED_MUTEX == 1)
27 using shared_mutex = std::shared_mutex;
29 using shared_mutex = std::shared_timed_mutex;
32 using json = nlohmann::json;
36 #pragma region rest params
42 create_message_t & content(
const std::string & param) { _content = param;
return *
this; }
43 create_message_t & embed(
const json & param) { _embed = param;
return *
this; }
44 create_message_t & nonce(int64_t param) { _nonce = param;
return *
this; }
45 create_message_t & file(rest::aegis_file file)
47 this->_file.emplace(std::move(file));
54 lib::optional<rest::aegis_file> _file;
60 edit_message_t & content(
const std::string & param) { _content = param;
return *
this; }
61 edit_message_t & embed(
const json & param) { _embed = param;
return *
this; }
69 enum class get_messages_type {
76 get_messages_t & around() { _type = get_messages_type::AROUND;
return *
this; }
77 get_messages_t & before() { _type = get_messages_type::BEFORE;
return *
this; }
78 get_messages_t & after() { _type = get_messages_type::AFTER;
return *
this; }
79 get_messages_t & limit(int16_t param) { _limit = param;
return *
this; }
80 get_messages_type _type = get_messages_type::LAST;
87 modify_channel_t & name(
const std::string & param) { _name = param;
return *
this; }
89 modify_channel_t & topic(
const std::string & param) { _topic = param;
return *
this; }
92 modify_channel_t & user_limit(
int param) { _user_limit = param;
return *
this; }
93 modify_channel_t & permission_overwrites(
const std::vector<gateway::objects::permission_overwrite> & param)
95 _permission_overwrites = param;
return *
this;
98 modify_channel_t & rate_limit_per_user(
int param) { _rate_limit_per_user = param;
return *
this; }
99 lib::optional<std::string> _name = {};
100 lib::optional<int> _position = {};
101 lib::optional<std::string> _topic = {};
102 lib::optional<bool> _nsfw = {};
103 lib::optional<int> _bitrate = {};
104 lib::optional<int> _user_limit = {};
105 lib::optional<std::vector<gateway::objects::permission_overwrite>> _permission_overwrites = {};
106 lib::optional<snowflake> _parent_id = {};
107 lib::optional<int> _rate_limit_per_user = {};
113 create_reaction_t & emoji_text(
const std::string & param) { _emoji_text = param;
return *
this; }
115 std::string _emoji_text;
123 std::string _emoji_text;
132 std::string _emoji_text;
139 get_reactions_t & emoji_text(
const std::string & param) { _emoji_text = param;
return *
this; }
141 std::string _emoji_text;
162 lib::optional<int> _max_age;
163 lib::optional<int> _max_uses;
164 lib::optional<bool> _temporary;
165 lib::optional<bool> _unique;
194 AEGIS_DECL
guild &
get_guild(std::error_code & ec)
const noexcept;
196 #if !defined(AEGIS_DISABLE_ALL_CACHE)
203 std::shared_lock<shared_mutex> l(_m);
204 std::string _name = name;
205 return std::move(_name);
338 lib::optional<int> _position = {}, lib::optional<std::string> _topic = {},
339 lib::optional<bool> _nsfw = {}, lib::optional<int> _bitrate = {},
340 lib::optional<int> _user_limit = {},
341 lib::optional<std::vector<gateway::objects::permission_overwrite>> _permission_overwrites = {},
342 lib::optional<snowflake> _parent_id = {}, lib::optional<int> _rate_limit_per_user = {});
352 return modify_channel(obj._name, obj._position, obj._topic, obj._nsfw,
353 obj._bitrate, obj._user_limit, obj._permission_overwrites,
354 obj._parent_id, obj._rate_limit_per_user);
483 const lib::optional<int> max_uses,
484 const lib::optional<bool> temporary,
485 const lib::optional<bool> unique);
583 return _guild ==
nullptr;
590 shared_mutex &
mtx() const noexcept
595 #if !defined(AEGIS_DISABLE_ALL_CACHE)
611 AEGIS_DECL
void _load_with_guild(
guild & _guild,
const json & obj,
shards::shard * _shard);
613 AEGIS_DECL
void _load_with_guild_nolock(
guild & _guild,
const json & obj,
shards::shard * _shard);
619 #if !defined(AEGIS_DISABLE_ALL_CACHE)
624 uint32_t position = 0;
626 uint16_t bitrate = 0;
627 uint16_t user_limit = 0;
628 std::unordered_map<int64_t, gateway::objects::permission_overwrite> overrides;
629 uint16_t rate_limit_per_user = 0;
631 asio::io_context & _io_context;
632 mutable shared_mutex _m;
633 core * _bot =
nullptr;
aegis::future< rest::rest_reply > group_dm_remove_recipient(snowflake user_id)
Remove member from a group direct message.
Definition: channel.cpp:633
Definition: channel.hpp:110
Stores creation time and extra data specific to Discord for entities.
Definition: snowflake.hpp:21
Utility class for permission checks.
Definition: permission.hpp:57
Definition: channel.hpp:118
aegis::future< rest::rest_reply > get_pinned_messages()
Get pinned messages in channel.
Definition: channel.cpp:582
aegis::future< rest::rest_reply > create_channel_invite(create_channel_invite_t obj)
Create a new channel invite.
Definition: channel.hpp:493
Class for performing actions pertaining to a specified guild.
Definition: guild.hpp:159
channel(const snowflake channel_id, const snowflake guild_id, core *_bot, asio::io_context &_io, ratelimit::ratelimit_mgr &_ratelimit)
Constructor for the channel object.
Definition: channel.cpp:28
aegis::future< rest::rest_reply > edit_channel_permissions(snowflake _overwrite_id, int64_t _allow, int64_t _deny, const std::string &_type)
Edit channel permission override.
Definition: channel.cpp:501
Primary class for managing a bot interface.
Definition: core.hpp:157
aegis::future< rest::rest_reply > add_pinned_channel_message(snowflake message_id)
Add a pinned message in channel.
Definition: channel.cpp:590
aegis::future< gateway::objects::channel > modify_channel(lib::optional< std::string > _name={}, lib::optional< int > _position={}, lib::optional< std::string > _topic={}, lib::optional< bool > _nsfw={}, lib::optional< int > _bitrate={}, lib::optional< int > _user_limit={}, lib::optional< std::vector< gateway::objects::permission_overwrite >> _permission_overwrites={}, lib::optional< snowflake > _parent_id={}, lib::optional< int > _rate_limit_per_user={})
Modify this channel (all parameters optional)
Definition: channel.cpp:365
aegis::future< gateway::objects::channel > modify_channel(modify_channel_t obj)
Modify this channel (all parameters optional)
Definition: channel.hpp:350
aegis::future< gateway::objects::message > edit_message_embed(snowflake message_id, const std::string &content, const json &embed)
Edit an embed message in this channel.
Definition: channel.cpp:289
aegis::future< rest::rest_reply > delete_channel_permission(snowflake overwrite_id)
Delete channel permission override.
Definition: channel.cpp:559
aegis::future< rest::rest_reply > delete_user_reaction(snowflake message_id, const std::string &emoji_text, snowflake member_id)
Delete specified member reaction on message.
Definition: channel.cpp:459
Class for performing actions pertaining to a specified channel.
Definition: channel.hpp:170
aegis::future< rest::rest_reply > create_reaction(create_reaction_t obj)
Add new reaction on message.
Definition: channel.hpp:377
aegis::future< rest::rest_reply > create_reaction(snowflake message_id, const std::string &emoji_text)
Add new reaction on message.
Definition: channel.cpp:429
snowflake get_id() const noexcept
Get the aegis::snowflake of this channel.
Definition: channel.hpp:563
channel * find_channel(snowflake id) const noexcept
Obtain a pointer to a channel by snowflake.
Definition: core.cpp:342
Definition: channel.hpp:85
aegis::future< rest::rest_reply > bulk_delete_message(const std::vector< int64_t > &messages)
Delete up to 100 messages at once.
Definition: channel.cpp:325
shared_mutex & mtx() const noexcept
Get the mutex for the channel.
Definition: channel.hpp:590
permission perms() const noexcept
Get bot's permission for this channel.
Definition: channel.cpp:55
aegis::snowflake get_parent_id() const noexcept
Get parent channel snowflake.
Definition: channel.hpp:554
aegis::future< rest::rest_reply > edit_channel_permissions(edit_channel_permissions_t obj)
Edit channel permission override.
Definition: channel.hpp:463
std::string get_name() const noexcept
Get channel name.
Definition: channel.hpp:201
Definition: channel.hpp:144
gateway::objects::channel::channel_type get_type() const noexcept
Get the type of this channel.
Definition: channel.hpp:212
create_message_t & user_id(snowflake param)
Only used for sending DMs.
Definition: channel.hpp:40
snowflake get_guild_id() const noexcept
Get the snowflake of this channel's guild - 0 if DM.
Definition: channel.hpp:572
aegis::future< gateway::objects::message > create_message_embed(const std::string &content, const json &embed, int64_t nonce=0)
Send an embed message to this channel.
Definition: channel.cpp:241
bool nsfw() const noexcept
Get if this channel is set to NSFW.
Definition: channel.hpp:600
Definition: channel.hpp:126
Definition: channel.hpp:136
aegis::future< gateway::objects::message > edit_message(snowflake message_id, const std::string &content)
Edit a message in this channel.
Definition: channel.cpp:272
aegis::future< rest::rest_reply > delete_all_reactions(snowflake message_id)
Delete all reactions by message.
Definition: channel.cpp:486
aegis::channel * get_parent() const
Get parent channel.
Definition: channel.hpp:545
channel_type
Enumeration of the channel types.
Definition: channel.hpp:50
aegis::future< gateway::objects::messages > get_messages(get_messages_t obj)
Get multiple messages from this channel.
Definition: channel.cpp:181
future
Definition: futures.hpp:41
aegis::future< rest::rest_reply > trigger_typing_indicator()
Trigger typing indicator in channel (lasts 10 seconds)
Definition: channel.cpp:574
Definition: channel.hpp:37
aegis::future< rest::rest_reply > get_channel_invites()
Get active channel invites.
Definition: channel.cpp:521
Factory class for managing ratelimit bucket factory objects.
Definition: ratelimit.hpp:41
Definition: channel.hpp:67
aegis::future< rest::rest_reply > group_dm_add_recipient(snowflake user_id)
Add member to a group direct message.
Definition: channel.cpp:621
bool is_dm() const noexcept
Is this channel a DM or in a guild.
Definition: channel.hpp:581
aegis::future< rest::rest_reply > delete_user_reaction(delete_user_reaction_t obj)
Delete specified member reaction on message.
Definition: channel.hpp:416
aegis::future< rest::rest_reply > delete_channel()
Delete this channel.
Definition: channel.cpp:416
aegis::future< rest::rest_reply > delete_own_reaction(delete_own_reaction_t obj)
Delete own reaction on message.
Definition: channel.hpp:396
aegis::future< rest::rest_reply > create_channel_invite(const lib::optional< int > max_age, const lib::optional< int > max_uses, const lib::optional< bool > temporary, const lib::optional< bool > unique)
Create a new channel invite.
Definition: channel.cpp:535
aegis::future< rest::rest_reply > delete_own_reaction(snowflake message_id, const std::string &emoji_text)
Delete own reaction on message.
Definition: channel.cpp:444
aegis::future< rest::rest_reply > delete_pinned_channel_message(snowflake message_id)
Delete a pinned message in channel.
Definition: channel.cpp:604
Definition: channel.hpp:156
aegis::future< gateway::objects::message > create_message(const std::string &content, int64_t nonce=0)
Send message to this channel.
Definition: channel.cpp:150
Tracks websocket shards and their connections.
Definition: shard.hpp:42
aegis::future< gateway::objects::message > get_message(snowflake message_id)
Get message from this channel.
Definition: channel.cpp:168
guild & get_guild() const
Get a reference to the guild object this channel belongs to.
Definition: channel.cpp:38
aegis::future< rest::rest_reply > get_reactions(snowflake message_id, const std::string &emoji_text)
Get all reactions for this message.
Definition: channel.cpp:477
aegis::future< rest::rest_reply > get_reactions(get_reactions_t obj)
Get all reactions for this message.
Definition: channel.hpp:435
aegis::future< rest::rest_reply > delete_message(snowflake message_id)
Delete a message.
Definition: channel.cpp:310
Definition: channel.hpp:57