예제 #1
0
 protected void TriggerAdvert(int advertID)
 {
     LogFormater.Info("Processing advert: " + (advertID + 1).ToString(), true);
     foreach (UUID group in groups[advertID])
     {
         if (asNotice[advertID] == true)
         {
             if (attachments[advertID] != UUID.Zero)
             {
                 controler.getBot().CallAPI(
                     "GroupnoticeWithAttachment",
                     new[] { group.ToString(), titles[advertID], content[advertID], attachments[advertID].ToString() }
                     );
             }
             else
             {
                 controler.getBot().CallAPI(
                     "Groupnotice",
                     new[] { group.ToString(), titles[advertID], content[advertID] }
                     );
             }
         }
         else
         {
             controler.getBot().CallAPI(
                 "Groupchat",
                 new[] { group.ToString(), content[advertID] }
                 );
         }
     }
 }
예제 #2
0
        protected void HTTPWiki()
        {
            mdWiki.AppendLine("View as [HTML](https://wiki.blackatom.live/files/Commands.html)");
            mdWiki.AppendLine(" ");
            mdWiki.AppendLine("Host it yourself: [+Docker image](https://hub.docker.com/r/madpeter/secondbot_wiki)");
            mdWiki.AppendLine(" ");
            mdWiki.AppendLine("---");
            mdWiki.AppendLine("# Commands list");

            LogFormater.Info("[WIKI] Starting area HTTP endpoint");
            HTTPendpoint HTTP = new HTTPendpoint();

            HTTPmenu("Commands", HTTP);

            // create workspaces
            HTTPWorkspaces("Commands", HTTP);

            // create commands
            HTTPCommands("Commands", HTTP);

            io.WriteFile("../commands.md", mdWiki.ToString());

            HTTP = null;
            LogFormater.Info("[WIKI] Done with area");
        }
예제 #3
0
        protected void loadFromDockerEnv()
        {
            LogFormater.Info("Loading onEvents from ENV", true);
            int  loop  = 1;
            bool found = true;

            while (found == true)
            {
                string title = getEnv("event_" + loop.ToString() + "_title");
                if (helpers.notempty(title) == true)
                {
                    OnEvent config = new OnEvent();
                    bool.TryParse(getEnv("event_" + loop.ToString() + "_enabled"), out bool enabled);
                    config.Enabled = enabled;
                    if (enabled == true)
                    {
                        config.title   = title;
                        config.Monitor = getEnv("event_" + loop.ToString() + "_monitor");
                        config.On      = getEnv("event_" + loop.ToString() + "_on");

                        int           loop2       = 1;
                        bool          found2      = true;
                        List <string> wherefields = new List <string>();
                        while (found2 == true)
                        {
                            found2 = false;
                            string wherefield = getEnv("event_" + loop.ToString() + "_where_" + loop2.ToString());
                            if (helpers.notempty(wherefield) == true)
                            {
                                found2 = true;
                                wherefields.Add(wherefield);
                            }
                            loop2++;
                        }
                        config.Where = wherefields.ToArray();
                        loop2        = 1;
                        found2       = true;
                        List <string> actionfields = new List <string>();
                        while (found2 == true)
                        {
                            found2 = false;
                            string actionfield = getEnv("event_" + loop.ToString() + "_action_" + loop2.ToString());
                            if (helpers.notempty(actionfield) == true)
                            {
                                found2 = true;
                                actionfields.Add(actionfield);
                            }
                            loop2++;
                        }
                        config.Actions = actionfields.ToArray();
                        Events.Add(config);
                    }
                }
                else
                {
                    found = false;
                }
                loop++;
            }
        }
