コード例 #1
0
        static void setCurrentRPCApp(dRPCApplication app, bool reInit = true)
        {
            pPrint($"[I] Setting RPresence to: '{app.sAppName}'...", ConsoleColor.DarkYellow);
            if (dRpcClient != null && dRpcClient.IsInitialized)
            {
                if (reInit)
                {
                    pPrint("[I] Closing current RPC instance...", ConsoleColor.Yellow);
                    dRpcClient.ClearPresence();
                    dRpcClient.Deinitialize();

                    pPrint("[I] Creating a new RPC instance...", ConsoleColor.Yellow);
                    dRpcClient        = new DiscordRpcClient(app.sAppId);
                    dRpcClient.Logger = new ConsoleLoggerFormatted()
                    {
                        Level = lLogLevel
                    };
                    dRpcClient.Initialize();
                }
                RichPresence rp     = new RichPresence();
                Assets       assets = new Assets();
                assets.LargeImageKey  = app.sLargeImgKey;
                assets.SmallImageKey  = app.sSmallImgKey;
                assets.LargeImageText = app.sLargeImgText;
                assets.SmallImageText = app.sSmallImgText;
                rp.Assets             = assets;

                rp.Details = app.sDetails;
                rp.State   = app.sState;
                pPrint("[I] Updating Rich Presence...", ConsoleColor.Yellow);
                dRpcClient.SetPresence(rp);
                dRPCActiveApp = app;
            }
        }
コード例 #2
0
        private void load(IAPIProvider provider)
        {
            client = new DiscordRpcClient(client_id)
            {
                SkipIdenticalPresence = false // handles better on discord IPC loss, see updateStatus call in onReady.
            };

            client.OnReady += onReady;

            // safety measure for now, until we performance test / improve backoff for failed connections.
            client.OnConnectionFailed += (_, __) => client.Deinitialize();

            client.OnError += (_, e) => Logger.Log($"An error occurred with Discord RPC Client: {e.Code} {e.Message}", LoggingTarget.Network);

            (user = provider.LocalUser.GetBoundCopy()).BindValueChanged(u =>
            {
                status.UnbindBindings();
                status.BindTo(u.NewValue.Status);

                activity.UnbindBindings();
                activity.BindTo(u.NewValue.Activity);
            }, true);

            ruleset.BindValueChanged(_ => updateStatus());
            status.BindValueChanged(_ => updateStatus());
            activity.BindValueChanged(_ => updateStatus());

            client.Initialize();
        }
コード例 #3
0
 public static void Hide()
 {
     if (initialized)
     {
         client.Deinitialize();
     }
 }
コード例 #4
0
 private void Button1_Click(object sender, EventArgs e)
 {
     label1.Text = "";
     label2.Text = "";
     client.Deinitialize();
     Initialization();
 }
コード例 #5
0
 private void stop_Click(object sender, EventArgs e)
 {
     if (isEnabled)
     {
         client.Deinitialize();
     }
     else
     {
         MessageBox.Show("Custom status is already disabled!");
     }
     labelStatus.Text = "Status: STOPPED";
     isEnabled        = false;
 }
コード例 #6
0
 private void OnPresenceTimedEvent(object sender, EventArgs e)
 {
     if (Parser.isGameRunning())
     {
         ClientPresence.update();
     }
     else
     {
         presenceTicker.Dispose();
         client.Deinitialize();
         client.Dispose();
         Properties.Settings.Default.Save();
         Environment.Exit(0);
     }
 }
コード例 #7
0
        public void Init()
        {
            client = new DiscordRpcClient(ApplicationId, -1, new VEDiscordLogger());

            client.OnError            += (sender, args) => Logger.Error("Error with Discord RPC: {@Code}:{@Message}", args.Code, args.Message);
            client.OnReady            += (sender, args) => Logger.Info("Client ready: " + args.User.Username);
            client.OnConnectionFailed += (sender, args) =>
            {
                Logger.Error("Error communicating with Discord: Pipe: `{@FailedPipe}`. Is Discord running?", args.FailedPipe);
                client.Deinitialize();
            };
            client.OnClose += (sender, args) => Logger.Info($"Discord RPC was closed: {args.Code}:{args.Reason}");

            client.Initialize();
        }
