Пример #1
0
		/// <summary>
		/// Adds a RantPattern containing a subroutine to this module.
		/// </summary>
		/// <param name="name">The name of the function to add.</param>
		/// <param name="pattern">The pattern that will make up the body of the function.</param>
		public void AddSubroutineFunction(string name, RantPattern pattern)
		{
			var action = (pattern.Action.GetType() == typeof(RASequence) ? 
				((RASequence)pattern.Action).Actions[0] : 
				pattern.Action);
			if (action.GetType() != typeof(RADefineSubroutine))
				throw new RantRuntimeException(pattern, pattern.Code, "Attempted to add non-subroutine pattern to a module.");
			_objects[name] = new RantObject(action);
		}
Пример #2
0
        static async void HandleMessages()
        {
            while (true)
            {
                var result = await _bot.GetMessages();
                foreach (Message m in result)
                {
                    if (m.Date < DateTime.Now.AddMinutes(-1)) { continue; }
                    if (m.Text == null) { continue; }

                    MessageTarget target = (m.Chat ?? (MessageTarget)m.From);

                    _engine["username"] = new RantObject(m.From.Username);
                    
                    if (m.Text.StartsWith("/rant"))
                    {
                        string[] parm = m.Text.Split(new [] {' '}, 2, StringSplitOptions.RemoveEmptyEntries);

                        if (parm.Length < 2) { continue; }

                        try
                        {
                            RantPattern pattern = RantPattern.FromString(parm[1]);

                            RantOutput output = _engine.Do(pattern, 1000, 1);

                            _bot.SendMessage(target, output.Main, true, m);

                            historyDictionary[m.From.Username] = pattern;
                        }
                        catch (Exception ex)
                        {
                            _bot.SendMessage(target, "Rant had an error: " + ex.Message, true, m);
                        }

                    }

                    if (m.Text.StartsWith("/again"))
                    {
                        if (historyDictionary.ContainsKey(m.From.Username))
                        {
                            RantOutput output = _engine.Do(historyDictionary[m.From.Username]);
                            _bot.SendMessage(target, output.Main, true, m);
                        }
                        else
                        {
                            _bot.SendMessage(target, "You haven't sent anything yet!", true, m);
                        }
                    }
                }
            }
        }
Пример #3
0
		internal void AddActionFunction(string name, RantAction body)
		{
			_objects[name] = new RantObject(body);
		}