zaun_client/bots/
channel.rs1use zaun_community_protocol::command::interaction::{Create, CreateData};
5use zaun_community_protocol::command::object::{InteractionType, OptionValue, SubmittedInput};
6use zaun_community_protocol::ids::{CommandId, InteractionId};
7
8use crate::error::Result;
9use crate::objects::Channel;
10
11impl Channel {
12 fn interact(&self, kind: InteractionType, data: CreateData) -> Result<InteractionId> {
13 let created: zaun_community_protocol::command::interaction::Created = self
14 .community
15 .client
16 .command(self.community.id, Some(self.id), Create { kind, data })?;
17 Ok(created.interaction_id)
18 }
19
20 pub fn invoke_command(
26 &self,
27 command: CommandId,
28 options: Vec<OptionValue>,
29 target: Option<String>,
30 ) -> Result<InteractionId> {
31 let data = CreateData::Command {
32 command_id: command,
33 options,
34 target_id: target,
35 };
36 self.interact(InteractionType::ApplicationCommand, data)
37 }
38
39 pub fn autocomplete(
45 &self,
46 command: CommandId,
47 options: Vec<OptionValue>,
48 ) -> Result<InteractionId> {
49 let data = CreateData::Command {
50 command_id: command,
51 options,
52 target_id: None,
53 };
54 self.interact(InteractionType::Autocomplete, data)
55 }
56
57 pub fn submit_modal(
63 &self,
64 modal: InteractionId,
65 custom_id: &str,
66 components: Vec<SubmittedInput>,
67 ) -> Result<InteractionId> {
68 let data = CreateData::Modal {
69 modal_id: modal,
70 custom_id: custom_id.to_owned(),
71 components,
72 };
73 self.interact(InteractionType::ModalSubmit, data)
74 }
75}