コード例 #8
0
        private void Update(object sender, EventArgs e)
        {
            if (mem.procs.HasExited)
            {
                Status.Content    = "Currently not injected";
                Status.Foreground = new SolidColorBrush(Color.FromArgb(255, 249, 38, 114));
                client.Deinitialize();
                updater.Stop();
            }
            else
            {
                var map   = getMap();
                var speed = getSpeed();
                // var ts = getTimescale();
                Map.Content   = "Map: " + map.Replace("_", "___");
                Speed.Content = "Speed: " + speed + " hu";

                if (map != "" && previousMap != map)
                {
                    start = DateTime.UtcNow;
                }
                else if (map == "")
                {
                    start = null;
                }

                var futurePresence = new RichPresence()
                {
                    Details = map == "" ? "Main menu" : map,
                    State   = speed + " hammer units", // ts == 1 ? (speed.ToString() + " hammer units") : $"TASing at {ts}x",
                    Assets  = new Assets()
                    {
                        LargeImageKey  = "logo",
                        LargeImageText = "Custom momentum presence.",
                    },
                    Timestamps = new Timestamps()
                    {
                        Start = start
                    }
                };

                if (!client.CurrentPresence || client.CurrentPresence.Details != futurePresence.Details || client.CurrentPresence.State != futurePresence.State)
                {
                    client.SetPresence(futurePresence);
                }
                previousMap = map;
            }
        }
コード例 #9
0
        public CDiscordRichPresence(string strApplicationID)
        {
            client          = new DiscordRpcClient(strApplicationID);
            client.OnReady += (s, a) => Trace.TraceInformation($"Discord Rich Presence ready.");
            client.OnError += (s, a) => Trace.TraceError($"Discord Rich Presence error: {a.Message} ({a.Code})");

            // if this occurs then discord is likely not open,
            // so dont continue spamming connection attempts
            client.OnConnectionFailed += (s, a) =>
            {
                Trace.TraceInformation($"Unable to connect to Discord, disabling Rich Presence.");
                client.Deinitialize();
            };

            client.Initialize();
        }
コード例 #10
0
        public void load()
        {
            client = new DiscordRpcClient(client_id)
            {
                SkipIdenticalPresence = true,
            };

            client.OnReady += onReady;

            client.OnError += Client_OnError;

            client.OnConnectionFailed += (_, __) =>
            {
                client.Deinitialize();
                MessageBox.Show("Клиент был отключен: " + __.FailedPipe);
            };

            client.Initialize();
        }
コード例 #11
0
ファイル: Form1.cs プロジェクト: thebardockgames/GOS2-TOOLS
 private void button1_Click(object sender, EventArgs e)
 {
     if (IsAdmin)
     {
         client.UpdateDetails("Compilando");
         abrirformhija(new Empaquetadores());
         client.UpdateDetails("Compilando");
     }
     else
     {
         MessageBox.Show("Ejecute la Herramienta como Administrador");
         client.Deinitialize();
         Application.Exit();
     }
 }
コード例 #12
0
ファイル: Discord.cs プロジェクト: woke999/Slurp-Juice-
 //you need to deinitilize the discord client when the program exits otherwise it may not shutdown properly
 public static void ShutDown()
 {
     client.Deinitialize();
 }
