void OnDisable() { DiscordRpc.ClearPresence(); DiscordRpc.Shutdown(); }
void Update() { UpdatePresence(); DiscordRpc.RunCallbacks(); }
private static void WorkerLoop() { string lib = null; if (!string.IsNullOrEmpty(CoreModule.Settings.DiscordLib)) { lib = CoreModule.Settings.DiscordLib; } else if (Environment.OSVersion.Platform == PlatformID.Win32NT) { lib = "discord-rpc.dll"; } else if (Environment.OSVersion.Platform == PlatformID.MacOSX) { lib = "libdiscord-rpc.dylib"; // FIXME: macOS doesn't see libdiscord-rpc.dylib wherever Celeste.exe is. } else if (Environment.OSVersion.Platform == PlatformID.Unix) { lib = "libdiscord-rpc.so"; } if (!string.IsNullOrEmpty(lib)) { DynDll.Mappings["discord-rpc"] = new DynDllMapping() { ResolveAs = lib } } ; string discordID = "430794114037055489"; if (!string.IsNullOrEmpty(CoreModule.Settings.DiscordID)) { discordID = CoreModule.Settings.DiscordID; } try { typeof(DiscordRpc).ResolveDynDllImports(); } catch { } if (DiscordRpc.Initialize == null) { Logger.Log(LogLevel.Info, "discord", "Discord_Initialize not found - skipping Discord Rich Presence."); return; } Logger.Log(LogLevel.Verbose, "discord", $"Discord_Initialize found - initializing Discord Rich Presence, app ID {discordID}"); DiscordHandlers.readyCallback += OnDiscordReady; DiscordHandlers.disconnectedCallback += OnDiscordDisconnect; DiscordHandlers.errorCallback += OnDiscordError; DiscordRpc.Initialize.Invoke(discordID, ref DiscordHandlers, true, "504230"); DiscordRpc.UpdatePresence(DiscordPresence); while (Worker != null) { while (WaitTokenSource == null) { continue; } try { WaitTokenSource.Token.WaitHandle.WaitOne(); } catch (OperationCanceledException) { } catch (ObjectDisposedException) { } Action nextAction = null; lock (Queue) { if (Queue.Count > 0) { nextAction = Queue.Dequeue(); } } nextAction?.Invoke(); } DiscordRpc.Shutdown(); }
private void OnRemovePresenceClick(Object sender, EventArgs e) { this.LockRichPresenceButtons(); DiscordRpc.ClearPresence(); }
public override void OnApplicationQuit() { DiscordRpc.Shutdown(); }
public void RequestRespondNo() { Debug.Log("Discord: responding no to Ask to Join request"); DiscordRpc.Respond(joinRequest.userId, DiscordRpc.Reply.No); hasResponded.Invoke(); }
/// <summary> /// Changes the discord presence to an idle state /// </summary> private static void ChangeDiscordPresenceToIdle() { DiscordHelper.Presence.Details = $"Idle"; DiscordHelper.Presence.State = "In the Menus"; DiscordRpc.UpdatePresence(ref DiscordHelper.Presence); }
public void Chrome() { Process[] procsChrome = Process.GetProcessesByName("chrome"); if (procsChrome.Length > 1) { Console.WriteLine("Chrome Process found"); while (true) { Thread.Sleep(25000); foreach (Process chrome in procsChrome) { if (chrome.MainWindowHandle == IntPtr.Zero) { continue; } AutomationElement soruceElement = AutomationElement.FromHandle(chrome.MainWindowHandle); Condition condition = new OrCondition(new Condition[2] { new PropertyCondition(AutomationElement.ControlTypeProperty, (object)ControlType.Edit), new PropertyCondition(AutomationElement.AccessKeyProperty, (object)"Ctrl+L", PropertyConditionFlags.IgnoreCase), }); AutomationElement elmUrlBar = soruceElement.FindFirst(TreeScope.Descendants, condition); if (elmUrlBar != null) { AutomationPattern[] pattern = elmUrlBar.GetSupportedPatterns(); if (pattern.Length > 0) { ValuePattern val = (ValuePattern)elmUrlBar.GetCurrentPattern(pattern[0]); if (val.Current.Value.Contains("youtube.com/watch?v=")) { Console.WriteLine("youtube url found " + val.Current.Value); YouTube ytb = YouTube.Default; var vid = ytb.GetVideo(val.Current.Value); string ttl = vid.Title; this.presence.details = ttl; this.presence.state = "Youtube Presence By LeonimusT"; this.presence.largeImageKey = "large"; //this.presence.smallImageKey = "small"; //this.presence.largeImageText = "Image 1 Text"; //this.presence.smallImageText = "Image 2 Text"; DiscordRpc.UpdatePresence(ref this.presence); } else { Console.WriteLine("youtube url not found. Current url " + val.Current.Value); this.presence.details = "No Video Found"; this.presence.state = "Youtube Presence By LeonimusT"; this.presence.largeImageKey = "large"; //this.presence.smallImageKey = "small"; //this.presence.largeImageText = "Image 1 Text"; //this.presence.smallImageText = "Image 2 Text"; DiscordRpc.UpdatePresence(ref this.presence); } } } } } } else { // Console.WriteLine("Chrome not found"); Process[] procsfirefox = Process.GetProcessesByName("firefox"); if (procsfirefox.Length > 1) { Console.WriteLine("Firefox Process found"); Console.WriteLine("To continue you will have to write below what and write in the search bar. Go see the screen shot if you did not understand ->> https://imgur.com/a/J0EV3uv"); string nameProperty = Console.ReadLine(); while (true) { Thread.Sleep(25000); foreach (Process firefox in procsfirefox) { if (firefox.MainWindowHandle == IntPtr.Zero) { continue; } AutomationElement sourceElement = AutomationElement.FromHandle(firefox.MainWindowHandle); //works with latest version of firefox and for older version replace 'Search with Google or enter address' with this 'Search or enter address' AutomationElement editBox = sourceElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, nameProperty)); if (editBox != null) { ValuePattern val = ((ValuePattern)editBox.GetCurrentPattern(ValuePattern.Pattern)); // Console.WriteLine("\n Firefox URL found: " + val.Current.Value); if (val.Current.Value.Contains("https://www.youtube.com/watch?v=")) { Console.WriteLine("youtube url found " + val.Current.Value); YouTube ytb = YouTube.Default; var vid = ytb.GetVideo(val.Current.Value); string ttl = vid.Title; this.presence.details = ttl; this.presence.state = "Youtube Presence By LeonimusT"; this.presence.largeImageKey = "large"; //this.presence.smallImageKey = "small"; //this.presence.largeImageText = "Image 1 Text"; //this.presence.smallImageText = "Image 2 Text"; DiscordRpc.UpdatePresence(ref this.presence); } else { Console.WriteLine("youtube url not found. Current url " + val.Current.Value); this.presence.details = "No Video Found"; this.presence.state = "Youtube Presence By LeonimusT"; this.presence.largeImageKey = "large"; //this.presence.smallImageKey = "small"; //this.presence.largeImageText = "Image 1 Text"; //this.presence.smallImageText = "Image 2 Text"; DiscordRpc.UpdatePresence(ref this.presence); } } else { Console.WriteLine("You didn't spell out what's in the search bar. Review the screen shot to better understand - >> https://imgur.com/a/J0EV3uv"); Console.WriteLine("Please rewrite what is in the search bar"); nameProperty = Console.ReadLine(); } } } } else { Console.WriteLine("Firefox or Chrome process not found"); } } }
public void PushPresence() => DiscordRpc.UpdatePresence(presence);
/// <summary> /// Changes the discord presence to a listening state. /// </summary> private static void ChangeDiscordPresenceToSongTitle() { DiscordHelper.Presence.Details = $"{MapManager.Selected.Value.Artist} - {MapManager.Selected.Value.Title}"; DiscordHelper.Presence.State = "In the Menus - Listening"; DiscordRpc.UpdatePresence(ref DiscordHelper.Presence); }
private void OnApplicationQuit() => DiscordRpc.Shutdown();
void OnDisable() => DiscordRpc.Shutdown();
public Form1() { InitializeComponent(); MyApplicationID.Text = "0"; StateBox.Text = "My Lobby"; DetailsBox.Text = "Rich Presence Is Cool!"; SmallImageKeyBox.Text = ""; SmallImageTextBox.Text = ""; LargeImageKeyBox.Text = ""; LargeImageTextBox.Text = ""; PartyIDBox.Text = "myparty"; MatchSecretBox.Text = "match"; JoinSecretBox.Text = "join"; SpectateSecretBox.Text = "spectate"; CurrentPartySize.Value = 1; MaxPartySize.Value = 6; PartyTimerCounter.Value = 5; ResendPresenceCheckbox.Checked = true; LoadSettings(); FormLog.TextChanged += (sender, e) => { FormLog.SelectionStart = FormLog.TextLength; FormLog.ScrollToCaret(); }; FormLog.VisibleChanged += (sender, e) => { if (FormLog.Visible) { FormLog.SelectionStart = FormLog.TextLength; FormLog.ScrollToCaret(); } }; StartButton.Enabled = !isRunning; StopButton.Enabled = isRunning; ResendPresenceButton.Enabled = isRunning; Log("Creating Event Handlers..."); handlers = new DiscordRpc.EventHandlers(); handlers.readyCallback = ReadyCallback; handlers.disconnectedCallback += DisconnectedCallback; handlers.errorCallback += ErrorCallback; handlers.joinCallback += JoinCallback; handlers.spectateCallback += SpectateCallback; handlers.requestCallback += RequestCallback; m_oWorker = new BackgroundWorker(); timer = new Timer(); timer.Elapsed += TimerTick; m_oWorker.DoWork += delegate(object sender, DoWorkEventArgs e) { timer.Interval = TimeSpan.FromMinutes(Settings.Default.PartyTimer).TotalMilliseconds; timer.Start(); Log("Starting..."); while (isRunning) { DiscordRpc.RunCallbacks(); } ; Log("Stopping..."); DiscordRpc.Shutdown(); }; m_oWorker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { Log("Task Cancelled."); } else if (e.Error != null) { Log("Error " + e.Error.StackTrace); } else { Log("Task Completed..."); } DiscordRpc.Shutdown(); timer.Stop(); StartButton.Enabled = !isRunning; StopButton.Enabled = isRunning; ResendPresenceButton.Enabled = isRunning; }; m_oWorker.WorkerSupportsCancellation = true; Log("Loaded Event Handlers"); Log("Discord Presence Setter Log \r\nReady To Start!"); }
public void RefreshRPC() { DiscordRpc.UpdatePresence(ref presence); }
public DiscordRPC() { DiscordRpc.Initialize("576154452348633108", ref handlers, true, ""); Console.WriteLine("INITIALIZED!"); }
/// <summary> /// Pauses the game. /// </summary> internal void Pause(GameTime gameTime = null) { // Don't allow pausing if the play is already finished. if (IsPlayComplete) { return; } // Grab the casted version of the screenview. var screenView = (GameplayScreenView)View; // Handle pause. if (!IsPaused) { // Handle cases where someone (a developer) calls pause but there is not GameTime. // shouldn't ever happen though. if (gameTime == null) { const string log = "Cannot pause if GameTime is null"; Logger.Error(log, LogType.Runtime); throw new InvalidOperationException(log); } // Increase the time the pause key has been held. TimePauseKeyHeld += gameTime.ElapsedGameTime.TotalMilliseconds; screenView.Transitioner.Alpha = MathHelper.Lerp(screenView.Transitioner.Alpha, 1, (float)Math.Min(gameTime.ElapsedGameTime.TotalMilliseconds / TimeToHoldPause, 1)); // Make the user hold the pause key down before pausing if tap to pause is disabled. if (!ConfigManager.TapToPause.Value && TimePauseKeyHeld < TimeToHoldPause) { return; } IsPaused = true; IsResumeInProgress = false; PauseCount++; GameBase.Game.GlobalUserInterface.Cursor.Alpha = 1; if (!InReplayMode) { // Show notification to the user that their score is invalid. NotificationManager.Show(NotificationLevel.Warning, "WARNING! Your score will not be submitted due to pausing during gameplay!"); // Add the pause mod to their score. if (!ModManager.IsActivated(ModIdentifier.Paused)) { ModManager.AddMod(ModIdentifier.Paused); ReplayCapturer.Replay.Mods |= ModIdentifier.Paused; Ruleset.ScoreProcessor.Mods |= ModIdentifier.Paused; } } try { AudioEngine.Track.Pause(); } catch (Exception) { // ignored } DiscordHelper.Presence.State = $"Paused for the {StringHelper.AddOrdinal(PauseCount)} time"; DiscordHelper.Presence.EndTimestamp = 0; DiscordRpc.UpdatePresence(ref DiscordHelper.Presence); OnlineManager.Client?.UpdateClientStatus(GetClientStatus()); // Fade in the transitioner. screenView.Transitioner.Animations.Clear(); screenView.Transitioner.Animations.Add(new Animation(AnimationProperty.Alpha, Easing.Linear, screenView.Transitioner.Alpha, 0.75f, 400)); // Activate pause menu screenView.PauseScreen.Activate(); return; } if (IsResumeInProgress) { return; } // Setting the resume time in this case allows us to give the user time to react // with a delay before starting the audio track again. // When that resume time is past the specific set offset, it'll unpause the game. IsResumeInProgress = true; ResumeTime = GameBase.Game.TimeRunning; // Fade screen transitioner screenView.Transitioner.Animations.Clear(); var alphaTransformation = new Animation(AnimationProperty.Alpha, Easing.Linear, 0.75f, 0, 400); screenView.Transitioner.Animations.Add(alphaTransformation); // Deactivate pause screen. screenView.PauseScreen.Deactivate(); SetRichPresence(); OnlineManager.Client?.UpdateClientStatus(GetClientStatus()); }
public static void handleGameState(string uri, string serverreply = "", string POST = "", string GET = "") { var SBRW_XML = new XmlDocument(); string[] splitted_uri = uri.Split('/'); if (uri == "/User/SecureLoginPersona") { canUpdateProfileField = true; } if (uri == "/User/SecureLogoutPersona") { PersonaId = String.Empty; PersonaName = String.Empty; PersonaLevel = String.Empty; PersonaAvatarId = String.Empty; PersonaCarId = String.Empty; PersonaCarName = String.Empty; } //FIRST PERSONA EVER LOCALIZED IN CODE if (uri == "/User/GetPermanentSession") { try { SBRW_XML.LoadXml(serverreply); PersonaName = SBRW_XML.SelectSingleNode("UserInfo/personas/ProfileData/Name").InnerText.Replace("¤", "[S]"); PersonaLevel = SBRW_XML.SelectSingleNode("UserInfo/personas/ProfileData/Level").InnerText; PersonaAvatarId = (SBRW_XML.SelectSingleNode("UserInfo/personas/ProfileData/IconIndex").InnerText == "26") ? "nfsw" : "avatar_" + SBRW_XML.SelectSingleNode("UserInfo/personas/ProfileData/IconIndex").InnerText; PersonaId = SBRW_XML.SelectSingleNode("UserInfo/personas/ProfileData/PersonaId").InnerText; //Let's get rest of PERSONAIDs XmlNode UserInfo = SBRW_XML.SelectSingleNode("UserInfo"); XmlNodeList personas = UserInfo.SelectNodes("personas/ProfileData"); foreach (XmlNode node in personas) { PersonaIds.Add(node.SelectSingleNode("PersonaId").InnerText); } } catch (Exception) { } } //CREATE/DELETE PERSONA Handler if (uri == "/DriverPersona/CreatePersona") { SBRW_XML.LoadXml(serverreply); PersonaIds.Add(SBRW_XML.SelectSingleNode("ProfileData/PersonaId").InnerText); } //DRIVING CARNAME if (uri == "/DriverPersona/GetPersonaInfo" && canUpdateProfileField == true) { SBRW_XML.LoadXml(serverreply); PersonaName = SBRW_XML.SelectSingleNode("ProfileData/Name").InnerText.Replace("¤", "[S]"); PersonaLevel = SBRW_XML.SelectSingleNode("ProfileData/Level").InnerText; PersonaAvatarId = (SBRW_XML.SelectSingleNode("ProfileData/IconIndex").InnerText == "26") ? "nfsw" : "avatar_" + SBRW_XML.SelectSingleNode("ProfileData/IconIndex").InnerText; PersonaId = SBRW_XML.SelectSingleNode("ProfileData/PersonaId").InnerText; } if (uri == "/matchmaking/leavelobby") { _presence.details = "Driving " + PersonaCarName; _presence.state = serverName; _presence.largeImageText = PersonaName + " - Level: " + PersonaLevel; _presence.largeImageKey = PersonaAvatarId; _presence.smallImageText = "In-Freeroam"; _presence.smallImageKey = "gamemode_freeroam"; _presence.startTimestamp = RPCstartTimestamp; _presence.instance = true; DiscordRpc.UpdatePresence(_presence); eventTerminatedManually = true; } //IN LOBBY if (uri == "/matchmaking/acceptinvite") { SBRW_XML.LoadXml(serverreply); EventID = Convert.ToInt32(SBRW_XML.SelectSingleNode("LobbyInfo/EventId").InnerText); _presence.details = "In Lobby: " + EventList.getEventName(EventID); _presence.state = serverName; _presence.largeImageText = PersonaName + " - Level: " + PersonaLevel; _presence.largeImageKey = PersonaAvatarId; _presence.smallImageText = EventList.getEventName(Convert.ToInt32(EventID)); _presence.smallImageKey = EventList.getEventType(Convert.ToInt32(EventID)); _presence.startTimestamp = RPCstartTimestamp; _presence.instance = true; DiscordRpc.UpdatePresence(_presence); eventTerminatedManually = false; } //IN SAFEHOUSE/FREEROAM if (uri == "/DriverPersona/UpdatePersonaPresence") { string UpdatePersonaPresenceParam = GET.Split(';').Last().Split('=').Last(); if (UpdatePersonaPresenceParam == "1") { _presence.details = "Driving " + PersonaCarName; _presence.smallImageText = "In-Freeroam"; } else { _presence.details = "In Safehouse"; _presence.smallImageText = "In-Safehouse"; } _presence.state = serverName; _presence.largeImageText = PersonaName + " - Level: " + PersonaLevel; _presence.largeImageKey = PersonaAvatarId; _presence.smallImageKey = "gamemode_freeroam"; _presence.startTimestamp = RPCstartTimestamp; _presence.instance = true; DiscordRpc.UpdatePresence(_presence); } //IN EVENT if (Regex.Match(uri, "/matchmaking/launchevent").Success) { EventID = Convert.ToInt32(splitted_uri[3]); _presence.details = "In Event: " + EventList.getEventName(EventID); _presence.state = serverName; _presence.largeImageText = PersonaName + " - Level: " + PersonaLevel; _presence.largeImageKey = PersonaAvatarId; _presence.smallImageText = EventList.getEventName(EventID); _presence.smallImageKey = EventList.getEventType(EventID); _presence.startTimestamp = RPCstartTimestamp; _presence.instance = true; DiscordRpc.UpdatePresence(_presence); eventTerminatedManually = false; } if (uri == "/event/arbitration") { _presence.details = "In Event: " + EventList.getEventName(EventID); _presence.state = serverName; _presence.largeImageText = PersonaName + " - Level: " + PersonaLevel; _presence.largeImageKey = PersonaAvatarId; _presence.smallImageText = EventList.getEventName(EventID); _presence.smallImageKey = EventList.getEventType(EventID); _presence.startTimestamp = RPCstartTimestamp; _presence.instance = true; DiscordRpc.UpdatePresence(_presence); eventTerminatedManually = false; } if (uri == "/event/launched" && eventTerminatedManually == false) { _presence.details = "In Event: " + EventList.getEventName(EventID); _presence.state = serverName; _presence.largeImageText = PersonaName + " - Level: " + PersonaLevel; _presence.largeImageKey = PersonaAvatarId; _presence.smallImageText = EventList.getEventName(EventID); _presence.smallImageKey = EventList.getEventType(EventID); _presence.startTimestamp = Self.getTimestamp(true); _presence.instance = true; DiscordRpc.UpdatePresence(_presence); } //CARS RELATED foreach (var single_personaId in PersonaIds) { if (Regex.Match(uri, "/personas/" + single_personaId + "/carslots", RegexOptions.IgnoreCase).Success) { carslotsXML = serverreply; SBRW_XML.LoadXml(carslotsXML); int DefaultID = Convert.ToInt32(SBRW_XML.SelectSingleNode("CarSlotInfoTrans/DefaultOwnedCarIndex").InnerText); int current = 0; XmlNode CarsOwnedByPersona = SBRW_XML.SelectSingleNode("CarSlotInfoTrans/CarsOwnedByPersona"); XmlNodeList OwnedCarTrans = CarsOwnedByPersona.SelectNodes("OwnedCarTrans"); foreach (XmlNode node in OwnedCarTrans) { if (DefaultID == current) { PersonaCarName = CarList.getCarName(node.SelectSingleNode("CustomCar/Name").InnerText); } current++; } } if (Regex.Match(uri, "/personas/" + single_personaId + "/defaultcar", RegexOptions.IgnoreCase).Success) { if (splitted_uri.Last() != "defaultcar") { string receivedId = splitted_uri.Last(); SBRW_XML.LoadXml(carslotsXML); XmlNode CarsOwnedByPersona = SBRW_XML.SelectSingleNode("CarSlotInfoTrans/CarsOwnedByPersona"); XmlNodeList OwnedCarTrans = CarsOwnedByPersona.SelectNodes("OwnedCarTrans"); foreach (XmlNode node in OwnedCarTrans) { if (receivedId == node.SelectSingleNode("Id").InnerText) { PersonaCarName = CarList.getCarName(node.SelectSingleNode("CustomCar/Name").InnerText); } } } } } }
public override void OnUpdate() { DiscordRpc.RunCallbacks(); }
public void OnDisable() { DiscordRpc.Shutdown(); }
void OnDisable() { Debug.Log("Discord: shutdown"); DiscordRpc.Shutdown(); }
public void OnEnable() { var discordHandlers = new DiscordRpc.EventHandlers(); DiscordRpc.Initialize(DiscordAppID, ref discordHandlers, false, string.Empty); }
void Update() { DiscordRpc.RunCallbacks(); }
public void ApplicationQuit() { DiscordRpc.Shutdown(); }
public static void Initialize() { string lib = null; if (!string.IsNullOrEmpty(CoreModule.Settings.DiscordLib)) { lib = CoreModule.Settings.DiscordLib; } else if (Environment.OSVersion.Platform == PlatformID.Win32NT) { lib = "discord-rpc.dll"; } else if (Environment.OSVersion.Platform == PlatformID.MacOSX) { lib = "libdiscord-rpc.dylib"; // FIXME: macOS doesn't see libdiscord-rpc.dylib wherever Celeste.exe is. } else if (Environment.OSVersion.Platform == PlatformID.Unix) { lib = "libdiscord-rpc.so"; } if (!string.IsNullOrEmpty(lib)) { DynDll.Mappings["discord-rpc"] = new DynDllMapping() { ResolveAs = lib } } ; string discordID = "430794114037055489"; if (!string.IsNullOrEmpty(CoreModule.Settings.DiscordID)) { discordID = CoreModule.Settings.DiscordID; } try { typeof(DiscordRpc).ResolveDynDllImports(); } catch { } if (DiscordRpc.Initialize == null) { Logger.Log(LogLevel.Info, "discord", "Discord_Initialize not found - skipping Discord Rich Presence."); return; } Logger.Log(LogLevel.Verbose, "discord", $"Discord_Initialize found - initializing Discord Rich Presence, app ID {discordID}"); DiscordHandlers.readyCallback += OnDiscordReady; DiscordHandlers.disconnectedCallback += OnDiscordDisconnect; DiscordHandlers.errorCallback += OnDiscordError; DiscordRpc.Initialize.Invoke(discordID, ref DiscordHandlers, true, "504230"); DiscordRpc.UpdatePresence(DiscordPresence); Events.Celeste.OnExiting += OnGameExit; Events.MainMenu.OnCreateButtons += OnMainMenu; Events.Level.OnLoadLevel += OnLoadLevel; Events.Level.OnExit += OnLevelExit; }
private void OnUpdatePresenceClick(Object sender, EventArgs e) { this.LockRichPresenceButtons(); DiscordRpc.UpdatePresence(this.PresenceControl.GetRichPresence()); }