forked from nolan/titlebot-ng-ng
Implement gettitles command
This commit is contained in:
@@ -121,12 +121,30 @@ pub async fn suggest(
|
||||
pub async fn get_titles(
|
||||
event: &OriginalSyncRoomMessageEvent,
|
||||
room: &Room,
|
||||
text: &str,
|
||||
ctx: Ctx<MagbotContext>,
|
||||
) -> anyhow::Result<()> {
|
||||
// sends all the titles with an initial reaction to be used for voting
|
||||
// save the message ids into context for count_votes()?
|
||||
todo!()
|
||||
let user = event.sender.to_string();
|
||||
match ctx.0.status {
|
||||
MagbotStatus::Running => {
|
||||
for title in ctx.0.titles {
|
||||
let msg = RoomMessageEventContent::text_plain(format!(
|
||||
"{} : {}",
|
||||
title.title, title.user
|
||||
));
|
||||
let response = room.send(msg).await?;
|
||||
// save the message ids into context for count_votes()?
|
||||
let reaction =
|
||||
ReactionEventContent::new(Annotation::new(response.event_id, "👍".to_string()));
|
||||
room.send(reaction).await?;
|
||||
}
|
||||
}
|
||||
MagbotStatus::Sleeping => {
|
||||
let msg = RoomMessageEventContent::text_plain(format!("{user} Magbot is not running"));
|
||||
room.send(msg).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Counts the votes of title suggestions
|
||||
|
||||
@@ -75,7 +75,7 @@ async fn on_room_message(
|
||||
|
||||
// retrieve list of titles
|
||||
s if s.to_lowercase().starts_with("!gettitles") => {
|
||||
commands::get_titles(&event, &room, s, ctx).await?;
|
||||
commands::get_titles(&event, &room, ctx).await?;
|
||||
}
|
||||
|
||||
// count upvotes on posted suggestions
|
||||
|
||||
Reference in New Issue
Block a user