Skip to content

Commit

Permalink
Discord: Allow changing presence status
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jun 11, 2021
1 parent fdf5379 commit 7cf4748
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 4 additions & 3 deletions MCGalaxy/Modules/Relay/Discord/DiscordBot.cs
Expand Up @@ -55,7 +55,8 @@ public sealed class DiscordBot : RelayBot {
protected override void DoConnect() {
socket = new DiscordWebsocket();
socket.Token = Config.BotToken;
socket.GetStatus = GetStatus;
socket.Status = Config.Status;
socket.GetStatus = GetStatusMessage;

socket.OnReady = HandleReadyEvent;
socket.OnMessageCreate = HandleMessageEvent;
Expand Down Expand Up @@ -197,9 +198,9 @@ public sealed class DiscordBot : RelayBot {
return sb.ToString();
}

string GetStatus() {
string GetStatusMessage() {
string online = PlayerInfo.NonHiddenCount().ToString();
return Config.Status.Replace("{PLAYERS}", online);
return Config.StatusMessage.Replace("{PLAYERS}", online);
}

void UpdateDiscordStatus() {
Expand Down
7 changes: 6 additions & 1 deletion MCGalaxy/Modules/Relay/Discord/DiscordPlugin.cs
Expand Up @@ -28,7 +28,7 @@ public sealed class DiscordConfig {
[ConfigString("bot-token", null, "", true)]
public string BotToken = "";
[ConfigString("status-message", null, "with {PLAYERS} players")]
public string Status = "with {PLAYERS} players";
public string StatusMessage = "with {PLAYERS} players";
[ConfigBool("use-nicknames", null, true)]
public bool UseNicks = true;

Expand All @@ -39,6 +39,9 @@ public sealed class DiscordConfig {
[ConfigString("ignored-user-ids", null, "", true)]
public string IgnoredUsers = "";

[ConfigEnum("presence-status", null, PresenceStatus.online, typeof(PresenceStatus))]
public PresenceStatus Status = PresenceStatus.online;

const string file = "properties/discordbot.properties";
static ConfigElement[] cfg;

Expand All @@ -56,6 +59,8 @@ public sealed class DiscordConfig {
}
}

public enum PresenceStatus { online, dnd, idle, invisible }

public sealed class DiscordPlugin : Plugin {
public override string creator { get { return Server.SoftwareName + " team"; } }
public override string MCGalaxy_Version { get { return Server.Version; } }
Expand Down
4 changes: 3 additions & 1 deletion MCGalaxy/Modules/Relay/Discord/DiscordWebsocket.cs
Expand Up @@ -34,6 +34,8 @@ public sealed class DiscordWebsocket : ClientWebSocket {

/// <summary> Authorisation token for the bot account </summary>
public string Token;
/// <summary> Presence status (E.g. online) </summary>
public PresenceStatus Status;
/// <summary> Callback function to retrieve the activity status message </summary>
public Func<string> GetStatus;
public bool CanReconnect = true;
Expand Down Expand Up @@ -237,7 +239,7 @@ public sealed class DiscordWebsocket : ClientWebSocket {
{
{ "since", null },
{ "activities", new JsonArray() { activity } },
{ "status", "online" },
{ "status", Status.ToString() },
{ "afk", false }
};
return obj;
Expand Down

0 comments on commit 7cf4748

Please sign in to comment.