Merge branch 'main' of https://github.com/vaporvee/discord-sdk-godot into get-variables-directly-from-sdk
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -9,6 +9,8 @@ func _ready():
|
|||||||
discord_sdk.connect("activity_spectate",_on_activity_spectate)
|
discord_sdk.connect("activity_spectate",_on_activity_spectate)
|
||||||
download_texture("https://cdn.discordapp.com/embed/avatars/1.png", "res://discord_pfp_cache/invitepfp.png")
|
download_texture("https://cdn.discordapp.com/embed/avatars/1.png", "res://discord_pfp_cache/invitepfp.png")
|
||||||
debug_text_update()
|
debug_text_update()
|
||||||
|
print(discord_sdk.get_current_user())
|
||||||
|
|
||||||
func download_texture(url, file_name):
|
func download_texture(url, file_name):
|
||||||
$user_request_avatar/HTTPRequest.download_file = file_name
|
$user_request_avatar/HTTPRequest.download_file = file_name
|
||||||
invite_pfp = file_name
|
invite_pfp = file_name
|
||||||
@@ -30,6 +32,7 @@ func set_activity():
|
|||||||
discord_sdk.small_image = "boss"
|
discord_sdk.small_image = "boss"
|
||||||
discord_sdk.small_image_text = "Fighting the end boss! D:"
|
discord_sdk.small_image_text = "Fighting the end boss! D:"
|
||||||
discord_sdk.end_timestamp = int(Time.get_unix_time_from_system()) + 3600 # +1 hour in unix time
|
discord_sdk.end_timestamp = int(Time.get_unix_time_from_system()) + 3600 # +1 hour in unix time
|
||||||
|
print(discord_sdk.get_is_overlay_enabled())
|
||||||
|
|
||||||
# It is NOT recommended to manage secrets locally! It's meant to be a payload wich the server
|
# It is NOT recommended to manage secrets locally! It's meant to be a payload wich the server
|
||||||
# understands and returns the other variables like current_party_size, party_id etc. Most of the values must differ from the others.
|
# understands and returns the other variables like current_party_size, party_id etc. Most of the values must differ from the others.
|
||||||
@@ -44,7 +47,7 @@ func set_activity():
|
|||||||
discord_sdk.is_public_party = true
|
discord_sdk.is_public_party = true
|
||||||
discord_sdk.instanced = true #required for spectate
|
discord_sdk.instanced = true #required for spectate
|
||||||
#discord_sdk.start_timestamp = int(Time.get_unix_time_from_system())
|
#discord_sdk.start_timestamp = int(Time.get_unix_time_from_system())
|
||||||
#discord_sdk.register_command("steam://rungameid/1389990")
|
discord_sdk.register_command("C:\\Users\\yanni\\Desktop\\demo\\discord_sdk.exe")
|
||||||
#discord_sdk.register_steam(1389990)
|
#discord_sdk.register_steam(1389990)
|
||||||
discord_sdk.refresh()
|
discord_sdk.refresh()
|
||||||
|
|
||||||
@@ -91,3 +94,7 @@ func _on_line_edit_text_submitted(new_text):
|
|||||||
func _on_line_edit_2_text_submitted(new_text):
|
func _on_line_edit_2_text_submitted(new_text):
|
||||||
discord_sdk.accept_invite(int(new_text))
|
discord_sdk.accept_invite(int(new_text))
|
||||||
print(int(new_text))
|
print(int(new_text))
|
||||||
|
|
||||||
|
|
||||||
|
func _on_button_2_pressed():
|
||||||
|
print(discord_sdk.get_current_user())
|
||||||
|
@@ -138,8 +138,19 @@ grow_horizontal = 2
|
|||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
placeholder_text = "Accept Invite with user_id here"
|
placeholder_text = "Accept Invite with user_id here"
|
||||||
|
|
||||||
|
[node name="Button2" type="Button" parent="."]
|
||||||
|
anchors_preset = 4
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_top = -4.0
|
||||||
|
offset_right = 136.0
|
||||||
|
offset_bottom = 29.0
|
||||||
|
grow_vertical = 2
|
||||||
|
text = "Get current user"
|
||||||
|
|
||||||
[connection signal="toggled" from="CheckButton" to="." method="_on_check_button_toggled"]
|
[connection signal="toggled" from="CheckButton" to="." method="_on_check_button_toggled"]
|
||||||
[connection signal="request_completed" from="user_request_avatar/HTTPRequest" to="." method="_on_http_request_request_completed"]
|
[connection signal="request_completed" from="user_request_avatar/HTTPRequest" to="." method="_on_http_request_request_completed"]
|
||||||
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
|
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
|
||||||
[connection signal="text_submitted" from="LineEdit" to="." method="_on_line_edit_text_submitted"]
|
[connection signal="text_submitted" from="LineEdit" to="." method="_on_line_edit_text_submitted"]
|
||||||
[connection signal="text_submitted" from="LineEdit2" to="." method="_on_line_edit_2_text_submitted"]
|
[connection signal="text_submitted" from="LineEdit2" to="." method="_on_line_edit_2_text_submitted"]
|
||||||
|
[connection signal="pressed" from="Button2" to="." method="_on_button_2_pressed"]
|
||||||
|
@@ -44,4 +44,5 @@ paths=["res://example.gdextension"]
|
|||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
|
renderer/rendering_method="gl_compatibility"
|
||||||
environment/defaults/default_environment="res://default_env.tres"
|
environment/defaults/default_environment="res://default_env.tres"
|
||||||
|
@@ -93,6 +93,17 @@ void discord_sdk::_bind_methods()
|
|||||||
ClassDB::bind_method(D_METHOD("send_invite", "user_id", "is_spectate", "message_content"), &discord_sdk::send_invite);
|
ClassDB::bind_method(D_METHOD("send_invite", "user_id", "is_spectate", "message_content"), &discord_sdk::send_invite);
|
||||||
ClassDB::bind_method(D_METHOD("accept_invite", "user_id"), &discord_sdk::accept_invite);
|
ClassDB::bind_method(D_METHOD("accept_invite", "user_id"), &discord_sdk::accept_invite);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_current_user"), &discord_sdk::get_current_user);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_is_overlay_enabled"), &discord_sdk::get_is_overlay_enabled);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_is_overlay_locked"), &discord_sdk::get_is_overlay_locked);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_is_overlay_locked", "is_overlay_locked"), &discord_sdk::set_is_overlay_locked);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_overlay_locked"), "set_is_overlay_locked", "get_is_overlay_locked");
|
||||||
|
ClassDB::bind_method(D_METHOD("open_invite_overlay", "is_spectate"), &discord_sdk::open_invite_overlay);
|
||||||
|
ClassDB::bind_method(D_METHOD("open_server_invite_overlay", "invite_code"), &discord_sdk::open_server_invite_overlay);
|
||||||
|
ClassDB::bind_method(D_METHOD("open_voice_settings"), &discord_sdk::open_voice_settings);
|
||||||
|
ADD_SIGNAL(MethodInfo("overlay_toggle", PropertyInfo(Variant::BOOL, "is_locked")));
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_is_discord_working"), &discord_sdk::get_is_discord_working);
|
ClassDB::bind_method(D_METHOD("get_is_discord_working"), &discord_sdk::get_is_discord_working);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_result_int"), &discord_sdk::get_result_int);
|
ClassDB::bind_method(D_METHOD("get_result_int"), &discord_sdk::get_result_int);
|
||||||
@@ -120,9 +131,7 @@ discord_sdk::~discord_sdk()
|
|||||||
void discord_sdk::coreupdate()
|
void discord_sdk::coreupdate()
|
||||||
{
|
{
|
||||||
if (result == discord::Result::Ok && app_id > 0)
|
if (result == discord::Result::Ok && app_id > 0)
|
||||||
{
|
|
||||||
::core->RunCallbacks();
|
::core->RunCallbacks();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void discord_sdk::debug()
|
void discord_sdk::debug()
|
||||||
{
|
{
|
||||||
@@ -149,6 +158,10 @@ void discord_sdk::set_app_id(int64_t value)
|
|||||||
|
|
||||||
if (result == discord::Result::Ok && app_id > 0)
|
if (result == discord::Result::Ok && app_id > 0)
|
||||||
{
|
{
|
||||||
|
// initialize currentuser stuff
|
||||||
|
core->UserManager().OnCurrentUserUpdate.Connect([]()
|
||||||
|
{discord::User user{};
|
||||||
|
core->UserManager().GetCurrentUser(&user); });
|
||||||
// signals
|
// signals
|
||||||
core->ActivityManager().OnActivityJoin.Connect([](const char *secret)
|
core->ActivityManager().OnActivityJoin.Connect([](const char *secret)
|
||||||
{ discord_sdk::get_singleton()
|
{ discord_sdk::get_singleton()
|
||||||
@@ -170,6 +183,10 @@ void discord_sdk::set_app_id(int64_t value)
|
|||||||
user_requesting.make_read_only();
|
user_requesting.make_read_only();
|
||||||
discord_sdk::get_singleton()
|
discord_sdk::get_singleton()
|
||||||
->emit_signal("activity_join_request",user_requesting); });
|
->emit_signal("activity_join_request",user_requesting); });
|
||||||
|
|
||||||
|
core->OverlayManager().OnToggle.Connect([](bool is_locked)
|
||||||
|
{ discord_sdk::get_singleton()
|
||||||
|
->emit_signal("overlay_toggle", is_locked); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int64_t discord_sdk::get_app_id()
|
int64_t discord_sdk::get_app_id()
|
||||||
@@ -357,11 +374,46 @@ bool discord_sdk::get_instanced()
|
|||||||
return instanced;
|
return instanced;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool discord_sdk::get_is_overlay_enabled()
|
||||||
|
{
|
||||||
|
bool ie;
|
||||||
|
if (result == discord::Result::Ok && app_id > 0)
|
||||||
|
core->OverlayManager().IsEnabled(&ie);
|
||||||
|
return ie;
|
||||||
|
}
|
||||||
|
bool discord_sdk::get_is_overlay_locked()
|
||||||
|
{
|
||||||
|
bool il;
|
||||||
|
if (result == discord::Result::Ok && app_id > 0)
|
||||||
|
core->OverlayManager().IsLocked(&il);
|
||||||
|
return il;
|
||||||
|
}
|
||||||
|
void discord_sdk::set_is_overlay_locked(bool value)
|
||||||
|
{
|
||||||
|
is_overlay_locked = value;
|
||||||
|
if (result == discord::Result::Ok && app_id > 0)
|
||||||
|
core->OverlayManager().SetLocked(value, {});
|
||||||
|
}
|
||||||
|
void discord_sdk::open_invite_overlay(bool is_spectate)
|
||||||
|
{
|
||||||
|
if (result == discord::Result::Ok && app_id > 0)
|
||||||
|
core->OverlayManager().OpenActivityInvite(static_cast<discord::ActivityActionType>(is_spectate + 1), {});
|
||||||
|
}
|
||||||
|
void discord_sdk::open_server_invite_overlay(String invite_code)
|
||||||
|
{
|
||||||
|
if (result == discord::Result::Ok && app_id > 0)
|
||||||
|
core->OverlayManager().OpenGuildInvite(invite_code.utf8().get_data(), {});
|
||||||
|
}
|
||||||
|
void discord_sdk::open_voice_settings()
|
||||||
|
{
|
||||||
|
if (result == discord::Result::Ok && app_id > 0)
|
||||||
|
core->OverlayManager().OpenVoiceSettings({});
|
||||||
|
}
|
||||||
|
|
||||||
void discord_sdk::set_is_public_party(bool value)
|
void discord_sdk::set_is_public_party(bool value)
|
||||||
{
|
{
|
||||||
is_public_party = value;
|
is_public_party = value;
|
||||||
if (result == discord::Result::Ok && app_id > 0)
|
activity.GetParty().SetPrivacy(static_cast<discord::ActivityPartyPrivacy>(value)); // normaly true
|
||||||
activity.GetParty().SetPrivacy(static_cast<discord::ActivityPartyPrivacy>(value)); // normaly true
|
|
||||||
}
|
}
|
||||||
bool discord_sdk::get_is_public_party()
|
bool discord_sdk::get_is_public_party()
|
||||||
{
|
{
|
||||||
@@ -394,6 +446,26 @@ void discord_sdk::register_steam(int32_t value)
|
|||||||
if (result == discord::Result::Ok && app_id > 0)
|
if (result == discord::Result::Ok && app_id > 0)
|
||||||
core->ActivityManager().RegisterSteam(value);
|
core->ActivityManager().RegisterSteam(value);
|
||||||
}
|
}
|
||||||
|
Dictionary discord_sdk::get_current_user()
|
||||||
|
{
|
||||||
|
Dictionary userdict;
|
||||||
|
if (result == discord::Result::Ok && app_id > 0)
|
||||||
|
{
|
||||||
|
discord::User user{};
|
||||||
|
core->UserManager().GetCurrentUser(&user);
|
||||||
|
userdict["avatar"] = user.GetAvatar(); // can be empty when user has no avatar
|
||||||
|
userdict["is_bot"] = user.GetBot();
|
||||||
|
userdict["discriminator"] = user.GetDiscriminator();
|
||||||
|
userdict["id"] = user.GetId();
|
||||||
|
userdict["username"] = user.GetUsername();
|
||||||
|
if (String(userdict["avatar"]).is_empty())
|
||||||
|
userdict["avatar_url"] = String(std::string("https://cdn.discordapp.com/embed/avatars/" + std::to_string((userdict["discriminator"].INT % 5) - 1) + ".png").c_str());
|
||||||
|
else
|
||||||
|
userdict["avatar_url"] = String(std::string("https://cdn.discordapp.com/avatars/" + std::to_string(user.GetId()) + "/" + user.GetAvatar() + ".png?size=512").c_str());
|
||||||
|
userdict.make_read_only();
|
||||||
|
}
|
||||||
|
return userdict;
|
||||||
|
}
|
||||||
|
|
||||||
bool discord_sdk::get_is_discord_working()
|
bool discord_sdk::get_is_discord_working()
|
||||||
{
|
{
|
||||||
|
@@ -42,6 +42,8 @@ private:
|
|||||||
|
|
||||||
bool instanced;
|
bool instanced;
|
||||||
|
|
||||||
|
bool is_overlay_locked;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static discord_sdk *
|
static discord_sdk *
|
||||||
get_singleton();
|
get_singleton();
|
||||||
@@ -95,6 +97,13 @@ public:
|
|||||||
bool get_instanced();
|
bool get_instanced();
|
||||||
void set_instanced(bool value);
|
void set_instanced(bool value);
|
||||||
|
|
||||||
|
bool get_is_overlay_enabled();
|
||||||
|
bool get_is_overlay_locked();
|
||||||
|
void set_is_overlay_locked(bool value);
|
||||||
|
void open_invite_overlay(bool is_spectate);
|
||||||
|
void open_server_invite_overlay(String invite_code);
|
||||||
|
void open_voice_settings();
|
||||||
|
|
||||||
void accept_join_request(int64_t user_id);
|
void accept_join_request(int64_t user_id);
|
||||||
void send_invite(int64_t user_id, bool is_spectate, String message_content);
|
void send_invite(int64_t user_id, bool is_spectate, String message_content);
|
||||||
void accept_invite(int64_t user_id);
|
void accept_invite(int64_t user_id);
|
||||||
@@ -102,6 +111,9 @@ public:
|
|||||||
void register_command(String value);
|
void register_command(String value);
|
||||||
void register_steam(int32_t value);
|
void register_steam(int32_t value);
|
||||||
|
|
||||||
|
Dictionary get_current_user();
|
||||||
|
void set_current_user(Dictionary value);
|
||||||
|
|
||||||
bool get_is_discord_working();
|
bool get_is_discord_working();
|
||||||
int get_result_int();
|
int get_result_int();
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user