Exemplo n.º 1
0
        public override void _Ready()
        {
            Client = new DiscordRpcClient("770277582460551178", -1, null, true, new UnityNamedPipe())
            {
                ShutdownOnly = true
            };

            Client.OnReady += (o, e) =>
            {
                GD.Print($"Received Ready from user {Client.CurrentUser}");
            };

            Client.Initialize();

            DiscordRPC.RichPresence rp = new DiscordRPC.RichPresence
            {
                Details = "https://github.com/iJSD-Org/Labyrinth",
                Assets  = new Assets()
                {
                    SmallImageKey  = "godot",
                    SmallImageText = "Made with Godot Engine",
                    LargeImageKey  = "minotaur",
                },
                Timestamps = new Timestamps(DateTime.UtcNow)
            };
            Client.SetPresence(rp);
        }
Exemplo n.º 2
0
        public override void _Ready()
        {
            Client = new DiscordRpcClient("752376874339926187", -1, null, true, new UnityNamedPipe())
            {
                ShutdownOnly = true
            };

            Client.OnReady += (o, e) =>
            {
                GD.Print($"Received Ready from user {Client.CurrentUser}");
            };

            Client.Initialize();

            DiscordRPC.RichPresence rp = new DiscordRPC.RichPresence
            {
                Details = "https://github.com/sitiom/Debugmancer",
                Assets  = new Assets()
                {
                    SmallImageKey  = "godot-3",
                    SmallImageText = "Made with Godot Engine",
                    LargeImageKey  = "bugmancer",
                },
                Timestamps = new Timestamps(DateTime.UtcNow)
            };
            Client.SetPresence(rp);
        }
Exemplo n.º 3
0
        private void UpdatePresence(RichPresence presence)
        {
            //If we're not running, return;
            if (!IsRunning)
            {
                return;
            }

            api.Logger.LogDebug($"Updated rich presence: '{Newtonsoft.Json.JsonConvert.SerializeObject(presence)}'.");

            DiscordRPC.RichPresence discordPresence = new DiscordRPC.RichPresence
            {
                Details = presence.Text,
                State   = presence.TextTwo,
                Assets  = new Assets()
                {
                    LargeImageKey  = presence.Icon,
                    LargeImageText = presence.IconText,
                    SmallImageKey  = presence.IconTwo,
                    SmallImageText = presence.IconTextTwo
                }
            };

            rpc.SetPresence(discordPresence);
        }
        public DiscordPresenceManager(DiscordRPC.RichPresence initialPresence, string clientId)
        {
            _initialPresence = initialPresence;
            _clientId        = clientId;

            CreateClient();
        }
Exemplo n.º 5
0
        private void UpdatePresence(DiscordRPC.RichPresence presence = null)
        {
            if (!BasicTeraData.Instance.WindowData.EnableRichPresence || !BasicTeraData.Instance.WindowData.EnableChat)
            {
                return;
            }

            presence = presence ?? Presence;
            try { Client?.SetPresence(presence); }
            catch (Exception e) { BasicTeraData.LogError("Discord RPC set presence fail: " + e.Message, false, true); }
        }
        public void SetPresence(DiscordRPC.RichPresence presence)
        {
            if (_rpcClient.IsDisposed)
            {
                CreateClient();
            }

            if (presence.State != _rpcClient.CurrentPresence.State ||
                presence.Details != _rpcClient.CurrentPresence.Details ||
                presence.Assets.SmallImageText != _rpcClient.CurrentPresence.Assets.SmallImageText ||
                presence.Assets.LargeImageText != _rpcClient.CurrentPresence.Assets.LargeImageText)
            {
                _rpcClient.SetPresence(presence);
            }
        }
