Skip to content

Commit

Permalink
Added serverID check in GetRoleName
Browse files Browse the repository at this point in the history
Added EditChannel function
  • Loading branch information
Luckshya committed May 15, 2020
1 parent 9b936a3 commit 4bc24db
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ target_compile_definitions(SqDiscord PUBLIC SQMOD_PLUGIN_API=1)
# Determine if build mode
if(CMAKE_BUILD_TYPE MATCHES Release)
target_compile_definitions(SqDiscord PRIVATE NDEBUG=1)
message("aassa")
else()
target_compile_definitions(SqDiscord PRIVATE _DEBUG=1 SQMOD_EXCEPTLOC=1)
message("aasa")
endif()

# Link to base libraries
Expand Down
80 changes: 78 additions & 2 deletions src/CSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ SQInteger CSession::MessageEmbed(HSQUIRRELVM vm) {
}

StackStrF content(vm, 3);
if (SQ_FAILED(channelID.Proc(false)))
if (SQ_FAILED(content.Proc(false)))
{
return content.mRes; // Propagate the error!
}
Expand Down Expand Up @@ -361,8 +361,15 @@ SQInteger CSession::GetRoleName(HSQUIRRELVM vm) {
}

try {
std::list<SleepyDiscord::Role> roles = session->client->s_servers.at(std::string(serverID.mPtr)).roles;
std::string s_serverID = std::string(serverID.mPtr);

auto rolesIndex = session->client->s_servers.find(std::string(serverID.mPtr));

if(rolesIndex == session->client->s_servers.end()) {
return sq_throwerror(vm, "Invalid server ID");
}

std::list<SleepyDiscord::Role>& roles = (rolesIndex->second).roles;
bool found = false;
CCStr role_name = nullptr;

Expand All @@ -386,6 +393,74 @@ SQInteger CSession::GetRoleName(HSQUIRRELVM vm) {
return 1;
}

// ------------------------------------------------------------------------------------------------
SQInteger CSession::EditChannel(HSQUIRRELVM vm) {
const int top = sq_gettop(vm);

if (top <= 1)
{
return sq_throwerror(vm, "Missing the channel ID value");
}

else if (top <= 2)
{
return sq_throwerror(vm, "Missing the channel name value");
}

else if (top <= 3)
{
return sq_throwerror(vm, "Missing the channel topic value");
}

CSession * session = nullptr;

try {
session = Sqrat::Var< CSession * >(vm, 1).value;
}
catch (const Sqrat::Exception& e) {
return sq_throwerror(vm, e.what());
}

if (!session) {
return sq_throwerror(vm, "Invalid session instance");
}

else if (!session->client) {
return sq_throwerror(vm, "Invalid Discord client");
}

else if (!session->isConnected) {
return sq_throwerror(vm, "Session is not connected");
}

StackStrF channelID(vm, 2);
if (SQ_FAILED(channelID.Proc(false)))
{
return channelID.mRes; // Propagate the error!
}

StackStrF name(vm, 3);
if (SQ_FAILED(name.Proc(false)))
{
return name.mRes; // Propagate the error!
}

StackStrF topic(vm, 4);
if (SQ_FAILED(topic.Proc(false)))
{
return topic.mRes; // Propagate the error!
}

try {
auto response = session->client->editChannel(std::string(channelID.mPtr), std::string(name.mPtr), std::string(topic.mPtr), SleepyDiscord::Async);
}
catch (...) {
SqMod_LogErr("An Error has occured at [CSession] function => [EditChannel]");
}

return 0;
}

// ------------------------------------------------------------------------------------------------
SQInteger CSession::SetActivity(HSQUIRRELVM vm) {
const int top = sq_gettop(vm);
Expand Down Expand Up @@ -593,6 +668,7 @@ void CSession::DRegister_CSession(Table& discordcn)
.SquirrelFunc("Message", &CSession::Message)
.SquirrelFunc("MessageEmbed", &CSession::MessageEmbed)
.SquirrelFunc("GetRoleName", &CSession::GetRoleName)
.SquirrelFunc("EditChannel", &CSession::EditChannel)
.SquirrelFunc("SetActivity", &CSession::SetActivity)
);
}
Expand Down
1 change: 1 addition & 0 deletions src/CSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public :
static SQInteger Message(HSQUIRRELVM);
static SQInteger MessageEmbed(HSQUIRRELVM);
static SQInteger GetRoleName(HSQUIRRELVM);
static SQInteger EditChannel(HSQUIRRELVM);
static SQInteger SetActivity(HSQUIRRELVM);

void OnReady();
Expand Down

0 comments on commit 4bc24db

Please sign in to comment.