Commit 5e2dde414b

5e2dde414bf9133f8deb150e86662820b32af1a3

parent: 99fe647b95

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-07-21 23:21 UTC
committer: <strk@kbt.io>

fix: run moderation actions on the Matrix runtime

Layout: unified · split

src/commands/moderation.rs +4 −21
@@ -108,32 +108,15 @@ impl ModerationCommand {
108 return; 108 return;
109 }; 109 };
110 110
111 let room = room.room().clone();
112 let action = self.action; 111 let action = self.action;
113 let error_user_id = user_id.clone();
114 Weechat::spawn(async move { 112 Weechat::spawn(async move {
115 let result = match action { 113 match action {
116 ModerationAction::Ban => { 114 ModerationAction::Ban => room.ban_user(user_id, reason).await,
117 room.ban_user(&user_id, reason.as_deref()).await 115 ModerationAction::Kick => room.kick_user(user_id, reason).await,
118 }
119 ModerationAction::Kick => {
120 room.kick_user(&user_id, reason.as_deref()).await
121 }
122 ModerationAction::Unban => { 116 ModerationAction::Unban => {
123 room.unban_user(&user_id, reason.as_deref()).await 117 room.unban_user(user_id, reason).await
124 } 118 }
125 }; 119 };
126
127 if let Err(error) = result {
128 Weechat::print(&format!(
129 "{}{}: Failed to {} {}: {}",
130 Weechat::prefix(Prefix::Error),
131 PLUGIN_NAME,
132 action.verb(),
133 error_user_id,
134 error
135 ));
136 }
137 }) 120 })
138 .detach(); 121 .detach();
139 } 122 }
src/room/mod.rs +73
@@ -1084,6 +1084,79 @@ impl MatrixRoom {
1084 } 1084 }
1085 } 1085 }
1086 1086
1087 pub async fn ban_user(&self, user_id: OwnedUserId, reason: Option<String>) {
1088 let Some(connection) = self.connection.borrow().clone() else {
1089 self.print_error("Not connected. Please connect first.");
1090 return;
1091 };
1092
1093 let room = self.room().clone();
1094 let error_user_id = user_id.clone();
1095
1096 match connection
1097 .spawn(
1098 async move { room.ban_user(&user_id, reason.as_deref()).await },
1099 )
1100 .await
1101 {
1102 Ok(_) => (),
1103 Err(error) => self.print_error(&format!(
1104 "Failed to ban {}: {}",
1105 error_user_id, error
1106 )),
1107 }
1108 }
1109
1110 pub async fn kick_user(
1111 &self,
1112 user_id: OwnedUserId,
1113 reason: Option<String>,
1114 ) {
1115 let Some(connection) = self.connection.borrow().clone() else {
1116 self.print_error("Not connected. Please connect first.");
1117 return;
1118 };
1119
1120 let room = self.room().clone();
1121 let error_user_id = user_id.clone();
1122
1123 match connection
1124 .spawn(async move { room.kick_user(&user_id, reason.as_deref()).await })
1125 .await
1126 {
1127 Ok(_) => (),
1128 Err(error) => self.print_error(&format!(
1129 "Failed to kick {}: {}",
1130 error_user_id, error
1131 )),
1132 }
1133 }
1134
1135 pub async fn unban_user(
1136 &self,
1137 user_id: OwnedUserId,
1138 reason: Option<String>,
1139 ) {
1140 let Some(connection) = self.connection.borrow().clone() else {
1141 self.print_error("Not connected. Please connect first.");
1142 return;
1143 };
1144
1145 let room = self.room().clone();
1146 let error_user_id = user_id.clone();
1147
1148 match connection
1149 .spawn(async move { room.unban_user(&user_id, reason.as_deref()).await })
1150 .await
1151 {
1152 Ok(_) => (),
1153 Err(error) => self.print_error(&format!(
1154 "Failed to unban {}: {}",
1155 error_user_id, error
1156 )),
1157 }
1158 }
1159
1087 pub async fn send_attachment(&self, path: PathBuf) { 1160 pub async fn send_attachment(&self, path: PathBuf) {
1088 let Some(filename) = path 1161 let Some(filename) = path
1089 .file_name() 1162 .file_name()