예제 #4
0
 protected void SetupMonitor()
 {
     string[] skipped = new string[] { "None", "" };
     foreach (OnEvent E in Events)
     {
         if (E.Enabled == false)
         {
             continue;
         }
         if ((E.Monitor == "None") || (E.Monitor == ""))
         {
             continue;
         }
         UUID checking = UUID.Zero;
         if (UUID.TryParse(E.Monitor, out checking) == false)
         {
             continue;
         }
         if (checking == UUID.Zero)
         {
             continue;
         }
         if (group_membership_update_q.ContainsKey(checking) == true)
         {
             continue;
         }
         if (DebugWhere == true)
         {
             LogFormater.Info("OnEvent - attaching to group membership: " + checking.ToString(), true);
         }
         group_membership_update_q.Add(checking, new KeyValuePair <long, int>(helpers.UnixTimeNow(), 45));
     }
 }
예제 #5
0
        public Cli(JsonConfig Config, bool as_docker, bool use_self_keep_alive, string loadingFromFolder)
        {
            exitBot    = false;
            use_folder = loadingFromFolder;
            LogFormater.Info("Starting cli");
            if (helpers.botRequired(Config) == true)
            {
                Bot = new SecondBot();
                Bot.setFolder(use_folder);
                Bot.Setup(Config, AssemblyInfo.GetGitHash());

                if (as_docker == true)
                {
                    Bot.AsDocker();
                }

                Bot.Start(false);

                attachEventListenerObjects(Config, as_docker);
                if (use_self_keep_alive == true)
                {
                    keep_alive();
                }
            }
            else
            {
                LogFormater.Warn("Required settings missing");
            }
            if (use_self_keep_alive == true)
            {
                exitBot = true;
            }
        }
예제 #6
0
 public BetterAtHome(Cli setcontroler, JsonConfig configfile)
 {
     controler       = setcontroler;
     this.configfile = configfile;
     attach_events();
     SetBetterAtHomeAction("Standby");
     foreach (string a in configfile.Basic_HomeRegions)
     {
         string[] bits = helpers.ParseSLurl(a);
         homeRegions.Add(bits[0]);
         LogFormater.Info("Added home region: " + bits[0]);
     }
     if (configfile.Basic_AvoidRestartRegions != null)
     {
         foreach (string a in configfile.Basic_AvoidRestartRegions)
         {
             string[] bits = helpers.ParseSLurl(a);
             avoidRestartRegions.Add(bits[0]);
             LogFormater.Info("Added restart region: " + bits[0]);
         }
     }
     else
     {
         LogFormater.Warn("Config is old - please update");
     }
 }
예제 #7
0
        protected void ApplyRelayConfig(string sourcename, string sourcevalue, string targetname, string targetvalue, bool jsonEncoded)
        {
            relay_config relay = new relay_config();

            relay.encode_as_json = jsonEncoded;
            relay.sourcename     = sourcename;
            relay.sourcevalue    = sourcevalue;
            relay.targetname     = targetname;
            relay.targetvalue    = targetvalue;
            LogFormater.Info("Attaching relay: " + relay.sourcename + " to " + relay.targetname);
            if (relay.sourcename == "localchat")
            {
                LocalchatRelay.Add(relay);
            }
            else if (relay.sourcename == "groupchat")
            {
                GroupChatRelay.Add(relay);
            }
            else if (relay.sourcename == "avatarim")
            {
                AvatarIMRelay.Add(relay);
            }
            else if (relay.sourcename == "objectim")
            {
                ObjectIMRelay.Add(relay);
            }
            else if (relay.sourcename == "discord")
            {
                DiscordRelay.Add(relay);
            }
        }
예제 #8
0
 protected override Task DiscordClientLoggedOut()
 {
     LogFormater.Info("Discord has logged out", true);
     ReconnectTimer           = new Timer();
     ReconnectTimer.Interval  = 10000;
     ReconnectTimer.Elapsed  += ReconnectTimerEvent;
     ReconnectTimer.AutoReset = false;
     ReconnectTimer.Enabled   = false;
     return(Task.CompletedTask);
 }
예제 #9
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;
            }
        }
예제 #10
0
 public void unattach_events()
 {
     LogFormater.Info("Relay - disconnecting");
     if (superV != null)
     {
         superV.MessageEvent -= DiscordMessageHandler;
     }
     if (controler.getBot() != null)
     {
         controler.getBot().MessageEvent -= SLMessageHandler;
     }
 }
