discorb 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_version.yml +2 -2
  3. data/.rubocop.yml +12 -75
  4. data/Changelog.md +10 -0
  5. data/Rakefile +482 -454
  6. data/lib/discorb/allowed_mentions.rb +68 -72
  7. data/lib/discorb/app_command/command.rb +466 -398
  8. data/lib/discorb/app_command/common.rb +65 -25
  9. data/lib/discorb/app_command/handler.rb +304 -266
  10. data/lib/discorb/app_command.rb +5 -5
  11. data/lib/discorb/application.rb +198 -197
  12. data/lib/discorb/asset.rb +101 -101
  13. data/lib/discorb/attachment.rb +134 -119
  14. data/lib/discorb/audit_logs.rb +412 -385
  15. data/lib/discorb/automod.rb +279 -269
  16. data/lib/discorb/channel/base.rb +107 -108
  17. data/lib/discorb/channel/category.rb +32 -32
  18. data/lib/discorb/channel/container.rb +44 -44
  19. data/lib/discorb/channel/dm.rb +26 -28
  20. data/lib/discorb/channel/guild.rb +311 -246
  21. data/lib/discorb/channel/stage.rb +156 -140
  22. data/lib/discorb/channel/text.rb +430 -336
  23. data/lib/discorb/channel/thread.rb +374 -325
  24. data/lib/discorb/channel/voice.rb +85 -79
  25. data/lib/discorb/channel.rb +5 -5
  26. data/lib/discorb/client.rb +635 -621
  27. data/lib/discorb/color.rb +178 -182
  28. data/lib/discorb/common.rb +168 -164
  29. data/lib/discorb/components/button.rb +107 -106
  30. data/lib/discorb/components/select_menu.rb +157 -145
  31. data/lib/discorb/components/text_input.rb +103 -106
  32. data/lib/discorb/components.rb +68 -66
  33. data/lib/discorb/dictionary.rb +135 -135
  34. data/lib/discorb/embed.rb +404 -398
  35. data/lib/discorb/emoji.rb +309 -302
  36. data/lib/discorb/emoji_table.rb +16099 -8857
  37. data/lib/discorb/error.rb +131 -131
  38. data/lib/discorb/event.rb +360 -314
  39. data/lib/discorb/event_handler.rb +39 -39
  40. data/lib/discorb/exe/about.rb +17 -17
  41. data/lib/discorb/exe/irb.rb +72 -67
  42. data/lib/discorb/exe/new.rb +323 -315
  43. data/lib/discorb/exe/run.rb +69 -68
  44. data/lib/discorb/exe/setup.rb +57 -55
  45. data/lib/discorb/exe/show.rb +12 -12
  46. data/lib/discorb/extend.rb +25 -45
  47. data/lib/discorb/extension.rb +89 -83
  48. data/lib/discorb/flag.rb +126 -128
  49. data/lib/discorb/gateway.rb +984 -804
  50. data/lib/discorb/gateway_events.rb +670 -638
  51. data/lib/discorb/gateway_requests.rb +45 -48
  52. data/lib/discorb/guild.rb +2115 -1626
  53. data/lib/discorb/guild_template.rb +280 -241
  54. data/lib/discorb/http.rb +247 -232
  55. data/lib/discorb/image.rb +42 -42
  56. data/lib/discorb/integration.rb +169 -161
  57. data/lib/discorb/intents.rb +161 -163
  58. data/lib/discorb/interaction/autocomplete.rb +76 -62
  59. data/lib/discorb/interaction/command.rb +279 -224
  60. data/lib/discorb/interaction/components.rb +114 -104
  61. data/lib/discorb/interaction/modal.rb +36 -32
  62. data/lib/discorb/interaction/response.rb +379 -336
  63. data/lib/discorb/interaction/root.rb +271 -257
  64. data/lib/discorb/interaction.rb +5 -5
  65. data/lib/discorb/invite.rb +154 -153
  66. data/lib/discorb/member.rb +344 -311
  67. data/lib/discorb/message.rb +615 -544
  68. data/lib/discorb/message_meta.rb +197 -186
  69. data/lib/discorb/modules.rb +371 -290
  70. data/lib/discorb/permission.rb +305 -291
  71. data/lib/discorb/presence.rb +352 -346
  72. data/lib/discorb/rate_limit.rb +81 -76
  73. data/lib/discorb/reaction.rb +55 -54
  74. data/lib/discorb/role.rb +272 -240
  75. data/lib/discorb/shard.rb +76 -74
  76. data/lib/discorb/sticker.rb +193 -171
  77. data/lib/discorb/user.rb +205 -188
  78. data/lib/discorb/utils/colored_puts.rb +16 -16
  79. data/lib/discorb/utils.rb +12 -16
  80. data/lib/discorb/voice_state.rb +305 -281
  81. data/lib/discorb/webhook.rb +537 -507
  82. data/lib/discorb.rb +62 -56
  83. data/sig/discorb/application.rbs +2 -0
  84. data/sig/discorb/automod.rbs +10 -1
  85. data/sig/discorb/guild.rbs +2 -0
  86. data/sig/discorb/message.rbs +2 -0
  87. data/sig/discorb/user.rbs +22 -20
  88. metadata +2 -2
