Exemple #1
0
        private void On_NewInventoryOffer(object sender, InventoryObjectOfferedEventArgs e)
        {
            MHE(Destinations.DEST_LOCAL, e.Offer.FromAgentID, "Checking notice creation sessions..");
            OCBotMemory ocMem = OCBotMemory.Memory;

            if (ocMem.NoticeSessions.ContainsKey(e.Offer.FromAgentID))
            {
                MHE(Destinations.DEST_LOCAL, e.Offer.FromAgentID, "Checking..");
                OCBotMemory.NoticeCreationSessions nCS = ocMem.NoticeSessions[e.Offer.FromAgentID];
                if (nCS.State == 5)
                {
                    MHE(Destinations.DEST_LOCAL, e.Offer.FromAgentID, "Stand by.. Accepting inventory and moving it into place");
                    AssetType dataType          = e.AssetType;
                    UUID      AssetID           = e.ObjectID;
                    UUID      DestinationFolder = grid.Inventory.FindFolderForType(dataType);

                    e.Accept   = true;
                    e.FolderID = DestinationFolder;

                    nCS.TemporaryNotice.NoticeAttachment = AssetID;
                    nCS.State++;
                    ocMem.NoticeSessions[e.Offer.FromAgentID] = nCS;
                    ocMem.Save();
                    MHE(Destinations.DEST_LOCAL, e.Offer.FromAgentID, "Here's the details of the built notice, please very it is correct\n \nNotice Summary: " + nCS.TemporaryNotice.NoticeSummary + "\nNotice Description: " + nCS.TemporaryNotice.NoticeDescription + "\nNotice has attachment: " + nCS.TemporaryNotice.HasAttachment.ToString() + "\nNotice Attachment ID: " + nCS.TemporaryNotice.NoticeAttachment.ToString() + "\nRepeats: " + nCS.TemporaryNotice.Repeats.ToString() + "\n \n[To confirm this, say 'confirm']");
                }
            }
            else
            {
                MHE(Destinations.DEST_LOCAL, e.Offer.FromAgentID, "Notice session does not exist!");
                e.Accept = false;
            }
        }
Exemple #2
0
        public void PerformSitCommand(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory bmem = OCBotMemory.Memory;

            if (additionalArgs[0] == "unsit")
            {
                BotSession.Instance.grid.Self.Stand();
                bmem.sit_cube = UUID.Zero;
                bmem.Save();
            }
            else
            {
                UUID obj = UUID.Zero;
                try
                {
                    obj = UUID.Parse(additionalArgs[0]);
                    BotSession.Instance.grid.Self.RequestSit(obj, Vector3.Zero);
                    bmem.sit_cube = obj;
                    bmem.Save();
                }
                catch (Exception e)
                {
                    MHE(source, client, "Failed to sit! UUID invalid");
                }
            }
        }
Exemple #3
0
        public void sl_search_exact(UUID client, int level, string[] additionalArgs,
                                    Destinations source,
                                    UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            BotSession.Instance.grid.Directory.StartPeopleSearch(additionalArgs[0] + " " + additionalArgs[1], 0);


            mre.Reset();
            BotSession.Instance.grid.Directory.DirPeopleReply += name_search;
            if (mre.WaitOne(TimeSpan.FromSeconds(30)))
            {
                // output the search results

                MHE(source, client, "Okay! I got a reply from search results!");
                BotSession.Instance.grid.Directory.DirPeopleReply -= name_search;

                foreach (DirectoryManager.AgentSearchData asd in peopleSearchResults)
                {
                    MHE(source, client, "Result: secondlife:///app/agent/" + asd.AgentID.ToString() + "/about [" + asd.AgentID.ToString() + "] [online? " + asd.Online.ToString() + "]");
                }
            }
            else
            {
                MHE(source, client, "Failed to get results in time");
                BotSession.Instance.grid.Directory.DirPeopleReply -= name_search;
            }



            peopleSearchResults = new List <DirectoryManager.AgentSearchData>();
        }
