Add join command to join user in cottage
This commit is contained in:
37
src/main.rs
37
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<'_>, 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)]
|
||||
async fn st(ctx: Context<'_>, mut spectators: Vec<serenity::UserId>) -> Result<()> {
|
||||
let guild = ctx
|
||||
@@ -282,7 +313,7 @@ async fn main() -> Result<()> {
|
||||
|
||||
let framework = poise::Framework::builder()
|
||||
.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(),
|
||||
..Default::default()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user