Example #1
0
        public void GetConversations()
        {
            ConversationContainer conversationContainer = reddit.Models.Modmail.GetConversations(new ModmailGetConversationsInput(sort: "user"));

            Validate(conversationContainer);

            conversationContainer = reddit.Models.Modmail.GetConversations(
                new ModmailGetConversationsInput(entity: reddit.Models.Subreddits.About(testData["Subreddit"]).Data.Name, sort: "recent"));

            Validate(conversationContainer);
        }
Example #2
0
    private void GenerateConversations()
    {
        conversations = new Dictionary <string, ConversationContainer>();
        var beckyConvo = new ConversationContainer(0);

        var firstConvo = new Conversation();

        firstConvo.text          = "Oh hi! It's really\n nice to meet you!";
        firstConvo.dialogChoices = new List <string>();
        firstConvo.dialogChoices.Add("Yeah you too!");
        firstConvo.action = "";
        var secondConvo = new Conversation();

        secondConvo.text          = "Cool! Hope we will\nbecome fast friends!";
        secondConvo.dialogChoices = new List <string>();
        secondConvo.action        = "";

        beckyConvo.AddConversation(firstConvo);
        beckyConvo.AddConversation(secondConvo);

        conversations["Becky"] = beckyConvo;

        var nickConvo = new ConversationContainer(0);

        firstConvo               = new Conversation();
        firstConvo.text          = "Sup bro. I'm Nick.";
        firstConvo.dialogChoices = new List <string>();
        firstConvo.dialogChoices.Add("Sup. I'm Keith");
        firstConvo.action         = "";
        secondConvo               = new Conversation();
        secondConvo.text          = "Chill. Wanna chug a\nbeer with me?";
        secondConvo.dialogChoices = new List <string>();
        secondConvo.dialogChoices.Add("Yeah I'm down");
        secondConvo.dialogChoices.Add("Sorry dude not right now");
        secondConvo.action = "";
        var thirdConvo = new Conversation();

        thirdConvo.text          = "Hell yeah. You're\ncool by me.";
        thirdConvo.dialogChoices = new List <string>();
        thirdConvo.action        = "drinkBeer";
        var fourthConvo = new Conversation();

        fourthConvo.text          = "Aight, all good.";
        fourthConvo.dialogChoices = new List <string>();
        fourthConvo.action        = "";

        nickConvo.AddConversation(firstConvo);
        nickConvo.AddConversation(secondConvo);
        nickConvo.AddConversation(thirdConvo);
        nickConvo.AddConversation(fourthConvo);
        conversations["Nick"] = nickConvo;
    }
