Skip to content

Commit e2b0344

Browse files
committed
add introductions event
1 parent 49d6c33 commit e2b0344

5 files changed

Lines changed: 65 additions & 19 deletions

File tree

src/Cubic/Cubic.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ namespace cubic {
3636
namespace server {
3737
#ifdef CUBIC_LOCAL_BUILD
3838
inline constexpr dpp::snowflake id = 1330925786634522787;
39-
inline constexpr dpp::snowflake welcomeChannel = 1511704877481332806;
4039
#else
4140
inline constexpr dpp::snowflake id = 460081436637134859;
42-
inline constexpr dpp::snowflake welcomeChannel = 1412493998790021171;
4341
#endif
4442
};
4543

src/events/Crosspost.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
using namespace cubic::prelude;
44

5-
static constexpr auto crosspostingChannels = std::to_array<dpp::snowflake>({
65
#ifdef CUBIC_LOCAL_BUILD
7-
1412493998790021171,
6+
#define CUBIC_CROSSPOST_SNOWFLAKE 1412493998790021171
87
#else
9-
942554670201720852,
8+
#define CUBIC_CROSSPOST_SNOWFLAKE 942554670201720852
109
#endif
11-
});
10+
11+
static constexpr dpp::snowflake g_crosspostingChannel = CUBIC_CROSSPOST_SNOWFLAKE;
1212

1313
class CrosspostEvent final : public base::EventHandler {
1414
private:
@@ -29,7 +29,7 @@ class CrosspostEvent final : public base::EventHandler {
2929
dpp::message const& msg = ev.msg;
3030

3131
if (msg.author.id == bot.me.id) co_return;
32-
if (std::find(crosspostingChannels.begin(), crosspostingChannels.end(), msg.channel_id) == crosspostingChannels.end()) co_return;
32+
if (ev.msg.channel_id != g_crosspostingChannel) co_return;
3333

3434
if (string::startsWith(msg.content, "<@") || string::startsWith(msg.content, "<#")) {
3535
log::debug("Scanning crosspost message by #{} ({})", msg.author.username, msg.author.id);

src/events/Introductions.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <Cubic/Cubic.h>
2+
3+
using namespace cubic::prelude;
4+
5+
#ifdef CUBIC_LOCAL_BUILD
6+
#define CUBIC_INTRO_SNOWFLAKE 1512802853784260638
7+
#else
8+
#define CUBIC_INTRO_SNOWFLAKE 937047909122314290
9+
#endif
10+
11+
static constexpr dpp::snowflake g_introChannel = CUBIC_INTRO_SNOWFLAKE;
12+
13+
class IntroductionsEvent final : public base::EventHandler {
14+
public:
15+
void init(dpp::cluster& bot) {
16+
bot.on_message_create([&bot](dpp::message_create_t const& ev) -> dpp::task<void> {
17+
if (ev.msg.author.is_bot() || ev.msg.channel_id != g_introChannel) co_return;
18+
19+
auto msgsRes = co_await bot.co_messages_get(g_introChannel, 0, 0, 0, 100);
20+
if (msgsRes.is_error()) {
21+
log::error("Failed to fetch messages from introductions channel: {}", msgsRes.get_error().message);
22+
co_return;
23+
};
24+
25+
auto msgs = msgsRes.get<std::unordered_map<dpp::snowflake, dpp::message>>();
26+
27+
for (auto const& [sf, msg] : msgs) {
28+
if (ev.msg.author.id == msg.author.id && ev.msg.id != msg.id) {
29+
bot.message_delete(ev.msg.id, ev.msg.channel_id);
30+
31+
co_await bot.co_direct_message_create(
32+
ev.msg.author.id,
33+
dpp::message()
34+
.add_embed(
35+
dpp::embed()
36+
.set_description(fmt::format(":exclamation: Looks like you've already introduced yourself here. If you'd like to update your introduction, **edit the [message]({})** you initially sent of it.", msg.get_url()))
37+
.set_color(theme::colors::secondary)));
38+
39+
co_return;
40+
};
41+
};
42+
43+
co_return;
44+
});
45+
};
46+
};
47+
48+
static IntroductionsEvent ev;

src/events/Welcome.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
using namespace cubic::prelude;
44

5+
#ifdef CUBIC_LOCAL_BUILD
6+
#define CUBIC_WELCOME_SNOWFLAKE 1512802838026260602
7+
#else
8+
#define CUBIC_WELCOME_SNOWFLAKE 1412493998790021171
9+
#endif
10+
11+
static constexpr dpp::snowflake g_welcomeChannel = CUBIC_WELCOME_SNOWFLAKE;
12+
513
class WelcomeEvent final : public base::EventHandler {
614
public:
715
void init(dpp::cluster& bot) override {
@@ -36,15 +44,7 @@ class WelcomeEvent final : public base::EventHandler {
3644
co_return;
3745
};
3846

39-
auto channelRes = co_await bot.co_channel_get(server::welcomeChannel);
40-
if (channelRes.is_error()) {
41-
log::error("Failed to fetch welcome channel: {}", channelRes.get_error().message);
42-
co_return;
43-
};
44-
45-
auto channel = channelRes.get<dpp::channel>();
46-
47-
auto msgRes = co_await bot.co_message_create(dpp::message(channel.id, fmt::format("Welcome to Cubic Studios's community server, {}! Please check your DMs for important information about the server and its channels.", newM.get_user()->global_name)));
47+
auto msgRes = co_await bot.co_message_create(dpp::message(g_welcomeChannel, fmt::format("Welcome to Cubic Studios's community server, {}! Please check your DMs for important information about the server and its channels.", newM.get_user()->global_name)));
4848
if (msgRes.is_error()) {
4949
log::error("Failed to send welcome message to '{}': {}", newM.get_user()->global_name, msgRes.get_error().message);
5050
co_return;

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ int main() {
4242
wh.avatar_url = getAvatarURL();
4343

4444
#ifdef CUBIC_LOCAL_BUILD
45-
#define AVATAR_FORMAT dpp::i_png
45+
#define CUBIC_AVATAR_FORMAT dpp::i_png
4646
#else // the test bot's avatar isn't animated lol
47-
#define AVATAR_FORMAT dpp::i_gif
47+
#define CUBIC_AVATAR_FORMAT dpp::i_gif
4848
#endif
4949

5050
co_await ev.owner->co_execute_webhook(
@@ -55,7 +55,7 @@ int main() {
5555
.set_author("Service Status", "", "")
5656
.set_description(fmt::format(":white_check_mark: **{}** is now __online__", getUsername()))
5757
.set_color(theme::colors::primary)
58-
.set_footer(getUsername(), getAvatarURL(AVATAR_FORMAT))));
58+
.set_footer(getUsername(), getAvatarURL(CUBIC_AVATAR_FORMAT))));
5959
};
6060

6161
co_return;

0 commit comments

Comments
 (0)