From 69e15e8455b23cde87d0267569ea9e2a96f92651 Mon Sep 17 00:00:00 2001 From: bluepython508 <16466646+bluepython508@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:50:45 +0000 Subject: [PATCH] Add join command to join user in cottage --- src/main.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5a64a5b..a7ce03d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -123,7 +123,11 @@ async fn spread( Ok(()) } -async fn join(ctx: Context<'_>, from: serenity::ChannelId, to: serenity::ChannelId) -> Result<()> { +async fn collect( + ctx: Context<'_>, + from: serenity::ChannelId, + to: serenity::ChannelId, +) -> Result<()> { let guild = ctx .guild_id() .ok_or_eyre("This bot only works in servers")?; @@ -169,11 +173,38 @@ async fn dawn(ctx: Context<'_>) -> Result<()> { .. } = ctx.data().get(guild).await?; - join(ctx, cottages, town_square).await?; + collect(ctx, cottages, town_square).await?; Ok(()) } +#[poise::command(slash_command, ephemeral)] +async fn join(ctx: Context<'_>, user: serenity::UserId) -> Result<()> { + let guild = ctx + .guild_id() + .ok_or_eyre("This bot only works in servers")?; + let GuildData { cottages, .. } = ctx.data().get(guild).await?; + + let channel = channel_children(&ctx, cottages) + .await? + .into_iter() + .find(|chan| { + chan.members(ctx) + .is_ok_and(|members| members.iter().any(|member| member.user.id == user)) + }); + + match channel { + Some(channel) => { + guild.move_member(ctx, ctx.author().id, channel).await?; + ctx.reply("Joined player").await?; + } + None => { + ctx.reply("User is not in cottages").await?; + } + } + Ok(()) +} + #[poise::command(slash_command, ephemeral)] async fn st(ctx: Context<'_>, mut spectators: Vec) -> Result<()> { let guild = ctx