Exemple #4
0
        public void InviteToGroupByChat(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            if (DateTime.Now < ocb.InviteLastSent)
            {
                MHE(source, client, "There is a 2 minute cooldown between sending group invites.");
            }

            ocb.InviteLastSent = DateTime.Now.AddMinutes(2);
            ocb.Save();
            UUID groupID = client;
            UUID sendTo  = UUID.Zero;

            if (additionalArgs.Length == 1)
            {
                sendTo = UUID.Parse(additionalArgs[0]);
            }

            if (sendTo == UUID.Zero)
            {
                return;
            }
            else
            {
                List <UUID> role = new List <UUID>();
                role.Add(UUID.Zero);
                BotSession.Instance.grid.Groups.Invite(groupID, role, sendTo);

                MHE(source, client, "Sent the invite");
            }
        }
        public static OCBotMemory Reload(string CustomName = "OpenCollarBot")
        {
            if (!File.Exists(CustomName + ".json"))
            {
                return(new OCBotMemory());                                    // We Must comply with the Singleton Pattern
            }
            try
            {
                if (instance != null)
                {
                    if (instance.SingletonInitialized)
                    {
                        return(Memory);
                    }
                }
            }
            catch (Exception e)
            {
            }
            SerialManager sm  = new SerialManager();
            OCBotMemory   ocb = sm.Read <OCBotMemory>(CustomName);

            ocb.CheckIntegrity();
            return(ocb);
        }
Exemple #6
0
        public void auto_buildnotice(UUID client, int level, string[] additionalArgs,
                                     Destinations source,
                                     UUID agentKey, string agentName)
        {
            // Check staff group is set
            OCBotMemory ocb = OCBotMemory.Memory;

            if (ocb.StaffGroup != UUID.Zero)
            {
                // Build notice & send
                OCBotMemory.Notices new_notice = new OCBotMemory.Notices();
                new_notice.GroupKey         = ocb.StaffGroup;
                new_notice.HasAttachment    = false;
                new_notice.InternalName     = "kicknotice";
                new_notice.LastSent         = DateTime.MinValue;
                new_notice.NoticeAttachment = UUID.Zero;
                string kicked    = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(additionalArgs[0]));
                string raw_msg   = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(additionalArgs[1]));
                string kicked_by = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(additionalArgs[2]));
                new_notice.NoticeSummary     = "Automatic Kick Notification";
                new_notice.Repeats           = false;
                new_notice.NoticeDescription = raw_msg;

                ocb.NoticeLists.Add("kicknotice", new_notice);
                ocb.Save();
            }
        }
        public void SetAlertGroup(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            ocb.AlertGroup = UUID.Parse(additionalArgs[0]);

            ocb.Save();
        }
        public void Set_GitRepo(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            ocb.gitrepo = additionalArgs[0];
            ocb.Save();

            MHE(source, client, "Repository name set");
        }
Exemple #9
0
        public void resave(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            if (File.Exists("OpenCollarBot.json"))
            {
                File.Delete("OpenCollarBot.json");
            }
            ocb.Save();
        }
        public void ResetAllRateLimits(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            // Reset limits!
            ocb.RateLimiter = new Dictionary <UUID, OCBotMemory.RateData>();
            MHE(source, client, "Reset completed");

            ocb.Save();
        }
Exemple #11
0
        public void set_staffgroup(UUID client, int level, string[] additionalArgs,
                                   Destinations source,
                                   UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            ocb.StaffGroup = UUID.Parse(additionalArgs[0]);
            ocb.Save();
            MHE(source, client, "Staff Group has been set to: " + ocb.StaffGroup.ToString() + "\n \n[I will send kick notices to this group automatically]");
        }
        public void clear_bug_reports(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            ocb.ActiveReportSessions  = new Dictionary <UUID, OCBotMemory.ReportData>();
            ocb.ActiveFeatureSessions = new Dictionary <UUID, OCBotMemory.ReportData>();
            ocb.ActiveCommentSessions = new Dictionary <UUID, OCBotMemory.ReportData>();
            ocb.Save();

            MHE(source, client, "Cleared all active reports");
        }
