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

Function to_twilight_commands

components/scheduler/src/command_manager.rs:232–347  ·  view source on GitHub ↗
(
    guild_id: Id<GuildMarker>,
    commands: &[Command],
    groups: &[CommandGroup],
)

Source from the content-addressed store, hash-verified

230}
231
232pub fn to_twilight_commands(
233 guild_id: Id<GuildMarker>,
234 commands: &[Command],
235 groups: &[CommandGroup],
236) -> Vec<TwilightCommand> {
237 // handle top level commands
238 let mut result = commands
239 .iter()
240 .filter(|c| c.group.is_none())
241 .map(|cmd| TwilightCommand {
242 name: cmd.name.clone(),
243 description: if matches!(
244 cmd.kind,
245 runtime_models::internal::interaction::CommandType::Chat
246 ) {
247 cmd.description.clone()
248 } else {
249 String::new()
250 },
251 application_id: None,
252 options: cmd.options.iter().map(|opt| opt.clone().into()).collect(),
253 guild_id: None,
254 id: None,
255 kind: cmd.kind.into(),
256 version: Id::new(1),
257 dm_permission: None,
258 default_member_permissions: cmd
259 .default_member_permissions
260 .as_ref()
261 .map(|perms| Permissions::from_bits_truncate(perms.parse().unwrap_or(0))),
262 description_localizations: Default::default(),
263 name_localizations: Default::default(),
264 nsfw: None,
265 contexts: None,
266 integration_types: None,
267 })
268 .collect::<Vec<_>>();
269
270 let mut groups = groups
271 .iter()
272 .map(|cg| group_to_twilight_command(guild_id, cg))
273 .collect::<Vec<_>>();
274
275 // add the commands to the groups and sub groups
276 for cmd in commands.iter() {
277 if let Some(cmd_group) = &cmd.group {
278 // find (or create) the group
279 let group = match groups.iter_mut().find(|g| *cmd_group == g.name) {
280 Some(g) => g,
281 None => {
282 // group not found, make a new one
283 groups.push(make_unknown_group(guild_id, cmd_group.clone()));
284
285 // return mut reference to the new group
286 let len = groups.len();
287 &mut groups[len - 1]
288 }
289 };

Callers 1

Calls 2

make_unknown_groupFunction · 0.85

Tested by

no test coverage detected