barebones prototype
This commit is contained in:
parent
83f340ea01
commit
b53d33584c
60 changed files with 3743 additions and 1 deletions
101
addons/discord_gd/classes/message_button.gd
Normal file
101
addons/discord_gd/classes/message_button.gd
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
class_name MessageButton
|
||||
"""
|
||||
Represents a Discord message button.
|
||||
"""
|
||||
|
||||
var _STYLES = {0: 'DEFAULT', 1: 'PRIMARY', 2: 'SECONDARY', 3: 'SUCCESS', 4: 'DANGER', 5: 'LINK'}
|
||||
|
||||
enum STYLES { DEFAULT, PRIMARY, SECONDARY, SUCCESS, DANGER, LINK }
|
||||
|
||||
var label: String: set = set_label, get = get_label
|
||||
var custom_id: String: set = set_custom_id, get = get_custom_id
|
||||
var url: String: set = set_url, get = get_url
|
||||
var disabled: bool = false: set = set_disabled, get = get_disabled
|
||||
var emoji: Dictionary
|
||||
|
||||
var _style: set = set_style
|
||||
var type: int = 2
|
||||
|
||||
|
||||
func set_style(style_number: int):
|
||||
_style = style_number
|
||||
return self
|
||||
|
||||
|
||||
func get_style_string():
|
||||
return _STYLES[_style]
|
||||
|
||||
|
||||
func set_label(new_label: String):
|
||||
assert(new_label.length() <= 80, 'label of MessageButton must be max 80 characters.')
|
||||
label = new_label
|
||||
return self
|
||||
|
||||
|
||||
func get_label() -> String:
|
||||
return label
|
||||
|
||||
|
||||
func set_custom_id(new_custom_id):
|
||||
assert(new_custom_id.length() <= 80, 'custom_id of MessageButton must be max 100 characters.')
|
||||
custom_id = new_custom_id
|
||||
return self
|
||||
|
||||
|
||||
func get_custom_id() -> String:
|
||||
return custom_id
|
||||
|
||||
|
||||
func set_url(new_url):
|
||||
url = new_url
|
||||
return self
|
||||
|
||||
|
||||
func get_url() -> String:
|
||||
return url
|
||||
|
||||
|
||||
func set_disabled(new_value: bool):
|
||||
disabled = new_value
|
||||
return self
|
||||
|
||||
|
||||
func get_disabled() -> bool:
|
||||
return disabled
|
||||
|
||||
|
||||
func set_emoji(new_emoji: Dictionary):
|
||||
emoji = new_emoji
|
||||
return self
|
||||
|
||||
func get_emoji() -> Dictionary:
|
||||
return emoji
|
||||
|
||||
|
||||
func _to_string(pretty: bool = false) -> String:
|
||||
return JSON.stringify(_to_dict(), '\t') if pretty else JSON.stringify(_to_dict())
|
||||
|
||||
|
||||
func print():
|
||||
print(_to_string(true))
|
||||
|
||||
|
||||
func _to_dict() -> Dictionary:
|
||||
# Default style is primary
|
||||
if _style == 0:
|
||||
_style = 1
|
||||
|
||||
if _style == STYLES.LINK:
|
||||
# Must have a url
|
||||
assert(Helpers.is_valid_str(url), 'A LINK MessageButton must have a url.')
|
||||
return {'type': type, 'style': _style, 'label': label, 'url': url, 'disabled': disabled}
|
||||
else:
|
||||
assert(Helpers.is_valid_str(custom_id), 'A button must have a custom_id.')
|
||||
return {
|
||||
'type': type,
|
||||
'style': _style,
|
||||
'label': label,
|
||||
'custom_id': custom_id,
|
||||
'disabled': disabled,
|
||||
'emoji': emoji if emoji else null
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue