MCPcopy Create free account
hub / github.com/Botloader/botloader / guild_add_plugin

Function guild_add_plugin

components/webapi/src/routes/plugins.rs:316–352  ·  view source on GitHub ↗
(
    State(state): State<AppState>,
    Extension(session): Extension<LoggedInSession>,
    Extension(current_guild): Extension<CurrentUserGuild>,
    Json(body): Json<GuildAddPluginData>,
)

Source from the content-addressed store, hash-verified

314}
315
316pub 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
354pub async fn fetch_plugin_author(
355 config: &DiscordConfig,

Callers

nothing calls this directly

Calls 3

fetch_pluginFunction · 0.85
reload_vmMethod · 0.80

Tested by

no test coverage detected