chat_sdk-discord 0.5.0 → 0.7.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 +61 -0
- data/lib/chat_sdk/discord/api_client.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7c564873850d8fbf2fceb8ea472cca9a2b9bcad9a104d43c24daef348d98bb48
|
|
4
|
+
data.tar.gz: 1cda95c4f066d1be9d84dfd1ea11951679d8363dc65ebfe7640118eed1eefca8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 229ccb06fb2c36c9d36777942bb2f23a6ec79bc9762d0bdc9a7f1a3ae8e619f4b23a19281a380e5f7d2aeab5c92f11378e239b2f409dceed34edf29c5e113c51
|
|
7
|
+
data.tar.gz: 0154ab9559ec3acd28663cc2f6ba2358e59a08ee07946bc0555ecddc45ca66d1bbd1b2b5f97f36d982c96d94a4470ad4f5590130eaab5e4e019da657340b7191
|
|
@@ -117,6 +117,19 @@ module ChatSDK
|
|
|
117
117
|
@client.remove_reaction(channel_id, message_id, emoji)
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
+
def get_user(user_id)
|
|
121
|
+
data = @client.get_user(user_id)
|
|
122
|
+
return nil unless data && data["id"]
|
|
123
|
+
|
|
124
|
+
ChatSDK::Author.new(
|
|
125
|
+
id: data["id"],
|
|
126
|
+
name: data["username"],
|
|
127
|
+
platform: :discord,
|
|
128
|
+
bot: data["bot"] || false,
|
|
129
|
+
raw: data
|
|
130
|
+
)
|
|
131
|
+
end
|
|
132
|
+
|
|
120
133
|
def open_dm(user_id)
|
|
121
134
|
@dm_channels[user_id] ||= @client.create_dm(user_id)["id"]
|
|
122
135
|
end
|
|
@@ -149,6 +162,54 @@ module ChatSDK
|
|
|
149
162
|
end
|
|
150
163
|
end
|
|
151
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
|
+
|
|
152
213
|
private
|
|
153
214
|
|
|
154
215
|
def prepare_message_payload(message)
|
|
@@ -44,6 +44,11 @@ module ChatSDK
|
|
|
44
44
|
request(:delete, "#{API_PREFIX}/channels/#{channel_id}/messages/#{message_id}/reactions/#{encoded}/@me")
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
# Users
|
|
48
|
+
def get_user(user_id)
|
|
49
|
+
request(:get, "#{API_PREFIX}/users/#{user_id}")
|
|
50
|
+
end
|
|
51
|
+
|
|
47
52
|
# DMs
|
|
48
53
|
def create_dm(user_id)
|
|
49
54
|
request(:post, "#{API_PREFIX}/users/@me/channels", {"recipient_id" => user_id})
|