예제 #11
0
        protected virtual async Task <Task> DicordClientLoggedin()
        {
            LogFormater.Info("Discord has logged in", true);
            await DiscordClient.StartAsync().ConfigureAwait(false);

            ReconnectTimer           = new Timer();
            ReconnectTimer.Interval  = 10000;
            ReconnectTimer.Elapsed  += ReconnectTimerEvent;
            ReconnectTimer.AutoReset = false;
            ReconnectTimer.Enabled   = false;
            return(Task.CompletedTask);
        }
예제 #12
0
        protected void InterfaceWiki(string area, API_supported_interface shared_interface, bool track_commands = false)
        {
            LogFormater.Info("[WIKI] Starting area " + area + "");
            // create index
            InterfaceIndex(area, shared_interface);

            // create workspaces
            InterfaceWorkspaces(area, shared_interface);

            // create commands
            InterfaceCommands(area, shared_interface, track_commands);
            LogFormater.Info("[WIKI] Done with area");
        }
예제 #13
0
 public advertsService(Cli Master, bool LoadFromDocker)
 {
     controler = Master;
     LogFormater.Info("Starting adverts service", true);
     if (LoadFromDocker == true)
     {
         loadFromDockerEnv();
     }
     else
     {
         loadFromDisk();
     }
     controler.getBot().StatusMessageEvent += StatusPing;
 }
예제 #14
0
        protected void Unpack(advertConfig config)
        {
            titles.Add(config.title);
            UUID attachment = UUID.Zero;

            UUID.TryParse(config.attachment, out attachment);
            attachments.Add(attachment);
            content.Add(config.content);
            bool asGroupNotice = false;

            bool.TryParse(config.notice, out asGroupNotice);
            asNotice.Add(asGroupNotice);
            string[]   unpackDays   = config.days.Split(',');
            List <int> activeondays = new List <int>();

            foreach (string Uday in unpackDays)
            {
                if (int.TryParse(Uday, out int dayid) == true)
                {
                    activeondays.Add(dayid);
                }
            }
            activeDays.Add(activeondays);
            int activeHourid = -2;

            int.TryParse(config.hour, out activeHourid);
            activeHours.Add(activeHourid);
            int activeMinid = -2;

            int.TryParse(config.min, out activeMinid);
            activeMins.Add(activeMinid);
            bool asEnabled = false;

            bool.TryParse(config.enabled, out asEnabled);
            enabled.Add(asEnabled);
            List <UUID> selectedGroups = new List <UUID>();

            foreach (string groupA in config.groups)
            {
                UUID groupUUID = UUID.Zero;
                UUID.TryParse(groupA, out groupUUID);
                if (groupUUID != UUID.Zero)
                {
                    selectedGroups.Add(groupUUID);
                }
            }
            groups.Add(selectedGroups);
            LogFormater.Info("Loaded advert: (" + config.enabled + ") " + config.title + " " + config.days + " | " + config.hour + "h " + config.min + "m", true);
        }
예제 #15
0
 public onevent(Cli master, bool LoadFromDocker)
 {
     controler = master;
     LogFormater.Info("{onEvents} starting", true);
     if (LoadFromDocker == true)
     {
         loadFromDockerEnv();
     }
     else
     {
         loadFromDisk();
     }
     controler.getBot().StatusMessageEvent += statusMessage;
     LogFormater.Info("{onEvents} ready", true);
 }
예제 #16
0
 protected virtual async Task StartDiscordClientService()
 {
     DiscordClient                  = new DiscordSocketClient();
     DiscordClient.Ready           += DiscordClientReady;
     DiscordClient.LoggedOut       += DiscordClientLoggedOut;
     DiscordClient.LoggedIn        += DicordClientLoggedin;
     DiscordClient.MessageReceived += DiscordClientMessageReceived;
     ReconnectTimer                 = new Timer();
     ReconnectTimer.Interval        = 10000;
     ReconnectTimer.Elapsed        += ReconnectTimerEvent;
     ReconnectTimer.AutoReset       = false;
     ReconnectTimer.Enabled         = false;
     LogFormater.Info("Discord is starting", true);
     await DiscordClient.LoginAsync(TokenType.Bot, myconfig.DiscordFull_Token);
 }
