Пример #1
0
        private RichPresence GetPresence()
        {
            var presence = new RichPresence {
                Details = api.FormatText(Conf.Details),
                State   = api.FormatText(Conf.State)
            };
            var assets = new Assets {
                LargeImageKey  = "default_large",
                LargeImageText = api.FormatText(Conf.LargeImageText),
                SmallImageText = api.FormatText(Conf.SmallImageText)
            };

            if (Conf.ForceSmallImage || assets.SmallImageText?.Length > 0)
            {
                assets.SmallImageKey = "default_small";
            }

            if (Context.IsWorldReady)
            {
                var conf = (GamePresence)Conf;
                if (conf.ShowSeason)
                {
                    assets.LargeImageKey = $"{Game1.currentSeason}_{FarmTypeKey()}";
                }
                if (conf.ShowWeather)
                {
                    assets.SmallImageKey = "weather_" + WeatherKey();
                }
                if (conf.ShowPlayTime)
                {
                    presence.Timestamps = timestampFarm;
                }
                if (Context.IsMultiplayer && conf.AllowAskToJoin)
                {
                    try {
                        presence.Party = new Party {
                            ID   = Game1.MasterPlayer.UniqueMultiplayerID.ToString(),
                            Size = Game1.numberOfPlayers(),
                            Max  = Game1.getFarm().getNumberBuildingsConstructed("Cabin") + 1
                        };
                        presence.Secrets = new Secrets {
                            JoinSecret = Game1.server.getInviteCode()
                        };
                    } catch { }
                }
            }

            if (config.ShowGlobalPlayTime)
            {
                presence.Timestamps = timestampSession;
            }

            return(presence.WithAssets(assets));
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.Title           = "Discord-RPC";
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Attempting to start Discord-RPC, if something errors after this message, you've got an error in your config");
            try
            {
                dynamic      JSON    = JObject.Parse(File.ReadAllText("config.json"));
                var          Context = new DiscordRpcClient(JSON.AppID.ToString());
                RichPresence RP      = new RichPresence();

                Context.Initialize();

                RP.WithState(JSON.State.ToString());
                RP.WithDetails(JSON.Details.ToString());

                string StartTime = JSON.StartTime.ToString();
                if (!string.IsNullOrEmpty(StartTime))
                {
                    Context.UpdateStartTime(DateTime.Parse(StartTime));
                }

                Assets _Assets = new Assets()
                {
                    LargeImageKey  = JSON.LargeAsset.Key.ToString(),
                    LargeImageText = JSON.LargeAsset.Tooltip.ToString(),
                    SmallImageKey  = JSON.SmallAsset.Key.ToString(),
                    SmallImageText = JSON.SmallAsset.Tooltip.ToString()
                };

                RP.WithAssets(_Assets);
                // Add Buttons

                List <Button> UserButtons = new List <Button>();

                string Btn1Label = JSON.Buttons.Button1.Text.ToString();
                string Btn2Label = JSON.Buttons.Button2.Text.ToString();

                string Btn1URL = JSON.Buttons.Button1.URL.ToString();
                string Btn2URL = JSON.Buttons.Button2.URL.ToString();

                Button Button1 = new Button();
                Button Button2 = new Button();

                if (Btn1Label != "" && Btn1URL != "")
                {
                    Button1.Label = Btn1Label;
                    Button1.Url   = Btn1URL;
                    UserButtons.Add(Button1);
                }
                if (Btn2Label != "" && Btn2URL != "")
                {
                    Button2.Label = Btn2Label;
                    Button2.Url   = Btn2URL;
                    UserButtons.Add(Button2);
                }

                RP.Buttons = UserButtons.ToArray();
                Context.SetPresence(RP);

                System.Threading.Thread.Sleep(2500);

                Console.ForegroundColor = ConsoleColor.Green;
                Console.Title           = "Discord-RPC @ Connected";
                Console.WriteLine($"Sucesfully updated {Context.CurrentUser.Username}#{Context.CurrentUser.Discriminator} presence");
                Console.ForegroundColor = ConsoleColor.White;

                System.Threading.Thread.Sleep(-1);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
                Console.ForegroundColor = ConsoleColor.White;
                Console.ReadLine();
            }
        }