update to discord.gd 2.0.1
This commit is contained in:
parent
c8c4a55a99
commit
b7ada53c1d
3 changed files with 13 additions and 14 deletions
|
|
@ -58,7 +58,7 @@ var MESSAGE_TYPES = {
|
||||||
'22': 'GUILD_INVITE_REMINDER'
|
'22': 'GUILD_INVITE_REMINDER'
|
||||||
}
|
}
|
||||||
|
|
||||||
func _init(message: Dictionary):
|
func _init(message: Dictionary, client = null):
|
||||||
# Compulsory
|
# Compulsory
|
||||||
assert(typeof(message) == TYPE_DICTIONARY, 'Invalid type: message must be a Dictionary')
|
assert(typeof(message) == TYPE_DICTIONARY, 'Invalid type: message must be a Dictionary')
|
||||||
assert(message.id, 'Message must have an id')
|
assert(message.id, 'Message must have an id')
|
||||||
|
|
@ -81,6 +81,9 @@ func _init(message: Dictionary):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
# sent by user
|
# sent by user
|
||||||
|
if not message.author is User:
|
||||||
|
message.author = User.new(client, message.author)
|
||||||
|
else:
|
||||||
assert(message.author is User, 'author attribute of Mesage must be of type User')
|
assert(message.author is User, 'author attribute of Mesage must be of type User')
|
||||||
author = message.author
|
author = message.author
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -785,13 +785,9 @@ func _handle_events(dict: Dictionary) -> void:
|
||||||
if d.sticker_items.size() != 0:
|
if d.sticker_items.size() != 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
var coroutine = await _parse_message(d)
|
await _parse_message(d)
|
||||||
if coroutine == null:
|
|
||||||
# message might be a thread
|
|
||||||
# TODO: Handle sending messages in threads
|
|
||||||
return
|
|
||||||
|
|
||||||
d = Message.new(d)
|
d = Message.new(d, self)
|
||||||
|
|
||||||
var channel = channels.get(str(d.channel_id))
|
var channel = channels.get(str(d.channel_id))
|
||||||
message_create.emit(self, d, channel)
|
message_create.emit(self, d, channel)
|
||||||
|
|
@ -1222,6 +1218,10 @@ func _setup_heartbeat_timer(interval: int) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _send_dict_wss(d: Dictionary) -> void:
|
func _send_dict_wss(d: Dictionary) -> void:
|
||||||
|
if _client.get_ready_state() != WebSocketPeer.STATE_OPEN:
|
||||||
|
if VERBOSE:
|
||||||
|
print("Failed to send packet as websocket state is not open. Got state: " + str(_client.get_ready_state()))
|
||||||
|
return
|
||||||
var payload = JSON.stringify(d)
|
var payload = JSON.stringify(d)
|
||||||
var err = _client.put_packet(payload.to_utf8_buffer())
|
var err = _client.put_packet(payload.to_utf8_buffer())
|
||||||
if OK != err:
|
if OK != err:
|
||||||
|
|
@ -1294,11 +1294,7 @@ func _parse_message(message):
|
||||||
channel = await _get_dm_channel(message.channel_id)
|
channel = await _get_dm_channel(message.channel_id)
|
||||||
_clean_channel(channel)
|
_clean_channel(channel)
|
||||||
|
|
||||||
if channel and channel.has('type') and channel.type == 'DM':
|
|
||||||
channels[str(message.channel_id)] = channel
|
channels[str(message.channel_id)] = channel
|
||||||
else:
|
|
||||||
# not a valid channel, it might be a thread
|
|
||||||
return null
|
|
||||||
|
|
||||||
if message.has('author') and typeof(message.author) == TYPE_DICTIONARY:
|
if message.has('author') and typeof(message.author) == TYPE_DICTIONARY:
|
||||||
# get the cached author of the message
|
# get the cached author of the message
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,5 @@
|
||||||
name="discord.gd"
|
name="discord.gd"
|
||||||
description="A Discord bot API wrapper for Godot."
|
description="A Discord bot API wrapper for Godot."
|
||||||
author="Delano Lourenco"
|
author="Delano Lourenco"
|
||||||
version="2.0.0"
|
version="2.0.1"
|
||||||
script="plugin.gd"
|
script="plugin.gd"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue