A Discord API Library for Gleam! 💫
0

Configure Feed

Select the types of activity you want to include in your feed.

update deps, add checkbox group component

+118 -2
+2 -2
manifest.toml
··· 9 9 { name = "gleam_httpc", version = "5.0.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gleam_httpc", source = "hex", outer_checksum = "C545172618D07811494E97AAA4A0FB34DA6F6D0061FDC8041C2F8E3BE2B2E48F" }, 10 10 { name = "gleam_json", version = "3.1.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "44FDAA8847BE8FC48CA7A1C089706BD54BADCC4C45B237A992EDDF9F2CDB2836" }, 11 11 { name = "gleam_otp", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_erlang", "gleam_stdlib"], otp_app = "gleam_otp", source = "hex", outer_checksum = "BA6A294E295E428EC1562DC1C11EA7530DCB981E8359134BEABC8493B7B2258E" }, 12 - { name = "gleam_stdlib", version = "0.65.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "7C69C71D8C493AE11A5184828A77110EB05A7786EBF8B25B36A72F879C3EE107" }, 13 - { name = "gleam_time", version = "1.5.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_time", source = "hex", outer_checksum = "D560E672C7279C89908981E068DF07FD16D0C859DCA266F908B18F04DF0EB8E6" }, 12 + { name = "gleam_stdlib", version = "0.69.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "AAB0962BEBFAA67A2FBEE9EEE218B057756808DC9AF77430F5182C6115B3A315" }, 13 + { name = "gleam_time", version = "1.7.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_time", source = "hex", outer_checksum = "56DB0EF9433826D3B99DB0B4AF7A2BFED13D09755EC64B1DAAB46F804A9AD47D" }, 14 14 { name = "gleeunit", version = "1.9.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "DA9553CE58B67924B3C631F96FE3370C49EB6D6DC6B384EC4862CC4AAA718F3C" }, 15 15 { name = "gramps", version = "6.0.0", build_tools = ["gleam"], requirements = ["gleam_crypto", "gleam_erlang", "gleam_http", "gleam_stdlib"], otp_app = "gramps", source = "hex", outer_checksum = "8B7195978FBFD30B43DF791A8A272041B81E45D245314D7A41FC57237AA882A0" }, 16 16 { name = "logging", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "logging", source = "hex", outer_checksum = "1098FBF10B54B44C2C7FDF0B01C1253CAFACDACABEFB4B0D027803246753E06D" },
+89
src/grom/component/checkbox_group.gleam
··· 1 + import gleam/json.{type Json} 2 + import gleam/list 3 + import gleam/option.{None, Some} 4 + 5 + pub type CheckboxGroup { 6 + CheckboxGroup( 7 + id: option.Option(Int), 8 + /// 1-100 characters. 9 + custom_id: String, 10 + /// Minimum 1, maximum 10. 11 + options: List(Option), 12 + /// Defaults to 1. If set to 0, `is_required` must be set to False. 13 + min_values: option.Option(Int), 14 + /// Defaults to the count of options. 15 + max_values: option.Option(Int), 16 + /// Defaults to True. 17 + is_required: Bool, 18 + ) 19 + } 20 + 21 + pub type Option { 22 + Option( 23 + /// Dev facing value, max 100 characters 24 + value: String, 25 + /// User facing text, max 100 characters 26 + label: String, 27 + /// Max 100 characters 28 + description: option.Option(String), 29 + is_default_selected: Bool, 30 + ) 31 + } 32 + 33 + @internal 34 + pub fn to_json(group: CheckboxGroup) -> Json { 35 + let id = case group.id { 36 + Some(id) -> [#("id", json.int(id))] 37 + None -> [] 38 + } 39 + 40 + let custom_id = [#("custom_id", json.string(group.custom_id))] 41 + 42 + let options = [#("options", json.array(group.options, option_to_json))] 43 + 44 + let min_values = case group.min_values { 45 + Some(min) -> [#("min_values", json.int(min))] 46 + None -> [] 47 + } 48 + 49 + let max_values = case group.max_values { 50 + Some(max) -> [#("max_values", json.int(max))] 51 + None -> [] 52 + } 53 + 54 + let is_required = [#("required", json.bool(group.is_required))] 55 + 56 + [id, custom_id, options, min_values, max_values, is_required] 57 + |> list.flatten 58 + |> json.object 59 + } 60 + 61 + fn option_to_json(option: Option) -> Json { 62 + let value = [#("value", json.string(option.value))] 63 + 64 + let label = [#("label", json.string(option.label))] 65 + 66 + let description = case option.description { 67 + Some(description) -> [#("description", json.string(description))] 68 + None -> [] 69 + } 70 + 71 + let is_default_selected = [ 72 + #("default", json.bool(option.is_default_selected)), 73 + ] 74 + 75 + [value, label, description, is_default_selected] 76 + |> list.flatten 77 + |> json.object 78 + } 79 + 80 + pub fn new( 81 + custom_id custom_id: String, 82 + options options: List(Option), 83 + ) -> CheckboxGroup { 84 + CheckboxGroup(None, custom_id, options, None, None, True) 85 + } 86 + 87 + pub fn new_option(named label: String, value value: String) -> Option { 88 + Option(value, label, None, False) 89 + }
+3
src/grom/component/label.gleam
··· 3 3 import gleam/list 4 4 import gleam/option.{type Option, None, Some} 5 5 import grom/component/channel_select.{type ChannelSelect} 6 + import grom/component/checkbox_group.{type CheckboxGroup} 6 7 import grom/component/file_upload.{type FileUpload} 7 8 import grom/component/mentionable_select.{type MentionableSelect} 8 9 import grom/component/radio_group.{type RadioGroup} ··· 31 32 ChannelSelect(ChannelSelect) 32 33 FileUpload(FileUpload) 33 34 RadioGroup(RadioGroup) 35 + CheckboxGroup(CheckboxGroup) 34 36 } 35 37 36 38 // DECODERS -------------------------------------------------------------------- ··· 98 100 ChannelSelect(channel_select) -> channel_select.to_json(channel_select) 99 101 FileUpload(file_upload) -> file_upload.to_json(file_upload) 100 102 RadioGroup(radio_group) -> radio_group.to_json(radio_group) 103 + CheckboxGroup(checkbox_group) -> checkbox_group.to_json(checkbox_group) 101 104 } 102 105 } 103 106
+24
src/grom/interaction.gleam
··· 118 118 LabelChannelSelectSubmitted(ChannelSelectExecution) 119 119 LabelFileUploadSubmitted(FileUploadSubmission) 120 120 LabelRadioGroupSubmitted(RadioGroupSubmission) 121 + LabelCheckboxGroupSubmitted(CheckboxGroupSubmission) 122 + } 123 + 124 + pub type CheckboxGroupSubmission { 125 + CheckboxGroupSubmission( 126 + id: Int, 127 + custom_id: String, 128 + selected_values: List(String), 129 + ) 121 130 } 122 131 123 132 pub type TextDisplaySubmission { ··· 662 671 ) 663 672 19 -> decode.map(file_upload_submission_decoder(), LabelFileUploadSubmitted) 664 673 21 -> decode.map(radio_group_submission_decoder(), LabelRadioGroupSubmitted) 674 + 22 -> 675 + decode.map( 676 + checkbox_group_submission_decoder(), 677 + LabelCheckboxGroupSubmitted, 678 + ) 665 679 _ -> 666 680 decode.failure( 667 681 LabelStringSelectSubmitted(StringSelectExecution("", [], None)), 668 682 "SubmittedLabelComponent", 669 683 ) 670 684 } 685 + } 686 + 687 + fn checkbox_group_submission_decoder() -> decode.Decoder( 688 + CheckboxGroupSubmission, 689 + ) { 690 + use id <- decode.field("id", decode.int) 691 + use custom_id <- decode.field("custom_id", decode.string) 692 + use selected_values <- decode.field("values", decode.list(of: decode.string)) 693 + 694 + decode.success(CheckboxGroupSubmission(id, custom_id, selected_values)) 671 695 } 672 696 673 697 @internal