Exemple #13
0
        public void SetActiveGroup(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            UUID groupKey = UUID.Parse(additionalArgs[0]);

            BotSession.Instance.grid.Groups.ActivateGroup(groupKey);

            OCBotMemory bmem = OCBotMemory.Memory;

            bmem.GroupKey = groupKey;
            bmem.Save();
        }
        public void ResetRateLimits(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            // Reset limit!
            UUID userKey = UUID.Parse(additionalArgs[0]);

            ocb.RateLimiter.Remove(userKey);
            MHE(source, client, "User now has 5 remaining queries");
            MHE(Destinations.DEST_AGENT, userKey, "Rate blocks reset for you. You now have 5 remaining bugs/features you can submit from inworld. Remember there is not a limit if you use the github site.");

            ocb.Save();
        }
        public void DoActionComment(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            MHE(source, client, "Okay I can post a comment on Ticket " + additionalArgs[0] + ". Please type out your comments below.\n \n[If you're done type '@', if you want to make a new line type '#', to cancel say 'cancel']");

            OCBotMemory.ReportData rd = new OCBotMemory.ReportData();
            rd.TicketNumber = int.Parse(additionalArgs[0]);
            rd.ReportStage  = 0;
            ocb.ActiveCommentSessions.Add(agentKey, rd);

            ocb.Save();
        }
        public void ShowRate(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory bm = OCBotMemory.Memory;


            if (bm.RateLimiter.ContainsKey(agentKey))
            {
                MHE(source, client, "Hi secondlife:///app/agent/" + agentKey.ToString() + "/about your current usage is [" + bm.RateLimiter[agentKey].SubmitCount.ToString() + "/" + bm.HardLimit.ToString() + "] until " + bm.RateLimiter[agentKey].Reset_At.ToString("MM/dd/yyyy HH:mm:ss tt") + " - Current timestamp: " + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss tt"));
            }
            else
            {
                MHE(source, client, "No usage found");
            }
        }
Exemple #17
0
        public void SetLoginDefault(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory mem = OCBotMemory.Memory;

            if (additionalArgs[0].ToLower() == "region")
            {
                mem.DefaultRegion = BotSession.Instance.grid.Network.CurrentSim.Name;
            }
            else
            {
                mem.DefaultLocation = BotSession.Instance.grid.Self.SimPosition;
            }

            mem.Save();
        }
Exemple #18
0
        public void sl_search(UUID client, int level, string[] additionalArgs,
                              Destinations source,
                              UUID agentKey, string agentName)
        {
            OCBotMemory ocb          = OCBotMemory.Memory;
            int         queued       = 0;
            int         queueRequest = 0;

            while (peopleSearchResults.Count == 0 || peopleSearchResults.Count >= 29)
            {
                peopleSearchResults = new List <DirectoryManager.AgentSearchData>();
                BotSession.Instance.grid.Directory.StartPeopleSearch(additionalArgs[0], queueRequest);
                mre.Reset();
                BotSession.Instance.grid.Directory.DirPeopleReply += name_search;
                if (mre.WaitOne(TimeSpan.FromSeconds(30)))
                {
                    // output the search results

                    //MHE(source, client, "Okay! I got a reply from search results! [" + peopleSearchResults.Count.ToString() + "]");
                    BotSession.Instance.grid.Directory.DirPeopleReply -= name_search;

                    foreach (DirectoryManager.AgentSearchData asd in peopleSearchResults)
                    {
                        MHE(source, client, "Result: secondlife:///app/agent/" + asd.AgentID.ToString() + "/about [" + asd.AgentID.ToString() + "] [online? " + asd.Online.ToString() + "]");
                        queued++;
                    }
                }
                else
                {
                    MHE(source, client, "Failed to get results in time");
                    BotSession.Instance.grid.Directory.DirPeopleReply -= name_search;
                    return;
                }
                queueRequest++;

                if (queued > 300)
                {
                    BotSession.Instance.MSGSVC.QUEUE.Clear();
                    peopleSearchResults = new List <DirectoryManager.AgentSearchData>();
                    MHE(source, client, "Search has been canceled. There were more than 100 results!");

                    BotSession.Instance.grid.Directory.DirPeopleReply -= name_search;
                    return;
                }
            }

            peopleSearchResults = new List <DirectoryManager.AgentSearchData>();
        }
Exemple #19
0
        public void run()
        {
            if (Directory.Exists("GroupCache"))
            {
                Directory.Delete("GroupCache", true);                                 // Clear cache on restart
            }
            registry = CommandRegistry.Instance;

            grid = BotSession.Instance.grid;
            grid.Inventory.InventoryObjectOffered += On_NewInventoryOffer;
            grid.Groups.GroupRoleDataReply        += CacheGroupRoles;
            grid.Groups.GroupMembersReply         += Groups_GroupMembersReply;

            LastScheduleCheck = DateTime.Now - TimeSpan.FromMinutes(5);
            Log  = BotSession.Instance.Logger;
            BMem = OCBotMemory.Memory;

            if (BMem.status != "")
            {
                MHE(Destinations.DEST_LOCAL, UUID.Zero, BMem.status);
            }

            CM = new CommandManager();

            ReloadGroupsCache();
            if (grid.Network.CurrentSim.Name != BMem.DefaultRegion && BMem.DefaultRegion != "")
            {
                if (BMem.DefaultLocation != Vector3.Zero)
                {
                    grid.Self.Teleport(BMem.DefaultRegion, BMem.DefaultLocation);
                }
            }

            if (BMem.sit_cube != UUID.Zero)
            {
                grid.Self.RequestSit(BMem.sit_cube, Vector3.Zero);
            }

            if (BMem.GroupKey != UUID.Zero)
            {
                grid.Groups.ActivateGroup(BMem.GroupKey);
            }


            BMem.iHaveBeenTeleported = false;
            BMem.Save(); // disable on relog
            grid.Self.ScriptDialog += onScriptDialog;
        }
        public void FileFeatureRequest(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            MHE(source, client, "Hi secondlife:///app/agent/" + agentKey.ToString() + "/about ! Can you give me a short summary in a sentence or less about your feature request?\n \n[You can always say 'cancel' at any time to delete this request.]\n[To create a new line type '#']");

            OCBotMemory.ReportData rd = new OCBotMemory.ReportData();
            rd.ReportStage = 0;
            if (ocb.ActiveFeatureSessions.ContainsKey(agentKey))
            {
                MHE(source, client, "* You already had a report session started. I've reset that session for you");
                ocb.ActiveFeatureSessions.Remove(agentKey);
            }

            ocb.ActiveFeatureSessions.Add(agentKey, rd);

            ocb.Save();
        }
        public void BeginBugReport(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName)
        {
            MHE(source, client, "Hi secondlife:///app/agent/" + agentKey.ToString() + "/about\nCan you please tell me in a single sentence or less a summary of what this bug is?\n \n[Say 'cancel' at any time before I open a github ticket if you change your mind]");
            OCBotMemory bm = OCBotMemory.Memory;

            OCBotMemory.ReportData RD = new OCBotMemory.ReportData();
            RD.ReportStage = 0;
            if (!bm.ActiveReportSessions.ContainsKey(agentKey))
            {
                bm.ActiveReportSessions.Add(agentKey, RD);
                bm.Save();
            }
            else
            {
                MHE(source, client, "Seems you already had a bug report started. I'll start it from the beginning");
                bm.ActiveReportSessions.Remove(agentKey);
                bm.ActiveReportSessions.Add(agentKey, RD);
                bm.Save();
            }
        }
Exemple #22
0
        public void sl_key2name(UUID client, int level, string[] additionalArgs,
                                Destinations source,
                                UUID agentKey, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            k2n.Reset();
            BotSession.Instance.grid.Avatars.UUIDNameReply += key2name_reply;
            BotSession.Instance.grid.Avatars.RequestAvatarName(UUID.Parse(additionalArgs[0]));

            if (k2n.WaitOne(TimeSpan.FromSeconds(30)))
            {
                BotSession.Instance.grid.Avatars.UUIDNameReply -= key2name_reply;
                MHE(source, client, "UUID [secondlife:///app/agent/" + additionalArgs[0] + "/about " + additionalArgs[0] + "] is " + DiscoveredNames[UUID.Parse(additionalArgs[0])]);
            }
            else
            {
                MHE(source, client, "Failed to lookup that user! Do they exist?");
                BotSession.Instance.grid.Avatars.UUIDNameReply -= key2name_reply;
            }

            DiscoveredNames = new Dictionary <UUID, string>();
        }
Exemple #23
0
 public void LoadConfiguration()
 {
     BMem = OCBotMemory.Memory;
 }
        public void FeatureResponse(UUID from, UUID agent, int reportStage, string reply, Destinations source, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            OCBotMemory.ReportData RD = ocb.ActiveFeatureSessions[agent];

            if (reply == "cancel")
            {
                ocb.ActiveFeatureSessions.Remove(agent);
                ocb.Save();
                MHE(source, from, "Canceled\n \n[Report Data has been deleted]");
                return;
            }
            ocb.ActiveFeatureSessions.Remove(agent);
            if (RD.ReportStage == 0)
            {
                // Save report title and prompt user for additional details
                RD.ReportTitle = reply;
                RD.ReportStage++;
                ocb.ActiveFeatureSessions.Add(agent, RD);
                MHE(source, from, "Saved. Can I get an extended description about your feature request?\n \n[Say '@' when you are ready to proceed]");
            }
            else if (RD.ReportStage == 1)
            {
                if (reply == "#")
                {
                    RD.ReportBody += "\n";
                }
                else
                {
                    RD.ReportBody += reply;
                }

                if (reply == "@")
                {
                    RD.ReportStage++;
                    MHE(source, from, "Saved!\n \n[If you are ready to submit this request say '@']");
                }

                ocb.ActiveFeatureSessions.Add(agent, RD);
            }
            else if (RD.ReportStage == 2)
            {
                int LVL = 0;
                if (MainConfiguration.Instance.BotAdmins.ContainsKey(agent))
                {
                    LVL = MainConfiguration.Instance.BotAdmins[agent];
                }
                if (!ocb.SubmitNewRateUsage(agent) && LVL < 3)
                {
                    // Notify user
                    ocb.Save();
                    MHE(source, from, "You have hit your rate limit (5 max) for 7 days. Your rate limit resets at " + ocb.RateLimiter[agent].Reset_At.ToString());
                    return;
                }

                GitHubClient ghc  = new GitHubClient(new ProductHeaderValue("OpenCollarBot"));
                Credentials  cred = new Credentials("opencollarangel", Bot.Assemble.ASMInfo.GitPassword);
                ghc.Credentials = cred;
                NewIssue NI = new NewIssue(RD.ReportTitle);
                NI.Body = "Feature Request filed by: " + agentName + "\n\n" + RD.ReportBody;

                Task <Issue> filed_issue = ghc.Issue.Create(ocb.gitowner, ocb.gitrepo, NI);

                filed_issue.Wait();

                int num = filed_issue.Result.Number;

                if (filed_issue.Result.State == ItemState.Open)
                {
                    MHE(source, from, "[http://github.com/" + ocb.gitowner + "/" + ocb.gitrepo + "/issues/" + num.ToString() + " Feature Request Created]");
                }
                else
                {
                    MHE(source, from, "Ticket creation failure. Try again later.");
                }
            }


            ocb.Save();
        }
        public static void Process(string Response, string GHEvent)
        {
            dynamic stuff = JsonConvert.DeserializeObject(Response);

            OCBotMemory ocb = OCBotMemory.Memory;

            if (Directory.Exists("RequestLogs"))
            {
                Directory.CreateDirectory("RequestLogs");
            }
            Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

            File.WriteAllText("RequestLogs/" + unixTimestamp + "_Event.txt", GHEvent);
            File.WriteAllText("RequestLogs/" + unixTimestamp + "_Resp.txt", Response);

            try
            {
                //KeyValuePair<string, string> item = new KeyValuePair<string, string>("X-Github-Event", GHEvent);
                GHEvents item = new GHEvents
                {
                    Key   = "X-Github-Event",
                    Value = GHEvent
                };

                if (item.Key == "X-Github-Event")
                {
                    if (item.Value == "issues")
                    {
                        if (!MainConfiguration.Instance.Authed(Convert.ToString(stuff.issue.user.login)))
                        {
                            return;
                        }

                        int    Issue_Number = Convert.ToInt32(stuff.issue.number);
                        string HTMLUrl      = Convert.ToString(stuff.issue.html_url);
                        string Title        = Convert.ToString(stuff.issue.title);
                        if (stuff.action == "opened")
                        {
                            MH(Destinations.DEST_GROUP, ocb.AlertGroup, "New Issue #" + Issue_Number.ToString() + " [" + HTMLUrl + " " + Title + "]");
                        }
                        else if (stuff.action == "closed")
                        {
                            MH(Destinations.DEST_GROUP, ocb.AlertGroup, "Closed Issue #" + Issue_Number.ToString() + " [" + HTMLUrl + " " + Title + "]");
                        }
                        else if (stuff.action == "reopened")
                        {
                            MH(Destinations.DEST_GROUP, ocb.AlertGroup, "Reopened Issue #" + Issue_Number.ToString() + " [" + HTMLUrl + " " + Title + "]");
                        }
                        else if (stuff.action == "assigned")
                        {
                            MH(Destinations.DEST_GROUP, ocb.AlertGroup, "Issue #" + Issue_Number.ToString() + " has changed assigned users [" + HTMLUrl + " " + Title + "]");
                        }
                    }
                    else if (item.Value == "issue_comment")
                    {
                        if (!MainConfiguration.Instance.Authed(Convert.ToString(stuff.comment.user.login)))
                        {
                            return;
                        }
                        if (stuff.action == "created" || stuff.action == "edited")
                        {
                            int    Issue_Number = Convert.ToInt32(stuff.issue.number);
                            string HTMLUrl      = Convert.ToString(stuff.issue.html_url);
                            string Title        = Convert.ToString(stuff.issue.title);
                            MH(Destinations.DEST_GROUP, ocb.AlertGroup, "Issue #" + Issue_Number.ToString() + " has a new comment [" + HTMLUrl + " " + Title + "]");
                        }
                    }
                    else if (item.Value == "push")
                    {
                        if (!MainConfiguration.Instance.Authed(Convert.ToString(stuff.pusher.name)))
                        {
                            return;
                        }
                        int  I    = 0;
                        bool loop = true;
                        while (loop)
                        {
                            try
                            {
                                string msg = Convert.ToString(stuff.commits[I].message);
                                if (msg.Contains("Merged"))
                                {
                                    msg = "Pull Request Merged";
                                }

                                MH(Destinations.DEST_GROUP, ocb.AlertGroup, "New Commit: " + msg);
                                I++;

                                if (stuff.commits[I] == null)
                                {
                                    loop = false;
                                }
                            }
                            catch (Exception e)
                            {
                                loop = false;
                            }
                        }
                    }
                    else if (item.Value == "pull_request")
                    {
                        int    PRN = Convert.ToInt32(stuff.pull_request.number);
                        string PRU = stuff.pull_request.html_url;
                        string PRT = stuff.pull_request.title;
                        if (stuff.action == "closed")
                        {
                            if (Convert.ToBoolean(stuff.pull_request.merged))
                            {
                                MH(Destinations.DEST_GROUP, ocb.AlertGroup, "Pull request " + PRN + " merged and closed\n View it at: [" + PRU + " " + PRT + "]");
                            }
                            else
                            {
                                MH(Destinations.DEST_GROUP, ocb.AlertGroup, "Pull request closed without merging\nView at [" + PRU + " " + PRT + "]");
                            }
                        }
                        else if (stuff.action == "opened")
                        {
                            MH(Destinations.DEST_GROUP, ocb.AlertGroup, "New Pull request opened #" + PRN + " [" + PRU + " " + PRT + "]");
                        }
                    }
                    else if (item.Value == "pull_request_review_comment")
                    {
                        int    PRN = Convert.ToInt32(stuff.pull_request.number);
                        string PRU = stuff.pull_request.html_url;
                        string PRT = stuff.pull_request.title;
                        if (stuff.action == "created")
                        {
                            // New review comment
                            MH(Destinations.DEST_GROUP, ocb.AlertGroup, "New Pull Request Review Comment on PR #" + PRN + "\nReview Comment Author: " + stuff.comment.user.login + "\nReview Comment: " + stuff.comment.body + "\n \nView it at: [" + PRU + " " + PRT + "]");
                        }
                    }
                    else if (item.Value == "pull_request_review")
                    {
                        int    PRN = Convert.ToInt32(stuff.pull_request.number);
                        string PRU = stuff.pull_request.html_url;
                        string PRT = stuff.pull_request.title;

                        MH(Destinations.DEST_GROUP, ocb.AlertGroup, "New Pull Request Review on PR #" + PRN + "\n \nView it at: [" + PRU + " " + PRT + "]");
                    }
                }
            }
            catch (Exception e)
            {
                MH(Destinations.DEST_LOCAL, UUID.Zero, "Exception caught in WebHook_Processor: " + e.Message + "\nStack: " + e.StackTrace);
                File.WriteAllText("replay.txt", Response);
                MH(Destinations.DEST_LOCAL, UUID.Zero, "Wrote JSON to local file [replay.txt]");
            }
        }
Exemple #26
0
        public void getTick()
        {
            GroupSystem.PerformCheck(LastScheduleCheck);

            if (DateTime.Now > LastScheduleCheck)
            {
                LastScheduleCheck = DateTime.Now + TimeSpan.FromMinutes(5);
            }

            foreach (KeyValuePair <UUID, OCBotMemory.ReplyData> kvp in OCBotMemory.Memory.AntiSpamReply)
            {
                if (kvp.Value.Ignore)
                {
                    continue;                   // This will not get reset here
                }
                if (kvp.Value.InitialReply.AddMinutes(OCBotMemory.Memory.REPLY_BLOCK_EXPIRE.TotalMinutes) <= DateTime.Now)
                {
                    if (kvp.Value.TriggerCount < OCBotMemory.Memory.MAX_TRIGGERS)
                    {
                        // add to removal queue
                        if (OCBSession.Instance.RemoveReplyHandle.Contains(kvp.Key) == false)
                        {
                            OCBSession.Instance.RemoveReplyHandle.Add(kvp.Key);
                        }
                    }
                    else
                    {
                        kvp.Value.SetIgnore();
                    }
                }
            }
            BMem = OCBotMemory.Memory; // Read Singleton
            if (!BMem.iHaveBeenTeleported)
            {
                // check current region
                if (BMem.DefaultRegion != "" && DateTime.Now > OCBSession.Instance.NextTeleportAttempt)
                {
                    if (grid.Network.CurrentSim.Name != BMem.DefaultRegion)
                    {
                        OCBSession.Instance.NextTeleportAttempt = DateTime.Now.AddMinutes(1);
                        grid.Self.Teleport(BMem.DefaultRegion, BMem.DefaultLocation);
                    }
                }
            }


            if (BMem.AutoRestartSim && !OCBSession.Instance.RestartTriggered)
            {
                // Do checks
                DateTime  timestamp = DateTime.Now;
                bool      everyDay  = false;
                DayOfWeek restarter = DayOfWeek.Monday;
                switch (BMem.RestartDay)
                {
                case "mon":
                    restarter = DayOfWeek.Monday;
                    break;

                case "tue":
                    restarter = DayOfWeek.Tuesday;
                    break;

                case "wed":
                    restarter = DayOfWeek.Wednesday;
                    break;

                case "thur":
                    restarter = DayOfWeek.Thursday;
                    break;

                case "fri":
                    restarter = DayOfWeek.Friday;
                    break;

                case "sat":
                    restarter = DayOfWeek.Saturday;
                    break;

                case "sun":
                    restarter = DayOfWeek.Sunday;
                    break;

                default:
                    everyDay = true;
                    break;
                }

                if (restarter == timestamp.DayOfWeek)
                {
                    everyDay = true; // this will keep logic to a minimum
                }
                if (everyDay)
                {
                    // do more checks
                    string timestampStr = timestamp.ToString("hh:mmtt");
                    timestampStr = timestampStr.ToLower();
                    string compareStr = BMem.TimeStringForRestart;

                    if (compareStr == timestampStr)
                    {
                        // restart
                        OCBSession.Instance.RestartTriggered = true;
                        BotSession.Instance.grid.Estate.RestartRegion();
                        BotSession.Instance.WaitForFiveMinutes = true;
                    }
                }
                else
                {
                    // do nothing
                }
            }

            return;
        }
        public void comment(UUID from, UUID agent, int reportStage, string reply, Destinations source, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            OCBotMemory.ReportData RD = ocb.ActiveCommentSessions[agent];
            if (reply == "cancel")
            {
                ocb.ActiveCommentSessions.Remove(agent);
                ocb.Save();
                MHE(source, from, "Canceled\n \n[Data removed]");
                return;
            }

            ocb.ActiveCommentSessions.Remove(agent);
            if (RD.ReportStage == 0)
            {
                if (reply == "#")
                {
                    RD.ReportBody += "\n";
                }
                else if (reply == "@")
                {
                    RD.ReportStage++;
                    MHE(source, from, "OK. Last question! Is this an Issue or a pull request you want to comment on? \n \n[issue/pr]");
                }
                else
                {
                    RD.ReportBody += reply;
                }
            }
            else if (RD.ReportStage == 1)
            {
                if (reply.ToLower() == "issue")
                {
                    RD.ReportTitle = "issue";
                    RD.ReportStage++;
                    MHE(source, from, "OK\n \n[If you're ready to submit this say 'ready']");
                }
                else if (reply.ToLower() == "pr")
                {
                    RD.ReportTitle = "pr";
                    RD.ReportStage++;
                    MHE(source, from, "OK\n \n[If you're ready to submit this say 'ready']");
                }
                else
                {
                    MHE(source, from, "Unable to recognize reply. Try again");
                }
            }
            else if (RD.ReportStage == 2)
            {
                if (reply != "ready")
                {
                    return;
                }
                else
                {
                    GitHubClient ghc = new GitHubClient(new ProductHeaderValue("OpenCollarBot"));
                    ghc.Credentials = new Credentials("opencollarangel", "Gai3+cOLOkUUIn==");

                    if (RD.ReportTitle == "issue")
                    {
                        if (!ocb.SubmitNewRateUsage(agent))
                        {
                            MHE(source, from, "You have reached your request rate limit for the week.");
                            ocb.Save();
                            return;
                        }
                        ghc.Issue.Comment.Create(ocb.gitowner, ocb.gitrepo, RD.TicketNumber, "Comment from " + agentName + "\n \n" + RD.ReportBody);
                        MHE(source, from, "Data has been submitted!!");
                        ocb.Save();
                        return;
                    }
                    else if (RD.ReportTitle == "pr")
                    {
                        MHE(source, from, "*Error*\n \n[Only issues are supported at this time]\n[Your request limit has not been modified]");
                        ocb.Save();
                        return;
                    }
                    else
                    {
                        ocb.Save();
                        MHE(source, from, "Unrecognized request");
                        return;
                    }
                }
            }



            ocb.ActiveCommentSessions.Add(agent, RD);
            ocb.Save();
        }
        public void BugResponse(UUID from, UUID agent, int reportStage, string reply, Destinations source, string agentName)
        {
            OCBotMemory ocb = OCBotMemory.Memory;

            OCBotMemory.ReportData RD = ocb.ActiveReportSessions[agent];
            ocb.ActiveReportSessions.Remove(agent);

            if (reply == "cancel")
            {
                MHE(source, from, "Canceled \n \n[Any entered data has been discarded]");
                ocb.Save();
                return;
            }

            if (reportStage == 0)
            {
                MHE(source, from, "Okay give me a moment");
                RD.ReportTitle = reply;
                RD.ReportStage = 1;
                ocb.ActiveReportSessions.Add(agent, RD);
                MHE(source, from, "Okay. Now please go into as much detail about the problem as you would like.  \n \n[Say '@' on a new line when you are done typing out the full description]");
            }
            else if (reportStage == 1)
            {
                if (reply == "@")
                {
                    RD.ReportStage++;
                    MHE(source, from, "Okay secondlife:///app/agent/" + agent.ToString() + "/about if you have any logs to add please add them below.\n \n[If you have no logs, or are done entering your logs, say '@']");
                }
                else
                {
                    RD.ReportBody += "\n" + reply;
                    MHE(source, from, "-Data Added-");
                }
                ocb.ActiveReportSessions.Add(agent, RD);
            }
            else if (reportStage == 2)
            {
                if (reply == "@")
                {
                    RD.ReportStage++;
                    MHE(source, from, "Okay!\n \n[If you are ready to upload this report say 'ready']");
                }
                else
                {
                    MHE(source, from, "-Data Added-");
                    RD.ReportExtraData += "<details>\n<summary>Extra Data</summary>\n\n```\n" + reply + "\n```\n</details>";
                }
                ocb.ActiveReportSessions.Add(agent, RD);
            }
            else
            {
                if (reply != "ready")
                {
                    return;
                }
                int userLevel = 0;
                if (MainConfiguration.Instance.BotAdmins.ContainsKey(agent))
                {
                    userLevel = MainConfiguration.Instance.BotAdmins[agent];
                }

                if (!ocb.SubmitNewRateUsage(agent) && userLevel < 3)
                {
                    MHE(source, from, "You have hit your rate limit (5 max) for 7 days. Your rate limit resets at " + ocb.RateLimiter[agent].Reset_At.ToString());
                    ocb.Save();
                    return;
                }
                MHE(source, from, "Please stand by..");

                GitHubClient ghc  = new GitHubClient(new ProductHeaderValue("OpenCollarBot"));
                Credentials  cred = new Credentials("opencollarangel", Bot.Assemble.ASMInfo.GitPassword);
                ghc.Credentials = cred;
                NewIssue issueX = new NewIssue(RD.ReportTitle);

                issueX.Body = "Issue created by: " + agentName + "\n\n" + RD.ReportBody + "\n\n" + RD.ReportExtraData;
                Task <Issue> tskI = ghc.Issue.Create(ocb.gitowner, ocb.gitrepo, issueX);
                tskI.Wait();

                int issueNumber = tskI.Result.Number;

                if (tskI.Result.State == ItemState.Open)
                {
                    MHE(source, from, "[http://github.com/" + ocb.gitowner + "/" + ocb.gitrepo + "/issues/" + issueNumber.ToString() + " Issue Created - Click Here To View]");
                }
                else
                {
                    MHE(source, from, "Issue creation failure. Try again later. If this issue persists please report this as a bug to group staff. Thank you");
                }
            }

            ocb.Save();
        }