Skip to content

Commit 69de49e

Browse files
committed
upgrades
1 parent 3d67088 commit 69de49e

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

lib/discordrb/bot.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,7 @@ def update_guild_automod_rule(data)
12161216
if rule
12171217
rule.from_other(data)
12181218
else
1219-
server&.cache_automod_rule(AutoModRule.new(data, self, server))
1219+
server&.cache_automod_rule(AutoModRule.new(data, server, self))
12201220
end
12211221
end
12221222

lib/discordrb/container.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ def application_command_permissions_update(attributes = {}, &block)
685685
# @param attributes [Hash] The event's attributes.
686686
# @option attributes [String, Integer, Server] :server A server to match against.
687687
# @option attributes [String, Regexp] :name A name to match against.
688-
# @option attributes [String, Integer, AutoModRule] :automod_rule An automod rule to match against.
688+
# @option attributes [String, Integer, AutoModRule] :id An automod rule to match against.
689689
# @option attributes [String, Integer, User, Member] :creator A creator to match against.
690690
# @option attributes [Symbol, Integer] :event_type An event type to match against.
691691
# @option attributes [Symbol, Integer] :trigger_type A trigger type to match against.
@@ -701,7 +701,7 @@ def automod_rule_create(attributes = {}, &block)
701701
# @param attributes [Hash] The event's attributes.
702702
# @option attributes [String, Integer, Server] :server A server to match against.
703703
# @option attributes [String, Regexp] :name A name to match against.
704-
# @option attributes [String, Integer, AutoModRule] :automod_rule An automod rule to match against.
704+
# @option attributes [String, Integer, AutoModRule] :id An automod rule to match against.
705705
# @option attributes [String, Integer, User, Member] :creator A creator to match against.
706706
# @option attributes [Symbol, Integer] :event_type An event type to match against.
707707
# @option attributes [Symbol, Integer] :trigger_type A trigger type to match against.
@@ -717,7 +717,7 @@ def automod_rule_update(attributes = {}, &block)
717717
# @param attributes [Hash] The event's attributes.
718718
# @option attributes [String, Integer, Server] :server A server to match against.
719719
# @option attributes [String, Regexp] :name A name to match against.
720-
# @option attributes [String, Integer, AutoModRule] :automod_rule An automod rule to match against.
720+
# @option attributes [String, Integer, AutoModRule] :id An automod rule to match against.
721721
# @option attributes [String, Integer, User, Member] :creator A creator to match against.
722722
# @option attributes [Symbol, Integer] :event_type An event type to match against.
723723
# @option attributes [Symbol, Integer] :trigger_type A trigger type to match against.

lib/discordrb/data/auto_moderation.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class AutoModRule
1616
# @return [String] the name of this automod rule.
1717
attr_reader :name
1818

19+
# @return [Server] the server this automod rule is form.
20+
attr_reader :server
21+
1922
# @return [Integer] the event type of this automod rule.
2023
# @see EVENT_TYPES
2124
attr_reader :event_type
@@ -37,11 +40,10 @@ class AutoModRule
3740
attr_reader :exempt_channels
3841

3942
# @!visibility private
40-
def initialize(data, bot, server = nil)
43+
def initialize(data, server, bot)
4144
@bot = bot
4245
@server = server
4346
@id = data['id'].to_i
44-
@server_id = data['guild_id'].to_i
4547
@creator_id = data['creator_id'].to_i
4648
from_other(data)
4749
end
@@ -51,11 +53,6 @@ def creator
5153
@bot.user(@creator_id)
5254
end
5355

54-
# @return [Server] the server this automod rule is associated with.
55-
def server
56-
@server ||= @bot.server(@server_id)
57-
end
58-
5956
# Check if something is exempt from this automod rule.
6057
# @param other [Role, Channel, Member] The thing to check for exemption.
6158
# @return [true, false] Whether the provided object is exempt or not.
@@ -121,8 +118,8 @@ def delete(reason: nil)
121118
end
122119

123120
# Add one or more actions that will execute when this automod rule is triggered.
124-
# @note Creating a new action for an existing type will overwrite the current one.
125121
# @yieldparam builder [ActionBuilder] builder subclass for creating automod actions.
122+
# @note Creating a new action for an existing action type will overwrite the existing action.
126123
# @return [void]
127124
def create_actions
128125
yield (builder = ActionBuilder.new)
@@ -169,7 +166,7 @@ def from_other(new_data)
169166

