Exemplo n.º 1
0
 void Help()
 {
     this.AddReRule(
         bot + s + anyOf("help", "справка", "?", "-h"),
         async(request, match, cancel) =>
     {
         var dir  = AppDomain.CurrentDomain.BaseDirectory;
         var file = Path.Combine(dir, "YobaBotHelp.txt");
         var text = File.ReadAllText(file);
         return(Ok(await _telegram.ReplyAsync(request, text, cancel)));
     });
 }
Exemplo n.º 2
0
 void NewProfile()
 {
     this.AddReRule(
         bot + s + add + s + profile + s + phrase("name"),
         async(request, match, cancel) =>
     {
         await _dao.CreateProfile(new YobaProfile
         {
             Id       = Guid.NewGuid(),
             MainName = match.Value("name"),
         }, cancel);
         return(Ok(await _telegram.ReplyAsync(request, "Профиль создан", cancel)));
     });
 }
Exemplo n.º 3
0
    void AddOrUpdateNote()
    {
        MatchHandle <Message> MakeHandle(bool update) =>
        async(request, match, cancel) =>
        {
            var data        = match.Value("data");
            var displayName = match.Value("name").Trim();
            var name        = YobaNote.MakePkName(displayName);
            var note        = await _dao.FindNote(name, cancel);

            if (note == null)
            {
                note = new YobaNote
                {
                    Content     = data,
                    Created     = DateTime.Now,
                    DisplayName = displayName
                };
            }
            else
            {
                var content = update ? data : note.Content + Environment.NewLine + data;
                note.Content = string.Join(Environment.NewLine, Lines(content));
            }
            await Save(note, cancel);

            return(Ok(await _telegram.ReplyAsync(request, "Ок", cancel)));
        };

        this.AddReRule(
            bot + (s + "добавь").opt + (s + "в").opt + s + "заметку" + phrase("name") + ":" + phrase("data"),
            MakeHandle(false));
        this.AddReRule(
            bot + s + "обнови" + s + "заметку" + phrase("name") + ":" + phrase("data"),
            MakeHandle(true));
    }