Add join command to join user in cottage

This commit is contained in:
bluepython508
2024-12-09 17:50:45 +00:00
parent 4245102bf5
commit 69e15e8455

View File

@@ -123,7 +123,11 @@ async fn spread(
Ok(()) 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 let guild = ctx
.guild_id() .guild_id()
.ok_or_eyre("This bot only works in servers")?; .ok_or_eyre("This bot only works in servers")?;
@@ -169,11 +173,38 @@ async fn dawn(ctx: Context<'_>) -> Result<()> {
.. ..
} = ctx.data().get(guild).await?; } = ctx.data().get(guild).await?;
join(ctx, cottages, town_square).await?; collect(ctx, cottages, town_square).await?;
Ok(()) 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)] #[poise::command(slash_command, ephemeral)]
async fn st(ctx: Context<'_>, mut spectators: Vec<serenity::UserId>) -> Result<()> { async fn st(ctx: Context<'_>, mut spectators: Vec<serenity::UserId>) -> Result<()> {
let guild = ctx let guild = ctx