diff --git a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll index cd6aa06..48cb7c8 100644 Binary files a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll and b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding.dll differ diff --git a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll index 7dc2112..f5e76f6 100644 Binary files a/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll and b/project/addons/discord-sdk-gd/bin/windows/discord_game_sdk_binding_debug.dll differ diff --git a/project/addons/discord-sdk-gd/nodes/Debug.tscn b/project/addons/discord-sdk-gd/nodes/Debug.tscn index 2b2acb9..7b39f88 100644 --- a/project/addons/discord-sdk-gd/nodes/Debug.tscn +++ b/project/addons/discord-sdk-gd/nodes/Debug.tscn @@ -67,11 +67,12 @@ func _on_print_current_user_on_console_pressed(): func _on_toggle_sdk_toggled(button_pressed): if(button_pressed): - debug_text_update() discord_sdk.unclear() else: discord_sdk.clear() - debug_text_update() + +func _on_print_friends_pressed(): + print(discord_sdk.get_all_relationships()) " [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_8abo6"] @@ -163,21 +164,33 @@ anchors_preset = 4 anchor_top = 0.5 anchor_bottom = 0.5 offset_left = 12.0 -offset_top = 156.375 +offset_top = 138.375 offset_right = 245.0 -offset_bottom = 189.375 +offset_bottom = 171.375 grow_vertical = 2 text = "Print current user on console" +[node name="PrintFriends" type="Button" parent="Panel"] +layout_mode = 1 +anchors_preset = 4 +anchor_top = 0.5 +anchor_bottom = 0.5 +offset_left = 12.0 +offset_top = 176.5 +offset_right = 204.0 +offset_bottom = 207.5 +grow_vertical = 2 +text = "Print friends on console" + [node name="AcceptJoinRequest" type="Button" parent="Panel"] layout_mode = 1 anchors_preset = 4 anchor_top = 0.5 anchor_bottom = 0.5 offset_left = 12.0 -offset_top = 193.875 +offset_top = 212.875 offset_right = 154.0 -offset_bottom = 224.875 +offset_bottom = 243.875 grow_vertical = 2 text = "ACCEPT REQUEST" @@ -187,9 +200,9 @@ anchors_preset = 4 anchor_top = 0.5 anchor_bottom = 0.5 offset_left = 11.0 -offset_top = 230.375 +offset_top = 250.375 offset_right = 210.0 -offset_bottom = 261.375 +offset_bottom = 281.375 grow_vertical = 2 size_flags_horizontal = 0 placeholder_text = "Invite with user_id here" @@ -200,9 +213,9 @@ anchors_preset = 4 anchor_top = 0.5 anchor_bottom = 0.5 offset_left = 11.0 -offset_top = 265.875 +offset_top = 286.875 offset_right = 260.0 -offset_bottom = 296.875 +offset_bottom = 317.875 grow_vertical = 2 placeholder_text = "Accept Invite with user_id here" @@ -246,6 +259,7 @@ libraries = { } [connection signal="pressed" from="Panel/PrintCurrentUserOnConsole" to="." method="_on_print_current_user_on_console_pressed"] +[connection signal="pressed" from="Panel/PrintFriends" to="." method="_on_print_friends_pressed"] [connection signal="pressed" from="Panel/AcceptJoinRequest" to="." method="_on_accept_join_request_pressed"] [connection signal="text_submitted" from="Panel/InviteWithUserID" to="." method="_on_invite_with_user_id_text_submitted"] [connection signal="text_submitted" from="Panel/AcceptWithUserID" to="." method="_on_accept_with_user_id_text_submitted"] diff --git a/project/addons/discord-sdk-gd/nodes/assets/Group_1.svg b/project/addons/discord-sdk-gd/nodes/assets/Group_1.svg deleted file mode 100644 index d01f59d..0000000 --- a/project/addons/discord-sdk-gd/nodes/assets/Group_1.svg +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/project/addons/discord-sdk-gd/nodes/assets/Group_1.svg.import b/project/addons/discord-sdk-gd/nodes/assets/Group_1.svg.import deleted file mode 100644 index 69adaea..0000000 --- a/project/addons/discord-sdk-gd/nodes/assets/Group_1.svg.import +++ /dev/null @@ -1,37 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://c70jidlptani4" -path="res://.godot/imported/Group_1.svg-8cf36058739c5884a9a47a4dfa7d001a.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://addons/discord-sdk-gd/nodes/assets/Group_1.svg" -dest_files=["res://.godot/imported/Group_1.svg-8cf36058739c5884a9a47a4dfa7d001a.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 -svg/scale=1.0 -editor/scale_with_editor_scale=false -editor/convert_colors_with_editor_theme=false diff --git a/project/main.gd b/project/main.gd index c8fba9a..ca2fc32 100644 --- a/project/main.gd +++ b/project/main.gd @@ -1,11 +1,12 @@ extends Node func _ready() -> void: - print(discord_sdk.get_current_user()) set_activity() discord_sdk.connect("activity_join_request",_on_activity_join_request) discord_sdk.connect("activity_join",_on_activity_join) discord_sdk.connect("activity_spectate",_on_activity_spectate) + discord_sdk.connect("relationships_init",_on_relationship_init) + discord_sdk.connect("updated_relationship", _on_updated_relationship) func set_activity() -> void: discord_sdk.clear() @@ -19,8 +20,8 @@ func set_activity() -> void: 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 - # 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. + # 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. var my_secret: String = str(randi_range(0,999999)) discord_sdk.party_id = "mylobbycanbeeverything_" + my_secret @@ -53,3 +54,10 @@ func _on_activity_join(secret) -> void: func _on_activity_spectate(secret) -> void: print(secret) + +func _on_relationship_init(): + print("initialized") + +func _on_updated_relationship(relationship): + print(relationship) + diff --git a/src/discordgodot.cpp b/src/discordgodot.cpp index eb28d2a..817a830 100644 --- a/src/discordgodot.cpp +++ b/src/discordgodot.cpp @@ -83,6 +83,9 @@ void discord_sdk::_bind_methods() ADD_SIGNAL(MethodInfo("activity_spectate", PropertyInfo(Variant::STRING, "spectate_secret"))); ADD_SIGNAL(MethodInfo("activity_join_request", PropertyInfo(Variant::DICTIONARY, "user_requesting"))); + ADD_SIGNAL(MethodInfo("relationships_init")); + ADD_SIGNAL(MethodInfo("updated_relationship", PropertyInfo(Variant::DICTIONARY, "relationship"))); + ClassDB::bind_method(D_METHOD("refresh"), &discord_sdk::refresh); ClassDB::bind_method(D_METHOD("clear", "reset_values"), &discord_sdk::clear, DEFVAL(false)); ClassDB::bind_method(D_METHOD("unclear"), &discord_sdk::unclear); @@ -95,6 +98,7 @@ void discord_sdk::_bind_methods() 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_all_relationships"), &discord_sdk::get_all_relationships); 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); @@ -173,23 +177,18 @@ void discord_sdk::set_app_id(int64_t value) { discord_sdk::get_singleton() ->emit_signal("activity_spectate", secret); }); core->ActivityManager().OnActivityJoinRequest.Connect([this](discord::User const &user) - { Dictionary user_requesting; - user_requesting["avatar"] = user.GetAvatar(); //can be empty when user has no avatar - user_requesting["is_bot"] = user.GetBot(); - user_requesting["discriminator"] = user.GetDiscriminator(); - user_requesting["id"] = user.GetId(); - user_requesting["username"] = user.GetUsername(); - if(String(user_requesting["avatar"]).is_empty()) - user_requesting["avatar_url"] = String(std::string("https://cdn.discordapp.com/embed/avatars/" + std::to_string((user_requesting["discriminator"].INT % 5) - 1)+ ".png").c_str()); - else - user_requesting["avatar_url"] = String(std::string("https://cdn.discordapp.com/avatars/" + std::to_string(user.GetId()) + "/" + user.GetAvatar() + ".png?size=512").c_str());//I don't know what the hell i did there but removing ?size=512 will crash the whole editor - user_requesting.make_read_only(); - discord_sdk::get_singleton() - ->emit_signal("activity_join_request",user_requesting); }); + { discord_sdk::get_singleton() + ->emit_signal("activity_join_request", user2dict(user)); }); core->OverlayManager().OnToggle.Connect([](bool is_locked) { discord_sdk::get_singleton() ->emit_signal("overlay_toggle", is_locked); }); + core->RelationshipManager().OnRefresh.Connect([&]() + { discord_sdk::get_singleton() + ->emit_signal("relationships_init"); }); + core->RelationshipManager().OnRelationshipUpdate.Connect([&](discord::Relationship const &relationship) + { discord_sdk::get_singleton() + ->emit_signal("updated_relationship", relationship2dict(relationship)); }); } } } @@ -479,20 +478,40 @@ Dictionary discord_sdk::get_current_user() { 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").c_str()); - userdict.make_read_only(); + return user2dict(user); } return userdict; } +Dictionary discord_sdk::get_relationship(int64_t user_id) +{ + if (result == discord::Result::Ok && app_id > 0) + { + discord::Relationship relationship{}; + core->RelationshipManager().Get(user_id, &relationship); + return relationship2dict(relationship); + } + Dictionary dict; + return dict; +} + +Array discord_sdk::get_all_relationships() +{ + Array all_relationships; + core->RelationshipManager().Filter( + [](discord::Relationship const &relationship) -> bool + { return true; }); + int32_t friendcount{0}; + core->RelationshipManager().Count(&friendcount); + for (int i = 0; i < friendcount; i++) + { + discord::Relationship relationship{}; + core->RelationshipManager().GetAt(2, &relationship); + all_relationships.append(relationship2dict(relationship)); + } + return all_relationships; +} + bool discord_sdk::get_is_discord_working() { return result == discord::Result::Ok && app_id > 0; @@ -502,3 +521,91 @@ int discord_sdk::get_result_int() { return static_cast(result); } + +Dictionary discord_sdk::user2dict(discord::User user) +{ + Dictionary userdict; + 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").c_str()); + userdict.make_read_only(); + return userdict; +} + +Dictionary discord_sdk::relationship2dict(discord::Relationship relationship) +{ + Dictionary dict_relationship; + Dictionary presence; + Dictionary presence_activity; + switch (static_cast(relationship.GetPresence().GetStatus())) + { + case 0: + presence["status"] = "Offline"; + break; + case 1: + presence["status"] = "Online"; + break; + case 2: + presence["status"] = "Idle"; + break; + case 3: + presence["status"] = "DoNotDisturb"; + break; + default: + presence["status"] = "NotAvailable"; + break; + } + presence_activity["application_id"] = relationship.GetPresence().GetActivity().GetApplicationId(); + presence_activity["name"] = relationship.GetPresence().GetActivity().GetName(); + presence_activity["state"] = relationship.GetPresence().GetActivity().GetState(); + presence_activity["details"] = relationship.GetPresence().GetActivity().GetDetails(); + presence_activity["large_image"] = relationship.GetPresence().GetActivity().GetAssets().GetLargeImage(); + presence_activity["large_text"] = relationship.GetPresence().GetActivity().GetAssets().GetLargeText(); + presence_activity["small_image"] = relationship.GetPresence().GetActivity().GetAssets().GetSmallImage(); + presence_activity["small_text"] = relationship.GetPresence().GetActivity().GetAssets().GetSmallText(); + presence_activity["timestamps_start"] = relationship.GetPresence().GetActivity().GetTimestamps().GetStart(); + presence_activity["timestamps_end"] = relationship.GetPresence().GetActivity().GetTimestamps().GetEnd(); + presence_activity["instance"] = relationship.GetPresence().GetActivity().GetInstance(); + presence_activity["party_id"] = relationship.GetPresence().GetActivity().GetParty().GetId(); + presence_activity["current_party_size"] = relationship.GetPresence().GetActivity().GetParty().GetSize().GetCurrentSize(); + presence_activity["max_party_size"] = relationship.GetPresence().GetActivity().GetParty().GetSize().GetMaxSize(); + presence_activity["join_secret"] = relationship.GetPresence().GetActivity().GetSecrets().GetJoin(); + presence_activity["spectate_secret"] = relationship.GetPresence().GetActivity().GetSecrets().GetSpectate(); + presence_activity["match_secret"] = relationship.GetPresence().GetActivity().GetSecrets().GetMatch(); + presence["activity"] = presence_activity; + presence.make_read_only(); + switch (relationship.GetType()) + { + case discord::RelationshipType::None: + dict_relationship["type"] = "None"; + break; + case discord::RelationshipType::Friend: + dict_relationship["type"] = "Friend"; + break; + case discord::RelationshipType::Blocked: + dict_relationship["type"] = "Blocked"; + break; + case discord::RelationshipType::PendingIncoming: + dict_relationship["type"] = "PendingIncoming"; + break; + case discord::RelationshipType::PendingOutgoing: + dict_relationship["type"] = "PendingOutgoing"; + break; + case discord::RelationshipType::Implicit: + dict_relationship["type"] = "Implicit"; + break; + default: + dict_relationship["type"] = "NotAvailable"; + break; + } + dict_relationship["user"] = user2dict(relationship.GetUser()); + dict_relationship["presence"] = presence; + dict_relationship.make_read_only(); + return dict_relationship; +} \ No newline at end of file diff --git a/src/discordgodot.h b/src/discordgodot.h index 16dfeb2..d531790 100644 --- a/src/discordgodot.h +++ b/src/discordgodot.h @@ -17,7 +17,19 @@ class discord_sdk : public RefCounted protected: static void _bind_methods(); -private: +public: + static discord_sdk * + get_singleton(); + + discord_sdk(); + ~discord_sdk(); + + // INTERBNAL + int64_t old_app_id; + Dictionary relationship2dict(discord::Relationship relationship); + Dictionary user2dict(discord::User user); + /// + int64_t app_id = 0; String state; @@ -44,18 +56,11 @@ private: bool is_overlay_locked; -public: - static discord_sdk * - get_singleton(); - - discord_sdk(); - ~discord_sdk(); - void debug(); void coreupdate(); void refresh(); void clear(bool reset_values); - int64_t old_app_id; + void unclear(); int64_t get_app_id(); void set_app_id(int64_t value); @@ -113,6 +118,8 @@ public: void register_steam(int32_t value); Dictionary get_current_user(); + Dictionary get_relationship(int64_t user_id); + Array get_all_relationships(); bool get_is_discord_working(); int get_result_int();