dispander.rb 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/custom_condition.rb +18 -0
- data/{samplebot.rb → examples/normal.rb} +0 -0
- data/lib/dispander/extension.rb +16 -2
- data/lib/dispander/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a45dba58a6aa5d443c2291232d5f52c9bab44354323add4c9be14e9cb0668658
|
4
|
+
data.tar.gz: 4153063d6540ecb03dcfeb957c2dc4a154e16c638068b850be70911d4833745f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47a0b093ce682e5a0a724a4713ad1b50a3ead9e2a095ec1ebe2b085119bc8316d58db7639bb5c95c7a3ea8e4f725b96fa59708a4d2d1db83cadc8a6988d9a1a0
|
7
|
+
data.tar.gz: be3b922fb5749554e9e581bf6319cce398131b7870cafb3e0a5060868eb19119894d936d595b3b4524e14b1b100ce2e0917846e1e7dd95a7fb725b9328d8cc00
|
@@ -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
|
|
@@ -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
|
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.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: 2022-05-
|
11
|
+
date: 2022-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: discorb
|
@@ -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
|