Exemplo n.º 1
0
 public void Execute(Message message)
 {
     var parameters = message.GetCommandParams();
     if (parameters.Length == 0)
     {
         _bot.SendText(message.Chat.Id, Responses.AliasCommand_Usage);
         return;
     }
     switch (parameters[0])
     {
         case "add":
             if (!ValidateAdd(parameters.Skip(2).ToArray(), message.Chat.Id))
                 return;
             var alias = new UserCommand
             {
                 Type = UserCommandType.Alias,
                 Command = parameters[1],
                 AliasCommand = parameters.Skip(2).Join(" "),
                 ChatId = message.Chat.Id
             };
             _db.SaveUserCommand(alias);
             _bot.SendText(message.Chat.Id, Responses.AliasCommand_AliasSaved);
             break;
         case "del": break;
         case "list": break;
         default:
             _bot.SendText(message.Chat.Id, Responses.AliasCommand_Usage);
             break;
     }
 }
Exemplo n.º 2
0
 private static void ExecuteRequestCommand(UserCommand userCommand)
 {
     var request = new RestRequest
     {
         Method = userCommand.Type == UserCommandType.PostRequest ? Method.POST : Method.GET
     };
     foreach (var parameter in userCommand.Data)
     {
         request.AddParameter(parameter.Key, parameter.Value);
     }
     new RestClient(new Uri(userCommand.Url)).Execute(request);
 }
Exemplo n.º 3
0
 public void Execute(Message message)
 {
     var text = message.Text.Split(' ');
     switch (text.Count())
     {
         case 1:
         case 2:
         case 3:
             _bot.SendText(message.Chat.Id, Responses.AddCommandUsageText);
             break;
         default:
             var newCommand = new UserCommand
             {
                 Command = text[1],
                 Type = text[2].ToLower() == "post" ? UserCommandType.PostRequest : UserCommandType.GetRequest,
                 ChatId = message.Chat.Id,
                 Url = text[3],
                 Data = GetData(text.Skip(4))
             };
             _db.SaveUserCommand(newCommand);
             _bot.SendText(message.Chat.Id, string.Format(Responses.AddCommandSuccesfullyAddedCommand, text[1]));
             break;
     }
 }
Exemplo n.º 4
0
 public void SaveUserCommand(UserCommand command)
 {
     _repositoryFactory.GetRepository<UserCommand>().Add(command);
 }