dispander.rb 0.1.0 → 0.3.2

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: f3e930967666092faf411622028c20fa7d31796cd0fe5e0eed7995fd82c79d30
4
- data.tar.gz: b34675bc0a76a89e04efec3a7dbb8ec25372b5797b7ac5e1ee00255a22bbe1c7
3
+ metadata.gz: ea355cc4fad7af49bc22fb7c4d1e02c191c9fdc30dfc4d9a9ad835ba4e9a6612
4
+ data.tar.gz: bc75b7af3b0a7137c334de052c3e1f1c04977372059676cce773a121d5d64ae3
5
5
  SHA512:
6
- metadata.gz: d964954609afb5804c4adcb7f0ad25513ebc9329d81de7dab8ed2e62d43b0db96c0b75dd8f6748469b48fb56cd45d5c27f515907b4ac23eb306410ee3165e663
7
- data.tar.gz: dfea449df14d2779df00890b8bfa60d288149130f00bcc2df34d35da97818ab01b245659ebc5a50c6a4e927118bd05311c4d79bf0e8d05580db9a5634cf6e6c1
6
+ metadata.gz: 24954a776d98dcee969e5a8183e141608f7989fe970ea4a4f5341487faa201f0fb846639fb56d8f6a577743abbb1d38ee35fa7cdfc0b7efe6533e182cc9ce5b0
7
+ data.tar.gz: 95560decaa07b8a031e19a5642c5253b1539deb907337b9c287f0bdc436a9ff1360053d2bf7102740eb6faeb7a2b8d292f53a11f7dd9d60698c89ecd2ae4045b
data/.gitignore CHANGED
@@ -6,3 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+
10
+ Gemfile.lock
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 sevenc-nanashi
3
+ Copyright (c) 2021 Discord Bot Portal JP
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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 :ready do
35
- puts <<~EOS
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.extend(Dispander)
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.dispand`でメッセージを展開、`Dispander.delete_message`で展開したメッセージを削除できます。
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
- Dispander.dispand(message)
58
+ dispander.dispand(message)
61
59
  end
62
60
 
63
61
  client.on :reaction_add do |event|
64
- Dispander.delete_message(event)
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.delete_emoji`に絵文字を指定してください。
70
+ `Dispander#delete_emoji`に絵文字を指定するか、`Client#load_extension`に引数として追加してください。
73
71
 
74
72
  ```ruby
75
- Dispander.delete_emoji = Discorb::UnicodeEmoji.new("x")
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.2.4"
31
+ spec.add_dependency "discorb", "~> 0.12.0"
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
@@ -1,20 +1,26 @@
1
1
  require "discorb"
2
2
 
3
3
  module Dispander
4
- extend 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,})(?!>)/
4
+ class Core
5
+ include Discorb::Extension
6
6
 
7
- event :message do |message|
8
- next if message.author.bot?
7
+ @@discord_url_pattern = /(?!<)https:\/\/(ptb.|canary.)?discord(app)?.com\/channels\/(?<guild>[0-9]{18,})\/(?<channel>[0-9]{18,})\/(?<message>[0-9]{18,})(?!>)/
9
8
 
10
- Dispander.dispand(message)
11
- end
9
+ def initialize(client, delete_emoji: Discorb::UnicodeEmoji["wastebasket"])
10
+ @delete_emoji = delete_emoji
11
+ super(client)
12
+ end
12
13
 
13
- event :reaction_add do |event|
14
- Dispander.delete_message(event)
15
- end
14
+ event :message do |message|
15
+ next if message.author.bot?
16
+
17
+ dispand(message)
18
+ end
19
+
20
+ event :reaction_add do |event|
21
+ delete_message(event)
22
+ end
16
23
 
17
- class << self
18
24
  # @return [Discorb::Emoji] 削除リアクションとして使う絵文字。
19
25
  attr_accessor :delete_emoji
20
26
 
@@ -27,7 +33,7 @@ module Dispander
27
33
  #
28
34
  def dispand(base_message)
29
35
  all_sent_messages = []
30
- base_message.content.scan(DISCORD_URL_PATTERN).each do |match|
36
+ base_message.content.scan(@@discord_url_pattern).each do |match|
31
37
  guild_id, channel_id, message_id = *match
32
38
  next unless base_message.guild.id == guild_id
33
39
 
@@ -35,8 +41,10 @@ module Dispander
35
41
 
36
42
  sent_messages = []
37
43
  begin
38
- message = @client.guilds[guild_id].channels[channel_id].fetch_message(message_id).wait
39
- rescue Discorb::NotFoundError
44
+ next unless guild = @client.guilds[guild_id]
45
+ next unless channel = guild.channels[channel_id] || @client.fetch_channel(channel_id).wait
46
+ next unless message = channel.fetch_message(message_id).wait
47
+ rescue Discorb::NotFoundError, NoMethodError
40
48
  next
41
49
  else
42
50
  embed = create_embed_from_message(message)
@@ -45,12 +53,12 @@ module Dispander
45
53
  embeds += message.attachments[1..]&.filter(&:image?)&.map { |attachment| create_embed_from_attachment(attachment) }.to_a
46
54
 
47
55
  until (embeds_send = embeds.slice!(..10)).empty?
48
- sent_messages << message.channel.post(embeds: embeds_send).wait
56
+ sent_messages << base_message.channel.post(embeds: embeds_send).wait
49
57
  end
50
58
  embed.url = "http://a.io/#{base_message.author.id}-#{message.author.id}-#{sent_messages.map(&:id).join(",")}"
51
59
  first_embeds = sent_messages[0].embeds
52
60
  first_embeds[0] = embed
53
- sent_messages[0].add_reaction(@delete_emoji || Discorb::UnicodeEmoji["wastebasket"])
61
+ sent_messages[0].add_reaction(@delete_emoji)
54
62
  sent_messages[0].edit(embeds: first_embeds).wait
55
63
  all_sent_messages += sent_messages
56
64
  end
@@ -102,7 +110,7 @@ module Dispander
102
110
  # @param [Discorb::Gateway::ReactionEvent] event リアクションのイベント。
103
111
  #
104
112
  def delete_message(event)
105
- return unless event.emoji != (@delete_emoji || Discorb::UnicodeEmoji["wastebasket"])
113
+ return unless event.emoji == @delete_emoji
106
114
  return if event.user_id == @client.user.id
107
115
 
108
116
  message = event.fetch_message.wait
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dispander
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.2"
5
5
  end
data/samplebot.rb CHANGED
@@ -3,14 +3,10 @@ require "dispander"
3
3
 
4
4
  client = Discorb::Client.new
5
5
 
6
- client.once :ready do
7
- puts <<~EOS
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.extend(Dispander)
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.1.0
4
+ version: 0.3.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: 2021-09-01 00:00:00.000000000 Z
11
+ date: 2021-10-24 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.2.4
19
+ version: 0.12.0
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.2.4
26
+ version: 0.12.0
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