170167
# @!visibility private
171168
def update_data(new_data)
172-
from_other(JSON.parse(API::Server.update_automod_rule(@bot.token, @server_id, @id,
169+
from_other(JSON.parse(API::Server.update_automod_rule(@bot.token, @server.id, @id,
173170
new_data[:name], new_data[:event_type],
174171
new_data[:trigger], new_data[:actions],
175172
new_data[:enabled], new_data[:exempt_roles],

lib/discordrb/data/server.rb

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -617,29 +617,31 @@ def max_emoji
617617
end
618618

619619
# Get a single automod rule.
620-
# @param id [Integer] The ID of the automod rule to look for.
621-
# @param request [true, false] Whether the automod rule should be requested from Discord if it's not cached. Defaults to true.
620+
# @param rule_id [Integer] The ID of the automod rule to look for.
621+
# @param request [true, false] Whether the automod rule should be requested from Discord if it's not cached.
622622
# @return [AutoModRule, nil] the automod rule in question, or nil if it couldn't be found.
623-
def automod_rule(id, request: true)
624-
id = id.resolve_id
623+
def automod_rule(rule_id, request: true)
624+
id = rule_id.resolve_id
625625
return @automod_rules[id] if @automod_rules[id]
626626
return nil unless request
627627

628-
rule = AutoModRule.new(JSON.parse(API::Server.get_automod_rule(@bot.token, @id, id)), @bot, self)
628+
rule = AutoModRule.new(JSON.parse(API::Server.get_automod_rule(@bot.token, @id, id)), self, @bot)
629629
@automod_rules[rule.resolve_id] = rule
630630
rescue StandardError
631631
nil
632632
end
633633

634634
# Get a list of all the automod rules configured on the server.
635+
# @param bypass_cache [true, false] Whether the cached automod rules
636+
# should be ignored and re-fetched via an HTTP request.
635637
# @return [Array<AutoModRule>] the configured automod rules on the server.
636-
def automod_rules
637-
return @automod_rules.values if @rules_chunked
638+
def automod_rules(bypass_cache: false)
639+
return @automod_rules.values if @rules_chunked && !bypass_cache
638640

639-
rules = API::Server.list_automod_rules(@bot.token, @id)
641+
rules = JSON.parse(API::Server.list_automod_rules(@bot.token, @id))
640642

641-
JSON.parse(rules).each do |data|
642-
element = AutoModRule.new(data, @bot, self)
643+
rules.each do |data|
644+
element = AutoModRule.new(data, self, @bot)
643645
@automod_rules[element.resolve_id] = element
644646
end
645647

@@ -688,7 +690,7 @@ def create_automod_rule(name:, event_type:, trigger_type:, enabled: false, exemp
688690

689691
response = API::Server.create_automod_rule(@bot.token, @id, name, event_type, trigger_type, metadata, builder.to_a, enabled,
690692
exempt_roles.map(&:resolve_id), exempt_channels.map(&:resolve_id), reason)
691-
rule = AutoModRule.new(JSON.parse(response), @bot, self)
693+
rule = AutoModRule.new(JSON.parse(response), self, @bot)
692694
@automod_rules[rule.id] = rule
693695
end
694696

lib/discordrb/events/auto_moderation.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AutoModRuleDeleteEvent < AutoModRuleEvent
3030
def initialize(data, bot)
3131
@bot = bot
3232
@server = bot.server(data['guild_id'].to_i)
33-
@automod_rule = Discordrb::AutoModRule.new(data, bot, @server)
33+
@automod_rule = Discordrb::AutoModRule.new(data, @server, bot)
3434
end
3535
end
3636

@@ -45,7 +45,7 @@ def matches?(event)
4545
a.resolve_id == e.resolve_id
4646
end,
4747

48-
matches_all(@attributes[:automod_rule], event.automod_rule) do |a, e|
48+
matches_all(@attributes[:id], event.automod_rule) do |a, e|
4949
a.resolve_id == e.resolve_id
5050
end,
5151

0 commit comments

Comments
 (0)