chat_sdk-discord 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/chat_sdk/discord/adapter.rb +48 -0
- data/lib/chat_sdk/discord/format_converter.rb +36 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3fd28694400d17ed002d3ea0f10ecda942af1d7876e3aae7d8c597bee6c2efc3
|
|
4
|
+
data.tar.gz: d499bedd48317531a060bc98ba84903adbaa7f5a6bdc36f7390aa8ed71887e92
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f7961d7d7132594e22a6190a688d1fe2c0a6d1a10af57a8d73005d108c4f2c3de796ccb8f4aa2c6cd6c3d99ef330185f16d02983ab6da4652a32983cf7f0334b
|
|
7
|
+
data.tar.gz: cd8ff652419fee58920f4d54464aa3a04e25012f5cbb5cdca45d3d3d541d1de37faed54bbe23df878d07484fddb3edbf70a78a5817c49a263aa09c36806f3e32
|
|
@@ -162,6 +162,54 @@ module ChatSDK
|
|
|
162
162
|
end
|
|
163
163
|
end
|
|
164
164
|
|
|
165
|
+
# Discord-specific: receive real-time events via the Discord Gateway WebSocket.
|
|
166
|
+
# Requires the optional 'discordrb' gem. Not part of the base adapter contract.
|
|
167
|
+
def start_gateway(&block)
|
|
168
|
+
raise ArgumentError, "start_gateway requires a block" unless block
|
|
169
|
+
|
|
170
|
+
begin
|
|
171
|
+
require "discordrb"
|
|
172
|
+
rescue LoadError
|
|
173
|
+
raise ChatSDK::ConfigurationError,
|
|
174
|
+
"Discord gateway requires the 'discordrb' gem. Add gem 'discordrb' to your Gemfile."
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
bot = Discordrb::Bot.new(token: "Bot #{@bot_token}")
|
|
178
|
+
|
|
179
|
+
bot.message do |event|
|
|
180
|
+
next if event.author.bot_account?
|
|
181
|
+
|
|
182
|
+
author = ChatSDK::Author.new(
|
|
183
|
+
id: event.author.id.to_s,
|
|
184
|
+
name: event.author.username,
|
|
185
|
+
platform: :discord,
|
|
186
|
+
bot: false
|
|
187
|
+
)
|
|
188
|
+
message = ChatSDK::Message.new(
|
|
189
|
+
id: event.message.id.to_s,
|
|
190
|
+
text: event.message.content,
|
|
191
|
+
author: author,
|
|
192
|
+
thread_id: event.message.id.to_s,
|
|
193
|
+
channel_id: event.channel.id.to_s,
|
|
194
|
+
platform: :discord,
|
|
195
|
+
raw: {content: event.message.content, author_id: event.author.id.to_s}
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
mention_event = ChatSDK::Events::Mention.new(
|
|
199
|
+
message: message,
|
|
200
|
+
thread_id: message.thread_id,
|
|
201
|
+
channel_id: message.channel_id,
|
|
202
|
+
platform: :discord,
|
|
203
|
+
adapter_name: :discord,
|
|
204
|
+
raw: message.raw
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
block.call(mention_event)
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
bot.run
|
|
211
|
+
end
|
|
212
|
+
|
|
165
213
|
private
|
|
166
214
|
|
|
167
215
|
def prepare_message_payload(message)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ChatSDK
|
|
4
|
+
module Discord
|
|
5
|
+
class FormatConverter < ChatSDK::Format::Converter
|
|
6
|
+
# Discord → Markdown
|
|
7
|
+
def to_markdown(platform_text)
|
|
8
|
+
text = platform_text.to_s
|
|
9
|
+
return "" if text.empty?
|
|
10
|
+
|
|
11
|
+
# Convert user mentions: <@123456> → @123456
|
|
12
|
+
text = text.gsub(/<@!?(\d+)>/, '@\1')
|
|
13
|
+
|
|
14
|
+
# Convert channel mentions: <#123456> → #123456
|
|
15
|
+
text = text.gsub(/<#(\d+)>/, '#\1')
|
|
16
|
+
|
|
17
|
+
# Convert animated custom emoji: <a:name:id> → :name:
|
|
18
|
+
text = text.gsub(/<a:(\w+):\d+>/, ':\1:')
|
|
19
|
+
|
|
20
|
+
# Convert custom emoji: <:name:id> → :name:
|
|
21
|
+
text = text.gsub(/<:(\w+):\d+>/, ':\1:')
|
|
22
|
+
|
|
23
|
+
# Strip spoiler markers: ||text|| → text
|
|
24
|
+
text.gsub(/\|\|(.+?)\|\|/m, '\1')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Markdown → Discord (mostly pass-through since Discord uses standard markdown)
|
|
28
|
+
def from_markdown(markdown)
|
|
29
|
+
text = markdown.to_s
|
|
30
|
+
return "" if text.empty?
|
|
31
|
+
|
|
32
|
+
text
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chat_sdk-discord
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Quentin Rousseau
|
|
@@ -63,6 +63,7 @@ files:
|
|
|
63
63
|
- lib/chat_sdk/discord/api_client.rb
|
|
64
64
|
- lib/chat_sdk/discord/embed_renderer.rb
|
|
65
65
|
- lib/chat_sdk/discord/event_parser.rb
|
|
66
|
+
- lib/chat_sdk/discord/format_converter.rb
|
|
66
67
|
- lib/chat_sdk/discord/signature.rb
|
|
67
68
|
homepage: https://github.com/rootlyhq/chat-sdk
|
|
68
69
|
licenses:
|