-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathclose_cmd.cpp
More file actions
80 lines (65 loc) · 3.1 KB
/
close_cmd.cpp
File metadata and controls
80 lines (65 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "commands.h"
#include "../globals/globals.h"
#include <dpp/channel.h>
#include <dpp/permissions.h>
#include <dpp/snowflake.h>
#include <dpp/unicode_emoji.h>
void cmd::closeCommand(dpp::cluster& bot, const dpp::slashcommand_t& event)
{
const dpp::channel* channel = dpp::find_channel(event.command.channel_id);
if (!channel)
{
event.reply(dpp::message("[!] Channel not found").set_flags(dpp::m_ephemeral));
return;
}
if (channel->get_type() == dpp::channel_type::CHANNEL_PUBLIC_THREAD)
{
bot.thread_get(event.command.channel_id, [&bot, event](const dpp::confirmation_callback_t& callback) {
if (callback.is_error())
return event.reply(dpp::message("[!] Callback error").set_flags(dpp::m_ephemeral));
dpp::thread thread = callback.get<dpp::thread>();
bool isOwner = (thread.owner_id == event.command.member.user_id);
bool hasManagePermission = event.command.member.has_permission(thread.guild_id, dpp::p_manage_threads);
if (!isOwner && !hasManagePermission)
return event.reply(dpp::message("You can only close your own posts or you need manage threads permission.").set_flags(dpp::m_ephemeral));
thread.metadata.locked = true;
thread.metadata.archived = true;
const std::string newThreadName = dpp::unicode_emoji::lock + std::string(" ") + thread.name;
thread.set_name(newThreadName);
bot.thread_edit(thread, [event](const dpp::confirmation_callback_t& callback2) {
if (callback2.is_error())
return event.reply(dpp::message("[!] Unable to close post.").set_flags(dpp::m_ephemeral));
const dpp::embed embed = dpp::embed()
.set_color(globals::color::defaultColor)
.add_field("Closed post!", "");
const dpp::message message(event.command.channel_id, embed);
event.reply(message);
});
});
}
else if (channel->parent_id == globals::category::ticketId)
{
bool isOwner = false;
bool hasManagePermission = event.command.member.has_permission(channel->guild_id, dpp::p_manage_channels);
for (const auto& overwrite : channel->permission_overwrites)
{
if (overwrite.id == event.command.member.user_id && overwrite.type == dpp::overwrite_type::ot_member)
{
isOwner = true;
break;
}
}
if (!isOwner && !hasManagePermission)
{
event.reply(dpp::message("You can only close your own tickets or you need manage channels permission.").set_flags(dpp::m_ephemeral));
return;
}
event.reply(dpp::message("Closed ticket!"));
// Remove user's access to the ticket
bot.channel_edit_permissions(*channel, event.command.member.user_id, 0, dpp::p_view_channel, true);
}
else
{
event.reply(dpp::message("This command only operates within tickets and threads.").set_flags(dpp::m_ephemeral));
}
}