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))); }); }
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))); }); }
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)); }