Ejemplo n.º 1
0
        static void MainLoop()
        {
            /*
             * Enter a infinite loop, polling the Discord Client for events.
             * In game termonology, this will be equivalent to our main game loop.
             * If you were making a GUI application without a infinite loop, you could implement
             * this with timers.
             */
            isRunning = true;
            while (client != null && isRunning)
            {
                //We will invoke the client events.
                // In a game situation, you would do this in the Update.
                if (client != null)
                {
                    client.Invoke();
                }

                //Try to read any keys if available
                if (Console.KeyAvailable)
                {
                    ProcessKey();
                }

                //This can be what ever value you want, as long as it is faster than 30 seconds.
                //Console.Write("+");
                Thread.Sleep(1000);

                //client.SetPresence(presence);
            }

            client.Dispose();
            Console.WriteLine("Press any key to terminate");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes connection to the Discord API.
        /// </summary>
        /// <returns><see langword="False"/> if ID isn't set, otherwise <see langword="true"/>.</returns>
        private bool Init()
        {
            if (settings.id == "")
            {
                MessageBox.Show(Strings.errorNoID, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return(false);
            }

            if (client != null && !client.IsDisposed)
            {
                client.Dispose();                                           // This stuff needs proper disposal
            }
            client = new DiscordRpcClient(settings.id, (int)settings.pipe); // Assigning the ID
            client.OnPresenceUpdate   += ClientOnPresenceUpdate;
            client.OnError            += ClientOnError;
            client.OnConnectionFailed += ClientOnConnFailed;

            client.Logger = new TimestampFileLogger(Application.StartupPath + "\\rpc.log");

            client.Initialize();

            SetPresence();

            return(true);
        }
Ejemplo n.º 3
0
        private void Update()
        {
            if (m_Client != null)
            {
                m_Lock.EnterReadLock();
                try
                {
                    m_Client.SetPresence(m_Presence);
                }
                finally
                {
                    m_Lock.ExitReadLock();
                }
                m_Client.Invoke();
            }

            if (m_Active == true)
            {
                if (m_Client == null)
                {
                    m_Client = new DiscordRpcClient(DiscordAppId);
                    if (m_Client.Initialize() == false)
                    {
                        m_Client.Dispose();
                        m_Client = null;
                    }
                }
            }
            else if (m_Client != null)
            {
                m_Client.Dispose();
                m_Client = null;
            }
        }
Ejemplo n.º 4
0
 public static void DisposeDiscord()
 {
     if (discordClient != null && !discordClient.IsDisposed)
     {
         discordClient.Dispose();
     }
 }
Ejemplo n.º 5
0
        public void Dispose()
        {
            discord.Dispose();
            timer.Dispose();

            pluginStatusText.Text = "Plugin Unloaded";
        }
Ejemplo n.º 6
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (RpcClient != null && RpcClient.IsInitialized)
     {
         RpcClient.ClearPresence();
         RpcClient.Dispose();
     }
 }
Ejemplo n.º 7
0
        protected override void Dispose(bool disposing)
        {
            if (client.IsInitialized)
            {
                client.ClearPresence();
            }

            client.Dispose();
            base.Dispose(disposing);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Tests the connection with the chosen pipe.
        /// </summary>
        private void TestConnection()
        {
            if (client != null && !client.IsDisposed)
            {
                client.Dispose();
            }

            client                     = new DiscordRpcClient("896771305108553788", (int)numericUpDownPipe.Value);
            client.OnReady            += ConnectionSuccessful;
            client.OnConnectionFailed += ConnectionFailed;
            client.Initialize();
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Disposes the DiscordRpc class
 /// </summary>
 public void Dispose()
 {
     ClearPresence();
     Deinitialize();
     _client.Dispose();
     GC.SuppressFinalize(this);
 }
Ejemplo n.º 10
0
        static void mainPresence()
        {
            var client = new DiscordRpcClient(_ClientID);

            //client.Logger = new ConsoleLogger() {Level = DiscordLogLevel, Colored = true};

            //client.OnReady += (sender, msg) => { Console.WriteLine("Connected to discord under user: {0}", msg.User.Username); };
            //client.OnPresenceUpdate += (sender, msg) => { Console.WriteLine("Presence has been updated"); };

            //timer to regularly invoke
            var timer = new System.Timers.Timer(150);

            timer.Elapsed += (sender, evt) => { client.Invoke(); };
            timer.Start();

            //connect
            client.Initialize();

            client.SetPresence(presence);

            Console.WriteLine("Discord Rich Presence Initialization Finished.");
            Console.WriteLine("This window close in 15 seconds.");
            Console.WriteLine("You can terminate the program in task manager. It will be called CustomPresence.exe in background processes.");
            Thread.Sleep(15000);
            //Hide
            var handle = GetConsoleWindow();

            ShowWindow(handle, SW_HIDE);

            Console.ReadKey();
            timer.Dispose();
            client.Dispose();
        }
Ejemplo n.º 11
0
 void Deinitialize()
 {
     if (client2 != null)
     {
         client2.Dispose();
     }
 }
Ejemplo n.º 12
0
        public void Close()
        {
            LoggingHandler.Log("Closing Discord integration");

            client.ClearPresence();
            client.Dispose();
        }
 public void Stop()
 {
     _discordReady   = false;
     _discordRunning = false;
     _discordClient?.Dispose();
     _discordClient = null;
 }
Ejemplo n.º 14
0
 //Dispose client
 public static void Cleanup()
 {
     if (isReady)
     {
         _client.Dispose();
     }
 }
Ejemplo n.º 15
0
 public static void Dispose()
 {
     if (client != null)
     {
         client.Dispose();
     }
 }
 public static void ShutDown()
 {
     //temporarily shuts down the rich presence to set a new one up with a different ID
     client.ShutdownOnly = true;
     client.ClearPresence();
     client.Dispose();
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Listens on URI for State-Information and handles responses
 /// </summary>
 private void Listen()
 {
     try
     {
         while (true)
         {
             this.UpdateServiceStatus(ServiceState.SERVICE_RUNNING);
             HttpListener listener = new HttpListener();
             listener.Prefixes.Add(this.uri + "/");
             listener.Start();
             HttpListenerContext  context  = listener.GetContext();
             HttpListenerResponse response = context.Response;
             dynamic Json = JObject.Parse(this.GetRequestData(context.Request));
             response.StatusCode = 200;
             Stream output = response.OutputStream;
             output.Write(new byte[1], 0, (new byte[1]).Length);
             listener.Stop();
             this.UpdateDiscordPresence(Json);
             this.Listen();
         }
     }
     catch (ThreadAbortException)
     {
         this.UpdateServiceStatus(ServiceState.SERVICE_STOPPED);
         discordClient.ClearPresence();
         discordClient.Dispose();
     }
 }
Ejemplo n.º 18
0
        public static void Shutdown()
        {
            App.Logging.LogEvent(App.Text.Client, App.Text.ShuttingDown);

            _uptime?.Stop();
            _uptime?.Dispose();
            RPCClient?.Dispose();
            MainPage._MainPage.frmRPCPreview.Dispatcher.Invoke(async() =>
            {
                await((RPCPreview)MainPage._MainPage.frmRPCPreview.Content).UpdateUIViewType(RPCPreview.ViewType
                                                                                             .Default);

                MainPage._MainPage.btnStart.SetResourceReference(FrameworkElement.StyleProperty, "ButtonGreen");
                switch (MainPage._MainPage.frmContent.Content)
                {
                case MultiRPCPage multiRpcPage:
                    MainPage._MainPage.btnStart.Content = App.Text.Start + " MultiRPC";
                    multiRpcPage.CanRunRPC();
                    break;

                case MasterCustomPage _CustomPage:
                    MainPage._MainPage.btnStart.Content = App.Text.StartCustom;
                    _CustomPage.CustomPage.CanRunRPC();
                    break;

                default:
                    MainPage._MainPage.btnStart.Content = _pageUserWasOnWhenStarted.Contains("MultiRPC")
                            ? App.Text.Start + " MultiRPC"
                            : App.Text.StartCustom;
                    break;
                }

                MainPage._MainPage.btnUpdate.IsEnabled = false;
                MainPage._MainPage.rCon.Text           = App.Text.Disconnected;
            });

            AFK = false;

            if (MasterCustomPage._MasterCustomPage != null)
            {
                MasterCustomPage._MasterCustomPage.Dispatcher.Invoke(() =>
                {
                    if (MasterCustomPage._MasterCustomPage != null)
                    {
                        for (var i = 0; i < MasterCustomPage.ProfileButtons.Count; i++)
                        {
                            MasterCustomPage.ProfileButtons[i].IsEnabled = true;
                        }

                        MasterCustomPage._MasterCustomPage.imgProfileAdd.IsEnabled    = true;
                        MasterCustomPage._MasterCustomPage.imgProfileDelete.IsEnabled = true;
                    }
                });
                CustomPage._CustomPage.Dispatcher.Invoke(() => CustomPage._CustomPage.tbClientID.IsEnabled = true);
            }

            IsRPCRunning = false;
            RPCShutdown?.Invoke(null, EventArgs.Empty);
        }
Ejemplo n.º 19
0
        static async void IssueMultipleSets()
        {
            // == Create the client
            var client = new DiscordRpcClient("424087019149328395", pipe: discordPipe)
            {
                Logger = new Logging.ConsoleLogger(logLevel, true)
            };

            // == Subscribe to some events
            client.OnReady += (sender, msg) =>
            {
                //Create some events so we know things are happening
                Console.WriteLine("Connected to discord with user {0}", msg.User.Username);
            };

            client.OnPresenceUpdate += (sender, msg) =>
            {
                //The presence has updated
                Console.WriteLine("Presence has been updated! ");
            };

            // == Initialize
            client.Initialize();
            int attempt = 0;

            while (true && !Console.KeyAvailable)
            {
                attempt++;

                Console.WriteLine("Setting: {0}", attempt);
                client.SetPresence(new DiscordRPC.RichPresence()
                {
                    Details    = "Test",
                    State      = attempt.ToString() + " attempt",
                    Timestamps = Timestamps.Now,
                    Assets     = new Assets()
                    {
                        LargeImageKey  = $"image_large_" + (attempt % 4),
                        LargeImageText = "Fish Sticks",
                    }
                });

                await Task.Delay(15000);

                //Thread.Sleep(15000);

                client.ClearPresence();

                await Task.Delay(1500);

                //Thread.Sleep(1500);
            }

            Console.WriteLine("EXITED");

            // == At the very end we need to dispose of it
            Console.ReadKey();
            client.Dispose();
        }
Ejemplo n.º 20
0
 internal void Exit()
 {
     lock (this)
     {
         m_Timer.Change(-1, -1);
         m_Client?.Dispose();
     }
 }
Ejemplo n.º 21
0
 // Disconnects the client if connected
 private void DisconnectClient()
 {
     if (client != null)
     {
         Console.WriteLine("Disposing client (possibly due to reconnection attempt)");
         client.Dispose();
     }
 }
Ejemplo n.º 22
0
 public void Dispose()
 {
     if (!_disposed)
     {
         _discClient.Dispose();
         _disposed = true;
     }
 }
Ejemplo n.º 23
0
        void StartDSActivity()
        {
            DiscordRpcClient client = new DiscordRpcClient(!String.IsNullOrEmpty(Properties.Settings.Default.DSRPkey) ? Properties.Settings.Default.DSRPkey
                        : "796786581708079115");

            client.OnReady += (se, evu) =>
            {
                AddLog("[Discord] Получено событие Ready от пользователя " + evu.User.Username);
            };

            client.OnPresenceUpdate += (se, evu) =>
            {
                AddLog("[Discord] Детали игровой активности изменены: \"" + evu.Presence.Details + "\"");
            };

            if (!client.Initialize())
            {
                throw new Exception("Неверный ClientID приложения");
            }

            if (Properties.Settings.Default.DSRPmode == 0)
            {
                client.SetPresence(new RichPresence()
                {
                    Details = "Idling",
                    Assets  = new Assets()
                    {
                        LargeImageKey  = "logo",
                        LargeImageText = "CustomStatus",
                    }
                });
            }
            else
            {
                client.SetPresence(new RichPresence()
                {
                    Details = !String.IsNullOrEmpty(Properties.Discord.Default.Details) ? Properties.Discord.Default.Details : null,
                    State   = !String.IsNullOrEmpty(Properties.Discord.Default.State) ? Properties.Discord.Default.State : null,
                    Assets  = new Assets()
                    {
                        LargeImageKey  = !String.IsNullOrEmpty(Properties.Discord.Default.LargeImg) ? Properties.Discord.Default.LargeImg : null,
                        LargeImageText = !String.IsNullOrEmpty(Properties.Discord.Default.LargeText) ? Properties.Discord.Default.LargeText : null,
                        SmallImageKey  = !String.IsNullOrEmpty(Properties.Discord.Default.SmallImg) ? Properties.Discord.Default.SmallImg : null,
                        SmallImageText = !String.IsNullOrEmpty(Properties.Discord.Default.SmallText) ? Properties.Discord.Default.SmallText : null,
                    },
                    Timestamps = new Timestamps()
                    {
                        StartUnixMilliseconds = Properties.Discord.Default.UseTimer ? (ulong?)(DateTime.Now.ToUniversalTime()
                                                                                               - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds : null
                    }
                });
            }
            Task.Factory.StartNew(() => {
                DSStatus(client);
                client.Dispose();
            });
            AddLog("[Discord] Бот успешно запущен!");
        }
Ejemplo n.º 24
0
 public static void PresenceDelete()
 {
     if (client == null || client.CurrentPresence == null)
     {
         return;
     }
     client.ClearPresence();
     client.Dispose();
 }
Ejemplo n.º 25
0
 public static void Exit()
 {
     tray.Dispose();
     client.Dispose();
     Thread.Sleep(1000);
     Console.WriteLine("RPC closed.");
     sw.Close();
     Application.Exit();
 }
Ejemplo n.º 26
0
 public void CloseConnection()
 {
     if (Client != null)
     {
         Debugger.Discord("Closed connection");
         Client.ClearPresence();
         Client.Dispose();
     }
 }
Ejemplo n.º 27
0
 public void Dispose()
 {
     if (client != null)
     {
         client.Dispose();
         client   = null;
         instance = null;
     }
 }
 private void OnDisable()
 {
     if (_client != null)
     {
         Debug.Log("[DRP] Disposing Discord IPC Client...");
         _client.Dispose();
         _client = null;
         Debug.Log("[DRP] Finished Disconnecting");
     }
 }
Ejemplo n.º 29
0
 private void guna2ImageButton2_Click(object sender, EventArgs e)
 {
     if (chkStartUp.Checked == true)
     {
         if (guna2CheckBox1.Checked == true)
         {
             client.Dispose();
         }
         if (Properties.Settings.Default.langtr == true)
         {
             this.Alert("Launcher küçültüldü", "Tekrar açmak için bildirim ", "simgesine 2 kere tıklayın.", Form_Info.enmType.minimized);
         }
         else
         {
             this.Alert("Launcher minimized", "Click the tray icon for", "open program.", Form_Info.enmType.minimized);
         }
     }
     this.WindowState = FormWindowState.Minimized;
 }
Ejemplo n.º 30
0
        public void Deinitialize()
        {
            if (_client == null)
            {
                return;
            }

            _client.Dispose();
            _client = null;
        }