data/lib/discorb/flag.rb CHANGED
@@ -1,128 +1,126 @@
1
- # frozen_string_literal: true
2
-
3
- module Discorb
4
- #
5
- # Represents a flag.
6
- # @abstract
7
- #
8
- class Flag
9
- # @return [Hash{Symbol => Boolean}] the values of the flag.
10
- attr_reader :values
11
- alias to_h values
12
- # @return [Integer] the value of the flag.
13
- attr_reader :value
14
-
15
- @bits = {}
16
-
17
- # Initialize the flag.
18
- # @note This is usually called by the subclass.
19
- #
20
- # @param [Integer] value The value of the flag.
21
- def initialize(value)
22
- @value = value
23
- @values = {}
24
- self.class.bits.each do |bn, bv|
25
- @values[bn] = value & (1 << bv) != 0
26
- end
27
- end
28
-
29
- #
30
- # Returns the value of the flag.
31
- #
32
- def method_missing(name, *_args, **_kwargs)
33
- if @values.key?(name.to_s.delete_suffix("?").to_sym)
34
- @values[name.to_s.delete_suffix("?").to_sym]
35
- else
36
- super
37
- end
38
- end
39
-
40
- def respond_to_missing?(sym, include_private)
41
- @values.key?(name.to_s.delete_suffix("?").to_sym) ? true : super
42
- end
43
-
44
- #
45
- # Union of two flags.
46
- #
47
- # @param [Discorb::Flag] other The other flag.
48
- #
49
- # @return [Discorb::Flag] The union of the two flags.
50
- #
51
- def |(other)
52
- self.class.new(@value | other.value)
53
- end
54
-
55
- alias + |
56
-
57
- #
58
- # Subtraction of two flags.
59
- #
60
- # @param [Discorb::Flag] other The other flag.
61
- #
62
- # @return [Discorb::Flag] The subtraction of the two flags.
63
- #
64
- def -(other)
65
- self.class.new(@value & (@value ^ other.value))
66
- end
67
-
68
- #
69
- # Intersection of two flags.
70
- #
71
- # @param [Discorb::Flag] other The other flag.
72
- #
73
- # @return [Discorb::Flag] The intersection of the two flags.
74
- #
75
- def &(other)
76
- self.class.new(@value & other.value)
77
- end
78
-
79
- #
80
- # XOR of two flags.
81
- #
82
- # @param [Discorb::Flag] other The other flag.
83
- #
84
- # @return [Discorb::Flag] The XOR of the two flags.
85
- #
86
- def ^(other)
87
- self.class.new(@value ^ other.value)
88
- end
89
-
90
- #
91
- # Negation of the flag.
92
- #
93
- # @return [Discorb::Flag] The negation of the flag.
94
- #
95
- def ~
96
- self.class.new(~@value)
97
- end
98
-
99
- def to_i
100
- @value
101
- end
102
-
103
- def inspect
104
- "#<#{self.class}: #{@value}>"
105
- end
106
-
107
- class << self
108
- # @return [Hash{Integer => Symbol}] the bits of the flag.
109
- attr_reader :bits
110
-
111
- #
112
- # Max value of the flag.
113
- #
114
- # @return [Integer] the max value of the flag.
115
- #
116
- def max_value
117
- 2 ** @bits.values.max - 1
118
- end
119
-
120
- #
121
- # Initialize a new flag with keys.
122
- #
123
- def from_keys(*keys)
124
- new(keys.sum { |k| 1 << @bits[k] })
125
- end
126
- end
127
- end
128
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Discorb
4
+ #
5
+ # Represents a flag.
6
+ # @abstract
7
+ #
8
+ class Flag
9
+ # @return [Hash{Symbol => Boolean}] the values of the flag.
10
+ attr_reader :values
11
+ alias to_h values
12
+ # @return [Integer] the value of the flag.
13
+ attr_reader :value
14
+
15
+ @bits = {}
16
+
17
+ # Initialize the flag.
18
+ # @note This is usually called by the subclass.
19
+ #
20
+ # @param [Integer] value The value of the flag.
21
+ def initialize(value)
22
+ @value = value
23
+ @values = {}
24
+ self.class.bits.each { |bn, bv| @values[bn] = value & (1 << bv) != 0 }
25
+ end
26
+
27
+ #
28
+ # Returns the value of the flag.
29
+ #
30
+ def method_missing(name, *_args, **_kwargs)
31
+ if @values.key?(name.to_s.delete_suffix("?").to_sym)
32
+ @values[name.to_s.delete_suffix("?").to_sym]
33
+ else
34
+ super
35
+ end
36
+ end
37
+
38
+ def respond_to_missing?(sym, include_private)
39
+ @values.key?(name.to_s.delete_suffix("?").to_sym) ? true : super
40
+ end
41
+
42
+ #
43
+ # Union of two flags.
44
+ #
45
+ # @param [Discorb::Flag] other The other flag.
46
+ #
47
+ # @return [Discorb::Flag] The union of the two flags.
48
+ #
49
+ def |(other)
50
+ self.class.new(@value | other.value)
51
+ end
52
+
53
+ alias + |
54
+
55
+ #
56
+ # Subtraction of two flags.
57
+ #
58
+ # @param [Discorb::Flag] other The other flag.
59
+ #
60
+ # @return [Discorb::Flag] The subtraction of the two flags.
61
+ #
62
+ def -(other)
63
+ self.class.new(@value & (@value ^ other.value))
64
+ end
65
+
66
+ #
67
+ # Intersection of two flags.
68
+ #
69
+ # @param [Discorb::Flag] other The other flag.
70
+ #
71
+ # @return [Discorb::Flag] The intersection of the two flags.
72
+ #
73
+ def &(other)
74
+ self.class.new(@value & other.value)
75
+ end
76
+
77
+ #
78
+ # XOR of two flags.
79
+ #
80
+ # @param [Discorb::Flag] other The other flag.
81
+ #
82
+ # @return [Discorb::Flag] The XOR of the two flags.
83
+ #
84
+ def ^(other)
85
+ self.class.new(@value ^ other.value)
86
+ end
87
+
88
+ #
89
+ # Negation of the flag.
90
+ #
91
+ # @return [Discorb::Flag] The negation of the flag.
92
+ #
93
+ def ~
94
+ self.class.new(~@value)
95
+ end
96
+
97
+ def to_i
98
+ @value
99
+ end
100
+
101
+ def inspect
102
+ "#<#{self.class}: #{@value}>"
103
+ end
104
+
105
+ class << self
106
+ # @return [Hash{Integer => Symbol}] the bits of the flag.
107
+ attr_reader :bits
108
+
109
+ #
110
+ # Max value of the flag.
111
+ #
112
+ # @return [Integer] the max value of the flag.
113
+ #
114
+ def max_value
115
+ (2**@bits.values.max) - 1
116
+ end
117
+
118
+ #
119
+ # Initialize a new flag with keys.
120
+ #
121
+ def from_keys(*keys)
122
+ new(keys.sum { |k| 1 << @bits[k] })
123
+ end
124
+ end
125
+ end
126
+ end