コード例 #13
0
        //this checks the status for the process
        public void mainProcess(object value)
        {
            while (true)
            {
                try
                {
                    //JK
                    if (!memory.HookProcess())
                    {
                        this.process.Invoke((MethodInvoker) delegate
                        {
                            this.process.Text      = off;
                            this.process.ForeColor = System.Drawing.Color.Red;
                            this.toolTip.SetToolTip(this.process, "Process not found.");
                        });
                        discStatus = false;
                    }
                    else
                    {
                        this.process.Invoke((MethodInvoker) delegate
                        {
                            this.process.Text      = on;
                            this.process.ForeColor = System.Drawing.Color.Green;
                            this.toolTip.SetToolTip(this.process, "JumpKing.exe has been found");
                        });
                        discStatus = true;

                        //check level
                        playerX       = memory.PlayerX();
                        playerY       = memory.PlayerY();
                        playerScreen  = memory.PlayerScreen();
                        gameTime      = TimeSpan.FromSeconds((int)Math.Round(memory.GameTime()));
                        totalGameTime = TimeSpan.FromSeconds((int)Math.Round(memory.TotalGameTime()));
                        Section(playerScreen, playerX, playerY);
                        this.panelStats.Invoke((MethodInvoker) delegate
                        {
                            this.liveSession.Text = "Session n." + memory.Sessions();
                            this.liveLevel.Text   = "Level playing: " + level;
                            this.liveZone.Text    = "Currently in: " + location;
                            if (!(playerX == 0) && !(playerY == 0))
                            {
                                this.toolTip.SetToolTip(this.liveZone, playerScreen.ToString());
                            }
                            this.liveJumpsFalls.Text = "Jumps: " + memory.LiveJumps() + "  —  Falls: " + memory.LiveFalls();
                            this.liveTimestamp.Text  = "Time elapsed: " + (int)gameTime.TotalHours + gameTime.ToString("\\:mm\\:ss");
                            this.totalAttempts.Text  = "Attempts count: " + memory.Attempts();
                            this.totalJumps.Text     = "Total jumps: " + memory.Jumps();
                            this.totalFalls.Text     = "Total falls: " + memory.Falls();
                            this.totalTimestamp.Text = "Time elapsed: " + (int)totalGameTime.TotalHours + totalGameTime.ToString("\\:mm\\:ss");
                        });
                    }
                    SmallImage(giantBoots, snakeRing);
                    Thread.Sleep(250);

                    //Discord
                    if (discStatus && gameStatus == false)
                    {
                        client.Initialize();
                        if (client.IsInitialized)
                        {
                            gameStatus = true;
                        }
                        date = DateTime.UtcNow;
                    }
                    else if (discStatus && gameStatus)
                    {
                        if (playerX == 0 && playerY == 0 && playerScreen == Screen.RedcrownWoods1)
                        {
                            client.SetPresence(new RichPresence()
                            {
                                Details    = "Main Menu",
                                State      = "",
                                Timestamps = new Timestamps()
                                {
                                    Start = date
                                },
                                Assets = new Assets()
                                {
                                    LargeImageKey  = "jklogo",
                                    LargeImageText = details
                                }
                            });
                        }
                        else
                        {
                            UpdateRPC();
                        }

                        this.discordStatus.Invoke((MethodInvoker) delegate
                        {
                            this.discordStatus.Text      = on;
                            this.discordStatus.ForeColor = System.Drawing.Color.Green;
                        });
                    }
                    else if (discStatus == false && gameStatus == true)
                    {
                        client.ClearPresence();
                        client.Deinitialize();
                        this.discordStatus.Invoke((MethodInvoker) delegate
                        {
                            this.discordStatus.Text      = off;
                            this.discordStatus.ForeColor = System.Drawing.Color.Red;
                            this.toolTip.SetToolTip(this.discordStatus, "This can sometimes break.\r\nConsider reopening the application if it does not show up correctly.");
                        });
                        gameStatus = false;
                    }
                }
                catch (NotImplementedException notImp)
                {
                    Console.WriteLine("errorlol: " + notImp.Message);
                }
            }
        }
コード例 #14
0
 protected override void OnExit(ExitEventArgs e)
 {
     client.Deinitialize();
     client.Dispose();
     base.OnExit(e);
 }
コード例 #15
0
 public void DeInitClient()
 {
     client.Dispose();
     client.Deinitialize();
 }
コード例 #16
0
 public static void StopRPC()
 {
     client.ClearPresence();
     client.Deinitialize();
     client = null;
 }
