Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #260 from GiganticMinecraft/update-poise
Browse files Browse the repository at this point in the history
fix: update poise
  • Loading branch information
Lucky authored Jul 7, 2024
2 parents 53cd7dc + 9947222 commit 2992bbb
Show file tree
Hide file tree
Showing 15 changed files with 900 additions and 584 deletions.
955 changes: 629 additions & 326 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion c-presentation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tokio.workspace = true
once_cell = "1.18"
fern = "0.6"
log = "0.4"
poise = "0.5"
poise = "0.6"
argh = "0.1"
thiserror = "1.0"
sentry = "0.31.8"
28 changes: 19 additions & 9 deletions c-presentation/src/commands/agenda/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ use crate::{
use c_domain::redmine::model::id::{AgendaId, RecordId};

use log::info;
use poise::{
serenity_prelude::{CreateEmbed, CreateMessage},
CreateReply,
};

/// 議題を追加します
#[poise::command(slash_command)]
Expand Down Expand Up @@ -39,14 +43,15 @@ pub async fn add(
new_agenda_id, record_id
);
let _ = ctx
.send(|c| {
c.embed(|e| {
e.custom_default(&record_id)
.send(
CreateReply::default().embed(
CreateEmbed::new()
.custom_default(&record_id)
.title("議題を追加しました")
.description(format!("追加した議題: {}", new_agenda_id.formatted()))
.success_color()
})
})
.success_color(),
),
)
.await?;

// 現在進行中の議題がなければ、議題として提示
Expand All @@ -55,9 +60,14 @@ pub async fn add(
ctx.data().current_agenda_id.save(new_agenda.id);
let _ = ctx
.channel_id()
.send_message(&ctx.http(), |c| {
c.embed(|e| discord_embed::next_agenda_embed(e, &record_id, &new_agenda))
})
.send_message(
&ctx.http(),
CreateMessage::new().embed(discord_embed::next_agenda_embed(
CreateEmbed::new(),
&record_id,
&new_agenda,
)),
)
.await?;
}

Expand Down
75 changes: 42 additions & 33 deletions c-presentation/src/commands/create/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use c_usecase::{github::model::CreateIssueParam, redmine::model::CreateNoteParam

use itertools::Itertools;
use log::info;
use poise::{futures_util::future, serenity_prelude::CreateEmbed};
use poise::{futures_util::future, serenity_prelude::CreateEmbed, CreateReply};

type ErrAgendas = Vec<(AgendaId, anyhow::Error)>;

Expand All @@ -30,11 +30,11 @@ where
(succeeded, failed)
}

fn create_failures_embed<'a>(
embed: &'a mut CreateEmbed,
fn create_failures_embed(
embed: CreateEmbed,
errs: &ErrAgendas,
record_id: &RecordId,
) -> &'a mut CreateEmbed {
) -> CreateEmbed {
let contents = errs
.iter()
.map(|(id, err)| format!("{}\n{:?}", id.formatted(), err))
Expand Down Expand Up @@ -122,6 +122,18 @@ pub async fn issue(
.collect_vec();
let (gh_issues, err_gh_issues) = group_results::<String>(github_issue_results);

if !err_gh_issues.is_empty() {
ctx.send(
CreateReply::default().embed(
create_failures_embed(CreateEmbed::new(), &err_gh_issues, &record_id)
.title("GitHubにIssueを起票できなかった議題があります"),
),
)
.await?;

return Ok(());
}

info!("Add Redmine notes");
let create_redmine_notes = gh_issues
.into_iter()
Expand Down Expand Up @@ -151,35 +163,32 @@ pub async fn issue(
.collect_vec();
let (redmine_notes, err_redmine_notes) = group_results::<()>(redmine_note_results);

ctx.send(|r| {
if !redmine_notes.is_empty() {
r.embed(|e| {
e.custom_default(&record_id)
.title("GitHubへの起票とRedmineへの注記をどちらも完了した議題は以下の通りです")
.description(
redmine_notes
.iter()
.map(|(id, _)| id.formatted())
.join(", "),
)
.success_color()
});
}
if !err_gh_issues.is_empty() {
r.embed(|e| {
create_failures_embed(e, &err_gh_issues, &record_id)
.title("GitHubにIssueを起票できなかった議題があります")
});
}
if !err_redmine_notes.is_empty() {
r.embed(|e| {
create_failures_embed(e, &err_redmine_notes, &record_id)
.title("Redmineに注記をできなかった議題があります")
});
}

r
})
if !err_redmine_notes.is_empty() {
ctx.send(
CreateReply::default().embed(
create_failures_embed(CreateEmbed::new(), &err_redmine_notes, &record_id)
.title("Redmineに注記をできなかった議題があります"),
),
)
.await?;

return Ok(());
}

ctx.send(
CreateReply::default().embed(
CreateEmbed::new()
.custom_default(&record_id)
.title("GitHubへの起票とRedmineへの注記をどちらも完了した議題は以下の通りです")
.description(
redmine_notes
.iter()
.map(|(id, _)| id.formatted())
.join(", "),
)
.success_color(),
),
)
.await?;

Ok(())
Expand Down
35 changes: 19 additions & 16 deletions c-presentation/src/commands/create/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use c_domain::redmine::model::id::{AgendaId, RecordId};

use itertools::Itertools;
use log::{debug, info};
use poise::serenity_prelude::{AutoArchiveDuration, CreateEmbed, CreateMessage, CreateThread};

/// 承認されたアイデアについて追加議論を行うためのスレッドを作成します
#[poise::command(slash_command)]
Expand Down Expand Up @@ -68,33 +69,35 @@ pub async fn thread(
)
.await
.unwrap();
if let Ok(th) = ctx
let thread = ctx
.channel_id()
.create_public_thread(&ctx.http(), msg.id, |b| {
// Threads will be archived in 24 hours automatically
b.name(format!(
.create_thread_from_message(
&ctx.http(),
msg.id,
CreateThread::new(format!(
"{}: {}",
record.discussion_title(),
formatted_agenda_id
))
// 24時間でアーカイブされる
.auto_archive_duration(60 * 24)
})
.await
{
let _ = th
.send_message(&ctx.http(), |b|
b.content(format!(
.auto_archive_duration(AutoArchiveDuration::OneDay),
)
.await?;
let _ = thread
.send_message(
&ctx.http(),
CreateMessage::new().content(
format!(
"このスレッドは、{}にて承認されたアイデア{}について個別に議論を行うためのものです。",
record.discussion_title(),
formatted_agenda_id
)).embed(|e|
discord_embed::next_agenda_embed(e, &record_id, agenda)
.title(format!("このスレッドで議論を行う議題は{}です", formatted_agenda_id))
)
).embed(
discord_embed::next_agenda_embed(CreateEmbed::new(), &record_id, agenda)
.title(format!("このスレッドで議論を行う議題は{}です", formatted_agenda_id))
)
)
.await;
}
.await?;
}

Ok(())
Expand Down
13 changes: 7 additions & 6 deletions c-presentation/src/commands/end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use c_usecase::redmine::model::CreateNoteParam;

use itertools::Itertools;
use log::{debug, info};
use poise::futures_util::future;
use poise::{futures_util::future, serenity_prelude::CreateEmbed, CreateReply};

/// 会議を終了します
#[poise::command(slash_command)]
Expand Down Expand Up @@ -70,11 +70,12 @@ pub async fn end(ctx: Context<'_>) -> CommandResult {
data.current_agenda_id.clear();

let _ = ctx
.send(|r| {
r.embed(|e| {
discord_embed::agendas_result(e, record, result).title("会議を終了しました")
})
})
.send(
CreateReply::default().embed(
discord_embed::agendas_result(CreateEmbed::new(), record, result)
.title("会議を終了しました"),
),
)
.await;

Ok(())
Expand Down
4 changes: 3 additions & 1 deletion c-presentation/src/commands/ping.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use poise::CreateReply;

use crate::commands::{CommandResult, Context};

#[poise::command(slash_command)]
pub async fn ping(ctx: Context<'_>) -> CommandResult {
let _ = ctx.send(|b| b.content("pong!")).await;
let _ = ctx.send(CreateReply::default().content("Pong!")).await?;

Ok(())
}
31 changes: 17 additions & 14 deletions c-presentation/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use c_domain::redmine::model::id::{AgendaId, RecordId};
use anyhow::ensure;
use itertools::Itertools;
use log::{debug, info};
use poise::futures_util::future;
use poise::{futures_util::future, serenity_prelude::CreateEmbed, CreateReply};

/// 会議を開始します
#[poise::command(slash_command)]
Expand All @@ -29,7 +29,7 @@ pub async fn start(

let vc_id = ctx
.guild()
.map(|g| g.voice_states)
.map(|g| g.clone().voice_states)
.and_then(|map| map.get(&ctx.author().id).cloned())
.and_then(|state| state.channel_id)
.ok_or_else(|| anyhow::anyhow!("会議を開始するにはVCに参加してください"))?;
Expand Down Expand Up @@ -79,19 +79,22 @@ pub async fn start(
data.current_agenda_id.save(agenda.id);
};

let embed = match next_agenda {
Some(agenda) => discord_embed::next_agenda_embed(CreateEmbed::new(), &record_id, agenda),
None => discord_embed::no_next_agenda(CreateEmbed::new(), &record_id),
};
let _ = ctx
.send(|r| {
r.embed(|e| {
e.custom_default(&record_id)
.title("会議を開始しました")
.custom_field("議事録チケット", record.url(), false)
})
.embed(|e| match next_agenda {
Some(agenda) => discord_embed::next_agenda_embed(e, &record_id, agenda),
None => discord_embed::no_next_agenda(e, &record_id),
})
})
.await;
.send(
CreateReply::default()
.embed(
CreateEmbed::new()
.custom_default(&record_id)
.title("会議を開始しました")
.custom_field("議事録チケット", record.url(), false),
)
.embed(embed),
)
.await?;

Ok(())
}
51 changes: 30 additions & 21 deletions c-presentation/src/commands/vote/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use c_usecase::redmine::model::CreateNoteParam;

use itertools::Itertools;
use log::info;
use poise::serenity_prelude::CacheHttp;
use poise::{
serenity_prelude::{CacheHttp, CreateEmbed, CreateMessage},
CreateReply,
};

pub async fn end_votes(ctx: &Context<'_>, choice: VoteChoice) -> anyhow::Result<()> {
info!("Vote finished: {}", choice);
Expand All @@ -36,15 +39,24 @@ pub async fn end_votes(ctx: &Context<'_>, choice: VoteChoice) -> anyhow::Result<
if data.vote_message_id.get().is_some() {
let _ = ctx
.channel_id()
.send_message(&ctx.http(), |c| {
c.embed(|e| discord_embed::vote_result(e, &record_id, &current_agenda_id, &choice))
})
.send_message(
&ctx.http(),
CreateMessage::new().embed(discord_embed::vote_result(
CreateEmbed::new(),
&record_id,
&current_agenda_id,
&choice,
)),
)
.await;
} else {
let _ = ctx
.send(|r| {
r.embed(|e| discord_embed::vote_result(e, &record_id, &current_agenda_id, &choice))
})
.send(CreateReply::default().embed(discord_embed::vote_result(
CreateEmbed::new(),
&record_id,
&current_agenda_id,
&choice,
)))
.await;
}

Expand Down Expand Up @@ -85,22 +97,19 @@ pub async fn end_votes(ctx: &Context<'_>, choice: VoteChoice) -> anyhow::Result<
data.current_agenda_id.save(agenda.id);
}
// 次の議題の存否に応じてEmbedを送信
let embed = match next_agenda {
Some(agenda) => {
info!("Next Agenda: {}", AgendaId::new(agenda.id).formatted());
discord_embed::next_agenda_embed(CreateEmbed::new(), &record_id, agenda)
}
None => {
info!("No next agenda");
discord_embed::no_next_agenda(CreateEmbed::new(), &record_id)
}
};
let _ = ctx
.channel_id()
.send_message(&ctx.http(), |c| {
c.embed(|e| match next_agenda {
Some(agenda) => {
info!("Next Agenda: {}", AgendaId::new(agenda.id).formatted());

discord_embed::next_agenda_embed(e, &record_id, agenda)
}
None => {
info!("No next agenda");

discord_embed::no_next_agenda(e, &record_id)
}
})
})
.send_message(&ctx.http(), CreateMessage::new().embed(embed))
.await;

Ok(())
Expand Down
Loading

0 comments on commit 2992bbb

Please sign in to comment.