Example #3
0
        private void MonitorModmailMessagesThread(ConversationContainer conversationContainer, string key, string type, int startDelayMs = 0, int?monitoringDelayMs = null)
        {
            if (startDelayMs > 0)
            {
                Thread.Sleep(startDelayMs);
            }

            monitoringDelayMs = (monitoringDelayMs.HasValue ? monitoringDelayMs : Monitoring.Count() * MonitoringWaitDelayMS);

            while (!Terminate &&
                   Monitoring.Get(key).Contains("ModmailMessages"))
            {
                if (MonitoringExpiration.HasValue &&
                    DateTime.Now > MonitoringExpiration.Value)
                {
                    MonitorModel.RemoveMonitoringKey(key, "ModmailMessages", ref Monitoring);
                    Threads.Remove(key);

                    break;
                }

                while (!IsScheduled())
                {
                    if (Terminate)
                    {
                        break;
                    }

                    Thread.Sleep(15000);
                }

                if (Terminate)
                {
                    break;
                }

                Dictionary <string, Conversation>        oldConversationList;
                Dictionary <string, Conversation>        newConversationList;
                Dictionary <string, ConversationMessage> oldMessageList;
                Dictionary <string, ConversationMessage> newMessageList;

                ConversationContainer res;
                try
                {
                    switch (type)
                    {
                    default:
                        throw new RedditControllerException("Unrecognized type '" + type + "'.");

                    case "recent":
                        res = GetRecentConversations();
                        break;

                    case "mod":
                        res = GetModConversations();
                        break;

                    case "user":
                        res = GetUserConversations();
                        break;

                    case "unread":
                        res = GetUnreadConversations();
                        break;
                    }

                    oldConversationList = conversationContainer?.Conversations;
                    newConversationList = res.Conversations;
                    oldMessageList      = conversationContainer?.Messages;
                    newMessageList      = res.Messages;

                    if (Diff(oldConversationList, newConversationList, out Dictionary <string, Conversation> addedC, out Dictionary <string, Conversation> removedC))
                    {
                        if (Diff(oldMessageList, newMessageList, out Dictionary <string, ConversationMessage> addedM, out Dictionary <string, ConversationMessage> removedM))
                        {
                            // Event handler to alert the calling app that the list has changed.  --Kris
                            ModmailConversationsEventArgs args = new ModmailConversationsEventArgs
                            {
                                NewConversations     = newConversationList,
                                OldConversations     = oldConversationList,
                                AddedConversations   = addedC,
                                RemovedConversations = removedC,
                                NewMessages          = newMessageList,
                                OldMessages          = oldMessageList,
                                AddedMessages        = addedM,
                                RemovedMessages      = removedM
                            };
                            TriggerUpdate(args, type);
                        }
                    }
                }
                catch (Exception) when(!BreakOnFailure)
                {
                }

                Wait(monitoringDelayMs.Value);
            }
        }
Example #4
0
        private void MonitorModmailMessagesThread(ConversationContainer conversationContainer, string key, string type, int startDelayMs = 0)
        {
            if (startDelayMs > 0)
            {
                Thread.Sleep(startDelayMs);
            }

            while (!Terminate &&
                   Monitoring.Get(key).Contains("ModmailMessages"))
            {
                Dictionary <string, Conversation>        oldConversationList;
                Dictionary <string, Conversation>        newConversationList;
                Dictionary <string, ConversationMessage> oldMessageList;
                Dictionary <string, ConversationMessage> newMessageList;

                ConversationContainer res;
                switch (type)
                {
                default:
                    throw new RedditControllerException("Unrecognized type '" + type + "'.");

                case "recent":
                    res = GetRecentConversations();
                    break;

                case "mod":
                    res = GetModConversations();
                    break;

                case "user":
                    res = GetUserConversations();
                    break;

                case "unread":
                    res = GetUnreadConversations();
                    break;
                }

                oldConversationList = conversationContainer?.Conversations;
                newConversationList = res.Conversations;
                oldMessageList      = conversationContainer?.Messages;
                newMessageList      = res.Messages;

                if (Diff(oldConversationList, newConversationList, out Dictionary <string, Conversation> addedC, out Dictionary <string, Conversation> removedC))
                {
                    if (Diff(oldMessageList, newMessageList, out Dictionary <string, ConversationMessage> addedM, out Dictionary <string, ConversationMessage> removedM))
                    {
                        // Event handler to alert the calling app that the list has changed.  --Kris
                        ModmailConversationsEventArgs args = new ModmailConversationsEventArgs
                        {
                            NewConversations     = newConversationList,
                            OldConversations     = oldConversationList,
                            AddedConversations   = addedC,
                            RemovedConversations = removedC,
                            NewMessages          = newMessageList,
                            OldMessages          = oldMessageList,
                            AddedMessages        = addedM,
                            RemovedMessages      = removedM
                        };
                        TriggerUpdate(args, type);
                    }
                }

                Thread.Sleep(Monitoring.Count() * MonitoringWaitDelayMS);
            }
        }
 // Start is called before the first frame update
 void Start()
 {
     MyConversations = new ConversationContainer();
     MyConversations.LoadJsonData("Manuscripts/villageManuscript.json");
 }