[Plugin] OpenBullet Colorizer



  • alt text

    OBColorizerPlugin.dll

    using Newtonsoft.Json;
    using PluginFramework;
    using PluginFramework.Attributes;
    using RuriLib;
    using RuriLib.Interfaces;
    using RuriLib.ViewModels;
    using System;
    using System.Diagnostics;
    using System.IO;
    
    namespace OBColorizerPlugin
    {
        public class Class1 : ViewModelBase, IPlugin
        {
            private static readonly Random random = new Random();
            public string Name => "Colorizer";
            [Button("Colorizer")]
            public void Randomizer(IApplication app)
            {
                try
                {
                    string json = File.ReadAllText(@"Settings\OBSettings.json");
                    dynamic jsonObj = JsonConvert.DeserializeObject(json);
                    jsonObj.Themes.BackgroundMain = String.Format("#{0:X6}", random.Next(0x1000000));
                    jsonObj.Themes.BackgroundSecondary = String.Format("#{0:X6}", random.Next(0x1000000));
                    jsonObj.Themes.ForegroundMain = String.Format("#{0:X6}", random.Next(0x1000000));
                    jsonObj.Themes.ForegroundMenuSelected = String.Format("#{0:X6}", random.Next(0x1000000));
                    string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
                    File.WriteAllText(@"Settings\OBSettings.json", output);
                    //OnPropertyChanged(); //DOES NOT WORK
                    Process.Start("OpenBullet.exe");
                    Environment.Exit(0);
                }
                catch (Exception ex)
                {
                    app.Logger.Log($"{ex}", LogLevel.Error, true);
                }
            }
            [Button("Reset")]
            public void Resetizer(IApplication app)
            {
                try
                {
                    string json = File.ReadAllText(@"Settings\OBSettings.json");
                    dynamic jsonObj = JsonConvert.DeserializeObject(json);
                    jsonObj.Themes.BackgroundMain = "#222";
                    jsonObj.Themes.BackgroundSecondary = "#111";
                    jsonObj.Themes.ForegroundMain = "#dcdcdc";
                    jsonObj.Themes.ForegroundMenuSelected = "#1e90ff";
                    string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
                    File.WriteAllText(@"Settings\OBSettings.json", output);
                    Process.Start("OpenBullet.exe");
                    Environment.Exit(0);
                }
                catch (Exception ex)
                {
                    app.Logger.Log($"{ex}", LogLevel.Error, true);
                }
            }
        }
    }
    

Log in to reply