예제 #17
0
 public void attachEventListenerObjects(JsonConfig Config, bool as_docker)
 {
     LogFormater.Info("HTTP service requested:" + Config.Http_Enable.ToString());
     if (Config.Http_Enable == true)
     {
         new Thread(() =>
         {
             new HttpAsService(Bot, Config, as_docker);
         }).Start();
     }
     Adverts             = new advertsService(this, as_docker);
     Events              = new onevent(this, as_docker);
     betterAtHomeService = new BetterAtHome(this, Config);
     betterTracking      = new BetterTracking(this);
     datastorage         = new Datastorage(this);
 }
예제 #18
0
        protected void loadRelayConfigFromFile()
        {
            JsonCustomRelays Demo = new JsonCustomRelays()
            {
                sourceFilter = "all", sourceType = "localchat", targetType = "groupchat", targetConfig = UUID.Zero.ToString()
            };
            JsonCustomRelaysSet LoadedRelays = new JsonCustomRelaysSet
            {
                Entrys = new JsonCustomRelays[] { Demo }
            };
            string   targetfile = "customrelays.json";
            SimpleIO io         = new SimpleIO();

            io.ChangeRoot(controler.getFolderUsed());
            if (SimpleIO.FileType(targetfile, "json") == false)
            {
                io.WriteJsonRelays(LoadedRelays, targetfile);
                return;
            }
            if (io.Exists(targetfile) == false)
            {
                io.WriteJsonRelays(LoadedRelays, targetfile);
                return;
            }
            string json = io.ReadFile(targetfile);

            if (json.Length > 0)
            {
                try
                {
                    LoadedRelays = JsonConvert.DeserializeObject <JsonCustomRelaysSet>(json);
                    int loop = 1;
                    foreach (JsonCustomRelays loaded in LoadedRelays.Entrys)
                    {
                        LogFormater.Info("Relay " + loop.ToString() + " [OK] sending to attach");
                        ApplyRelayConfig(loaded.sourceType, loaded.sourceFilter, loaded.targetType, loaded.targetConfig, loaded.encodeJson);
                        loop++;
                    }
                }
                catch
                {
                    io.MarkOld(targetfile);
                    io.WriteJsonRelays(LoadedRelays, targetfile);
                }
                return;
            }
        }
예제 #19
0
        protected override void GroupInvite(InstantMessageEventArgs e)
        {
            string[] stage1 = e.IM.FromAgentName.ToLowerInvariant().Split('.');
            if (stage1.Length == 1)
            {
                stage1 = e.IM.FromAgentName.ToLowerInvariant().Split(" ");
            }
            string name = "" + stage1[0].FirstCharToUpper() + "";

            if (stage1.Length == 1)
            {
                name = " Resident";
            }
            else
            {
                name = "" + name + " " + stage1[1].FirstCharToUpper() + "";
            }
            bool   accept_invite;
            string whyAccept = "";

            if (Is_avatar_master(name) == true)
            {
                accept_invite = true;
                whyAccept     = "Master";
            }
            else
            {
                name          = name.ToLowerInvariant();
                accept_invite = Accept_action_from_name("group", name);
                if (accept_invite == true)
                {
                    whyAccept = "Action auth";
                    Remove_action_from_name("group", name);
                }
            }
            if (accept_invite == true)
            {
                LogFormater.Info("Group invite event from: " + e.IM.FromAgentName + " Accepted - " + whyAccept);
                GroupInvitationEventArgs G = new GroupInvitationEventArgs(e.Simulator, e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message);
                Client.Self.GroupInviteRespond(G.AgentID, e.IM.IMSessionID, true);
                Client.Groups.RequestCurrentGroups();
            }
            else
            {
                LogFormater.Info("Group invite event from: " + e.IM.FromAgentName + " Rejected");
            }
        }
