dispander.rb 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/LICENSE.txt +1 -1
- data/README.en.md +80 -0
- data/README.md +10 -14
- data/dispander.gemspec +1 -1
- data/lib/dispander/extension.rb +17 -13
- data/lib/dispander/version.rb +1 -1
- data/samplebot.rb +3 -7
- metadata +5 -5
- data/Gemfile.lock +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72ece3741f679c4e18bfe11980bf92baa46d74fa86269ed8e93facabac2f993c
|
4
|
+
data.tar.gz: c6da4e5800057ef09807e4a878a4b6785ed13cfaa27e470149265617722a2390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b72de3c9775d139c533cb037caa0fa900eaf85bdd7815151b92d4add249c96b04c5469a1401b6861563f5018a0ffe778100aabe5b36bbbff1f1088031586a1eb
|
7
|
+
data.tar.gz: 02fdeac6d1c1fff4d728a19d37368955cb998ee3199b910c9d1867bc7a951ee91f7dd1eee44e6834e0a2f2de718e7e655d11d6ca8e6f8be3d857178b36e2b679
|
data/.gitignore
CHANGED
data/LICENSE.txt
CHANGED
data/README.en.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# dispander.rb
|
2
|
+
|
3
|
+
An extension that adds message expanding feature for discorb bot.
|
4
|
+
![image](https://user-images.githubusercontent.com/59691627/131650571-ec50bf35-c971-4aeb-9a58-8fbf9b3e759b.png)
|
5
|
+
|
6
|
+
Ruby version of [DiscordBotPortalJP/dispander](https://github.com/DiscordBotPortalJP/dispander).
|
7
|
+
|
8
|
+
## Install
|
9
|
+
|
10
|
+
Add this to Gemfile...
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'dispander'
|
14
|
+
```
|
15
|
+
|
16
|
+
And run this:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or...
|
21
|
+
|
22
|
+
$ gem install dispander
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Load as Extension
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require "discorb"
|
30
|
+
require "discorb"
|
31
|
+
require "dispander"
|
32
|
+
|
33
|
+
client = Discorb::Client.new
|
34
|
+
|
35
|
+
client.once :standby do
|
36
|
+
puts "Logged in as #{client.user}"
|
37
|
+
end
|
38
|
+
|
39
|
+
client.load_extension(Dispander::Core)
|
40
|
+
|
41
|
+
client.run ENV["DISCORD_BOT_TOKEN"]
|
42
|
+
```
|
43
|
+
|
44
|
+
### Expand Manually
|
45
|
+
|
46
|
+
`Dispander::Core#dispand` to expand, `Dispander::Core#delete_message` to delete message.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
require "discorb"
|
50
|
+
require "dispander"
|
51
|
+
|
52
|
+
client = Discorb::Client.new
|
53
|
+
|
54
|
+
dispander = Dispander::Core.new(client)
|
55
|
+
|
56
|
+
client.on :message do |message|
|
57
|
+
next if message.author.bot?
|
58
|
+
|
59
|
+
dispander.dispand(message)
|
60
|
+
end
|
61
|
+
|
62
|
+
client.on :reaction_add do |event|
|
63
|
+
dispander.delete_message(event)
|
64
|
+
end
|
65
|
+
|
66
|
+
client.run ENV["DISCORD_BOT_TOKEN"]
|
67
|
+
```
|
68
|
+
|
69
|
+
### Change emoji of deletion
|
70
|
+
|
71
|
+
Set emoji to `Dispander#delete_emoji`, or specify it in `Client#load_extension`.
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
client.load_extension(Dispander::Core, delete_emoji: Discorb::UnicodeEmoji["x"])
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
## License
|
79
|
+
|
80
|
+
Source is open under [MIT License](https://opensource.org/licenses/MIT).
|
data/README.md
CHANGED
@@ -31,22 +31,18 @@ require "dispander"
|
|
31
31
|
|
32
32
|
client = Discorb::Client.new
|
33
33
|
|
34
|
-
client.once :
|
35
|
-
puts
|
36
|
-
---------
|
37
|
-
Logged in as #{client.user}(#{client.user.id})
|
38
|
-
---------
|
39
|
-
EOS
|
34
|
+
client.once :standby do
|
35
|
+
puts "Logged in as #{client.user}"
|
40
36
|
end
|
41
37
|
|
42
|
-
client.
|
38
|
+
client.load_extension(Dispander::Core)
|
43
39
|
|
44
40
|
client.run ENV["DISCORD_BOT_TOKEN"]
|
45
41
|
```
|
46
42
|
|
47
43
|
### 手動で実行する
|
48
44
|
|
49
|
-
`Dispander
|
45
|
+
`Dispander::Core#dispand`でメッセージを展開、`Dispander::Core#delete_message`で展開したメッセージを削除できます。
|
50
46
|
|
51
47
|
```ruby
|
52
48
|
require "discorb"
|
@@ -54,14 +50,16 @@ require "dispander"
|
|
54
50
|
|
55
51
|
client = Discorb::Client.new
|
56
52
|
|
53
|
+
dispander = Dispander::Core.new(client)
|
54
|
+
|
57
55
|
client.on :message do |message|
|
58
56
|
next if message.author.bot?
|
59
57
|
|
60
|
-
|
58
|
+
dispander.dispand(message)
|
61
59
|
end
|
62
60
|
|
63
61
|
client.on :reaction_add do |event|
|
64
|
-
|
62
|
+
dispander.delete_message(event)
|
65
63
|
end
|
66
64
|
|
67
65
|
client.run ENV["DISCORD_BOT_TOKEN"]
|
@@ -69,12 +67,10 @@ client.run ENV["DISCORD_BOT_TOKEN"]
|
|
69
67
|
|
70
68
|
### 削除の絵文字を変更する
|
71
69
|
|
72
|
-
`Dispander
|
70
|
+
`Dispander#delete_emoji`に絵文字を指定するか、`Client#load_extension`に引数として追加してください。
|
73
71
|
|
74
72
|
```ruby
|
75
|
-
Dispander
|
76
|
-
|
77
|
-
client.extend(Dispander)
|
73
|
+
client.load_extension(Dispander::Core, delete_emoji: Discorb::UnicodeEmoji["x"])
|
78
74
|
```
|
79
75
|
|
80
76
|
|
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.10.1"
|
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
|
data/lib/dispander/extension.rb
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
require "discorb"
|
2
2
|
|
3
3
|
module Dispander
|
4
|
-
|
5
|
-
|
4
|
+
class Core < Discorb::Extension
|
5
|
+
@@discord_url_pattern = /(?!<)https:\/\/(ptb.|canary.)?discord(app)?.com\/channels\/(?<guild>[0-9]{18,})\/(?<channel>[0-9]{18,})\/(?<message>[0-9]{18,})(?!>)/
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
def initialize(client, delete_emoji: Discorb::UnicodeEmoji["wastebasket"])
|
8
|
+
@delete_emoji = delete_emoji
|
9
|
+
super(client)
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
event :message do |message|
|
13
|
+
next if message.author.bot?
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
dispand(message)
|
16
|
+
end
|
17
|
+
|
18
|
+
event :reaction_add do |event|
|
19
|
+
delete_message(event)
|
20
|
+
end
|
16
21
|
|
17
|
-
class << self
|
18
22
|
# @return [Discorb::Emoji] 削除リアクションとして使う絵文字。
|
19
23
|
attr_accessor :delete_emoji
|
20
24
|
|
@@ -27,7 +31,7 @@ module Dispander
|
|
27
31
|
#
|
28
32
|
def dispand(base_message)
|
29
33
|
all_sent_messages = []
|
30
|
-
base_message.content.scan(
|
34
|
+
base_message.content.scan(@@discord_url_pattern).each do |match|
|
31
35
|
guild_id, channel_id, message_id = *match
|
32
36
|
next unless base_message.guild.id == guild_id
|
33
37
|
|
@@ -50,7 +54,7 @@ module Dispander
|
|
50
54
|
embed.url = "http://a.io/#{base_message.author.id}-#{message.author.id}-#{sent_messages.map(&:id).join(",")}"
|
51
55
|
first_embeds = sent_messages[0].embeds
|
52
56
|
first_embeds[0] = embed
|
53
|
-
sent_messages[0].add_reaction(@delete_emoji
|
57
|
+
sent_messages[0].add_reaction(@delete_emoji)
|
54
58
|
sent_messages[0].edit(embeds: first_embeds).wait
|
55
59
|
all_sent_messages += sent_messages
|
56
60
|
end
|
@@ -102,7 +106,7 @@ module Dispander
|
|
102
106
|
# @param [Discorb::Gateway::ReactionEvent] event リアクションのイベント。
|
103
107
|
#
|
104
108
|
def delete_message(event)
|
105
|
-
return unless event.emoji
|
109
|
+
return unless event.emoji == @delete_emoji
|
106
110
|
return if event.user_id == @client.user.id
|
107
111
|
|
108
112
|
message = event.fetch_message.wait
|
data/lib/dispander/version.rb
CHANGED
data/samplebot.rb
CHANGED
@@ -3,14 +3,10 @@ require "dispander"
|
|
3
3
|
|
4
4
|
client = Discorb::Client.new
|
5
5
|
|
6
|
-
client.once :
|
7
|
-
puts
|
8
|
-
---------
|
9
|
-
Logged in as #{client.user}(#{client.user.id})
|
10
|
-
---------
|
11
|
-
EOS
|
6
|
+
client.once :standby do
|
7
|
+
puts "Logged in as #{client.user}"
|
12
8
|
end
|
13
9
|
|
14
|
-
client.
|
10
|
+
client.load_extension(Dispander::Core)
|
15
11
|
|
16
12
|
client.run ENV["DISCORD_BOT_TOKEN"]
|
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.2.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-
|
11
|
+
date: 2021-10-02 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.10.1
|
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.10.1
|
27
27
|
description:
|
28
28
|
email:
|
29
29
|
- sevenc-nanashi@sevenbot.jp
|
@@ -33,8 +33,8 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- ".gitignore"
|
35
35
|
- Gemfile
|
36
|
-
- Gemfile.lock
|
37
36
|
- LICENSE.txt
|
37
|
+
- README.en.md
|
38
38
|
- README.md
|
39
39
|
- Rakefile
|
40
40
|
- bin/console
|
data/Gemfile.lock
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
dispander.rb (0.1.0)
|
5
|
-
discorb (~> 0.2.4)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
async (1.30.1)
|
11
|
-
console (~> 1.10)
|
12
|
-
nio4r (~> 2.3)
|
13
|
-
timers (~> 4.1)
|
14
|
-
async-http (0.56.5)
|
15
|
-
async (>= 1.25)
|
16
|
-
async-io (>= 1.28)
|
17
|
-
async-pool (>= 0.2)
|
18
|
-
protocol-http (~> 0.22.0)
|
19
|
-
protocol-http1 (~> 0.14.0)
|
20
|
-
protocol-http2 (~> 0.14.0)
|
21
|
-
async-io (1.32.2)
|
22
|
-
async
|
23
|
-
async-pool (0.3.8)
|
24
|
-
async (>= 1.25)
|
25
|
-
async-websocket (0.19.0)
|
26
|
-
async-http (~> 0.54)
|
27
|
-
async-io (~> 1.23)
|
28
|
-
protocol-websocket (~> 0.7.0)
|
29
|
-
console (1.13.1)
|
30
|
-
fiber-local
|
31
|
-
discorb (0.2.4)
|
32
|
-
async
|
33
|
-
async-http
|
34
|
-
async-websocket
|
35
|
-
mime-types (~> 3.3)
|
36
|
-
fiber-local (1.0.0)
|
37
|
-
mime-types (3.3.1)
|
38
|
-
mime-types-data (~> 3.2015)
|
39
|
-
mime-types-data (3.2021.0704)
|
40
|
-
nio4r (2.5.8)
|
41
|
-
protocol-hpack (1.4.2)
|
42
|
-
protocol-http (0.22.5)
|
43
|
-
protocol-http1 (0.14.2)
|
44
|
-
protocol-http (~> 0.22)
|
45
|
-
protocol-http2 (0.14.2)
|
46
|
-
protocol-hpack (~> 1.4)
|
47
|
-
protocol-http (~> 0.18)
|
48
|
-
protocol-websocket (0.7.5)
|
49
|
-
protocol-http (~> 0.2)
|
50
|
-
protocol-http1 (~> 0.2)
|
51
|
-
rake (13.0.6)
|
52
|
-
timers (4.3.3)
|
53
|
-
|
54
|
-
PLATFORMS
|
55
|
-
x86-mingw32
|
56
|
-
|
57
|
-
DEPENDENCIES
|
58
|
-
dispander.rb!
|
59
|
-
rake (~> 13.0)
|
60
|
-
|
61
|
-
BUNDLED WITH
|
62
|
-
2.2.22
|