Exemplo n.º 7
0
        private void UpdatePresence(RichPresence presence)
        {
            //If we're not running, return;
            //if(!IsRunning) { return; }

            DiscordRPC.RichPresence discordPresence = new DiscordRPC.RichPresence
            {
                Details = presence.Text,
                State   = presence.TextTwo,
                Assets  = new Assets()
                {
                    LargeImageKey  = presence.Icon,
                    LargeImageText = presence.IconText,
                    SmallImageKey  = presence.IconTwo,
                    SmallImageText = presence.IconTextTwo
                }
            };

            rpc.SetPresence(discordPresence);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Update the rich presence.
 /// </summary>
 /// <param name="presence">The custom rich presence to display.</param>
 public RichPresenceClient UpdatePresence(RichPresence presence)
 {
     //If we're not running, return;
     if (!IsRunning)
     {
         return(this);
     }
     api.Logger.Log(Severity.Debug, $"Updated Discord rich presence.", presence);
     DiscordRPC.RichPresence discordPresence = new DiscordRPC.RichPresence
     {
         Details = presence.Text,
         State   = presence.TextTwo,
         Assets  = new Assets()
         {
             LargeImageKey  = presence.Icon,
             LargeImageText = presence.IconText,
             SmallImageKey  = presence.IconTwo,
             SmallImageText = presence.IconTextTwo
         }
     };
     rpc.SetPresence(discordPresence);
     return(this);
 }
Exemplo n.º 9
0
        private void Framework_OnUpdateEvent(Framework framework)
        {
            try
            {
                if (!_pi.Data.IsDataReady)
                {
                    return;
                }

                if (_territoryTypes == null)
                {
                    _territoryTypes = _pi.Data.GetExcelSheet <TerritoryType>().ToList();
                }

                var localPlayer     = _pi.ClientState.LocalPlayer;
                var territoryTypeId = _pi.ClientState.TerritoryType;

                // Data not ready
                if (localPlayer == null)
                {
                    return;
                }

                var placeName       = "The Source";
                var placeNameZone   = "Void";
                var loadingImageKey = 1;

                if (territoryTypeId != 0)
                {
                    var territoryType = _territoryTypes.First(x => x.RowId == territoryTypeId);
                    placeName       = territoryType.PlaceName.Value?.Name ?? "Unknown";
                    placeNameZone   = territoryType.PlaceNameRegion.Value?.Name ?? "Unknown";
                    loadingImageKey = territoryType.LoadingImage;
                }

                var largeImageKey = $"li_{loadingImageKey}";

                var fcName = localPlayer.CompanyTag;

                if (fcName != string.Empty)
                {
                    fcName = $" <{fcName}>";
                }

                var worldName = localPlayer.CurrentWorld.GameData.Name.ToString();

                if (localPlayer.CurrentWorld.Id != localPlayer.HomeWorld.Id)
                {
                    worldName = $"{worldName} (🏠{localPlayer.HomeWorld.GameData.Name})";
                }

                var playerName = $"{localPlayer.Name}{fcName}";
                if (!Config.ShowName)
                {
                    playerName = placeName;
                }

                if (!Config.ShowWorld)
                {
                    worldName = Config.ShowName ? placeName : placeNameZone;
                }


                var rp = new DiscordRPC.RichPresence
                {
                    Details = playerName,
                    State   = worldName,
                    Assets  = new Assets
                    {
                        LargeImageKey  = largeImageKey,
                        LargeImageText = placeName,
                        SmallImageKey  = $"class_{localPlayer.ClassJob.Id}",
                        SmallImageText = localPlayer.ClassJob.GameData.Abbreviation + " Lv." + localPlayer.Level
                    },
                };

                if (Config.ShowStartTime)
                {
                    rp.Timestamps = new Timestamps(startTime);
                }


                _discordPresenceManager.SetPresence(rp);
            }
            catch (Exception ex)
            {
                PluginLog.LogError(ex, "Could not run RichPresence OnUpdate.");
            }
        }
Exemplo n.º 10
0
        private void HandleMessage(IMessage message)
        {
            if (message == null)
            {
                return;
            }
            switch (message.Type)
            {
            //We got a update, so we will update our current presence
            case MessageType.PresenceUpdate:
                var pm = message as PresenceMessage;
                if (pm != null)
                {
                    //We need to merge these presences together
                    if (_presence == null)
                    {
                        _presence = pm.Presence;
                    }
                    else if (pm.Presence == null)
                    {
                        _presence = null;
                    }
                    else
                    {
                        _presence.Merge(pm.Presence);
                    }

                    //Update the message
                    pm.Presence = _presence;
                }

                break;

            //Update our configuration
            case MessageType.Ready:
                var rm = message as ReadyMessage;
                if (rm != null)
                {
                    _configuration = rm.Configuration;
                    _user          = rm.User;

                    //Resend our presence and subscription
                    SynchronizeState();
                }
                break;

            //Update the request's CDN for the avatar helpers
            case MessageType.JoinRequest:
                if (Configuration != null)
                {
                    //Update the User object within the join request if the current Cdn
                    var jrm = message as JoinRequestMessage;
                    if (jrm != null)
                    {
                        jrm.User.SetConfiguration(Configuration);
                    }
                }
                break;

            case MessageType.Subscribe:
                var sub = message as SubscribeMessage;
                _subscription |= sub.Event;
                break;

            case MessageType.Unsubscribe:
                var unsub = message as UnsubscribeMessage;
                _subscription &= ~unsub.Event;
                break;

            //We got a message we dont know what to do with.
            default:
                break;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Checks if the other rich presence differs from the current one
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        internal bool Matches(RichPresence other)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            if (other == null)
            {
                return(false);
            }

            if (State != other.State || Details != other.Details)
            {
                return(false);
            }

            //Checks if the timestamps are different
            if (Timestamps != null)
            {
                if (other.Timestamps == null ||
                    other.Timestamps.StartUnixMilliseconds != Timestamps.StartUnixMilliseconds ||
                    other.Timestamps.EndUnixMilliseconds != Timestamps.EndUnixMilliseconds)
                {
                    return(false);
                }
            }
            else if (other.Timestamps != null)
            {
                return(false);
            }

            //Checks if the secrets are different
            if (Secrets != null)
            {
                if (other.Secrets == null ||
                    other.Secrets.JoinSecret != Secrets.JoinSecret ||
                    other.Secrets.MatchSecret != Secrets.MatchSecret ||
                    other.Secrets.SpectateSecret != Secrets.SpectateSecret)
                {
                    return(false);
                }
            }
            else if (other.Secrets != null)
            {
                return(false);
            }

            //Checks if the timestamps are different
            if (Party != null)
            {
                if (other.Party == null ||
                    other.Party.ID != Party.ID ||
                    other.Party.Max != Party.Max ||
                    other.Party.Size != Party.Size ||
                    other.Party.Privacy != Party.Privacy)
                {
                    return(false);
                }
            }
            else if (other.Party != null)
            {
                return(false);
            }

            //Checks if the assets are different
            if (Assets != null)
            {
                if (other.Assets == null ||
                    other.Assets.LargeImageKey != Assets.LargeImageKey ||
                    other.Assets.LargeImageText != Assets.LargeImageText ||
                    other.Assets.SmallImageKey != Assets.SmallImageKey ||
                    other.Assets.SmallImageText != Assets.SmallImageText)
                {
                    return(false);
                }
            }
            else if (other.Assets != null)
            {
                return(false);
            }

            return(Instance == other.Instance);

#pragma warning restore CS0618 // Type or member is obsolete
        }
Exemplo n.º 12
0
        public RichPresence Clone()
        {
            RichPresence richPresence = new RichPresence();

            richPresence.State = this._state != null?this._state.Clone() as string : (string)null;

            richPresence.Details = this._details != null?this._details.Clone() as string : (string)null;

            Secrets secrets;

            if (this.HasSecrets())
            {
                secrets = new Secrets()
                {
                    JoinSecret     = this.Secrets.JoinSecret != null?this.Secrets.JoinSecret.Clone() as string         : (string)null,
                    SpectateSecret = this.Secrets.SpectateSecret != null?this.Secrets.SpectateSecret.Clone() as string : (string)null
                }
            }
            ;
            else
            {
                secrets = (Secrets)null;
            }
            richPresence.Secrets = secrets;
            Timestamps timestamps;

            if (this.HasTimestamps())
            {
                timestamps = new Timestamps()
                {
                    Start = this.Timestamps.Start,
                    End   = this.Timestamps.End
                }
            }
            ;
            else
            {
                timestamps = (Timestamps)null;
            }
            richPresence.Timestamps = timestamps;
            Assets assets;

            if (this.HasAssets())
            {
                assets = new Assets()
                {
                    LargeImageKey  = this.Assets.LargeImageKey != null?this.Assets.LargeImageKey.Clone() as string   : (string)null,
                    LargeImageText = this.Assets.LargeImageText != null?this.Assets.LargeImageText.Clone() as string : (string)null,
                    SmallImageKey  = this.Assets.SmallImageKey != null?this.Assets.SmallImageKey.Clone() as string   : (string)null,
                    SmallImageText = this.Assets.SmallImageText != null?this.Assets.SmallImageText.Clone() as string : (string)null
                }
            }
            ;
            else
            {
                assets = (Assets)null;
            }
            richPresence.Assets = assets;
            Party party;

            if (this.HasParty())
            {
                party = new Party()
                {
                    ID   = this.Party.ID,
                    Size = this.Party.Size,
                    Max  = this.Party.Max
                }
            }
            ;
            else
            {
                party = (Party)null;
            }
            richPresence.Party = party;
            return(richPresence);
        }
Exemplo n.º 13
0
        private unsafe void UpdateRichPresence(Framework framework)
        {
            try
            {
                DiscordPresenceManager.Update();

                var localPlayer = ClientState.LocalPlayer;

                // Show start timestamp if configured
                var richPresenceTimestamps =
                    RichPresenceConfig.ShowStartTime ? new Timestamps(startTime) : null;

                DiscordRPC.RichPresence richPresence;

                // Return early if data is not ready
                if (localPlayer is null)
                {
                    // Show login queue information if configured
                    if (!RichPresenceConfig.ShowLoginQueuePosition || !IpcManager.IsInLoginQueue())
                    {
                        // Reset to default presence if we have left the queue
                        if (presenceInQueue)
                        {
                            presenceInQueue = false;
                            SetDefaultPresence();
                        }

                        return;
                    }

                    var queuePosition = IpcManager.GetQueuePosition();
                    if (queuePosition < 0)
                    {
                        // Position not yet loaded, so we wait
                        return;
                    }

                    var queueEstimate          = IpcManager.GetQueueEstimate();
                    var queueEstimateFormatted = queueEstimate?.TotalSeconds >= 1d
                        ? String.Format(
                        LocalizationManager.Localize("DalamudRichPresenceQueueEstimate",
                                                     LocalizationLanguage.Client), queueEstimate)
                        : String.Empty;

                    // Create rich presence object
                    richPresence = new DiscordRPC.RichPresence
                    {
                        Details = String.Format(
                            LocalizationManager.Localize("DalamudRichPresenceInLoginQueue",
                                                         LocalizationLanguage.Client), queuePosition),
                        State  = queueEstimateFormatted,
                        Assets = new Assets
                        {
                            LargeImageKey = DEFAULT_LARGE_IMAGE_KEY,
                            SmallImageKey = DEFAULT_SMALL_IMAGE_KEY
                        },
                        Timestamps = richPresenceTimestamps
                    };

                    presenceInQueue = true;

                    // Request new presence to be set
                    DiscordPresenceManager.SetPresence(richPresence);

                    return;
                }

                var territoryId     = ClientState.TerritoryType;
                var territoryName   = LocalizationManager.Localize("DalamudRichPresenceTheSource", LocalizationLanguage.Client);
                var territoryRegion = LocalizationManager.Localize("DalamudRichPresenceVoid", LocalizationLanguage.Client);

                // Details defaults to player name
                var richPresenceDetails = localPlayer.Name.ToString();

                // State defaults to current world
                var richPresenceState = localPlayer.CurrentWorld.GameData.Name.ToString();

                // Large image defaults to world map
                var richPresenceLargeImageText = territoryName;
                var richPresenceLargeImageKey  = DEFAULT_LARGE_IMAGE_KEY;

                // Small image defaults to "Online"
                var richPresenceSmallImageKey  = DEFAULT_SMALL_IMAGE_KEY;
                var richPresenceSmallImageText = LocalizationManager.Localize("DalamudRichPresenceOnline", LocalizationLanguage.Client);

                if (territoryId != 0)
                {
                    // Read territory data from generated sheet
                    var territory = this.Territories.First(row => row.RowId == territoryId);
                    territoryName   = territory.PlaceName.Value?.Name ?? LocalizationManager.Localize("DalamudRichPresenceUnknown", LocalizationLanguage.Client);
                    territoryRegion = territory.PlaceNameRegion.Value?.Name ?? LocalizationManager.Localize("DalamudRichPresenceUnknown", LocalizationLanguage.Client);

                    // Set large image to territory
                    richPresenceLargeImageText = territoryName;
                    richPresenceLargeImageKey  = $"li_{territory.LoadingImage}";
                }

                // Show character name if configured
                if (RichPresenceConfig.ShowName)
                {
                    // Show free company tag if configured
                    if (RichPresenceConfig.ShowFreeCompany && localPlayer.CurrentWorld.Id == localPlayer.HomeWorld.Id)
                    {
                        var fcTag = localPlayer.CompanyTag.ToString();

                        // Append free company tag to player name if it exists
                        richPresenceDetails = fcTag.IsNullOrEmpty() ? richPresenceDetails : $"{richPresenceDetails} «{fcTag}»";
                    }
                    else if (RichPresenceConfig.ShowWorld && localPlayer.CurrentWorld.Id != localPlayer.HomeWorld.Id)
                    {
                        // Append home world name to current player name while visiting another world
                        richPresenceDetails = $"{richPresenceDetails} ❀ {localPlayer.HomeWorld.GameData.Name.ToString()}";
                    }
                }
                else
                {
                    // Replace character name with territory name
                    richPresenceDetails = territoryName;
                }

                // Show current job if configured
                if (RichPresenceConfig.ShowJob)
                {
                    // Set small image to job icon
                    richPresenceSmallImageKey = $"class_{localPlayer.ClassJob.Id}";

                    // Abbreviate job name if configured
                    richPresenceSmallImageText = (RichPresenceConfig.AbbreviateJob)
                        ? localPlayer.ClassJob.GameData.Abbreviation
                        : LocalizationManager.TitleCase(localPlayer.ClassJob.GameData.Name.ToString());

                    // Show current job level if configured
                    if (RichPresenceConfig.ShowLevel)
                    {
                        var levelText = String.Format(LocalizationManager.Localize("DalamudRichPresenceLevel", LocalizationLanguage.Client), localPlayer.Level);
                        richPresenceSmallImageText = $"{richPresenceSmallImageText} {levelText}";
                    }
                }

                // Hide world name if configured
                if (!RichPresenceConfig.ShowWorld)
                {
                    // Replace world name with territory name or territory region
                    richPresenceState = (RichPresenceConfig.ShowName) ? territoryName : territoryRegion;
                }

                // Create rich presence object
                richPresence = new DiscordRPC.RichPresence
                {
                    Details = richPresenceDetails,
                    State   = richPresenceState,
                    Assets  = new Assets
                    {
                        LargeImageKey  = richPresenceLargeImageKey,
                        LargeImageText = richPresenceLargeImageText,
                        SmallImageKey  = richPresenceSmallImageKey,
                        SmallImageText = richPresenceSmallImageText,
                    },
                    Timestamps = richPresenceTimestamps,
                };

                if (RichPresenceConfig.ShowParty)
                {
                    if (PartyList.Length > 0 && PartyList.PartyId != 0)
                    {
                        var cfcTerri = DataManager.Excel.GetSheet <ContentFinderCondition>() !
                                       .FirstOrDefault(x => x.TerritoryType.Row == ClientState.TerritoryType);

                        var partyMax = cfcTerri != null && cfcTerri.ContentType.Row == 2 ? 4 : 8;

                        if (PartyList.Length > partyMax)
                        {
                            partyMax = PartyList.Length;
                        }

                        if (cfcTerri != null)
                        {
                            richPresence.State = LocalizationManager.Localize("DalamudRichPresenceInADuty", LocalizationLanguage.Client);
                        }

                        var party = new Party
                        {
                            Size = PartyList.Length,
                            Max  = partyMax, // Check dungeon terris, change to 4
                            ID   = GetStringSha256Hash(PartyList.PartyId.ToString()),
                        };

                        richPresence.Party = party;
                    }
                    else
                    {
                        var ipCrossRealm = InfoProxyCrossRealm.Instance();

                        if (ipCrossRealm->IsInCrossRealmParty == 0x01)
                        {
                            var numMembers =
                                InfoProxyCrossRealm.GetGroupMemberCount(ipCrossRealm->LocalPlayerGroupIndex);

                            if (numMembers > 0)
                            {
                                var memberAry = new CrossRealmMember[numMembers];
                                for (var i = 0u; i < numMembers; i++)
                                {
                                    memberAry[i] = *InfoProxyCrossRealm.GetGroupMember(i, ipCrossRealm->LocalPlayerGroupIndex);
                                }

                                var lowestCid = memberAry.OrderBy(x => x.ContentId).Select(x => x.ContentId).First();

                                richPresence.Party = new Party
                                {
                                    Size = numMembers,
                                    Max  = 8,
                                    ID   = GetStringSha256Hash(lowestCid.ToString()),
                                };
                            }
                        }
                    }
                }

                var onlineStatusEn = localPlayer.OnlineStatus.GetWithLanguage(ClientLanguage.English);
                if (RichPresenceConfig.ShowAfk && onlineStatusEn != null && onlineStatusEn.Name.RawString.Contains("Away from Keyboard"))
                {
                    var text = localPlayer.OnlineStatus.GameData !.Name.RawString;
                    richPresence.State = text;
                    richPresence.Assets.SmallImageKey = "away";
                }

                // Request new presence to be set
                DiscordPresenceManager.SetPresence(richPresence);
            }
            catch (Exception ex)
            {
                PluginLog.LogError(ex, "Could not run OnUpdate.");
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Sets the Rich Presence.
        /// </summary>
        /// <param name="presence">The Rich Presence to set on the current Discord user.</param>
        public void SetPresence(RichPresence presence)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException("Discord IPC Client");
            }

            if (connection == null)
            {
                throw new ObjectDisposedException("Connection", "Cannot initialize as the connection has been deinitialized");
            }

            if (!IsInitialized)
            {
                Logger.Warning("The client is not yet initialized, storing the presence as a state instead.");
            }

            //Send the event
            if (!presence)
            {
                //Clear the presence
                if (!SkipIdenticalPresence || CurrentPresence != null)
                {
                    connection.EnqueueCommand(new PresenceCommand()
                    {
                        PID = this.ProcessID, Presence = null
                    });
                }
            }
            else
            {
                //Send valid presence
                //Validate the presence with our settings
                if (presence.HasSecrets() && !HasRegisteredUriScheme)
                {
                    throw new BadPresenceException("Cannot send a presence with secrets as this object has not registered a URI scheme. Please enable the uri scheme registration in the DiscordRpcClient constructor.");
                }

                if (presence.HasParty() && presence.Party.Max < presence.Party.Size)
                {
                    throw new BadPresenceException("Presence maximum party size cannot be smaller than the current size.");
                }

                if (presence.HasSecrets() && !presence.HasParty())
                {
                    Logger.Warning("The presence has set the secrets but no buttons will show as there is no party available.");
                }

                //Send the presence, but only if we are not skipping
                if (!SkipIdenticalPresence || !presence.HasDifference(CurrentPresence))
                {
                    connection.EnqueueCommand(new PresenceCommand()
                    {
                        PID = this.ProcessID, Presence = presence.Clone()
                    });
                }
            }

            //Update our local store
            lock (_sync) { CurrentPresence = presence != null?presence.Clone() : null; }
        }
Exemplo n.º 15
0
 public void SetPresence(DiscordRPC.RichPresence newPresence)
 {
     this.CreateClient();
     RpcClient.SetPresence(newPresence);
 }