PluralRichPresence/PluralRichPresnce/Program.cs
2023-10-17 21:04:18 +13:00

52 lines
1.6 KiB
C#

using DiscordRPC;
using DiscordRPC.Logging;
using Newtonsoft.Json;
using PluralRichPresence.SimplyPlural;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Net.WebSockets;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
namespace PluralRichPresence
{
internal class Program
{
private static ManualResetEvent waitHandle = new ManualResetEvent(false);
private static DiscordRPC discordRpc = new DiscordRPC();
public static System system;
public static async Task UpdateFronterStatus()
{
// get fronting members
Member[] frontingMembers = await system.GetCurrentFronterInfo();
if (frontingMembers.Length > 0)
{
Member fronter = frontingMembers.First();
discordRpc.SetFronter(fronter.Name, fronter.Pronouns, (fronter.AvatarURL is null) ? "plural" : fronter.AvatarURL);
}
else
{
discordRpc.SetFronter("No one is fronting.", "This doesn't make much sense?", "plural");
}
}
public static void Main(string[] args)
{
system = new System(ConfigReader.ReadString("SIMPLY_PLURAL_TOKEN"));
system.FronterChanged += onFronterChanged;
_ = UpdateFronterStatus();
waitHandle.WaitOne();
}
private static void onFronterChanged(object? sender, EventArgs e)
{
_ = UpdateFronterStatus();
}
}
}