예제 #20
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
            {
            }
        }
예제 #21
0
 public static JsonConfig Http_config_check(JsonConfig jsonConfig)
 {
     if (helpers.notempty(jsonConfig.Security_WebUIKey) == true)
     {
         if (helpers.notempty(jsonConfig.Http_Host) == true)
         {
             if (jsonConfig.Http_Enable == true)
             {
                 jsonConfig.Http_Enable = false;
                 if (jsonConfig.Security_WebUIKey.Length < 12)
                 {
                     LogFormater.Warn("Http disabled: Security_WebUIKey length must be 12 or more");
                 }
                 else if ((jsonConfig.Http_Host != "docker") && (jsonConfig.Http_Host.StartsWith("http") == false))
                 {
                     LogFormater.Warn("Http disabled: Http_Host must be vaild or \"docker\" - Given: (" + jsonConfig.Http_Host + ")");
                 }
                 else
                 {
                     if (jsonConfig.Http_Host == "docker")
                     {
                         jsonConfig.Http_Host = "http://*:80";
                     }
                     jsonConfig.Http_Enable = true;
                 }
             }
             else
             {
                 LogFormater.Info("Http interface disabled by config");
             }
         }
         else
         {
             LogFormater.Warn("Http disabled: Http_Host is null");
             jsonConfig.Http_Enable = false;
         }
     }
     else
     {
         LogFormater.Warn("Http disabled: Security_WebUIKey is null");
         jsonConfig.Http_Enable = false;
     }
     return(jsonConfig);
 }
예제 #22
0
        protected void loadFromDockerEnv()
        {
            LogFormater.Info("Loading adverts from ENV", true);
            int  loop  = 1;
            bool found = true;

            while (found == true)
            {
                string title = getEnv("advert_" + loop.ToString() + "_title");
                if (helpers.notempty(title) == true)
                {
                    advertConfig config = new advertConfig();
                    config.title      = title;
                    config.attachment = getEnv("advert_" + loop.ToString() + "_attachment");
                    config.content    = getEnv("advert_" + loop.ToString() + "_content");
                    config.notice     = getEnv("advert_" + loop.ToString() + "notice");
                    config.days       = getEnv("advert_" + loop.ToString() + "days");
                    config.hour       = getEnv("advert_" + loop.ToString() + "hour");
                    config.min        = getEnv("advert_" + loop.ToString() + "min");
                    List <string> groupentrys = new List <string>();
                    int           loop2       = 1;
                    bool          exitNow     = false;
                    while (exitNow == false)
                    {
                        exitNow = true;
                        string value = getEnv("advert_" + loop2.ToString() + "_group_" + loop2.ToString());
                        if (helpers.notempty(value) == true)
                        {
                            groupentrys.Add(value);
                            exitNow = false;
                        }
                        loop2++;
                    }
                    config.groups = groupentrys.ToArray();
                    Unpack(config);
                }
                else
                {
                    found = false;
                }
                loop++;
            }
        }
예제 #23
0
        protected virtual async Task <Task> DiscordClientReady()
        {
            ReconnectTimer.Enabled = false;
            bool hasAdmin = false;

            foreach (SocketRole Role in DiscordClient.GetGuild(myconfig.DiscordFull_ServerID).CurrentUser.Roles)
            {
                if (Role.Permissions.Administrator == true)
                {
                    hasAdmin = true;
                    break;
                }
            }
            if (hasAdmin == true)
            {
                LogFormater.Info("Discord is active", true);
                await DiscordClient.SetStatusAsync(Discord.UserStatus.Idle);

                await DiscordClient.SetGameAsync("Not connected", null, ActivityType.CustomStatus);

                DiscordServer = DiscordClient.GetGuild(myconfig.DiscordFull_ServerID);
                if (DiscordServer != null)
                {
                    if (myconfig.DiscordFull_Enable == true)
                    {
                        login_bot(false);
                    }
                    DiscordUnixTimeOnine   = helpers.UnixTimeNow();
                    DiscordClientConnected = true;
                    await DiscordRebuildChannels();
                }
                else
                {
                    DiscordClientConnected = false;
                }
            }
            else
            {
                LogFormater.Info("Discord has failed - missing admin perm", true);
            }
            return(Task.CompletedTask);
        }
