コード例 #1
0
        public CliDocker()
        {
            Thread.Sleep(3000);
            LogFormater.Status("-> Getting config from Docker");
            JsonConfig Config = MakeJsonConfig.FromENV();

            Config = MakeJsonConfig.Http_config_check(Config);
            new Discord_super(Config, true, "");
        }
コード例 #2
0
        protected void loadFromDisk()
        {
            LogFormater.Info("Loading adverts from Disk", true);
            advertsBlob  loadedAdverts = new advertsBlob();
            advertConfig demoAdvert    = new advertConfig();

            demoAdvert.attachment = UUID.Zero.ToString();
            demoAdvert.content    = "Content";
            demoAdvert.title      = "Title";
            demoAdvert.groups     = new[] { UUID.Zero.ToString(), UUID.Zero.ToString() };
            demoAdvert.days       = "0,1,2,3,4,5,6";
            demoAdvert.hour       = "12";
            demoAdvert.min        = "30";
            demoAdvert.notice     = "false";
            demoAdvert.enabled    = "false";
            loadedAdverts.adverts = new advertConfig[] { demoAdvert };


            string   targetfile = "adverts.json";
            SimpleIO io         = new SimpleIO();

            io.ChangeRoot(controler.getFolderUsed());
            if (SimpleIO.FileType(targetfile, "json") == false)
            {
                LogFormater.Status("Creating new adverts file", true);
                io.WriteJsonAdverts(loadedAdverts, targetfile);
                return;
            }
            if (io.Exists(targetfile) == false)
            {
                LogFormater.Status("Creating new adverts file", true);
                io.WriteJsonAdverts(loadedAdverts, targetfile);
                return;
            }
            string json = io.ReadFile(targetfile);

            if (json.Length > 0)
            {
                try
                {
                    loadedAdverts = JsonConvert.DeserializeObject <advertsBlob>(json);
                    foreach (advertConfig loaded in loadedAdverts.adverts)
                    {
                        Unpack(loaded);
                    }
                }
                catch
                {
                    io.MarkOld(targetfile);
                    io.WriteJsonAdverts(loadedAdverts, targetfile);
                }
                return;
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(PanicMode);
            if (helpers.notempty(Environment.GetEnvironmentVariable("Basic_BotUserName")) == true)
            {
                new CliDocker();
            }
            else
            {
                new CliHardware(args);
            }
            LogFormater.Status("- Exiting in 5 secs -");
            Thread.Sleep(5000);
        }
コード例 #4
0
        protected void loadFromDisk()
        {
            LogFormater.Info("Loading onEvents from Disk", true);
            try
            {
                OnEventBlob DemoloadedEvents = new OnEventBlob();
                OnEvent     demoEvent        = new OnEvent();
                demoEvent.Enabled           = false;
                demoEvent.Actions           = new string[] { "Say|||0~#~hi mom im on TV!" };
                demoEvent.title             = "demo";
                demoEvent.On                = "Clock";
                demoEvent.Where             = new string[] { "59 23 * * 7 {CRON} true" };
                demoEvent.Monitor           = "None";
                DemoloadedEvents.listEvents = new OnEvent[] { demoEvent };

                string   targetfile = "events.json";
                SimpleIO io         = new SimpleIO();
                io.ChangeRoot(controler.getFolderUsed());
                if (io.Exists(targetfile) == false)
                {
                    LogFormater.Status("Creating new events file", true);
                    io.WriteJsonEvents(DemoloadedEvents, targetfile);
                    return;
                }
                string json = io.ReadFile(targetfile);
                if (json.Length > 0)
                {
                    try
                    {
                        OnEventBlob loadedEvents = JsonConvert.DeserializeObject <OnEventBlob>(json);
                        foreach (OnEvent loaded in loadedEvents.listEvents)
                        {
                            Events.Add(loaded);
                        }
                    }
                    catch
                    {
                        LogFormater.Info("error loading events from " + targetfile + " skipping", true);
                    }
                    return;
                }
            }
            catch
            {
            }
        }
コード例 #5
0
ファイル: Helpers.cs プロジェクト: shadoskill/SecondBot
 public static bool botRequired(JsonConfig test)
 {
     if (helpers.notempty(test.Basic_BotUserName) && helpers.notempty(test.Basic_BotPassword) && helpers.notempty(test.Security_MasterUsername) && helpers.notempty(test.Security_SignedCommandkey))
     {
         // required values are set
         MakeJsonConfig Testing             = new MakeJsonConfig();
         string[]       testingfor          = new[] { "Basic_BotUserName", "Basic_BotPassword", "Security_SignedCommandkey", "Security_WebUIKey" };
         bool           default_value_found = false;
         foreach (string a in testingfor)
         {
             if (Testing.GetCommandArgTypes(a).First() == MakeJsonConfig.GetProp(test, a))
             {
                 LogFormater.Warn("" + a + " is currently set to the default");
                 default_value_found = true;
                 break;
             }
         }
         if (default_value_found == false)
         {
             LogFormater.Status("User => " + test.Basic_BotUserName);
             LogFormater.Status("Master => " + test.Security_MasterUsername);
         }
         return(!default_value_found);
     }
     else
     {
         if (helpers.notempty(test.Basic_BotUserName) == false)
         {
             LogFormater.Warn("Basic_BotUserName is null or empty");
         }
         if (helpers.notempty(test.Basic_BotPassword) == false)
         {
             LogFormater.Warn("Basic_BotPassword is null or empty");
         }
         if (helpers.notempty(test.Security_MasterUsername) == false)
         {
             LogFormater.Warn("Security_MasterUsername is null or empty");
         }
         if (helpers.notempty(test.Security_SignedCommandkey) == false)
         {
             LogFormater.Warn("Security_SignedCommandkey is null or empty");
         }
         return(false);
     }
 }
コード例 #6
0
ファイル: Discord-super.cs プロジェクト: shadoskill/SecondBot
        protected override void keep_alive()
        {
            while (exit_super == false)
            {
                if (HasBasicBot() == false)
                {
                    StatusMessageHandler(null, new BetterSecondBot.bottypes.StatusMessageEvent(false, "None"));
                }

                string NewStatusMessage = GetStatus();
                if (NewStatusMessage != LastStatusMessage)
                {
                    NewStatusMessage = NewStatusMessage.Trim();
                    if (DiscordClientConnected == true)
                    {
                        DiscordStatusUpdate();
                    }
                    if (NewStatusMessage.Replace(" ", "") != "")
                    {
                        if (LastStatusMessage != NewStatusMessage)
                        {
                            LastStatusMessage = NewStatusMessage;
                            if (HasBasicBot() == true)
                            {
                                controler.getBot().Log2File(LogFormater.Status(LastStatusMessage, false), ConsoleLogLogLevel.Status);
                            }
                            else
                            {
                                Console.WriteLine(LastStatusMessage);
                            }
                        }
                    }
                }
                Thread.Sleep(1500);
            }
        }
コード例 #7
0
 protected void keep_alive()
 {
     while (Bot.KillMe == false)
     {
         string NewStatusMessage = Bot.GetStatus();
         NewStatusMessage = NewStatusMessage.Trim();
         if (NewStatusMessage != Bot.LastStatusMessage)
         {
             if (NewStatusMessage.Replace(" ", "") != "")
             {
                 Bot.LastStatusMessage = NewStatusMessage;
                 Bot.Log2File(LogFormater.Status(Bot.LastStatusMessage, false), ConsoleLogLogLevel.Status);
             }
         }
         Thread.Sleep(1500);
     }
     Adverts             = null;
     Events              = null;
     betterAtHomeService = null;
     betterTracking      = null;
     datastorage         = null;
     Bot     = null;
     exitBot = true;
 }
コード例 #8
0
ファイル: BasicBot.cs プロジェクト: shadoskill/SecondBot
 public virtual void Status(string message)
 {
     Log2File(LogFormater.Status(message, false), ConsoleLogLogLevel.Status);
 }
コード例 #9
0
        public CliHardware(string[] args)
        {
            SimpleIO   io         = new SimpleIO();
            JsonConfig Config     = new JsonConfig();
            string     loadFolder = "debug";
            string     json_file  = "bot.json";

#if DEBUG
            LogFormater.Debug("!! RUNNING IN DEBUG !!");
#else
            LogFormater.Status("Hardware config");
            if (args.Length == 1)
            {
                loadFolder = args[0];
            }
            else
            {
                loadFolder = "default";
                io.ChangeRoot("default");
                LogFormater.Warn("Using: using default folder");
            }
#endif
            io.ChangeRoot(loadFolder);
            if (SimpleIO.DirExists("wiki") == false)
            {
                LogFormater.Info("Basic Wiki [Creating]");
                new DebugModeCreateWiki(AssemblyInfo.GetGitHash(), io);
                LogFormater.Info("Basic Wiki [Ready]");
                io = new SimpleIO();
            }
            bool ok_to_try_start = false;
            if (SimpleIO.FileType(json_file, "json") == true)
            {
                if (io.Exists(json_file))
                {
                    string json = io.ReadFile(json_file);
                    if (json.Length > 0)
                    {
                        try
                        {
                            Config          = JsonConvert.DeserializeObject <JsonConfig>(json);
                            ok_to_try_start = true;
                        }
                        catch (Exception e)
                        {
                            LogFormater.Warn("Unable to read config file\n moving config to " + json_file + ".old and creating a empty config\nError was: " + e.Message + "");
                            io.MarkOld(json_file);
                            Config = new JsonConfig();
                            io.WriteJsonConfig(MakeJsonConfig.GetDefault(), json_file);
                        }
                    }
                    else
                    {
                        LogFormater.Warn("Json config is empty creating an empty one for you");
                        io.WriteJsonConfig(MakeJsonConfig.GetDefault(), json_file);
                    }
                }
                else
                {
                    LogFormater.Warn("Json config does not Exist creating it for you");
                    io.WriteJsonConfig(MakeJsonConfig.GetDefault(), json_file);
                }
            }
            else
            {
                LogFormater.Crit("you must select a .json file for config! example \"BetterSecondBot.exe mybot\" will use the mybot.json file!");
            }
            if (ok_to_try_start == true)
            {
                Config = MakeJsonConfig.Http_config_check(Config);
                new Discord_super(Config, false, loadFolder);
            }
        }