コード例 #17
0
ファイル: Program.cs プロジェクト: hayden-droid/Cyrup-Source
        static void Draw(string color)
        {
            DiscordRpcClient client = new DiscordRpcClient("797124617268625408");

            client.SetPresence(new RichPresence()
            {
                Details = "Level 7 Roblox Lua Executor | TRIPLE API",
                State   = "Using Cyrup v4",
                Assets  = new Assets()
                {
                    LargeImageKey = "untitled_7_",
                }
            });

            if (Settings.Default.RPC == true)
            {
                client.Initialize();
            }
            Console.SetWindowSize(80, 20);
            Console.Title = "Coco Z";
            EasyExploits.Module easy = new EasyExploits.Module();
            ExploitAPI          wrd  = new ExploitAPI();

            Terminal.Gui.Application.Init();
            var top  = Terminal.Gui.Application.Top;
            var win  = new FrameView(new Rect(0, 0, top.Frame.Width - 68, top.Frame.Height), "Cyrup");
            var win2 = new FrameView(new Rect(12, 0, top.Frame.Width - 12, top.Frame.Height), "");

            if (color == "msdos")
            {
                Colors.Base.Normal   = Terminal.Gui.Application.Driver.MakeAttribute(Color.BrightYellow, Color.Blue);
                Colors.Menu.Normal   = Terminal.Gui.Application.Driver.MakeAttribute(Color.White, Color.Blue);
                Colors.Dialog.Normal = Terminal.Gui.Application.Driver.MakeAttribute(Color.BrightYellow, Color.BrightBlue);
            }
            else
            {
                Colors.Base.Normal   = Terminal.Gui.Application.Driver.MakeAttribute(Color.BrightMagenta, Color.Black);
                Colors.Menu.Normal   = Terminal.Gui.Application.Driver.MakeAttribute(Color.Cyan, Color.Black);
                Colors.Dialog.Normal = Terminal.Gui.Application.Driver.MakeAttribute(Color.Magenta, Color.Black);
            }
            win.ColorScheme  = Colors.Base;
            win2.ColorScheme = Colors.Base;
            top.Add(win);
            top.Add(win2);

            var exec = new Terminal.Gui.Button(1, 3, "Exec");
            var clr  = new Terminal.Gui.Button(1, 5, "Clr ");
            var open = new Terminal.Gui.Button(1, 7, "Open");
            var save = new Terminal.Gui.Button(1, 9, "Save");
            var inj  = new Terminal.Gui.Button(1, 1, "Inj ");
            var opt  = new Terminal.Gui.Button(1, 16, "Opt ");

            var editor = new TextView()
            {
                X           = 0,
                Y           = 0,
                Width       = Dim.Fill(),
                Height      = Dim.Fill(),
                ColorScheme = Colors.Menu
            };

            string credits = @"--[[
Stop cumming in me stepdaddy oh your hot warm milk~
--]]";

            editor.Text = credits.Replace("\r\n", "\n");

            win2.KeyDown += (k) =>
            {
                if (k.KeyEvent.Key == Key.CtrlMask)
                {
                    string paste = System.Windows.Forms.Clipboard.GetText();
                    editor.Text = paste.Replace("\r\n", "\n");
                    k.Handled   = true;
                }
            };

            inj.Clicked += () =>
            {
                if (Process.GetProcessesByName("RobloxPlayerBeta").Length < 1)
                {
                    Terminal.Gui.MessageBox.ErrorQuery(50, 5, "Error", "Please open Roblox before injecting!", "Okay");
                    return;
                }
                if (String.IsNullOrEmpty(Settings.Default.APIName))
                {
                    Terminal.Gui.MessageBox.ErrorQuery(50, 5, "Error", "Please select a DLL first!", "Okay");
                    return;
                }
                if (Settings.Default.APIName == "easy")
                {
                    if (easy.IsAttached())
                    {
                        Terminal.Gui.MessageBox.ErrorQuery(50, 5, "Error", "EasyExploits API is already injected!", "Okay");
                        return;
                    }
                    else
                    {
                        Process.Start(Environment.CurrentDirectory + "\\bin\\console.exe");
                        easy.LaunchExploit();
                        if (IsDirectoryEmpty(Environment.CurrentDirectory + "/autoexec") == false)
                        {
                            AutoExecEasy();
                        }
                        return;
                    }
                }
                if (Settings.Default.APIName == "wrd")
                {
                    if (wrd.isAPIAttached())
                    {
                        Terminal.Gui.MessageBox.ErrorQuery(50, 5, "Error", "WeAreDevs API is already injected!", "Okay");
                        return;
                    }
                    else
                    {
                        Process.Start(Environment.CurrentDirectory + "\\bin\\console.exe");
                        wrd.LaunchExploit();
                        if (IsDirectoryEmpty(Environment.CurrentDirectory + "/autoexec") == false)
                        {
                            AutoExecWRD();
                        }
                        return;
                    }
                }
                if (Settings.Default.APIName == "krnl")
                {
                    if (MainAPI.IsAttached())
                    {
                        Terminal.Gui.MessageBox.ErrorQuery(50, 5, "Error", "KRNL DLL is already injected!", "Okay");
                        return;
                    }
                    else
                    {
                        Process.Start(Environment.CurrentDirectory + "\\bin\\console.exe");
                        MainAPI.Inject();
                        if (IsDirectoryEmpty(Environment.CurrentDirectory + "/autoexec") == false)
                        {
                            AutoExecKRNL();
                        }
                        return;
                    }
                }
            };

            exec.Clicked += () =>
            {
                if (String.IsNullOrEmpty(Settings.Default.APIName))
                {
                    var error = Terminal.Gui.MessageBox.ErrorQuery(50, 5, "Error", "Please select a DLL first!", "Okay");
                    return;
                }
                if (Settings.Default.APIName == "easy")
                {
                    if (easy.IsAttached())
                    {
                        easy.ExecuteScript(Convert.ToString(editor.Text));
                        return;
                    }
                    else
                    {
                        Terminal.Gui.MessageBox.ErrorQuery(50, 5, "Error", "Exploit is not injected!", "Okay");
                        return;
                    }
                }
                if (Settings.Default.APIName == "wrd")
                {
                    if (wrd.isAPIAttached())
                    {
                        wrd.SendLuaScript(Convert.ToString(editor.Text));
                        return;
                    }
                    else
                    {
                        Terminal.Gui.MessageBox.ErrorQuery(50, 5, "Error", "Exploit is not injected!", "Okay");
                        return;
                    }
                }
                if (Settings.Default.APIName == "krnl")
                {
                    if (MainAPI.IsAttached())
                    {
                        MainAPI.Execute(Convert.ToString(editor.Text));
                        return;
                    }
                    else
                    {
                        Terminal.Gui.MessageBox.ErrorQuery(50, 5, "Error", "Exploit is not injected!", "Okay");
                        return;
                    }
                }
            };

            clr.Clicked += () =>
            {
                editor.Text = String.Empty;
            };

            save.Clicked += () =>
            {
                var saveChoice = Terminal.Gui.MessageBox.Query(50, 5, "Save Options", "Obfuscate script? (Lua only)", "Yes", "No");
                if (saveChoice == 0)
                {
                }
                if (saveChoice == 1)
                {
                    SaveFileDialog saveFileDialog1 = new SaveFileDialog
                    {
                        Title = "Save File",

                        CheckPathExists = true,

                        DefaultExt       = "txt",
                        Filter           = "Text files (*.txt)|*.txt",
                        FilterIndex      = 2,
                        RestoreDirectory = true
                    };
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        FileInfo fi = new FileInfo(saveFileDialog1.FileName);
                        using (StreamWriter sw = fi.CreateText())
                        {
                            sw.WriteLine(editor.Text.ToString());
                        }
                    }
                    return;
                }
            };

            open.Clicked += () =>
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog
                {
                    InitialDirectory = Environment.CurrentDirectory + "\\scripts",
                    Title            = "Browse Text Files",

                    CheckFileExists = true,
                    CheckPathExists = true,

                    DefaultExt       = "txt",
                    Filter           = "Text files (*.txt)|*.txt",
                    FilterIndex      = 2,
                    RestoreDirectory = true,

                    ReadOnlyChecked = true
                };

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    string text = File.ReadAllText(openFileDialog1.FileName);
                    editor.Text = text.Replace("\r\n", "\n");
                }
            };

            opt.Clicked += () =>
            {
                var optMenu = Terminal.Gui.MessageBox.Query(50, 5, "Options", "Options Menu", "Select DLL", "Discord RPC", "Kill Roblox");

                if (optMenu == 2)
                {
                    var areyousure = Terminal.Gui.MessageBox.Query(50, 5, "Stop", "Are you sure?", "Yes kill Roblox", "No");
                    if (areyousure == 0)
                    {
                        foreach (var process in Process.GetProcessesByName("RobloxPlayerBeta"))
                        {
                            process.Kill();
                        }
                    }

                    if (areyousure == 1)
                    {
                        return;
                    }
                }

                if (optMenu == 1)
                {
                    var _0 = Terminal.Gui.MessageBox.Query(50, 5, "Options Menu", "Discord RPC Settings", "Enable RPC", "Disable RPC");
                    if (_0 == 0)
                    {
                        Settings.Default.RPC = true;
                        Settings.Default.Save();
                        if (client.IsInitialized == false)
                        {
                            client.Initialize();
                            client.SetPresence(new RichPresence()
                            {
                                Details = "Level 7 Roblox Lua Executor | TRIPLE API",
                                State   = "Using Cyrup v4",
                                Assets  = new Assets()
                                {
                                    LargeImageKey = "untitled_7_",
                                }
                            });
                        }
                        Terminal.Gui.MessageBox.Query(50, 5, "Notice", "RPC has been enabled", "Okay");
                        return;
                    }

                    if (_0 == 1)
                    {
                        Settings.Default.RPC = false;
                        Settings.Default.Save();
                        client.Deinitialize();
                        Terminal.Gui.MessageBox.Query(50, 5, "Notice", "RPC has been disabled", "Okay");
                        return;
                    }
                }

                if (optMenu == 0)
                {
                    var dsec = Terminal.Gui.MessageBox.Query(50, 5, "Select DLL", "Select an API", "EasyExploits", "WeAreDevs", "KRNL DLL");
                    if (dsec == 0)
                    {
                        Settings.Default.APIName = "easy";
                        Settings.Default.Save();
                        Terminal.Gui.MessageBox.Query(50, 5, "Notice", "EasyExploits API has been selected", "Okay");
                        return;
                    }
                    if (dsec == 1)
                    {
                        Settings.Default.APIName = "wrd";
                        Settings.Default.Save();
                        Terminal.Gui.MessageBox.Query(50, 5, "Notice", "WeAreDevs API has been selected", "Okay");
                        return;
                    }
                    if (dsec == 2)
                    {
                        Settings.Default.APIName = "krnl";
                        Settings.Default.Save();
                        Terminal.Gui.MessageBox.Query(50, 5, "Notice", "KRNL DLL has been selected", "Okay");
                        return;
                    }
                    return;
                }
            };


            win.Add(
                inj,
                exec,
                clr,
                open,
                save,
                opt
                );

            win2.Add(
                editor
                );

            bool IsDirectoryEmpty(string path)
            {
                return(!Directory.EnumerateFileSystemEntries(path).Any());
            }

            void AutoExecEasy()
            {
                if (easy.IsAttached())
                {
                    foreach (string file in Directory.EnumerateFiles(Environment.CurrentDirectory + "/autoexec", "*.*"))
                    {
                        string contents = File.ReadAllText(file);
                        easy.ExecuteScript(contents);
                        Thread.Sleep(500);
                    }
                }
                else
                {
                    Thread.Sleep(500);
                    AutoExecEasy();
                }
            }

            void AutoExecWRD()
            {
                if (wrd.isAPIAttached())
                {
                    foreach (string file in Directory.EnumerateFiles(Environment.CurrentDirectory + "/autoexec", "*.*"))
                    {
                        string contents = File.ReadAllText(file);
                        wrd.SendLuaScript(contents);
                        Thread.Sleep(500);
                    }
                }
                else
                {
                    Thread.Sleep(500);
                    AutoExecWRD();
                }
            }

            void AutoExecKRNL()
            {
                if (MainAPI.IsAttached())
                {
                    foreach (string file in Directory.EnumerateFiles(Environment.CurrentDirectory + "/autoexec", "*.*"))
                    {
                        string contents = File.ReadAllText(file);
                        MainAPI.Execute(contents);
                        Thread.Sleep(500);
                    }
                }
                else
                {
                    Thread.Sleep(500);
                    AutoExecKRNL();
                }
            }

            Terminal.Gui.Application.Run();
        }
