static void Main(string[] args) { Console.WriteLine("Hello World!"); MovieController ctr = new MovieController(); ctr.Connect(); // test ctr.WipeDB(); ctr.InsertUser(0, "simmonde"); ctr.InsertUser(1, "saumonLeCitron"); ctr.AddFriend("simmonde", "saumonLeCitron"); ctr.InsertMovie(0, "Star Wars"); ctr.AddRate("simmonde", "Star Wars", 2); ctr.AddRate("saumonLeCitron", "Star Wars", 2); Console.WriteLine(ctr.GetAverageRateByMovie("Star Wars")); /* * ctr.AddFriend(1, "saumonlecitron"); * ctr.AddFriend(2, "simmonde"); * ctr.AddFriend(3, "fred"); * ctr.AddFriend(4, "jean-pierre"); * ctr.AddFriend(5, "jean-claude"); * ctr.InsertUser(6, "jean-paul"); * ctr.InsertUser(7, "arnold"); * * ctr.AddFriend(1, 2); * ctr.UserIsFriendWith(1, 3); * ctr.UserIsFriendWith(1, 4); * ctr.UserIsFriendWith(1, 5); * ctr.UserIsFriendWith(1, 6); * ctr.UserIsFriendWith(2, 7); * * ctr.InsertMovie(1, "The Adams Family"); * * ctr.UserRatesMovie(2, 1, 5.0); * ctr.UserRatesMovie(3, 1, 5.0); * ctr.UserRatesMovie(4, 1, 5.0); * ctr.UserRatesMovie(7, 1, 1); * * ctr.GetSuggestedMovies(1, 2); * * ctr.InsertMovie(1, "taf"); * * ctr.UserRatesMovie(1, 1, "Nice !"); * ctr.UserRatesMovie(3, 1, "Bullshit !"); * ctr.UserIsFriendWith(1, 2); * ctr.UserIsFriendWith(2, 1); * ctr.UserIsFriendWith(1, 3); * * Console.WriteLine(ctr.GetUsernameById(1)); */ }
private static async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs) { var message = messageEventArgs.Message; string username = message.From.Username; UserSession session; if (!_userSessions.TryGetValue(username, out session)) { session = new UserSession(username); _userSessions.Add(username, session); } session.Message = message; if (message == null || message.Type != MessageType.Text) { return; } var arguments = message.Text.Split(' ').ToList(); switch (arguments.First()) { case "/author": Bot.SendTextMessageAsync(message.Chat.Id, "Frédéric Korradi, Simon Flückiger, Simon Jobin"); break; case "/repo": Bot.SendTextMessageAsync(message.Chat.Id, "https://github.com/korradif/heigmac"); break; case "/addFriend": if (arguments.Count == 2) { Bot.SendTextMessageAsync(message.Chat.Id, "Adding " + arguments[1].Substring(1) + " as a friend to " + message.From.Username); _movieController.AddFriend(message.From.Username, arguments[1].Substring(1)); } break; case "/getFriends": List <string> friends = _movieController.GetFriends(username); DisplayFriends(friends, session); break; case "/getMovie": await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing); session.Step = Step.ChooseFilter; var inlineKeyboard = new InlineKeyboardMarkup(new[] { new [] // first row { InlineKeyboardButton.WithCallbackData("Name"), InlineKeyboardButton.WithCallbackData("Cast"), InlineKeyboardButton.WithCallbackData("Crew"), }, new [] // second row { InlineKeyboardButton.WithCallbackData("Genres"), InlineKeyboardButton.WithCallbackData("Year"), InlineKeyboardButton.WithCallbackData("Language"), } }); await Bot.SendTextMessageAsync( message.Chat.Id, "Choose", replyMarkup : inlineKeyboard); break; default: switch (session.Step) { case Step.InputFilterValue: session.FilterValue = arguments[0].Substring(1); displayFilteredMovies(session); break; case Step.CommentMovie: string comment2 = arguments[0].Substring(1); for (int i = 1; i < arguments.Count; ++i) { comment2 += " " + arguments[i]; } Bot.SendTextMessageAsync(message.Chat.Id, "Adding " + comment2 + " as a comment to " + session.SelectedMovie + " from user " + message.From.Username); _movieController.AddComment(message.From.Username, session.SelectedMovie, comment2); session.Step = Step.Default; break; case Step.RateMovie: bool parsedSucessfully = Double.TryParse(arguments[0].Substring(1).Replace('.', ','), out double rate); if (parsedSucessfully) { _movieController.AddRate(username, session.SelectedMovie, rate); Bot.SendTextMessageAsync(message.Chat.Id, "Adding " + rate + " as a mark to " + session.SelectedMovie + " from user " + message.From.Username); session.Step = Step.Default; } else { Bot.SendTextMessageAsync(message.Chat.Id, "Please enter a valid rate"); } break; default: const string usage = @" Usage: /author - display authors name /getMovie - get the Movie (various filters) /addFriend [username] - add an user as a friend /getFriends - display friends list "; await Bot.SendTextMessageAsync( message.Chat.Id, usage, replyMarkup : new ReplyKeyboardRemove()); break; } break; } }