|
|
@@ -14,7 +14,12 @@ namespace GamecraftRPC |
|
|
|
|
|
|
|
public string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
|
|
|
|
|
|
|
private static readonly long CLIENT_ID = 692733325902872619; |
|
|
|
private static readonly long CLIENT_ID = |
|
|
|
#if DEBUG |
|
|
|
692733325902872619; |
|
|
|
#else |
|
|
|
696732441012076605; |
|
|
|
#endif |
|
|
|
|
|
|
|
private Discord.Discord discordRPC; |
|
|
|
|
|
|
@@ -22,6 +27,11 @@ namespace GamecraftRPC |
|
|
|
public void OnApplicationQuit() |
|
|
|
{ |
|
|
|
// Shutdown this mod |
|
|
|
if (discordRPC != null) |
|
|
|
{ |
|
|
|
discordRPC.GetActivityManager().ClearActivity((result) => { GamecraftModdingAPI.Utility.Logging.LogDebug($"Cleared status: {result}"); }); |
|
|
|
discordRPC.Dispose(); |
|
|
|
} |
|
|
|
GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has shutdown"); |
|
|
|
|
|
|
|
// Shutdown the Gamecraft modding API last |
|
|
@@ -36,6 +46,18 @@ namespace GamecraftRPC |
|
|
|
|
|
|
|
// Initialize this mod |
|
|
|
discordRPC = new Discord.Discord(CLIENT_ID, (UInt64)Discord.CreateFlags.Default); |
|
|
|
discordRPC.SetLogHook(LogLevel.Debug, (_, msg) => { GamecraftModdingAPI.Utility.Logging.MetaLog(msg); }); |
|
|
|
|
|
|
|
discordRPC.GetRelationshipManager().OnRefresh += () => |
|
|
|
{ |
|
|
|
discordRPC.GetRelationshipManager().Filter((ref Relationship r) => { return r.Presence.Status == Status.Online && r.Type == RelationshipType.Friend; }); |
|
|
|
|
|
|
|
PresenceUtility.Users = new Relationship[discordRPC.GetRelationshipManager().Count()]; |
|
|
|
for (uint i = 0; i < discordRPC.GetRelationshipManager().Count(); i++) |
|
|
|
{ |
|
|
|
PresenceUtility.Users[i] = discordRPC.GetRelationshipManager().GetAt(i); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
SetDiscordActivity(discordRPC, state: "Loading...", details: "Initializing Gamecraft", start: (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds); |
|
|
|
|
|
|
@@ -50,8 +72,34 @@ namespace GamecraftRPC |
|
|
|
"Set Discord status (experimental)" // command description (displayed when help command is executed) |
|
|
|
); // this command can also be executed using the Command Computer |
|
|
|
|
|
|
|
SimpleCustomCommandEngine inviteNGniusCommand = new SimpleCustomCommandEngine(() => |
|
|
|
discordRPC.GetActivityManager().SendInvite(106537989684887552, ActivityActionType.Join, "Join the Borg", (res) => { GamecraftModdingAPI.Utility.Logging.LogDebug($"Send invite {res}"); }), |
|
|
|
"InviteNGnius", |
|
|
|
"Send a Discord lobby invite to NGnius"); |
|
|
|
SimpleCustomCommandEngine<long> inviteDiscordCommand = new SimpleCustomCommandEngine<long>((id) => |
|
|
|
discordRPC.GetActivityManager().SendInvite(id, ActivityActionType.Join, "Join the Borg", (res) => { GamecraftModdingAPI.Utility.Logging.LogDebug($"Send invite {res}"); }), |
|
|
|
"InviteDiscord", |
|
|
|
"Send a game invite to a Discord user"); |
|
|
|
SimpleCustomCommandEngine listDiscordUsersCommand = new SimpleCustomCommandEngine( |
|
|
|
() => |
|
|
|
{ |
|
|
|
string result = "Online Friends\n"; |
|
|
|
for (int i = 0; i < PresenceUtility.Users.Length; i++) |
|
|
|
{ |
|
|
|
result += $"{PresenceUtility.Users[i].User.Username} ({PresenceUtility.Users[i].User.Id})\n"; |
|
|
|
} |
|
|
|
GamecraftModdingAPI.Utility.Logging.CommandLog(result); |
|
|
|
}, |
|
|
|
"ListDiscordUsers", |
|
|
|
"List online Discord friends"); |
|
|
|
|
|
|
|
// register the command so the modding API knows about it |
|
|
|
CommandManager.AddCommand(rpcCommand); |
|
|
|
CommandManager.AddCommand(rpcCommand); |
|
|
|
CommandManager.AddCommand(inviteNGniusCommand); |
|
|
|
CommandManager.AddCommand(inviteDiscordCommand); |
|
|
|
CommandManager.AddCommand(listDiscordUsersCommand); |
|
|
|
|
|
|
|
GamecraftModdingAPI.Utility.GameEngineManager.AddGameEngine(new Engines.PlayerCountEngine(discordRPC)); |
|
|
|
|
|
|
|
GamecraftModdingAPI.Utility.Logging.LogDebug($"{Name} has started up"); |
|
|
|
} |
|
|
@@ -69,14 +117,12 @@ namespace GamecraftRPC |
|
|
|
if (discordRPC != null ) discordRPC.RunCallbacks(); |
|
|
|
} |
|
|
|
|
|
|
|
public static void SetDiscordActivity(Discord.Discord discordRPC, string state = null, string details = null, int start = 0, int end = 0, string largeImg = "gamecraft-logo-g", string largeTxt = "Gamecraft", string smallImg = "exmods-logo-xm2", string smallTxt = "Exmods", bool instance = true) |
|
|
|
public static void SetDiscordActivity(Discord.Discord discordRPC, string state = null, string details = null, int start = 0, int end = 0, string largeImg = "gamecraft-logo-g", string largeTxt = "Gamecraft", string smallImg = "exmods-logo-xm2", string smallTxt = "Exmods", string partyId = null, int partyCurrentSize = 0, int partyMaxSize = 0, string matchSecret = null, string joinSecret = null, string spectateSecret = null, bool instance = true, string debug = "") |
|
|
|
{ |
|
|
|
if (discordRPC == null) return; |
|
|
|
|
|
|
|
Activity activity = new Activity |
|
|
|
{ |
|
|
|
Instance = instance, |
|
|
|
}; |
|
|
|
ref Activity activity = ref PresenceUtility.Activity; |
|
|
|
activity.Instance = instance; |
|
|
|
|
|
|
|
if (state != null) activity.State = state; |
|
|
|
if (details != null) activity.Details = details; |
|
|
@@ -92,10 +138,39 @@ namespace GamecraftRPC |
|
|
|
activity.Assets.SmallImage = smallImg; |
|
|
|
activity.Assets.SmallText = smallTxt; |
|
|
|
} |
|
|
|
if (!string.IsNullOrEmpty(partyId)) |
|
|
|
{ |
|
|
|
activity.Party.Id = partyId; |
|
|
|
activity.Party.Size.CurrentSize = partyCurrentSize; |
|
|
|
activity.Party.Size.MaxSize = partyMaxSize; |
|
|
|
} |
|
|
|
if (!string.IsNullOrEmpty(matchSecret) || !string.IsNullOrEmpty(joinSecret) || !string.IsNullOrEmpty(spectateSecret)) |
|
|
|
{ |
|
|
|
activity.Secrets.Match = matchSecret; |
|
|
|
activity.Secrets.Join = joinSecret; |
|
|
|
activity.Secrets.Spectate = spectateSecret; |
|
|
|
} |
|
|
|
|
|
|
|
discordRPC.GetActivityManager().UpdateActivity(activity, result => |
|
|
|
{ |
|
|
|
GamecraftModdingAPI.Utility.Logging.MetaLog($"Update Activity Result: {result}"); |
|
|
|
GamecraftModdingAPI.Utility.Logging.MetaLog($"Update Activity Result: {result} {debug}"); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public static void SetDiscordActivity(Discord.Discord discordRPC, Discord.Activity activity, string debug = "") |
|
|
|
{ |
|
|
|
PresenceUtility.Activity = activity; |
|
|
|
discordRPC.GetActivityManager().UpdateActivity(PresenceUtility.Activity, result => |
|
|
|
{ |
|
|
|
GamecraftModdingAPI.Utility.Logging.MetaLog($"Update Activity Result: {result} {debug}"); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public static void SetDiscordActivity(Discord.Discord discordRPC, string debug = "") |
|
|
|
{ |
|
|
|
discordRPC.GetActivityManager().UpdateActivity(PresenceUtility.Activity, result => |
|
|
|
{ |
|
|
|
GamecraftModdingAPI.Utility.Logging.MetaLog($"Update Activity Result: {result} {debug}"); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |