Skip to content

Commit

Permalink
Fixed several issues in PR
Browse files Browse the repository at this point in the history
  • Loading branch information
wizard7377 authored and wizard7377 committed Aug 12, 2023
1 parent 8311b80 commit dadb962
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 92 deletions.
49 changes: 0 additions & 49 deletions cmake_install.cmake

This file was deleted.

4 changes: 1 addition & 3 deletions include/dpp/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,7 @@ struct active_thread_info {
* @brief A map of threads alongside optionally the thread_member tied to the bot if it is in the thread. The map's key is the thread id. Returned from the cluster::threads_get_active method
*/
using active_threads = std::map<snowflake, active_thread_info>;
/**
* @brief A stream wrapper to send messages
*/


} // namespace dpp

5 changes: 1 addition & 4 deletions include/dpp/dpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
#include <string>
#include <vector>
#include <map>

#include <functional>

#include <dpp/exception.h>
#include <dpp/snowflake.h>
#include <dpp/misc-enum.h>
Expand Down Expand Up @@ -75,5 +73,4 @@
#include <dpp/colors.h>
#include <dpp/discordevents.h>
#include <dpp/timed_listener.h>
#include <dpp/collector.h>

#include <dpp/collector.h>
41 changes: 30 additions & 11 deletions include/dpp/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,31 @@


namespace dpp {

/**
* @brief Structure to act as special end of message
*
*/
struct end_msg_t {};

/**
* @brief Structure to act as special end of message
*
*/
struct end_row_t {};

/**
* @brief Return end of message
* @return 0
*/
int end_msg();
* @brief End and send a message in stream
*
* @return end_msg_t Simple end message object
*/
end_msg_t eng_msg();
/**
* @brief End a row in stream
*
* @return end_row_t Simple end row object
*/
end_row_t eng_row(); //NOTE NOT USED YET, WILL BE USED IN NEXT COMMIT
/**
* @brief Simple parent for streams
*
Expand All @@ -47,11 +67,10 @@ class DPP_EXPORT base_stream {
*/
base_stream& operator<<(const std::string& msg);
/**
* @brief Finish and send message in stream
* @param n Number (currently irrelevant)
* @brief Finish and send message in stream, argument indicates end of message
* @return This stream, for purposes of chaining
*/
base_stream& operator<<(const int& n);
base_stream& operator<<(end_msg_t);
//TODO Make action rows work with this
/**
* @brief Build message in stream
Expand Down Expand Up @@ -87,14 +106,14 @@ class DPP_EXPORT dm_stream : public base_stream {
* @param bot Cluster that will send messages
* @param out_channel User to whom messages will be sent
*/
dm_stream(cluster& bot, const user& out_user);
dm_stream(cluster& bot_, const user& out_user);
/**
* @brief Constructer
*
* @param bot Cluster that will send messages
* @param out_channel_id User id to whom messages will be sent
*/
dm_stream(cluster& bot, snowflake out_user_id);
dm_stream(cluster& bot_, snowflake out_user_id_);
/**
* @brief Send message with stream
* @param callback Function to call when the API call completes. On success the callback will contain a dpp::message object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
Expand Down Expand Up @@ -125,14 +144,14 @@ class DPP_EXPORT channel_stream : public base_stream {
* @param bot Cluster that will send messages
* @param out_channel Channel where messages will be sent
*/
channel_stream(cluster& bot, const channel& out_channel);
channel_stream(cluster& bot_, const channel& out_channel);
/**
* @brief Constructer
*
* @param bot Cluster that will send messages
* @param out_channel_id Channel id where messages will be sent
*/
channel_stream(cluster& bot, snowflake out_channel_id);
channel_stream(cluster& bot_, snowflake out_channel_id_);
/**
* @brief Send message with stream
* @param msg Message to send
Expand Down
2 changes: 1 addition & 1 deletion include/dpp/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <dpp/utility.h>
#include <dpp/json_interface.h>
namespace dpp {
class cluster; //TODO Find a way to remove this forward declaration
class cluster; //Forward declaration
class dm_stream; //Forward declaration
/**
* @brief Various bitmask flags used to represent information about a dpp::user
Expand Down
44 changes: 20 additions & 24 deletions src/dpp/streams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,43 @@
*
************************************************************************************/


#include <dpp/streams.h>
#include <dpp/channel.h>


#include <utility>

namespace dpp {

int end_msg()
{
return 0;
end_msg_t end_msg() {
return {};
}
channel_stream::channel_stream(cluster& bot, const channel& out_channel) {
this->bot = &bot;
this->out_channel_id = out_channel.id;
}
channel_stream::channel_stream(cluster& bot, snowflake out_channel_id) {
this->bot = &bot;
this->out_channel_id = out_channel_id;

end_row_t end_row() {
return {};
}

channel_stream::channel_stream(cluster& bot_, const channel& out_channel) : bot(&bot_), out_channel_id(out_channel.id) {}

channel_stream::channel_stream(cluster& bot_, snowflake out_channel_id_) : bot(&bot_), out_channel_id(out_channel_id_) {}

void channel_stream::send(command_completion_event_t callback) {
this->msg.set_channel_id(this->out_channel_id); //Make sure message is sent to the right channel
this->bot->message_create(this->msg,callback);
}

message channel_stream::send_sync() {
this->msg.set_channel_id(this->out_channel_id);
return this->bot->message_create_sync(this->msg);
}

dm_stream::dm_stream(cluster& bot_, const user& out_user) : bot(&bot_), out_user_id(out_user.id) {}

dm_stream::dm_stream(cluster& bot_, snowflake out_user_id_) : bot(&bot_), out_user_id(out_user_id_) {}


dm_stream::dm_stream(cluster& bot, const user& out_user) {
this->bot = &bot;
this->out_user_id = out_user.id;
}
dm_stream::dm_stream(cluster& bot, snowflake out_user_id) {
this->bot = &bot;
this->out_user_id = out_user_id;
}
void dm_stream::send(command_completion_event_t callback) {

this->bot->direct_message_create(this->out_user_id,this->msg,callback);
}

message dm_stream::send_sync() {

return this->bot->direct_message_create_sync(out_user_id,this->msg);
Expand All @@ -74,22 +66,26 @@ base_stream& base_stream::operator<<(const std::string& msg) {
this->msg.set_content(this->msg.content + msg);
return (*this);
}
base_stream& base_stream::operator<<(const int& n) {
base_stream& base_stream::operator<<(end_msg_t) {
this->send();
this->msg = message();
return (*this);
}

base_stream& base_stream::operator<<(const embed& e) {
this->msg.add_embed(e);
return (*this);
}

base_stream& base_stream::operator<<(const component& c) {
this->msg.add_component(c);
return (*this);
}


base_stream& base_stream::operator<<(const std::pair<std::string,std::string> &f) {
this->msg.add_file(f.first,f.second);
return (*this);
}
} //namespace dpp

} //namespace dpp

0 comments on commit dadb962

Please sign in to comment.