1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-09 16:24:42 +00:00
Funkin/source/Discord.hx

93 lines
2 KiB
Haxe
Raw Normal View History

2021-02-26 12:27:32 +00:00
package;
import Sys.sleep;
2021-02-26 12:27:32 +00:00
using StringTools;
2021-03-31 17:08:55 +00:00
#if discord_rpc
import discord_rpc.DiscordRpc;
#end
2021-02-26 12:27:32 +00:00
class DiscordClient
{
2021-03-31 17:08:55 +00:00
#if discord_rpc
2021-02-26 12:27:32 +00:00
public function new()
{
trace("Discord Client starting...");
DiscordRpc.start({
clientID: "814588678700924999",
onReady: onReady,
onError: onError,
onDisconnected: onDisconnected
});
trace("Discord Client started.");
while (true)
{
DiscordRpc.process();
sleep(2);
2021-03-31 17:08:55 +00:00
// trace("Discord Client Update");
2021-02-26 12:27:32 +00:00
}
DiscordRpc.shutdown();
}
2021-04-02 21:37:58 +00:00
public static function shutdown()
{
DiscordRpc.shutdown();
}
2021-02-26 12:27:32 +00:00
static function onReady()
{
DiscordRpc.presence({
details: "In the Menus",
state: null,
largeImageKey: 'icon',
largeImageText: "Friday Night Funkin'"
});
}
static function onError(_code:Int, _message:String)
{
trace('Error! $_code : $_message');
}
static function onDisconnected(_code:Int, _message:String)
{
trace('Disconnected! $_code : $_message');
}
public static function initialize()
{
var DiscordDaemon = sys.thread.Thread.create(() ->
{
new DiscordClient();
});
trace("Discord Client initialized");
}
2021-03-31 17:08:55 +00:00
public static function changePresence(details:String, state:Null<String>, ?smallImageKey:String, ?hasStartTimestamp:Bool, ?endTimestamp:Float)
2021-02-26 12:27:32 +00:00
{
2021-03-31 17:08:55 +00:00
var startTimestamp:Float = if (hasStartTimestamp) Date.now().getTime() else 0;
if (endTimestamp > 0)
{
endTimestamp = startTimestamp + endTimestamp;
}
2021-02-26 12:27:32 +00:00
DiscordRpc.presence({
details: details,
state: state,
largeImageKey: 'icon',
2021-02-27 19:58:07 +00:00
largeImageText: "Friday Night Funkin'",
2021-03-31 17:08:55 +00:00
smallImageKey: smallImageKey,
// Obtained times are in milliseconds so they are divided so Discord can use it
2021-03-31 17:08:55 +00:00
startTimestamp: Std.int(startTimestamp / 1000),
endTimestamp: Std.int(endTimestamp / 1000)
2021-02-26 12:27:32 +00:00
});
2021-03-31 17:08:55 +00:00
// trace('Discord RPC Updated. Arguments: $details, $state, $smallImageKey, $hasStartTimestamp, $endTimestamp');
2021-02-26 12:27:32 +00:00
}
2021-03-31 17:08:55 +00:00
#end
2021-02-26 12:27:32 +00:00
}