Executing a loliscript in Plugin



  • Hello, I'm coding a small plugin that execute loliscript but I couldn't find right code for it.

    Need direction for executing a loliscript and get the result on app.Logger.Log


  • Admin

    Hello, you need to declare a new LoliScript object, pass it the script and then make a loop: while it CanProceed you call TakeStep and pass it the BotData (it will contain stuff like the data line, the proxy, and the logger a.k.a. BotLogger). Mind that that logger is not the same as the system logger so once the LoliScript ends processing stuff you need to convert the output of the BotLogger (take all the lines and output them in the system logger).

    You can check out this piece of code to understand how it works
    https://github.com/openbullet/openbullet/blob/master/RuriLib/Runner/RunnerViewModel.cs#L798

    If you have trouble post your code.



  • Thank you so much. That's exactly what I need. I prepared a very simple code and tested it. But however when I try to click my button OpenBullet closes itself everytime. I have no idea why It does that. That's my code;

            private RLSettingsViewModel Settings { get; set; }
            public Config Config { get; private set; }
            public ObservableCollection<RunnerBotViewModel> Bots { get; } = new ObservableCollection<RunnerBotViewModel>();
            public string Name => "MY TEST PLUGIN";
            [Button("Check the Config")]
            public void ChecktheConfig(IApplication app)
            {
                string myloliScript = "REQUEST GET \"https://forum.openbullet.dev\"\nKEYCHECK\nKEYCHAIN Success OR\nKEY \"OpenBullet</title>\"";
                LoliScript loli = new LoliScript(myloliScript);
                //loli.Reset();
    
                CData currentData = new CData("myData", null);
                Random random = null;
                bool UseProxies = false;
                CProxy currentProxy = null;
                BotData botData = null;
                var bot = Bots.First();
                botData = new BotData(Settings, Config.Settings, currentData, currentProxy, UseProxies, random, 0, false);
    
                do
                {
                    // Output the label of the current block being processed
                    if (Settings.General.BotsDisplayMode == BotsDisplayMode.Everything)
                        bot.Status = "<<< PROCESSING BLOCK: " + loli.NextBlock + " >>>";
    
                    // Try to take a step in the LoliScript and output any errors
                    try
                    {
                        loli.TakeStep(botData);
                    }
                    catch (Exception ex)
                    {
                        bot.Status = "<<< SCRIPT ERROR >>>";
                        Thread.Sleep(1000);
                    }
                }
                while (loli.CanProceed);
    
                    bot.Status = $"<<< FINISHED WITH RESULT: {botData.StatusString} >>>";
    
                app.Logger.Log("BOT STATUS" + bot.Status.ToString());
            }
    

  • Admin

    Hey, it will take me some time to review your code, I will test it personally and get back to you soon so wait 1-2 days for a response thanks.

    By the way when OpenBullet closes itself you can find a crash dump in the Log.txt file, so before opening OB again please take a look at the file and possibly post its contents here! Thanks!


  • Admin

    At first glance though the problem might be caused by the fact that you don't have anything inside the bots collection so calling .First() will throw an exception. You don't need to have any bots in order to run a config once in a single thread, so you should delete what you have and remove the lines that use the "bot" variable.



  • Indeed, I just noticed I don't have to use bot variable. I changed the code and made simple as I can. It says System.NullReferenceException in Log.txt. I have no idea what does that mean.

    Latest code and Log.txt below

    using PluginFramework;
    using RuriLib.Interfaces;
    using RuriLib.LS;
    using RuriLib.Models;
    using RuriLib.ViewModels;
    using System;
    using System.Threading;
    using RuriLib;
    using PluginFramework.Attributes;
    
    namespace ConfigCheckerPlugin
    {
        public class Class1 : IPlugin
        {
            private RLSettingsViewModel Settings { get; set; }
            public Config Config { get; private set; }
            private Random random;
            public WordlistType Type { get; set; }
            public string Name => "MY TEST PLUGIN";
            [Button("Check the Config")]
            public void ChecktheConfig(IApplication app)
            {
                string myloliScript = "REQUEST GET \"https://forum.openbullet.dev\"\nKEYCHECK\nKEYCHAIN Success OR\nKEY \"OpenBullet</title>\"";
                LoliScript loli = new LoliScript(myloliScript);
                //loli.Reset();
    
                CData currentData = new CData("mytestData", Type);
                
                bool UseProxies = false;
                CProxy currentProxy = null;
                BotData botData = new BotData(Settings, Config.Settings, currentData, currentProxy, UseProxies, random, 1, false);
    
                do
                {
                    try
                    {
                        loli.TakeStep(botData);
                    }
                    catch (Exception ex)
                    {
                        Thread.Sleep(1000);
                    }
                }
                while (loli.CanProceed);
    
                app.Logger.Log("BOT STATUS: " + botData.StatusString);
            }
        }
    }
    

    Log.txt
    https://pastebin.com/wN2Ws9K7


  • Admin

    Hello, I fixed your code

    using PluginFramework;
    using RuriLib.Interfaces;
    using RuriLib.LS;
    using RuriLib.Models;
    using System;
    using RuriLib;
    using PluginFramework.Attributes;
    
    namespace ConfigCheckerPlugin
    {
        public class Test : IPlugin
        {
            public string Name => "MY TEST PLUGIN";
    
            [Text("Data", "The data you want to test")]
            public string Data { get; set; }
    
            [Button("Check the Config")]
            public void Check(IApplication app)
            {
                // Build the LoliScript object
                string script = "REQUEST GET \"https://forum.openbullet.dev\"\nKEYCHECK\n  KEYCHAIN Success OR\n    KEY \"OpenBullet</title>\"";
                LoliScript loli = new LoliScript(script);
                loli.Reset();
    
                // Build the config settings since we have no starting existing config
                var settings = new ConfigSettings
                {
                    AllowedWordlist1 = "Default",
                };
    
                // Build the data line
                var wordlistType = app.Settings.Environment.GetWordlistType("Default");
                CData currentData = new CData(Data, wordlistType);
    
                // Set the proxy to null
                bool useProxy = false;
                CProxy currentProxy = null;
    
                // Build the Bot Data
                BotData botData = new BotData(app.Settings.RLSettings, settings, currentData, currentProxy, useProxy, new Random(), 1, false);
    
                // Run the script
                do
                {
                    try
                    {
                        loli.TakeStep(botData);
                    }
                    catch (Exception ex)
                    {
                        app.Logger.Log(ex.ToString(), LogLevel.Error, true);
                    }
                }
                while (loli.CanProceed);
    
                // Log the final bot status
                app.Logger.Log($"BOT STATUS: {botData.StatusString}", LogLevel.Info, true);
            }
        }
    }
    

  • Admin

    Remember to put spaces for indentation in your loliscript or it will fail to read it correctly! See how I changed it from yours



  • You're awesome!

    Also you showed me that it's so easier than I thought. Works perfectly


  • Admin

    I also just fixed a small thing in the code, the Data property was not used when building the CData object, now it is ^_^ If you want to bind the proxy as well just do a similar thing



  • @ShiyaVivala What does this Plugin do? maybe it will be useful for me so it basicly executes a loliscript?



  • @INFINITEY It just executes loliscript and returns with a result (FAIL, SUCCESS, BAN or ERROR)


Log in to reply