/// <summary>
 ///     Constuctor for class of arguments for event, which invoked when command ready to invoke (ARGH)
 /// </summary>
 /// <param name="command">Command</param>
 /// <param name="message">Message</param>
 public BeginInvokeEventArgs(ICommand command, Message message)
 {
     Command = command;
     Message = message;
     Refuse = false;
     RunSync = false;
 }
Exemple #2
0
		/// <summary>
		///	 Update constructor
		/// </summary>
		/// <param name="updateId">
		///	 The update‘s unique identifier. Update identifiers start from a certain positive number and
		///	 increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore
		///	 repeated updates or to restore the correct update sequence, should they get out of order.
		/// </param>
		/// <param name="message">New incoming message of any kind — text, photo, sticker, etc.</param>
		public Update(long updateId, Message message)
		{
			Id = updateId;
			Message = message;
		}
Exemple #3
0
		private void ExecuteSync(ICommand command, Message message)
		{
			try
			{
				// Execute command
				command.Executed(message);
			}
			catch (Exception exc)
			{
				if (Settings.ExceptionsToConsole)
					Telesharp.Logger.Log(LogType.Error, Settings.Name, $"Exception, when execute command:\n{exc}");
			}
		}
Exemple #4
0
		private void Execute(ICommand command, Message message)
		{
			if (Settings.MaximumThreadsForCommands > 0 && _threads >= Settings.MaximumThreadsForCommands)
			{
				while (_threads <= Settings.MaximumThreadsForCommands)
				{
					// Wait, when we can go to execute command
				}
			}
			Task.Factory.StartNew(() =>
			{
				try
				{
					_threads++;
					command.Executed(message);
				}
				catch (Exception exc)
				{
					if (Settings.ExceptionsToConsole)
						Telesharp.Logger.Log(LogType.Error, Settings.Name, $"Exception, when execute command:\n{exc}");
				}
				finally
				{
					_threads--;
				}
			});
		}
Exemple #5
0
		private ICommand FindCommand(Message message)
		{
			return Commands.FirstOrDefault(command => Comparer.Compare(command, message));
		}
 /// <summary>
 ///     ParseMessageEventArgs constructor
 /// </summary>
 /// <param name="message"></param>
 public ParseMessageEventArgs(Message message)
 {
     Message = message;
 }
 /// <summary>
 ///     <see cref="ICommand.Executed" />
 /// </summary>
 /// <param name="message"></param>
 public virtual void Executed(Message message)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 ///     Command consturctor
 /// </summary>
 /// <param name="prototype">Prototype</param>
 /// <param name="helpText">Helpful text</param>
 /// <param name="compareMode">Compare mode</param>
 public SimpleComparerCommand(Message prototype, string helpText = null, Mode compareMode = Mode.IsSame)
 {
     Prototype = prototype;
     CompareMode = compareMode;
     HelpText = helpText;
 }
 /// <summary>
 ///     Invoked for compare command
 /// </summary>
 /// <param name="command">Command</param>
 /// <param name="message">Message</param>
 /// <returns></returns>
 public virtual bool Compare(ICommand command, Message message)
 {
     return message.Text != null && command.Prototype.Text == message.Text;
 }