mirror of
https://github.com/Ale32bit/Capy64.git
synced 2025-01-18 18:46:43 +00:00
Added Discord RPC integration
This commit is contained in:
parent
72692be21a
commit
10646eb13b
6 changed files with 82 additions and 0 deletions
|
@ -6,5 +6,11 @@
|
||||||
"Enable": true,
|
"Enable": true,
|
||||||
"MaxActiveConnections": 5
|
"MaxActiveConnections": 5
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"Integrations": {
|
||||||
|
"Discord": {
|
||||||
|
"Enable": true,
|
||||||
|
"ApplicationId": "1068654606357377074"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using static Capy64.Utils;
|
using static Capy64.Utils;
|
||||||
|
using Capy64.Integrations;
|
||||||
|
|
||||||
namespace Capy64;
|
namespace Capy64;
|
||||||
|
|
||||||
|
@ -33,6 +34,8 @@ public class Capy64 : Game, IGame
|
||||||
public Drawing Drawing { get; private set; }
|
public Drawing Drawing { get; private set; }
|
||||||
public LuaState LuaRuntime { get; set; }
|
public LuaState LuaRuntime { get; set; }
|
||||||
public EventEmitter EventEmitter { get; private set; }
|
public EventEmitter EventEmitter { get; private set; }
|
||||||
|
public DiscordIntegration Discord { get; set; }
|
||||||
|
|
||||||
public Borders Borders = new()
|
public Borders Borders = new()
|
||||||
{
|
{
|
||||||
Top = 0,
|
Top = 0,
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
<EmbeddedResource Include="Icon.bmp" />
|
<EmbeddedResource Include="Icon.bmp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="DiscordRichPresence" Version="1.1.3.18" />
|
||||||
<PackageReference Include="FontStashSharp.MonoGame" Version="1.2.8" />
|
<PackageReference Include="FontStashSharp.MonoGame" Version="1.2.8" />
|
||||||
<PackageReference Include="KeraLua" Version="1.3.3" />
|
<PackageReference Include="KeraLua" Version="1.3.3" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using Capy64.API;
|
using Capy64.API;
|
||||||
using Capy64.Core;
|
using Capy64.Core;
|
||||||
using Capy64.Eventing;
|
using Capy64.Eventing;
|
||||||
|
using Capy64.Integrations;
|
||||||
using Capy64.Runtime;
|
using Capy64.Runtime;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using System;
|
using System;
|
||||||
|
@ -27,4 +28,7 @@ public interface IGame
|
||||||
event EventHandler<EventArgs> Exiting;
|
event EventHandler<EventArgs> Exiting;
|
||||||
void Run();
|
void Run();
|
||||||
void Exit();
|
void Exit();
|
||||||
|
|
||||||
|
// Integrations
|
||||||
|
DiscordIntegration Discord { get; }
|
||||||
}
|
}
|
||||||
|
|
64
Capy64/Integrations/DiscordIntegration.cs
Normal file
64
Capy64/Integrations/DiscordIntegration.cs
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
using Capy64.API;
|
||||||
|
using DiscordRPC;
|
||||||
|
using DiscordRPC.Logging;
|
||||||
|
using DiscordRPC.Message;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Capy64.Integrations;
|
||||||
|
|
||||||
|
public class DiscordIntegration : IPlugin
|
||||||
|
{
|
||||||
|
public DiscordRpcClient Client { get; private set; }
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
|
public DiscordIntegration(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
|
||||||
|
var discordConfig = _configuration.GetSection("Integrations:Discord");
|
||||||
|
Client = new(discordConfig["ApplicationId"])
|
||||||
|
{
|
||||||
|
Logger = new ConsoleLogger() { Level = LogLevel.Warning }
|
||||||
|
};
|
||||||
|
|
||||||
|
Capy64.Instance.Discord = this;
|
||||||
|
|
||||||
|
Client.OnReady += OnReady;
|
||||||
|
Client.OnPresenceUpdate += OnPresenceUpdate;
|
||||||
|
|
||||||
|
if (discordConfig.GetValue("Enable", false))
|
||||||
|
{
|
||||||
|
Client.Initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPresence(string details, string? state = null)
|
||||||
|
{
|
||||||
|
Client.SetPresence(new RichPresence()
|
||||||
|
{
|
||||||
|
Details = details,
|
||||||
|
State = state,
|
||||||
|
Assets = new Assets()
|
||||||
|
{
|
||||||
|
LargeImageKey = "image_large",
|
||||||
|
LargeImageText = "Capy64",
|
||||||
|
SmallImageKey = "image_small"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnReady(object sender, ReadyMessage e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Received Ready from user {0}", e.User.Username);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPresenceUpdate(object sender, PresenceMessage e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Received Update! {0}", e.Presence);
|
||||||
|
}
|
||||||
|
}
|
|
@ -84,6 +84,8 @@ internal class RuntimeManager : IPlugin
|
||||||
|
|
||||||
private void InitBIOS()
|
private void InitBIOS()
|
||||||
{
|
{
|
||||||
|
_game.Discord.SetPresence("Booting up...");
|
||||||
|
|
||||||
luaState = new LuaState();
|
luaState = new LuaState();
|
||||||
_game.LuaRuntime = luaState;
|
_game.LuaRuntime = luaState;
|
||||||
|
|
||||||
|
@ -115,6 +117,8 @@ internal class RuntimeManager : IPlugin
|
||||||
|
|
||||||
private void InitOS()
|
private void InitOS()
|
||||||
{
|
{
|
||||||
|
_game.Discord.SetPresence("On CapyOS");
|
||||||
|
|
||||||
luaState = new LuaState();
|
luaState = new LuaState();
|
||||||
_game.LuaRuntime = luaState;
|
_game.LuaRuntime = luaState;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue