dispander.rb 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8abef01b13dda9fa294f57b92345c0238b6cd064520d30c9443552ac1dc09679
4
- data.tar.gz: 6acd1059efdf0497a642dddb21c3f3644a4bf69f54722c0575ff2e0331ad9a4c
3
+ metadata.gz: a45dba58a6aa5d443c2291232d5f52c9bab44354323add4c9be14e9cb0668658
4
+ data.tar.gz: 4153063d6540ecb03dcfeb957c2dc4a154e16c638068b850be70911d4833745f
5
5
  SHA512:
6
- metadata.gz: 347f8ff590094e4638bda7875e4a96e0277c1f85e4fa7b1724390c45cb5bbe8b7e9c6cd39236f5ee33c6458271480fcbe11819cef57211619c8bad27bf042c11
7
- data.tar.gz: ac3426f499d4a63d2fb2a65464eef439a62e94c240d00b81d8e1e5cb4338cf29a03770cdc3fa045d1043841676ec18e539b4dacc940ab2169fa08d38fcdbc6cc
6
+ metadata.gz: 47a0b093ce682e5a0a724a4713ad1b50a3ead9e2a095ec1ebe2b085119bc8316d58db7639bb5c95c7a3ea8e4f725b96fa59708a4d2d1db83cadc8a6988d9a1a0
7
+ data.tar.gz: be3b922fb5749554e9e581bf6319cce398131b7870cafb3e0a5060868eb19119894d936d595b3b4524e14b1b100ce2e0917846e1e7dd95a7fb725b9328d8cc00
data/dispander.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  # Uncomment to register a new dependency of your gem
31
- spec.add_dependency "discorb", "~> 0.13.0"
31
+ spec.add_dependency "discorb", "~> 0.16"
32
32
 
33
33
  # For more information and examples about making a new gem, checkout our
34
34
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -0,0 +1,18 @@
1
+ require "discorb"
2
+ require "dispander"
3
+
4
+ client = Discorb::Client.new
5
+
6
+ client.once :standby do
7
+ puts "Logged in as #{client.user}"
8
+ end
9
+
10
+ dispander = Dispander::Core.new(client)
11
+
12
+ def dispander.should_expand?(base_message, ids)
13
+ ENV["ALLOWED_GUILDS"].split(",").include?(ids[0])
14
+ end
15
+
16
+ client.load_extension(dispander)
17
+
18
+ client.run ENV["DISCORD_BOT_TOKEN"]
File without changes
@@ -4,7 +4,7 @@ module Dispander
4
4
  class Core
5
5
  include Discorb::Extension
6
6
 
7
- @@discord_url_pattern = /(?!<)https:\/\/(ptb.|canary.)?discord(app)?.com\/channels\/(?<guild>[0-9]{18,})\/(?<channel>[0-9]{18,})\/(?<message>[0-9]{18,})(?!>)/
7
+ @@discord_url_pattern = /(?!<)https:\/\/(ptb.|canary.)?discord(app)?.com\/channels\/(?<guild>[0-9]{17,})\/(?<channel>[0-9]{17,})\/(?<message>[0-9]{17,})(?!>)/
8
8
 
9
9
  def initialize(client, delete_emoji: Discorb::UnicodeEmoji["wastebasket"])
10
10
  @delete_emoji = delete_emoji
@@ -35,7 +35,7 @@ module Dispander
35
35
  all_sent_messages = []
36
36
  base_message.content.scan(@@discord_url_pattern).each do |match|
37
37
  guild_id, channel_id, message_id = *match
38
- next unless base_message.guild.id == guild_id
38
+ next unless should_expand?(base_message, [guild_id, channel_id, message_id])
39
39
 
40
40
  embeds = []
41
41
 
@@ -125,5 +125,19 @@ module Dispander
125
125
  event.channel.delete_message!(sent_message_id).wait
126
126
  end
127
127
  end
128
+
129
+ #
130
+ # メッセージを展開するかどうか。
131
+ # デフォルトでは同じサーバーのみ展開されます。
132
+ # このメソッドをオーバーライドすることにより、条件を変更することができます。
133
+ #
134
+ # @params [Discorb::Message] base_message 展開するメッセージ。
135
+ # @params [Array<String>] match 展開するメッセージのID。`[guild_id, channel_id, message_id]`
136
+ #
137
+ # @return [Boolean] 展開する場合は `true`、展開しない場合は `false`。
138
+ #
139
+ def should_expand?(base_message, ids)
140
+ base_message.guild.id == ids[0]
141
+ end
128
142
  end
129
143
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dispander
4
- VERSION = "0.3.3"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dispander.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sevenc-nanashi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-02 00:00:00.000000000 Z
11
+ date: 2022-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: discorb
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.13.0
19
+ version: '0.16'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.13.0
26
+ version: '0.16'
27
27
  description:
28
28
  email:
29
29
  - sevenc-nanashi@sevenbot.jp
@@ -40,10 +40,11 @@ files:
40
40
  - bin/console
41
41
  - bin/setup
42
42
  - dispander.gemspec
43
+ - examples/custom_condition.rb
44
+ - examples/normal.rb
43
45
  - lib/dispander.rb
44
46
  - lib/dispander/extension.rb
45
47
  - lib/dispander/version.rb
46
- - samplebot.rb
47
48
  homepage: https://github.com/DiscordBotPortalJP/dispander.rb
48
49
  licenses:
49
50
  - MIT
@@ -66,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
67
  - !ruby/object:Gem::Version
67
68
  version: '0'
68
69
  requirements: []
69
- rubygems_version: 3.2.22
70
+ rubygems_version: 3.2.32
70
71
  signing_key:
71
72
  specification_version: 4
72
73
  summary: discorbのBotにメッセージ展開の機能を追加するExtension。