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

Function create_guild_script

components/webapi/src/routes/scripts.rs:88–128  ·  view source on GitHub ↗
(
    State(state): State<AppState>,
    Extension(current_guild): Extension<CurrentUserGuild>,
    Json(payload): Json<CreateRequestData>,
)

Source from the content-addressed store, hash-verified

86}
87
88pub async fn create_guild_script(
89 State(state): State<AppState>,
90 Extension(current_guild): Extension<CurrentUserGuild>,
91 Json(payload): Json<CreateRequestData>,
92) -> ApiResult<impl IntoResponse> {
93 let cs = CreateScript {
94 enabled: payload.enabled,
95 original_source: payload.original_source,
96 name: payload.name,
97 plugin_auto_update: None,
98 plugin_id: None,
99 plugin_version_number: None,
100 };
101
102 if let Err(verr) = validate(&cs, &()) {
103 return Err(ApiErrorResponse::ValidationFailed(verr));
104 }
105
106 if state
107 .db
108 .get_script(current_guild.id, cs.name.clone())
109 .await
110 .is_ok()
111 {
112 return Err(ApiErrorResponse::ValidationFailed(vec![ValidationError {
113 field: "name".to_string(),
114 msg: "Name already taken".to_string(),
115 }]));
116 }
117
118 let script = state
119 .db
120 .create_script(current_guild.id, cs)
121 .await
122 .map_err(|err| {
123 error!(%err, "failed creating guild script");
124 ApiErrorResponse::InternalError
125 })?;
126
127 Ok(Json(script))
128}
129
130#[derive(Debug, Clone, Deserialize)]
131pub struct UpdateRequestData {

Callers

nothing calls this directly

Calls 3

validateFunction · 0.85
create_scriptMethod · 0.80
get_scriptMethod · 0.45

Tested by

no test coverage detected