private void AddQuestionnaire(IIQuestionnaire quest, Action <string> method, int groupid, int userid, PalBot bot)
        {
            if (!GroupInstances.ContainsKey(groupid))
            {
                GroupInstances.Add(groupid, new Dictionary <int, KeyValuePair <IIQuestionnaire, Action <string> > >());
            }
            GroupInstances[groupid].Add(userid, new KeyValuePair <IIQuestionnaire, Action <string> >(quest, method));

            quest.Next   = (a) => GroupInstances[groupid][userid] = new KeyValuePair <IIQuestionnaire, Action <string> >(quest, a);
            quest.Finish = () =>
            {
                QuestionnaireFinished(quest);
                GroupInstances[groupid].Remove(userid);
            };
            quest.MoveToGroup   = (i) => false;
            quest.MoveToPrivate = () =>
            {
                if (PrivateInstances.ContainsKey(userid))
                {
                    return(false);
                }

                AddQuestionnaire(quest, GroupInstances[groupid][userid].Value, userid, bot);
                GroupInstances[groupid].Remove(userid);
                return(true);
            };
            ((IQuestionnaire)quest)._doStartUp(bot);
        }
        private void OnMessage(PalBot bot, Message message)
        {
            try
            {
                if (message.MesgType == Subprofile.Types.MessageType.Group && GroupInstances.ContainsKey(message.GroupId) && GroupInstances[message.GroupId].ContainsKey(message.SourceId))
                {
                    var p = GroupInstances[message.GroupId][message.SourceId];
                    RunQuestionnaire(p, message, bot);
                    return;
                }
                if (message.MesgType == Subprofile.Types.MessageType.Private && PrivateInstances.ContainsKey(message.SourceId))
                {
                    var p = PrivateInstances[message.SourceId];
                    RunQuestionnaire(p, message, bot);
                    return;
                }
            }
            catch (Exception ex)
            {
                bot.On.Trigger("e", ex);
                return;
            }

            DoTyping(bot, message, null, message.Content, null);
        }
        public bool RemovePrivateQuestionnaire(int userid)
        {
            if (!PrivateInstances.ContainsKey(userid))
            {
                return(false);
            }

            PrivateInstances[userid].Key.Finish();
            return(true);
        }
Example #4
0
 /// <summary>
 /// Removes an instance of a Forum based on the specifications of the Message supplied.
 /// </summary>
 /// <param name="msg"></param>
 public void RemoveInstance(Message msg)
 {
     if (msg.MesgType == MessageType.Group &&
         GroupInstances.ContainsKey(msg.GroupId) &&
         GroupInstances[msg.GroupId].ContainsKey(msg.SourceUser))
     {
         GroupInstances[msg.GroupId].Remove(msg.SourceUser);
     }
     else if (msg.MesgType == MessageType.Private &&
              PrivateInstances.ContainsKey(msg.SourceUser))
     {
         PrivateInstances.Remove(msg.SourceUser);
     }
 }
Example #5
0
        private void OnMessage(PalBot bot, Message msg)
        {
            try
            {
                if (msg.MesgType == MessageType.Group && GroupInstances.ContainsKey(msg.GroupId) && GroupInstances[msg.GroupId].ContainsKey(msg.SourceUser))
                {
                    GroupInstances[msg.GroupId][msg.SourceUser](msg);
                    return;
                }
                if (msg.MesgType == MessageType.Private && PrivateInstances.ContainsKey(msg.SourceUser))
                {
                    PrivateInstances[msg.SourceUser](msg);
                    return;
                }
            }
            catch (Exception ex)
            {
                bot.On.Trigger("e", ex);
                return;
            }

            DoPluginSort(bot, msg);
        }
 public bool IsInPrivateQuestionnaire(int userid)
 {
     return(PrivateInstances.ContainsKey(userid));
 }