66use Discord \Builders \Components \ActionRow ;
77use Discord \Builders \Components \Button ;
88use Discord \Builders \MessageBuilder ;
9+ use Discord \Discord ;
910use Discord \Helpers \Collection ;
10- use Discord \Parts \Channel \Attachment ;
1111use Discord \Parts \Embed \Embed ;
1212use Discord \Parts \Interactions \Command \Choice ;
1313use Discord \Parts \Interactions \Command \Option ;
1414use Discord \Parts \Interactions \Interaction ;
15- use Discord \Parts \Interactions \Request \Option as RequestOption ;
1615
17- function newOption (string $ name , string $ description , int $ type , bool $ required = false ): Option
16+ /**
17+ * Create a new Option used for building slash commands
18+ */
19+ function newSlashCommandOption (string $ name , string $ description , int $ type , bool $ required = false ): Option
1820{
19- return newPartDiscord (Option::class)
21+ return newDiscordPart (Option::class)
2022 ->setName ($ name )
2123 ->setDescription ($ description )
2224 ->setType ($ type )
2325 ->setRequired ($ required )
2426 ;
2527}
2628
27- function newChoice (string $ name , float |int |string $ value ): Choice
29+ /**
30+ * Create a new Choice used for building slash commands
31+ */
32+ function newSlashCommandChoice (string $ name , float |int |string $ value ): Choice
2833{
29- return newPartDiscord (Choice::class)
34+ return newDiscordPart (Choice::class)
3035 ->setName ($ name )
3136 ->setValue ($ value )
3237 ;
3338}
3439
35- function newPartDiscord (string $ class , mixed ...$ args ): mixed
40+ /**
41+ * Create a new instance of an object that requires `\Discord\Discord` as the first argument
42+ *
43+ * ```php
44+ * $embed = newDiscordPart("\Discord\Parts\Embed\Embed);
45+ * ```
46+ */
47+ function newDiscordPart (string $ class , mixed ...$ args ): mixed
3648{
3749 return (new $ class (Env::get ()->discord , ...$ args ));
3850}
3951
52+ /**
53+ * Create a new MessageBuilder object with the content define for creating simple MessageBuilders quickly
54+ *
55+ * ```php
56+ * $message = messageWithContent("Hello World");
57+ * ```
58+ */
4059function messageWithContent (string $ content ): MessageBuilder
4160{
4261 return MessageBuilder::new ()->setContent ($ content );
4362}
4463
45- function createLocalFileAttachment (string $ fileName ): Attachment
46- {
47- return new Attachment (Env::get ()->discord , [
48- "filename " => $ fileName
49- ]);
50- }
51-
64+ /**
65+ * Quickly build an action row with multiple buttons
66+ *
67+ * ```php
68+ * $banButton = (new Button(Button::STYLE_DANGER))->setLabel("Ban User");
69+ * $kickButton = (new Button(Button::STYLE_DANGER))->setLabel("Kick User");
70+ * $actionRow = buildActionRowWithButtons($banButton, $kickButton);
71+ * ```
72+ *
73+ * *This can also be paired with newButton*
74+ *
75+ * ```php
76+ * $actionRow = buildActionWithButtons(
77+ * newButton(Button::STYLE_DANGER, "Ban User")
78+ * newButton(Button::STYLE_DANGER, "Kick User")
79+ * );
80+ * ```
81+ */
5282function buildActionRowWithButtons (Button ...$ buttons ): ActionRow
5383{
5484 $ actionRow = new ActionRow ();
@@ -60,12 +90,36 @@ function buildActionRowWithButtons(Button ...$buttons): ActionRow
6090 return $ actionRow ;
6191}
6292
93+ /**
94+ * Quickly create button objects
95+ *
96+ * ```php
97+ * $button = newButton(Button::STYLE_DANGER, "Kick User", "Kick|Command_String");
98+ * ```
99+ */
63100function newButton (int $ style , string $ label , ?string $ custom_id = null ): Button
64101{
65102 return (new Button ($ style , $ custom_id ))->setLabel ($ label );
66103}
67104
68- function getOptionFromInteraction (Collection |Interaction $ options , string ...$ names ): ?RequestOption
105+ /**
106+ * Get an option from an Interaction/Interaction Repository by specifying the option(s) name
107+ *
108+ * For regular slash commands
109+ * `/ban :user`
110+ *
111+ * ```php
112+ * $user = getOptionFromInteraction($interaction, "user");
113+ * ```
114+ *
115+ * For sub commands / sub command groups you can stack the names
116+ * `/admin ban :user`
117+ *
118+ * ```php
119+ * $user = getOptionFromInteraction($interaction->data->options, "ban", "user");
120+ * ```
121+ */
122+ function getOptionFromInteraction (Collection |Interaction $ options , string ...$ names ): Option |null
69123{
70124 if ($ options instanceof Interaction) {
71125 $ options = $ options ->data ->options ;
@@ -87,6 +141,22 @@ function getOptionFromInteraction(Collection|Interaction $options, string ...$na
87141 return $ option ;
88142}
89143
144+ /**
145+ * Append to grab and empty array field. You can supply an embed to have the empty field added or
146+ * if you leave the `$embed` option `null` then an array containing the empty field will be returned
147+ *
148+ * ```php
149+ * $embed = newDiscordPart("\Discord\Parts\Embed\Embed");
150+ * emptyEmbedField($embed);
151+ * ```
152+ *
153+ * or
154+ *
155+ * ```php
156+ * $embed = newDiscordPart("\Discord\Parts\Embed\Embed");
157+ * $emptyField = emptyEmbedField();
158+ * ```
159+ */
90160function emptyEmbedField (?Embed $ embed = null ): array |Embed
91161{
92162 $ emptyField = ["name " => "\u{200b}" , "value " => "\u{200b}" ];
@@ -97,3 +167,11 @@ function emptyEmbedField(?Embed $embed = null): array|Embed
97167
98168 return $ emptyField ;
99169}
170+
171+ /**
172+ * Retrieve the `\Discord\Discord` instance from Environment
173+ */
174+ function getDiscord (): Discord
175+ {
176+ return Env::get ()->discord ;
177+ }
0 commit comments