dispander.rb 0.3.4 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.en.md +13 -0
- data/README.md +17 -4
- data/dispander.gemspec +1 -1
- data/examples/custom_condition.rb +18 -0
- data/{samplebot.rb → examples/normal.rb} +0 -0
- data/lib/dispander/extension.rb +17 -3
- data/lib/dispander/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c458f8fd4e1bb7cf7a16abe9472662cf5a898eea94758b8f0ad2a925a2d2f50
|
4
|
+
data.tar.gz: b3f6d59f99ab4286bb6e69972d552588b6d786251451fcc9982a5150c2c81ca3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a6c97d1457cdc23931e2c4831c11526796b124cc911c3a14fd7c11b1da55db7102722a53086a76c2947780cb92e77aad456c0296c9d78b1940646dd6c0d049e
|
7
|
+
data.tar.gz: bab35466c02227b52c026601904fefffa513841591792ec1797fbe998dde8401f730fbe01eed3981b95e3ff8e690687997d4f804f90c4c787bf4c21ec66c6939
|
data/README.en.md
CHANGED
@@ -74,6 +74,19 @@ Set emoji to `Dispander#delete_emoji`, or specify it in `Client#load_extension`.
|
|
74
74
|
client.load_extension(Dispander::Core, delete_emoji: Discorb::UnicodeEmoji["x"])
|
75
75
|
```
|
76
76
|
|
77
|
+
## Change the condition to expand
|
78
|
+
|
79
|
+
Override `Dispander#should_expand?`.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
dispander = Dispander::Core.new(client)
|
83
|
+
|
84
|
+
def dispander.should_expand?(base_message, ids)
|
85
|
+
ENV["ALLOWED_GUILDS"].split(",").include?(ids[0])
|
86
|
+
end
|
87
|
+
|
88
|
+
client.load_extension(dispander)
|
89
|
+
```
|
77
90
|
|
78
91
|
## License
|
79
92
|
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# dispander.rb
|
2
2
|
|
3
|
-
discorbで出来たBotにメッセージ展開の機能を追加するExtension。
|
3
|
+
discorb で出来た Bot にメッセージ展開の機能を追加する Extension。
|
4
4
|
![画像](https://user-images.githubusercontent.com/59691627/131650571-ec50bf35-c971-4aeb-9a58-8fbf9b3e759b.png)
|
5
5
|
|
6
|
-
[DiscordBotPortalJP/dispander](https://github.com/DiscordBotPortalJP/dispander) のRuby版。
|
6
|
+
[DiscordBotPortalJP/dispander](https://github.com/DiscordBotPortalJP/dispander) の Ruby 版。
|
7
7
|
|
8
8
|
## インストール
|
9
9
|
|
10
|
-
Gemfileに以下を追記し...
|
10
|
+
Gemfile に以下を追記し...
|
11
11
|
|
12
12
|
```ruby
|
13
13
|
gem 'dispander'
|
@@ -23,7 +23,7 @@ gem 'dispander'
|
|
23
23
|
|
24
24
|
## 使い方
|
25
25
|
|
26
|
-
### Extensionとして読み込む
|
26
|
+
### Extension として読み込む
|
27
27
|
|
28
28
|
```ruby
|
29
29
|
require "discorb"
|
@@ -73,6 +73,19 @@ client.run ENV["DISCORD_BOT_TOKEN"]
|
|
73
73
|
client.load_extension(Dispander::Core, delete_emoji: Discorb::UnicodeEmoji["x"])
|
74
74
|
```
|
75
75
|
|
76
|
+
### 展開条件を変更する
|
77
|
+
|
78
|
+
`Dispander#should_expand?`をオーバーライドしてください。
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
dispander = Dispander::Core.new(client)
|
82
|
+
|
83
|
+
def dispander.should_expand?(base_message, ids)
|
84
|
+
ENV["ALLOWED_GUILDS"].split(",").include?(ids[0])
|
85
|
+
end
|
86
|
+
|
87
|
+
client.load_extension(dispander)
|
88
|
+
```
|
76
89
|
|
77
90
|
## ライセンス
|
78
91
|
|
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.
|
31
|
+
spec.add_dependency "discorb", "~> 0.19"
|
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
|
data/lib/dispander/extension.rb
CHANGED
@@ -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]{
|
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
|
38
|
+
next unless should_expand?(base_message, [guild_id, channel_id, message_id])
|
39
39
|
|
40
40
|
embeds = []
|
41
41
|
|
@@ -122,8 +122,22 @@ module Dispander
|
|
122
122
|
return unless author_id == event.user_id || operator_id == event.user_id
|
123
123
|
|
124
124
|
sent_message_ids.split(",").each do |sent_message_id|
|
125
|
-
event.channel.delete_message
|
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
|
data/lib/dispander/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sevenc-nanashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-05 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.
|
19
|
+
version: '0.19'
|
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.
|
26
|
+
version: '0.19'
|
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.
|
70
|
+
rubygems_version: 3.3.17
|
70
71
|
signing_key:
|
71
72
|
specification_version: 4
|
72
73
|
summary: discorbのBotにメッセージ展開の機能を追加するExtension。
|