(
State(state): State<AppState>,
Extension(session): Extension<LoggedInSession>,
Extension(current_guild): Extension<CurrentUserGuild>,
Json(body): Json<GuildAddPluginData>,
)
| 314 | } |
| 315 | |
| 316 | pub async fn guild_add_plugin( |
| 317 | State(state): State<AppState>, |
| 318 | Extension(session): Extension<LoggedInSession>, |
| 319 | Extension(current_guild): Extension<CurrentUserGuild>, |
| 320 | Json(body): Json<GuildAddPluginData>, |
| 321 | ) -> ApiResult<impl IntoResponse> { |
| 322 | let plugin = fetch_plugin(&state.db, body.plugin_id).await?; |
| 323 | |
| 324 | if !plugin.is_public && plugin.author_id != session.session.user.id { |
| 325 | return Err(ApiErrorResponse::NoAccessToPlugin); |
| 326 | } |
| 327 | |
| 328 | let script = state |
| 329 | .db |
| 330 | .try_guild_add_script_plugin(current_guild.id, plugin.id, body.auto_update) |
| 331 | .await |
| 332 | .map_err(|err| match err { |
| 333 | ConfigStoreError::GuildAlreadyHasPlugin => ApiErrorResponse::GuildAlreadyHasPlugin, |
| 334 | _ => { |
| 335 | error!(?err, "failed adding plugin"); |
| 336 | ApiErrorResponse::InternalError |
| 337 | } |
| 338 | })?; |
| 339 | |
| 340 | state |
| 341 | .bot_rpc_client |
| 342 | .reload_vm(botrpc::types::GuildSpecifier { |
| 343 | guild_id: current_guild.id, |
| 344 | }) |
| 345 | .await |
| 346 | .map_err(|err| { |
| 347 | error!(%err, "failed reloading guild vm"); |
| 348 | ApiErrorResponse::InternalError |
| 349 | })?; |
| 350 | |
| 351 | Ok(Json(script)) |
| 352 | } |
| 353 | |
| 354 | pub async fn fetch_plugin_author( |
| 355 | config: &DiscordConfig, |
nothing calls this directly
no test coverage detected