forked from nolan/titlebot-ng-ng
Get titles command
This commit is contained in:
@@ -121,12 +121,32 @@ pub async fn suggest(
|
||||
pub async fn get_titles(
|
||||
event: &OriginalSyncRoomMessageEvent,
|
||||
room: &Room,
|
||||
text: &str,
|
||||
ctx: Ctx<MagbotContext>,
|
||||
mut ctx: Ctx<MagbotContext>,
|
||||
) -> anyhow::Result<()> {
|
||||
let user = event.sender.to_string();
|
||||
// sends all the titles with an initial reaction to be used for voting
|
||||
// save the message ids into context for count_votes()?
|
||||
todo!()
|
||||
match ctx.0.status {
|
||||
MagbotStatus::Running => {
|
||||
for title in ctx.0.titles {
|
||||
let msg = RoomMessageEventContent::text_plain(format!(
|
||||
"{} : {}",
|
||||
title.user, title.title
|
||||
));
|
||||
let response = room.send(msg).await?;
|
||||
let reaction = ReactionEventContent::new(Annotation::new(
|
||||
response.event_id.clone(),
|
||||
"👍".to_string(),
|
||||
));
|
||||
room.send(reaction).await?;
|
||||
ctx.0.message_ids.push(response.event_id);
|
||||
}
|
||||
}
|
||||
MagbotStatus::Sleeping => {
|
||||
let msg = RoomMessageEventContent::text_plain(format!("{user} magbot is not running"));
|
||||
room.send(msg).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Counts the votes of title suggestions
|
||||
|
||||
@@ -2,7 +2,10 @@ use matrix_sdk::{
|
||||
Client, Room, RoomState,
|
||||
config::SyncSettings,
|
||||
event_handler::Ctx,
|
||||
ruma::events::room::message::{MessageType, OriginalSyncRoomMessageEvent},
|
||||
ruma::{
|
||||
OwnedEventId,
|
||||
events::room::message::{MessageType, OriginalSyncRoomMessageEvent},
|
||||
},
|
||||
};
|
||||
|
||||
use crate::config::MagbotStatus;
|
||||
@@ -14,12 +17,14 @@ pub mod config;
|
||||
struct MagbotContext {
|
||||
pub(crate) status: MagbotStatus,
|
||||
pub(crate) titles: Vec<TitleSuggestion>,
|
||||
pub(crate) message_ids: Vec<OwnedEventId>,
|
||||
}
|
||||
impl Default for MagbotContext {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
status: MagbotStatus::Sleeping,
|
||||
titles: vec![],
|
||||
message_ids: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +80,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