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 062a419c94

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<'_>, to: serenity::UserId, user: Option<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 == to))
});
match channel {
Some(channel) => {
guild.move_member(ctx, user.unwrap_or(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
@@ -282,7 +313,7 @@ async fn main() -> Result<()> {
let framework = poise::Framework::builder() let framework = poise::Framework::builder()
.options(poise::FrameworkOptions { .options(poise::FrameworkOptions {
commands: vec![dusk(), dawn(), st(), currently_playing(), configure()], commands: vec![dusk(), dawn(), st(), currently_playing(), join(), configure()],
event_handler: |ctx, ev, ctxf, data| on_event(ctx, ev, ctxf, data).boxed(), event_handler: |ctx, ev, ctxf, data| on_event(ctx, ev, ctxf, data).boxed(),
..Default::default() ..Default::default()
}) })