feat: made discord rich presence toggleable
This commit is contained in:
parent
b9672f82d6
commit
4f9b342fa8
1 changed files with 16 additions and 7 deletions
23
Program.cs
23
Program.cs
|
@ -21,6 +21,7 @@ namespace chord
|
||||||
private ulong currentSelectedChannel;
|
private ulong currentSelectedChannel;
|
||||||
private ulong currentSelectedGuild;
|
private ulong currentSelectedGuild;
|
||||||
private SortedDictionary<ulong, List<ulong>> guilds;
|
private SortedDictionary<ulong, List<ulong>> guilds;
|
||||||
|
private DiscordRpcClient rpcClient;
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
private Window window;
|
private Window window;
|
||||||
|
|
||||||
|
@ -50,9 +51,11 @@ namespace chord
|
||||||
await client.LoginAsync(TokenType.Bot, settings.Token);
|
await client.LoginAsync(TokenType.Bot, settings.Token);
|
||||||
await client.StartAsync();
|
await client.StartAsync();
|
||||||
|
|
||||||
var rpcClient = new DiscordRpcClient("923436807297859625");
|
if (settings.EnableRichPresence) {
|
||||||
rpcClient.Initialize();
|
rpcClient = new DiscordRpcClient("923436807297859625");
|
||||||
rpcClient.SetPresence(new RichPresence());
|
rpcClient.Initialize();
|
||||||
|
rpcClient.SetPresence(new RichPresence());
|
||||||
|
}
|
||||||
|
|
||||||
Application.Init();
|
Application.Init();
|
||||||
|
|
||||||
|
@ -181,7 +184,9 @@ namespace chord
|
||||||
channelListTree.AddObject(category.Value);
|
channelListTree.AddObject(category.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcClient.UpdateDetails($"Chatting in {client.GetGuild(currentSelectedGuild).Name}");
|
if (settings.EnableRichPresence) {
|
||||||
|
rpcClient.UpdateDetails($"Chatting in {client.GetGuild(currentSelectedGuild).Name}");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
channelListTree.SelectionChanged += async (arg1, arg2) =>
|
channelListTree.SelectionChanged += async (arg1, arg2) =>
|
||||||
|
@ -253,8 +258,10 @@ namespace chord
|
||||||
userListTree.AddObject(role.Value);
|
userListTree.AddObject(role.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcClient.UpdateState($"In channel {client.GetGuild(currentSelectedGuild).GetTextChannel(currentSelectedChannel).Name}");
|
if (settings.EnableRichPresence) {
|
||||||
rpcClient.UpdateStartTime();
|
rpcClient.UpdateState($"In channel {client.GetGuild(currentSelectedGuild).GetTextChannel(currentSelectedChannel).Name}");
|
||||||
|
rpcClient.UpdateStartTime();
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
await chatBoxList.SetSourceAsync(new List<string>());
|
await chatBoxList.SetSourceAsync(new List<string>());
|
||||||
}
|
}
|
||||||
|
@ -352,7 +359,8 @@ namespace chord
|
||||||
};
|
};
|
||||||
|
|
||||||
Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => {
|
Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(100), caller => {
|
||||||
rpcClient.Invoke();
|
if (settings.EnableRichPresence)
|
||||||
|
rpcClient.Invoke();
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -440,6 +448,7 @@ namespace chord
|
||||||
public class Settings
|
public class Settings
|
||||||
{
|
{
|
||||||
public string Token { get; set; }
|
public string Token { get; set; }
|
||||||
|
public bool EnableRichPresence { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GetMessagesResponse
|
public class GetMessagesResponse
|
||||||
|
|
Reference in a new issue