예제 #24
0
        protected void processScopedTokenRaw(string raw)
        {
            raw = raw.Replace(" ", "");
            string[]        bits      = raw.Split(',');
            string          code      = null;
            int             accessids = 0;
            scopedTokenInfo stinfo    = new scopedTokenInfo();

            foreach (string bit in bits)
            {
                string[] subbits = bit.Split(':');
                if (subbits[0] == "t")
                {
                    code = subbits[1];
                }
                else if (subbits[0] == "cm")
                {
                    stinfo.AllowCommands.Add(subbits[1]);
                    accessids++;
                }
                else if (subbits[0] == "cg")
                {
                    stinfo.AllowAccessGroups.Add(subbits[1]);
                    accessids++;
                }
                else if (subbits[0] == "ws")
                {
                    stinfo.AllowWorkgroups.Add(subbits[1]);
                    accessids++;
                }
            }
            if ((code != null) && (accessids > 0))
            {
                Tokens.AddScopedToken(code, stinfo);
                LogFormater.Info("Adding scopped command " + code + " with: " + accessids.ToString() + " access types");
            }
            else
            {
                LogFormater.Warn("Scoped access code: " + raw + " did not pass checks");
            }
        }
예제 #25
0
        protected void groupMembershipChecks()
        {
            long        now   = helpers.UnixTimeNow();
            List <UUID> repop = new List <UUID>();

            foreach (KeyValuePair <UUID, KeyValuePair <long, int> > entry in group_membership_update_q)
            {
                long dif = now - entry.Value.Key;
                if (dif >= entry.Value.Value)
                {
                    repop.Add(entry.Key);
                }
            }
            foreach (UUID entry in repop)
            {
                if (controler.getBot().MyGroups.ContainsKey(entry) == false)
                {
                    if (DebugWhere == true)
                    {
                        LogFormater.Info("OnEvent - Unable to get membership " + entry.ToString() + " - group not loaded yet: " + entry.ToString(), true);
                    }
                    continue;
                }
                Group G = controler.getBot().MyGroups[entry];
                if (G.Powers.HasFlag(GroupPowers.AssignMember) == false)
                {
                    if (DebugWhere == true)
                    {
                        LogFormater.Info("OnEvent - Unable to get membership " + entry.ToString() + " - required power: AssignMember missing", true);
                    }
                    continue;
                }

                if (DebugWhere == true)
                {
                    LogFormater.Info("OnEvent - requesting group membership: " + entry.ToString(), true);
                }
                group_membership_update_q[entry] = new KeyValuePair <long, int>(now + 120, 45);
                controler.getBot().GetClient.Groups.RequestGroupMembers(entry);
            }
        }
예제 #26
0
 protected void attach_events()
 {
     if (controler.getBot() != null)
     {
         controler.getBot().MessageEvent += SLMessageHandler;
         LogFormater.Info("Relay - Grid support enabled");
     }
     else
     {
         LogFormater.Info("Relay - Grid support: [No] (Maybe the bot is offline)");
     }
     if (superV != null)
     {
         superV.MessageEvent += DiscordMessageHandler;
         LogFormater.Info("Relay - Discord support enabled");
     }
     else
     {
         LogFormater.Info("Relay - Discord support: [No]");
     }
 }
