[discord] cleanup, add helper functions
This commit is contained in:
parent
c2e3b5bfbf
commit
3cedc83bfa
11
command.c
11
command.c
|
@ -1834,9 +1834,6 @@ void command_playlist_update_write(
|
||||||
**/
|
**/
|
||||||
bool command_event(enum event_command cmd, void *data)
|
bool command_event(enum event_command cmd, void *data)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DISCORD
|
|
||||||
static bool discord_inited = false;
|
|
||||||
#endif
|
|
||||||
bool boolean = false;
|
bool boolean = false;
|
||||||
|
|
||||||
switch (cmd)
|
switch (cmd)
|
||||||
|
@ -2986,26 +2983,24 @@ TODO: Add a setting for these tweaks */
|
||||||
|
|
||||||
if (!settings->bools.discord_enable)
|
if (!settings->bools.discord_enable)
|
||||||
return false;
|
return false;
|
||||||
if (discord_inited)
|
if (discord_is_ready())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
discord_init();
|
discord_init();
|
||||||
discord_inited = true;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case CMD_EVENT_DISCORD_DEINIT:
|
case CMD_EVENT_DISCORD_DEINIT:
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
if (!discord_inited)
|
if (!discord_is_ready())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
discord_shutdown();
|
discord_shutdown();
|
||||||
discord_inited = false;
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case CMD_EVENT_DISCORD_UPDATE:
|
case CMD_EVENT_DISCORD_UPDATE:
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
if (!data || !discord_inited)
|
if (!data || !discord_is_ready())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,8 +49,6 @@
|
||||||
#include <file/file_path.h>
|
#include <file/file_path.h>
|
||||||
#include "../file_path_special.h"
|
#include "../file_path_special.h"
|
||||||
|
|
||||||
static int FrustrationLevel = 0;
|
|
||||||
|
|
||||||
static int64_t start_time = 0;
|
static int64_t start_time = 0;
|
||||||
static int64_t pause_time = 0;
|
static int64_t pause_time = 0;
|
||||||
static int64_t ellapsed_time = 0;
|
static int64_t ellapsed_time = 0;
|
||||||
|
@ -61,16 +59,33 @@ static unsigned discord_status = 0;
|
||||||
struct netplay_room *room;
|
struct netplay_room *room;
|
||||||
|
|
||||||
static char user_id[128];
|
static char user_id[128];
|
||||||
|
static char user_name[128];
|
||||||
|
static char avatar_path[PATH_MAX_LENGTH];
|
||||||
|
|
||||||
static char cdn_url[] = "https://cdn.discordapp.com/avatars";
|
static char cdn_url[] = "https://cdn.discordapp.com/avatars";
|
||||||
|
|
||||||
DiscordRichPresence discord_presence;
|
DiscordRichPresence discord_presence;
|
||||||
|
|
||||||
|
char* discord_get_own_username(void)
|
||||||
|
{
|
||||||
|
return user_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* discord_get_own_avatar(void)
|
||||||
|
{
|
||||||
|
return avatar_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool discord_is_ready()
|
||||||
|
{
|
||||||
|
return discord_ready;
|
||||||
|
}
|
||||||
|
|
||||||
static bool discord_download_avatar(const char* user_id, const char* avatar_id)
|
static bool discord_download_avatar(const char* user_id, const char* avatar_id)
|
||||||
{
|
{
|
||||||
static char url[PATH_MAX_LENGTH];
|
static char url[PATH_MAX_LENGTH];
|
||||||
static char url_encoded[PATH_MAX_LENGTH];
|
static char url_encoded[PATH_MAX_LENGTH];
|
||||||
static char fullpath[PATH_MAX_LENGTH];
|
static char avatar_path[PATH_MAX_LENGTH];
|
||||||
|
|
||||||
static char buf[PATH_MAX_LENGTH];
|
static char buf[PATH_MAX_LENGTH];
|
||||||
|
|
||||||
|
@ -79,9 +94,9 @@ static bool discord_download_avatar(const char* user_id, const char* avatar_id)
|
||||||
fill_pathname_application_special(buf,
|
fill_pathname_application_special(buf,
|
||||||
sizeof(buf),
|
sizeof(buf),
|
||||||
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_DISCORD_AVATARS);
|
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_DISCORD_AVATARS);
|
||||||
fill_pathname_join(fullpath, buf, avatar_id, sizeof(fullpath));
|
fill_pathname_join(avatar_path, buf, avatar_id, sizeof(avatar_path));
|
||||||
|
|
||||||
if(filestream_exists(fullpath))
|
if(filestream_exists(avatar_path))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -102,6 +117,7 @@ static bool discord_download_avatar(const char* user_id, const char* avatar_id)
|
||||||
|
|
||||||
static void handle_discord_ready(const DiscordUser* connectedUser)
|
static void handle_discord_ready(const DiscordUser* connectedUser)
|
||||||
{
|
{
|
||||||
|
strlcpy(user_name, connectedUser->username, sizeof(user_name));
|
||||||
RARCH_LOG("[Discord] connected to user: %s#%s - avatar id: %s\n",
|
RARCH_LOG("[Discord] connected to user: %s#%s - avatar id: %s\n",
|
||||||
connectedUser->username,
|
connectedUser->username,
|
||||||
connectedUser->discriminator,
|
connectedUser->discriminator,
|
||||||
|
|
|
@ -55,4 +55,10 @@ void discord_update(enum discord_presence presence);
|
||||||
|
|
||||||
void discord_run_callbacks();
|
void discord_run_callbacks();
|
||||||
|
|
||||||
|
bool discord_is_ready();
|
||||||
|
|
||||||
|
char* discord_get_own_username(void);
|
||||||
|
|
||||||
|
char* discord_get_own_avatar(void);
|
||||||
|
|
||||||
#endif /* __RARCH_DISCORD_H */
|
#endif /* __RARCH_DISCORD_H */
|
||||||
|
|
Loading…
Reference in New Issue