set up async processing of commands

This commit is contained in:
2025-12-16 10:14:45 -06:00
parent 1d2c6f10c7
commit 11fccbb609
2 changed files with 42 additions and 16 deletions
+30 -6
View File
@@ -1,16 +1,40 @@
///
pub fn suggest(text: &str) {
use matrix_sdk::{
Room,
ruma::events::room::message::{OriginalSyncRoomMessageEvent, RoomMessageEventContent},
};
/// Records title suggestions
pub async fn suggest(
event: &OriginalSyncRoomMessageEvent,
room: &Room,
text: &str,
) -> anyhow::Result<()> {
todo!()
}
pub fn get_titles(text: &str) {
/// Outputs all the recorded title suggestsions
pub async fn get_titles(
event: &OriginalSyncRoomMessageEvent,
room: &Room,
text: &str,
) -> anyhow::Result<()> {
todo!()
}
pub fn count_votes() {
/// Counts the votes of title suggestions
pub async fn count_votes(event: &OriginalSyncRoomMessageEvent, room: &Room) -> anyhow::Result<()> {
todo!()
}
pub fn not_implemented() {
todo!()
/// Command is not implemented yet
pub async fn not_implemented(
event: &OriginalSyncRoomMessageEvent,
room: &Room,
text: &str,
) -> anyhow::Result<()> {
// get '!' to the next '<space>' char and output as a command
let content = RoomMessageEventContent::text_plain("The command `{cmd}` is not implemented");
room.send(content).await?;
Ok(())
}
+12 -10
View File
@@ -6,44 +6,46 @@ use matrix_sdk::{
mod commands;
async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) {
async fn on_room_message(event: OriginalSyncRoomMessageEvent, room: Room) -> anyhow::Result<()> {
if room.state() != RoomState::Joined {
return;
return Ok(());
}
let MessageType::Text(text_content) = event.content.msgtype else {
return;
let MessageType::Text(text_content) = event.content.msgtype.clone() else {
return Ok(());
};
match &text_content.body {
// submit a title suggestion
s if s.to_lowercase().starts_with("!suggest") => {
commands::suggest(s);
commands::suggest(&event, &room, s).await?;
}
// retrieve list of titles
s if s.to_lowercase().starts_with("!gettitles") => {
commands::get_titles(s);
commands::get_titles(&event, &room, s).await?;
}
// count upvotes on posted suggestions
s if s.to_lowercase().starts_with("!countvotes") => {
commands::count_votes();
commands::count_votes(&event, &room).await?;
}
// generate chaotic text using Ollama
s if s.to_lowercase().starts_with("!mayhem") => {
commands::not_implemented();
commands::not_implemented(&event, &room, s).await?;
}
// output the voting URL where users can cast votes
s if s.to_lowercase().starts_with("!voteurl") => {
commands::not_implemented();
commands::not_implemented(&event, &room, s).await?;
}
// No match
// message is not a command; ie just a regular message
_ => {
return;
}
};
Ok(())
}
pub async fn login_and_sync(