public static bool AddUser(Chat chat, User user) { if (usersData.ContainsKey(chat.id)) { return(false); } Userdata userdata = new Userdata(chat, user); usersData.Add(chat.id, userdata); return(true); }
public void SetUser(Userdata userData) { if (listView_users.Items.ContainsKey(userData.chat.id.ToString())) { RemoveUser(userData); } List <Userdata> list = new List <Userdata>() { userData }; SetUsers(list); }
public void RemoveUser(Userdata userData) { listView_users.Items.RemoveByKey(userData.chat.id.ToString()); }
static public bool ParseMessage(Message message) { if (message.entities == null || message.entities.Count == 0) { return(false); } bool foundOne = false; foreach (MessageEntity entity in message.entities) { if (entity.type == MessageEntityTypes.bot_command.ToString()) { if (!foundOne) { foundOne = true; } else { sendMessage(message.chat.id, "I'm not so clever to handle multiple commands\nUse one by time, please", reply_to_message_id: message.message_id); return(false); } } } string command = message.text.Substring(message.entities[0].offset, message.entities[0].length).ToLower(); Userdata user = localUsersData.usersData[message.chat.id]; switch (command) { //the following cases are all the commands allowed in the bot case "/start": sendMessage(message.chat.id, "REMEMBER THIS BOT IS STILL IN DEVELOPMENT AND IS NOT WORKING BY NOW\nIf you keep this chat YOU WILL ME NOTIFIED AS SOON AS READY\n\nYou will receive a message at random times. Write something back as soon as you can!"); break; case "/faster": user.speed += 1; sendMessage(message.chat.id, "Speed is now set to " + localUsersData.usersData[message.chat.id].speed + " of 5"); break; case "/slower": user.speed -= 1; sendMessage(message.chat.id, "Speed is now set to " + localUsersData.usersData[message.chat.id].speed + " of 5"); break; case "/pause": user.activity = activity.Inactive; sendMessage(message.chat.id, "I will take a break...\nYou will no longer receive messages until you enter the command /write", true); break; case "/write": if (user.activity == activity.WaitingSend) { sendMessage(message.chat.id, "I am currently active. Sit down and wait my message."); } else { user.activity = activity.WaitingSend; sendMessage(message.chat.id, restart_phrases[new Random().Next(0, restart_phrases.Count)] + "\nSpeed is " + localUsersData.usersData[message.chat.id].speed); } break; case "/notificate": user.notificate = !user.notificate; if (user.notificate) { sendMessage(message.chat.id, "Notifications are now active"); } else { sendMessage(message.chat.id, "Notifications are now disabled. Be carefull!"); } break; case "/support": user.supportRequests++; sendMessage(Developer_chat_id, "An User request your attention!\n" + message.text, true); sendMessage(Developer_chat_id, string.Format("Details:\nchat_id: {0}\nuser_id: {1}\nUsername: {2}\nFirst name: {3}\nLast name: {4}\nJoin_date: {5}\nResponse_n: {6}\nResponse_avg: {7}\nSpeed: {8}\nNotificate: {9}\nSupport_req: {10}", message.chat.id, message.from.id, message.from.username, message.from.first_name, message.from.last_name, user.joinDate, user.response.Count, user.response.Average(), user.speed, user.notificate, user.supportRequests), true); sendMessage(message.chat.id, "A message was just sent to the developer.\nHe is magnanimous and will personally contact you."); break; case "/stats": user.SendStats(); break; default: sendMessage(message.chat.id, "Unrecognized command!", reply_to_message_id: message.message_id); break; } return(true); }