예제 #27
0
 protected void LoginProcess(object o, LoginProgressEventArgs e)
 {
     if (e.Status == LoginStatus.ConnectingToSim)
     {
         LogFormater.Info("Tracker - warming up");
         controler.getBot().LoginProgess -= LoginProcess;
         if (AfterLogin == false)
         {
             AfterLogin = true;
             if (output_to_channel == true)
             {
                 LogFormater.Info("Tracker - Enabled Chat on channel: " + output_channel.ToString());
             }
             if (output_to_url == true)
             {
                 LogFormater.Info("Tracker - Enabled HTTP: " + controler.getBot().getMyConfig.Setting_Tracker);
             }
             controler.getBot().StatusMessageEvent += StatusPing;
         }
     }
 }
예제 #28
0
        public HttpAsService(SecondBot MainBot, JsonConfig BotConfig, bool running_in_docker)
        {
            Bot    = MainBot;
            Config = BotConfig;

            Tokens = new TokenStorage();
            // Load scoped tokens
            if (running_in_docker == true)
            {
                // using ENV values
                loadScopedTokensFromENV();
            }
            else
            {
                // from file
                loadScopedTokensFromFile();
            }

            // Our web server is disposable
            try
            {
                if (killedLogger == false)
                {
                    killedLogger = true;
                    Swan.Logging.Logger.UnregisterLogger <ConsoleLogger>();
                }
                WebServer server = CreateWebServer(Config.Http_Host);
                // Once we've registered our modules and configured them, we call the RunAsync() method.
                LogFormater.Info("Starting HTTP service: " + Config.Http_Host);
                server.RunAsync();
                while (Bot.KillMe == false)
                {
                    Thread.Sleep(3000);
                }
            }
            catch (Exception e)
            {
                LogFormater.Info("HTTP service has ended because: " + e.Message);
            }
        }
예제 #29
0
        protected void loadRelayConfigFromENV()
        {
            int  loop  = 1;
            bool found = true;

            string[] needBits = new string[] { "asJson", "sourceType", "sourceFilter", "targetType", "targetConfig" };
            while (found == true)
            {
                found = false;
                bool configfound = true;
                Dictionary <string, string> config = new Dictionary <string, string>();
                foreach (string a in needBits)
                {
                    string value = Environment.GetEnvironmentVariable("CustomRelay_" + loop.ToString() + "_" + a);
                    if (helpers.notempty(value) == false)
                    {
                        configfound = false;
                        break;
                    }
                    else
                    {
                        config.Add(a, value);
                    }
                }
                if (configfound == false)
                {
                    LogFormater.Info("Relay " + loop.ToString() + " invaild config skipping");
                    continue;
                }
                LogFormater.Info("Relay " + loop.ToString() + " [OK] sending to attach");
                found = true;
                bool asJson = false;
                bool.TryParse(config["asJson"], out asJson);
                ApplyRelayConfig(config["sourceType"], config["sourceFilter"], config["targetType"], config["targetConfig"], asJson);
                loop++;
            }
        }
예제 #30
0
        public BetterTracking(Cli setcontroler)
        {
            controler = setcontroler;
            if (controler.getBot() == null)
            {
                LogFormater.Info("Tracker - error no bot");
                return;
            }
            SecondBot bot = controler.getBot();

            if (bot.getMyConfig.Setting_Tracker.ToLowerInvariant() == "false")
            {
                LogFormater.Info("Tracker - Disabled because set to false");
                return;
            }
            if (int.TryParse(controler.getBot().getMyConfig.Setting_Tracker, out output_channel) == true)
            {
                output_to_channel = true;
                LogFormater.Info("Tracker - Running as EventDriver + Channel output");
                attachEvents();
            }
            else if (controler.getBot().getMyConfig.Setting_Tracker.StartsWith("http") == true)
            {
                output_to_url = true;
                LogFormater.Info("Tracker - Running as EventDriver + HTTP output");
                attachEvents();
            }
            else if (controler.getBot().getMyConfig.Setting_Tracker != "Event")
            {
                LogFormater.Info("Tracker - Disabled not a vaild channel,http address or EventDriver");
            }
            else
            {
                LogFormater.Info("Tracker - Running as EventDriver");
                attachEvents();
            }
        }