Merge remote-tracking branch 'origin/rust-rewrite' into rust-rewrite

This commit is contained in:
2026-01-10 11:03:43 -06:00
5 changed files with 29 additions and 13 deletions
Generated
+2
View File
@@ -1539,6 +1539,7 @@ version = "0.35.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "133c182a6a2c87864fe97778797e46c7e999672690dc9fa3ee8e241aa4a9c13f"
dependencies = [
"cc",
"pkg-config",
"vcpkg",
]
@@ -1639,6 +1640,7 @@ name = "magbot-rs"
version = "0.1.0"
dependencies = [
"anyhow",
"libsqlite3-sys",
"matrix-sdk",
"serde",
"serde_yml",
+1
View File
@@ -14,6 +14,7 @@ path = "src/bin/main.rs"
[dependencies]
anyhow = "1.0.100"
libsqlite3-sys = { version = "0.35.0", features = ["bundled"] }
matrix-sdk = "0.16.0"
serde = { version = "1.0.228", features = ["derive"] }
serde_yml = "0.0.12"
+17 -9
View File
@@ -121,7 +121,7 @@ pub async fn suggest(
pub async fn get_titles(
event: &OriginalSyncRoomMessageEvent,
room: &Room,
ctx: Ctx<MagbotContext>,
mut ctx: Ctx<MagbotContext>,
) -> anyhow::Result<()> {
// sends all the titles with an initial reaction to be used for voting
let user = event.sender.to_string();
@@ -130,17 +130,19 @@ pub async fn get_titles(
for title in ctx.0.titles {
let msg = RoomMessageEventContent::text_plain(format!(
"{} : {}",
title.title, title.user
title.user, title.title
));
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()));
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"));
let msg = RoomMessageEventContent::text_plain(format!("{user} magbot is not running"));
room.send(msg).await?;
}
}
@@ -162,11 +164,17 @@ pub async fn count_votes(
pub async fn not_implemented(
event: &OriginalSyncRoomMessageEvent,
room: &Room,
text: &str,
ctx: Ctx<MagbotContext>,
) -> anyhow::Result<()> {
// get '!' to the next '<space>' char and output as a command
let content = RoomMessageEventContent::text_plain("The command `{cmd}` is not implemented");
let end_index = event
.content
.body()
.chars()
.position(|c| c == ' ')
.unwrap_or(event.content.body().chars().count());
let att_cmd = &event.content.body()[..end_index];
let content =
RoomMessageEventContent::text_plain(format!("The command `{att_cmd}` is not implemented"));
room.send(content).await?;
Ok(())
+1 -1
View File
@@ -3,7 +3,7 @@ use std::{fs::File, io::Read};
use serde::Deserialize;
/// The status of the bot
#[derive(Clone, Debug, Default, Deserialize)]
#[derive(Clone, Default, Debug, Deserialize)]
pub enum MagbotStatus {
/// Bot is waiting for title suggestions
Running,
+8 -3
View File
@@ -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![],
}
}
}
@@ -85,12 +90,12 @@ async fn on_room_message(
// generate chaotic text using Ollama
s if s.to_lowercase().starts_with("!mayhem") => {
commands::not_implemented(&event, &room, s, ctx).await?;
commands::not_implemented(&event, &room).await?;
}
// output the voting URL where users can cast votes
s if s.to_lowercase().starts_with("!voteurl") => {
commands::not_implemented(&event, &room, s, ctx).await?;
commands::not_implemented(&event, &room).await?;
}
// message is not a command; ie just a regular message