Skip to content

Commit

Permalink
Streaming presence updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
suicvne committed May 8, 2016
1 parent 02cc54c commit f131670
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
32 changes: 30 additions & 2 deletions DiscordSharp/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,15 @@ private void GetChannelsList(JObject m)
{
member.SetPresence(presence["status"].ToString());
if (!presence["game"].IsNullOrEmpty())
{
member.CurrentGame = presence["game"]["name"].ToString();
if (presence["d"]["game"]["type"].ToObject<int>() == 1)
{
member.Streaming = true;
if (presence["d"]["game"]["url"].ToString() != null)
member.StreamURL = presence["d"]["game"]["url"].ToString();
}
}
}
}
}
Expand Down Expand Up @@ -881,7 +889,9 @@ private DiscordMessage SendActualMessage(string id, string message, DiscordMembe
/// Updates the bot's 'Currently playing' status to the following text. Pass in null if you want to remove this.
/// </summary>
/// <param name="gameName">The game's name. Old gameid lookup can be seen at: http://hastebin.com/azijiyaboc.json/ </param>
public void UpdateCurrentGame(string gameName)
/// <param name="streaming">Whether or not you want your bot to appear as if it is streaming. True means it will show it's streaming.</param>
/// <param name="url">The 'url' for the stream, if your bot is streaming.</param>
public void UpdateCurrentGame(string gameName, bool streaming, string url = null)
{
string msg;
if (gameName.ToLower().Trim() != "")
Expand All @@ -893,7 +903,12 @@ public void UpdateCurrentGame(string gameName)
d = new
{
idle_since = IdleSinceUnixTime == null ? (object)null : IdleSinceUnixTime,
game = new { name = gameName }
game = new
{
name = gameName,
type = streaming ? 1 : 0,
url = (url != null) ? url : (object)null
}
}
});
CurrentGameName = gameName;
Expand Down Expand Up @@ -982,6 +997,13 @@ private void PresenceUpdateEvents(JObject message)
else
dpuea.Game = message["d"]["game"]["name"].ToString();
user.CurrentGame = dpuea.Game;

if (message["d"]["game"]["type"] != null && message["d"]["game"]["type"].ToObject<int>() == 1)
{
user.Streaming = true;
if (message["d"]["game"]["url"].ToString() != null)
user.StreamURL = message["d"]["game"]["url"].ToString();
}
}
dpuea.User = user;

Expand Down Expand Up @@ -1015,6 +1037,12 @@ private void PresenceUpdateEvents(JObject message)
{
dpuea.Game = message["d"]["game"]["name"].ToString();
memeber.CurrentGame = dpuea.Game;
if (message["d"]["game"]["type"].ToObject<int>() == 1)
{
user.Streaming = true;
if (message["d"]["game"]["url"].ToString() != null)
user.StreamURL = message["d"]["game"]["url"].ToString();
}
}

if (message["d"]["status"].ToString() == "online")
Expand Down
2 changes: 2 additions & 0 deletions DiscordSharp/Objects/DiscordMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class DiscordMember

public Status Status { get; internal set; } = Status.Offline;
public string CurrentGame { get; internal set; } = null;
public bool Streaming { get; internal set; } = false;
public string StreamURL { get; internal set; } = null;

/**
Voice only
Expand Down
2 changes: 1 addition & 1 deletion DiscordSharpTestApplication/LuigibotMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ private void SetupCommands()
}));
CommandsManager.AddCommand(new CommandStub("setplaying", "Sets the current game the bot is playing.", "", PermissionType.Owner, 1, cmdArgs =>
{
client.UpdateCurrentGame(cmdArgs.Args[0]);
client.UpdateCurrentGame(cmdArgs.Args[0], true, "http://www.google.com/");
}));
CommandsManager.AddCommand(new CommandStub("join", "Joins a specified server", "", PermissionType.Owner, 1, cmdArgs =>
{
Expand Down
12 changes: 10 additions & 2 deletions DiscordSharpTestApplication/Modules/TestingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,16 @@ public override void Install(CommandsManager manager)
msg += $"Username: {user.Username}\nID: {user.ID}";
if (user.Nickname != null || user.Nickname.Trim() != "")
msg += $"\nNickname: {user.Nickname}";
msg += $"\nDiscrim: {user.Discriminator}\n";
msg += $"```";
msg += $"\nDiscrim: {user.Discriminator}";
if(user.CurrentGame != null)
{
msg += $"\nCurrent Game: {user.CurrentGame}";
if(user.Streaming)
{
msg += $"\nStreaming at: {user.StreamURL}";
}
}
msg += $"\n```";
cmdArgs.Channel.SendMessage(msg);
}
}
Expand Down

0 comments on commit f131670

Please sign in to comment.