public override bool chatEvent(message m, chat c = null) { bool processed = false; if (c != null) //Needs to be done in a chat! { mod_birthday_data chatData = c.getPluginData <mod_birthday_data>(); if (m.text_msg.StartsWith("/birthday_add")) { TelegramAPI.GetExpectedReply(m.chatID, m.userID, "Whose birthday do you want to add?", true, this.GetType(), "ADD"); processed = true; } else if (m.text_msg.StartsWith("/birthday_remove")) { TelegramAPI.GetExpectedReply(m.chatID, m.userID, "Whose birthday do you want to remove?", true, this.GetType(), "REMOVE"); processed = true; } else if (m.text_msg.StartsWith("/birthday_list")) { chatData.listBirthdays(); processed = true; } } return(processed); }
public override void initChatData(chat c) { mod_birthday_data chatData = c.getPluginData <mod_birthday_data>(); if (chatData == null) { //Data doesnt exist, create, populate with sample data and register for saving chatData = new mod_birthday_data(); c.addChatData(chatData); } }
public bool removeBirthday(string name, chat c) { mod_birthday_data localData = c.getPluginData <mod_birthday_data>(); mod_birthday_birthday birthday = null; foreach (mod_birthday_birthday item in localData.birthdays) { if (item.name == name) { birthday = item; } } if (birthday != null) { return(localData.birthdays.Remove(birthday)); } return(false); }
protected override void backgroundProcessing() { foreach (chat c in Roboto.Settings.chatData) { mod_birthday_data localData = c.getPluginData <mod_birthday_data>(); //have we already processed today? if (localData.lastDayProcessed.Month != DateTime.Now.Month || localData.lastDayProcessed.Day != DateTime.Now.Day) { localData.lastDayProcessed = DateTime.Now; foreach (mod_birthday_birthday b in localData.birthdays) { if (b.birthday.Day == DateTime.Now.Day && b.birthday.Month == DateTime.Now.Month) { TelegramAPI.SendMessage(c.chatID, "Happy Birthday to " + b.name + "!"); } } } } }
public override bool replyReceived(ExpectedReply e, message m, bool messageFailed = false) { chat c = Roboto.Settings.getChat(e.chatID); mod_birthday_data chatData = c.getPluginData <mod_birthday_data>(); if (e.messageData == "ADD") { //reply to add word TelegramAPI.GetExpectedReply(e.chatID, m.userID, "What is their Birthday? (DD-MON-YYYY format, e.g. 01-JAN-1900)", true, this.GetType(), "ADD2-" + m.text_msg); return(true); } else if (e.messageData.StartsWith("ADD2")) { string uname = e.messageData.Substring(5); DateTime birthday; bool success = DateTime.TryParse(m.text_msg, out birthday); if (success) { mod_birthday_birthday data = new mod_birthday_birthday(uname, birthday); addBirthday(data, c); TelegramAPI.SendMessage(e.chatID, "Added " + uname + "'s Birthday (" + birthday.ToString("yyyy-MM-dd") + ")"); } else { Console.WriteLine("Failed to add birthday"); TelegramAPI.SendMessage(m.chatID, "Failed to add birthday"); } return(true); } else if (e.messageData == "REMOVE") { bool success = removeBirthday(m.text_msg, c); TelegramAPI.SendMessage(m.chatID, "Removed birthday for " + m.text_msg + " " + (success ? "successfully" : "but fell on my ass")); return(true); } return(false); }
public void addBirthday(mod_birthday_birthday birthday, chat c) { mod_birthday_data localData = c.getPluginData <mod_birthday_data>(); localData.birthdays.Add(birthday); }