forked from nolan/titlebot-ng-ng
add debug messages
This commit is contained in:
Generated
+4
-3
@@ -1042,9 +1042,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.17.0"
|
||||
version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51"
|
||||
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||
|
||||
[[package]]
|
||||
name = "hashlink"
|
||||
@@ -1443,7 +1443,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
|
||||
dependencies = [
|
||||
"equivalent",
|
||||
"hashbrown 0.17.0",
|
||||
"hashbrown 0.17.1",
|
||||
"serde",
|
||||
"serde_core",
|
||||
]
|
||||
@@ -1674,6 +1674,7 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_yml",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ matrix-sdk = "0.16.0"
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_yml = "0.0.12"
|
||||
tokio = { version = "1.48.0", features = ["rt-multi-thread", "macros"] }
|
||||
tracing = "0.1.41"
|
||||
tracing-subscriber = "0.3.22"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -24,16 +24,20 @@ pub async fn start(
|
||||
room: &Room,
|
||||
mut ctx: Ctx<MagbotContext>,
|
||||
) -> anyhow::Result<()> {
|
||||
tracing::debug!("Executing !start command");
|
||||
let user = event.sender.to_string();
|
||||
tracing::debug!("Command invoked by: {}", user);
|
||||
// set to listening
|
||||
match ctx.0.status {
|
||||
MagbotStatus::Running => {
|
||||
tracing::info!("Bot status already Running, not changing state");
|
||||
let msg = RoomMessageEventContent::text_plain(format!(
|
||||
"{user} Magbot is already listening for titles!"
|
||||
));
|
||||
room.send(msg).await?;
|
||||
}
|
||||
MagbotStatus::Sleeping => {
|
||||
tracing::info!("Changing bot status from Sleeping to Running");
|
||||
ctx.0.status = MagbotStatus::Running;
|
||||
let msg = RoomMessageEventContent::text_plain(format!(
|
||||
"{user} Magbot is now listening for titles!"
|
||||
@@ -50,8 +54,11 @@ pub async fn stop(
|
||||
room: &Room,
|
||||
mut ctx: Ctx<MagbotContext>,
|
||||
) -> anyhow::Result<()> {
|
||||
tracing::debug!("Executing !stop command");
|
||||
let user = event.sender.to_string();
|
||||
tracing::debug!("Command invoked by: {}", user);
|
||||
|
||||
tracing::debug!("Clearing {} saved titles", ctx.0.titles.len());
|
||||
// clear out saved titles
|
||||
ctx.0.titles.clear();
|
||||
|
||||
@@ -73,7 +80,10 @@ pub async fn help(
|
||||
room: &Room,
|
||||
ctx: Ctx<MagbotContext>,
|
||||
) -> anyhow::Result<()> {
|
||||
tracing::debug!("Executing !help command");
|
||||
let user = event.sender.to_string();
|
||||
tracing::debug!("Command invoked by: {}", user);
|
||||
tracing::debug!("Sending help message with current status: {}", ctx.0.status);
|
||||
// send message with available commands
|
||||
let msg = RoomMessageEventContent::text_plain(format!(
|
||||
"{user} available commands are:\n{HELP_MSG}\nBot current status: {}",
|
||||
@@ -89,10 +99,12 @@ pub async fn suggest(
|
||||
room: &Room,
|
||||
mut ctx: Ctx<MagbotContext>,
|
||||
) -> anyhow::Result<()> {
|
||||
// save the title into memory with author
|
||||
tracing::debug!("Executing !suggest command");
|
||||
let user = event.sender.to_string();
|
||||
tracing::debug!("Command invoked by: {}", user);
|
||||
match ctx.0.status {
|
||||
MagbotStatus::Running => {
|
||||
tracing::info!("Processing title suggestion");
|
||||
// grab the index of the first <space> character
|
||||
let start_index = event
|
||||
.content
|
||||
@@ -101,8 +113,13 @@ pub async fn suggest(
|
||||
.position(|c| c == ' ')
|
||||
.unwrap_or(8); // start at 8 if no space since '!suggest' is 8 chars
|
||||
let suggestion_str = &event.content.body()[start_index + 1..];
|
||||
tracing::debug!("Extracted suggestion: {}", suggestion_str);
|
||||
let suggestion = TitleSuggestion::new(event.sender.as_ref(), suggestion_str);
|
||||
ctx.0.titles.push(suggestion);
|
||||
tracing::info!(
|
||||
"Title suggestion saved, total titles: {}",
|
||||
ctx.0.titles.len()
|
||||
);
|
||||
let reaction = ReactionEventContent::new(Annotation::new(
|
||||
event.event_id.clone(),
|
||||
"👍".to_string(),
|
||||
@@ -124,6 +141,10 @@ pub async fn get_titles(
|
||||
room: &Room,
|
||||
mut ctx: Ctx<MagbotContext>,
|
||||
) -> anyhow::Result<()> {
|
||||
tracing::debug!("Executing !gettitles command");
|
||||
let user = event.sender.to_string();
|
||||
tracing::debug!("Command invoked by: {}", user);
|
||||
tracing::debug!("Retrieving {} titles", ctx.0.titles.len());
|
||||
// sends all the titles with an initial reaction to be used for voting
|
||||
let user = event.sender.to_string();
|
||||
match ctx.0.status {
|
||||
@@ -156,6 +177,9 @@ pub async fn count_votes(
|
||||
room: &Room,
|
||||
ctx: Ctx<MagbotContext>,
|
||||
) -> anyhow::Result<()> {
|
||||
tracing::debug!("Executing !countvotes command");
|
||||
tracing::debug!("Command invoked by: {}", event.sender);
|
||||
tracing::debug!("Processing {} title messages", ctx.0.message_ids.len());
|
||||
// count the reactions of the title messages
|
||||
// send message with winning title
|
||||
todo!()
|
||||
@@ -166,6 +190,8 @@ pub async fn not_implemented(
|
||||
event: &OriginalSyncRoomMessageEvent,
|
||||
room: &Room,
|
||||
) -> anyhow::Result<()> {
|
||||
tracing::debug!("Executing !not_implemented command");
|
||||
tracing::debug!("Command invoked by: {}", event.sender);
|
||||
// get '!' to the next '<space>' char and output as a command
|
||||
let end_index = event
|
||||
.content
|
||||
@@ -174,6 +200,7 @@ pub async fn not_implemented(
|
||||
.position(|c| c == ' ')
|
||||
.unwrap_or(event.content.body().chars().count());
|
||||
let att_cmd = &event.content.body()[..end_index];
|
||||
tracing::debug!("Not implemented command: {}", att_cmd);
|
||||
let content =
|
||||
RoomMessageEventContent::text_plain(format!("The command `{att_cmd}` is not implemented"));
|
||||
room.send(content).await?;
|
||||
|
||||
@@ -26,12 +26,14 @@ pub struct MagbotConfig {
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
pub room_id: String,
|
||||
pub status: MagbotStatus,
|
||||
|
||||
// has to be option since getting from configuration file will fail without the field
|
||||
pub status: Option<MagbotStatus>,
|
||||
}
|
||||
impl MagbotConfig {
|
||||
pub fn from_str(input: &str) -> anyhow::Result<Self> {
|
||||
let config: MagbotConfig = serde_yml::from_str(input)?;
|
||||
|
||||
let mut config: MagbotConfig = serde_yml::from_str(input)?;
|
||||
config.status = Some(MagbotStatus::default());
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
@@ -41,7 +43,7 @@ impl Default for MagbotConfig {
|
||||
username: String::new(),
|
||||
password: String::new(),
|
||||
room_id: String::new(),
|
||||
status: MagbotStatus::default(),
|
||||
status: Some(MagbotStatus::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
-2
@@ -57,49 +57,63 @@ async fn on_room_message(
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
match &text_content.body {
|
||||
let body = &text_content.body;
|
||||
tracing::debug!("Received message: {}", body);
|
||||
tracing::debug!("Message sender: {}", event.sender);
|
||||
|
||||
match body {
|
||||
// start listening for titles
|
||||
s if s.to_lowercase().starts_with("!showstart") => {
|
||||
tracing::info!("Processing command: !showstart");
|
||||
commands::start(&event, &room, ctx).await?;
|
||||
}
|
||||
|
||||
// stop listening for titles
|
||||
s if s.to_lowercase().starts_with("!showstop") => {
|
||||
tracing::info!("Processing command: !showstop");
|
||||
commands::stop(&event, &room, ctx).await?;
|
||||
}
|
||||
|
||||
// shows available commands
|
||||
s if s.to_lowercase().starts_with("!help") => {
|
||||
tracing::info!("Processing command: !help");
|
||||
commands::help(&event, &room, ctx).await?;
|
||||
}
|
||||
|
||||
// submit a title suggestion
|
||||
s if s.to_lowercase().starts_with("!suggest") => {
|
||||
tracing::info!("Processing command: !suggest");
|
||||
tracing::debug!("Suggestion text: {}", s);
|
||||
commands::suggest(&event, &room, ctx).await?;
|
||||
}
|
||||
|
||||
// retrieve list of titles
|
||||
s if s.to_lowercase().starts_with("!gettitles") => {
|
||||
tracing::info!("Processing command: !gettitles");
|
||||
commands::get_titles(&event, &room, ctx).await?;
|
||||
}
|
||||
|
||||
// count upvotes on posted suggestions
|
||||
s if s.to_lowercase().starts_with("!countvotes") => {
|
||||
tracing::info!("Processing command: !countvotes");
|
||||
commands::count_votes(&event, &room, ctx).await?;
|
||||
}
|
||||
|
||||
// generate chaotic text using Ollama
|
||||
s if s.to_lowercase().starts_with("!mayhem") => {
|
||||
tracing::info!("Processing command: !mayhem");
|
||||
commands::not_implemented(&event, &room).await?;
|
||||
}
|
||||
|
||||
// output the voting URL where users can cast votes
|
||||
s if s.to_lowercase().starts_with("!voteurl") => {
|
||||
tracing::info!("Processing command: !voteurl");
|
||||
commands::not_implemented(&event, &room).await?;
|
||||
}
|
||||
|
||||
// message is not a command; ie just a regular message
|
||||
_ => {
|
||||
tracing::debug!("Message not a recognized command, ignoring");
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
@@ -138,7 +152,7 @@ pub async fn login_and_sync(
|
||||
|
||||
// add our CommandBot to be notified of incoming messages, we do this after the
|
||||
// initial sync to avoid responding to messages before the bot was running.
|
||||
client.add_event_handler(|ctx| async move { on_room_message(ctx) });
|
||||
client.add_event_handler(on_room_message);
|
||||
|
||||
// since we called `sync_once` before we entered our sync loop we must pass
|
||||
// that sync token to `sync`
|
||||
|
||||
Reference in New Issue
Block a user