コード例 #18
0
 public static void Deinitialize() => _client.Deinitialize();
コード例 #19
0
 /// <summary>
 /// Deinitializes the DiscordRpc client
 /// </summary>
 public void Deinitialize()
 {
     _client.Deinitialize();
 }
コード例 #20
0
#pragma warning restore VSTHRD100 // Avoid async void methods

        /// <summary>
        /// Updates the presence with the document
        /// </summary>
        /// <param name="document"></param>
        /// <param name="overrideTimestampReset"></param>
        /// <returns></returns>
        internal async Task UpdatePresenceAsync(Document document, bool overrideTimestampReset = false)
        {
            try
            {
                await JoinableTaskFactory.SwitchToMainThreadAsync();

                if (Settings.enabled)
                {
                    Presence = new RichPresence();
                    if (Settings.secretMode)
                    {
                        Assets           = null;
                        Presence.Details = "I'm working on something you're";
                        Presence.State   = "not allowed to know about, sorry.";
                    }
                    else
                    {
                        string[] language = new string[] { };
                        if (document != null)
                        {
                            string filename = Path.GetFileName(document.FullName).ToLower();
                            string ext      = Path.GetExtension(filename);
                            List <KeyValuePair <string[], string[]> > list = Languages.Where(lang => Array.IndexOf(lang.Key, filename) > -1 || Array.IndexOf(lang.Key, ext) > -1).ToList();
                            language = list.Count > 0 ? list[0].Value : new string[] { };
                        }

                        bool supported = language.Length > 0;
                        Assets = new Assets()
                        {
                            LargeImageKey  = Settings.largeLanguage ? supported ? language[0] : "text" : $"vs{ideVersion}",
                            LargeImageText = Settings.largeLanguage ? supported ? language[1] : "Unrecognized extension" : $"Visual Studio {ideVersion}",
                            SmallImageKey  = Settings.largeLanguage ? $"vs{ideVersion}" : supported ? language[0] : "text",
                            SmallImageText = Settings.largeLanguage ? $"Visual Studio {ideVersion}" : supported ? language[1] : "Unrecognized extension"
                        };

                        if (Settings.showFileName)
                        {
                            Presence.Details = document != null?Path.GetFileName(document.FullName) : "No file.";
                        }

                        if (Settings.showSolutionName)
                        {
                            bool idling = ide.Solution == null || ide.Solution.FullName == string.Empty || ide.Solution.FullName == null;
                            Presence.State = idling ? "Idling" : $"Developing {Path.GetFileNameWithoutExtension(ide.Solution.FileName)}";
                            if (idling)
                            {
                                Assets = new Assets()
                                {
                                    LargeImageKey  = $"vs{ideVersion}",
                                    LargeImageText = $"Visual Studio {ideVersion}"
                                }
                            }
                            ;
                        }

                        if (Settings.showTimestamp && document != null)
                        {
                            if (!InitializedTimestamp)
                            {
                                Presence.Timestamps = new Timestamps()
                                {
                                    Start = DateTime.UtcNow
                                };
                                InitialTimestamps    = Presence.Timestamps;
                                InitializedTimestamp = true;
                            }

                            if (Settings.resetTimestamp && !overrideTimestampReset)
                            {
                                Presence.Timestamps = new Timestamps()
                                {
                                    Start = DateTime.UtcNow
                                }
                            }
                            ;
                            else if (Settings.resetTimestamp && overrideTimestampReset)
                            {
                                Presence.Timestamps = CurrentTimestamps;
                            }
                            else if (!Settings.resetTimestamp && !overrideTimestampReset)
                            {
                                Presence.Timestamps = InitialTimestamps;
                            }
                            CurrentTimestamps = Presence.Timestamps;
                        }
                    }

                    if (!discordClient.IsInitialized)
                    {
                        discordClient.Initialize();
                    }

                    Presence.Assets = Assets;
                    discordClient.SetPresence(Presence);
                }
                else if (!Settings.enabled && discordClient.IsInitialized)
                {
                    discordClient.Deinitialize();
                }
            }
            catch (Exception e)
            {
                ActivityLog.LogError(e.Source, e.Message);
            }
        }
コード例 #21
0
ファイル: Discord.cs プロジェクト: snowthestorm/epresence
 public void Reset()
 {
     DiscordRpcClient.Deinitialize();
 }