wip: bot-questionnaire.cpp now creates a individual chat for new user that only be seen by him
@@ -18,29 +18,11 @@ on_ready(client *client, const user::dati *me)
(void)client;
}
-u64_snowflake_t
-create_beginner_role(
- client *client,
- const guild::member::dati *member,
- const u64_snowflake_t guild_id)
-{
- role::dati rl;
- role::dati_init(&rl);
-
- guild::create_role::params params = {
- .name = "beginner"
- };
- guild::create_role::run(client, guild_id, &params, &rl);
-
- return rl.id;
-}
-
u64_snowflake_t
create_beginner_channel(
client *client,
const guild::member::dati *member,
- const u64_snowflake_t guild_id,
- const u64_snowflake_t role_id)
+ const u64_snowflake_t guild_id)
{
channel::dati ch;
channel::dati_init(&ch);
@@ -49,15 +31,32 @@ create_beginner_channel(
.name = "welcome",
.topic = "Questionnaire."
};
+
+ guild::role::dati **rls = guild::role::get_list(client, guild_id);
+ for (size_t i=0; rls[i]; ++i) {
+ if (0x8 & strtoull(rls[i]->permissions, NULL, 10)) { // if role is admin ignore it
+ continue;
+ }
+
channel::overwrite::append(
&params.permission_overwrites,
- role_id,
+ rls[i]->id,
0, // role type
- 0x40 | 0x400 | 0x800, // Read and Send Messages, Add Reactions
- 0);
+ 0, // Don't set allow permissions
+ 0x40 | 0x400 | 0x800); // Deny Read and Send Messages, Add Reactions permissions
+ }
+
+ channel::overwrite::append(
+ &params.permission_overwrites,
+ member->user->id,
+ 1, // user type
+ 0x40 | 0x400 | 0x800, // Allow Read and Send Messages, Add Reactions permissions
+ 0); // Don't set deny permissions
guild::create_channel::run(client, guild_id, &params, &ch);
+ guild::role::dati_list_free(rls);
+
return ch.id;
}
@@ -70,17 +69,9 @@ on_member_join(
{
if (member->user->bot) return; // ignore bots
- u64_snowflake_t role_id = create_beginner_role(client, member, guild_id);
- if (!role_id) return; /* @todo this is not how to properly handle this */
-
- u64_snowflake_t channel_id = create_beginner_channel(client, member, guild_id, role_id);
+ u64_snowflake_t channel_id = create_beginner_channel(client, member, guild_id);
if (!channel_id) return; /* @todo this is not how to properly handle this */
- // Assign newly created role to new user
- guild::modify_member::params params1 = {0};
- ja_u64_list_append(&params1.roles, &role_id);
- guild::modify_member::run(client, guild_id, member->user->id, &params1, NULL);
-
// Send some messages to be read by the newcomer
char text[512];
snprintf(text, sizeof(text), "Welcome, <@!%" PRIu64 ">!", member->user->id);
