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

Function update_guild_script

components/webapi/src/routes/scripts.rs:142–202  ·  view source on GitHub ↗
(
    Extension(current_guild): Extension<CurrentUserGuild>,
    State(state): State<AppState>,
    Path(GuildScriptPathParams { script_id }): Path<GuildScriptPathParams>,
    Json(payload): Json<Upda

Source from the content-addressed store, hash-verified

140}
141
142pub async fn update_guild_script(
143 Extension(current_guild): Extension<CurrentUserGuild>,
144 State(state): State<AppState>,
145 Path(GuildScriptPathParams { script_id }): Path<GuildScriptPathParams>,
146 Json(payload): Json<UpdateRequestData>,
147) -> ApiResult<impl IntoResponse> {
148 let current_script = state
149 .db
150 .get_script_by_id(current_guild.id, script_id)
151 .await
152 .map_err(|err| {
153 if err.is_not_found() {
154 ApiErrorResponse::ScriptNotFound
155 } else {
156 error!(%err, "failed fetching script");
157 ApiErrorResponse::InternalError
158 }
159 })?;
160
161 let sc = UpdateScript {
162 id: script_id,
163 enabled: payload.enabled,
164 original_source: payload.original_source,
165 name: payload.name,
166 plugin_version_number: None,
167 settings_values: payload.settings_values,
168 };
169
170 {
171 let validation_data = ScriptValidationContextData {
172 script: current_script,
173 guild_data: None,
174 };
175
176 if let Err(validation_errors) = validate(&sc, &validation_data) {
177 return Err(ApiErrorResponse::ValidationFailed(validation_errors));
178 }
179 }
180
181 let script = state
182 .db
183 .update_script(current_guild.id, sc)
184 .await
185 .map_err(|err| {
186 error!(%err, "failed updating guild script");
187 ApiErrorResponse::InternalError
188 })?;
189
190 state
191 .bot_rpc_client
192 .reload_vm(GuildSpecifier {
193 guild_id: current_guild.id,
194 })
195 .await
196 .map_err(|err| {
197 error!(?err, "failed reloading guild vm");
198 ApiErrorResponse::InternalError
199 })?;

Callers

nothing calls this directly

Calls 5

validateFunction · 0.85
get_script_by_idMethod · 0.80
is_not_foundMethod · 0.80
update_scriptMethod · 0.80
reload_vmMethod · 0.80

Tested by

no test coverage detected