Наследование: MonoBehaviour
Пример #1
0
    public int Solution(string s)
    {
        // edge case
        if (string.IsNullOrEmpty(s))
        {
            return(-1);
        }

        var res = new chat[26];

        // counts
        for (int i = 0; i < s.Length; i++)
        {
            res[s[i] - 'a']++;
        }

        // get first non repeating
        for (int i = 0; i < s.Length; i++)
        {
            if (res[s[i] - 'a'] == 1)
            {
                return(i);
            }
        }

        // if not exists
        return(-1);
    }
Пример #2
0
        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);
        }
Пример #3
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;

            if (m.text_msg.StartsWith("/craft_add"))
            {
                TelegramAPI.GetReply(m.chatID, "Enter the word to add", m.message_id, true);
                processed = true;
            }
            else if (m.text_msg.StartsWith("/craft_remove"))
            {
                TelegramAPI.GetReply(m.chatID, "Enter the word to remove", m.message_id, true);
                processed = true;
            }
            else if (m.text_msg.StartsWith("/craft"))
            {
                TelegramAPI.SendMessage(m.chatID, craftWord());
                processed = true;
            }
            else if (m.isReply && m.replyOrigMessage == "Enter the word to add" && m.replyOrigUser == Roboto.Settings.botUserName)
            {
                //reply to add word
                addCraftWord(m.text_msg);
                TelegramAPI.SendMessage(m.chatID, "Added " + m.text_msg + " for " + m.userFirstName);
                processed = true;
            }
            else if (m.isReply && m.replyOrigMessage == "Enter the word to remove" && m.replyOrigUser == Roboto.Settings.botUserName)
            {
                bool success = removeCraftWord(m.text_msg);
                TelegramAPI.SendMessage(m.chatID, "Removed " + m.text_msg + " for " + m.userFirstName + " " + (success ? "successfully" : "but fell on my ass"));
                processed = true;
            }

            return processed;
        }
Пример #4
0
        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;
        }
Пример #5
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;
            if (c != null)
            {
                mod_steam_chat_data chatData = (mod_steam_chat_data)c.getPluginData(typeof(mod_steam_chat_data));

                if (m.text_msg.StartsWith("/steam_addplayer"))
                {
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID
                        , "Enter the steamID of the player you want to add. /steam_help to find out how to get this."
                        , false
                        , typeof(mod_steam)
                        , "ADDPLAYER", m.message_id, true);
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/steam_help"))
                {
                    TelegramAPI.SendMessage(m.chatID, "You are looking for an ID from the Steam Community site, try http://steamcommunity.com/ and find your profile. You should have something like http://steamcommunity.com/profiles/01234567890132456 . Take this number on the end of the URL."
                        ,false, m.message_id);
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/steam_check"))
                {
                    checkChat(c);

                    processed = true;
                }
                else if (m.text_msg.StartsWith ("/steam_stats"))
                {
                    string announce = "Currently watching achievements from the following players: " + "\n\r";
                    foreach (mod_steam_player p in chatData.players)
                    {
                        announce += "*" + p.playerName + "* - " + p.chievs.Count().ToString() + " known achievements" + "\n\r";
                    }
                    int achievements = 0;
                    foreach (mod_steam_game g in localData.games)
                    {
                        achievements += g.chievs.Count();
                    }
                    announce += "Tracking " + achievements.ToString() + " achievements across " + localData.games.Count().ToString() + " games";

                    TelegramAPI.SendMessage(m.chatID, announce , true, m.message_id);
                }

                else if (m.text_msg.StartsWith("/steam_remove"))
                {
                    List<string> playerKeyboard = new List<string>();
                    foreach (mod_steam_player p in chatData.players)
                    {
                        playerKeyboard.Add(p.playerName);
                    }
                    playerKeyboard.Add("Cancel");
                    string playerKeyboardText = TelegramAPI.createKeyboard(playerKeyboard, 2);
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID, "Which player do you want to stop tracking?", false, typeof(mod_steam), "REMOVEPLAYER", m.message_id, true, playerKeyboardText);

                }
            }
            return processed;
        }
Пример #6
0
        public IHttpActionResult CreateChat(chat _chat)
        {
            var maxId = 1;

            if (db.chat.Any())
            {
                maxId = db.chat.Max(c => c.chat_id) + 1;
            }
            //ad newPost = _ad;
            //newPost.ad_id = maxId;
            //db.ad.Add(newPost);
            if (db.chat.Where(c => c.chat_id == _chat.chat_id && c.ad_id == _chat.ad_id && c.seller_id == _chat.seller_id && c.buyer_id == _chat.buyer_id).Any())
            {
                db.chat.Add(new chat()
                {
                    chat_id   = _chat.chat_id,
                    ad_id     = _chat.ad_id,
                    seller_id = _chat.seller_id,
                    buyer_id  = _chat.buyer_id
                });
                db.SaveChanges();
                return(Ok("Created new chat succesfully"));
            }
            return(Ok("Chat already exists"));
        }
Пример #7
0
        public static Chat CreateChat(int UserOneID, int UserTwoID)
        {
            chat chat = new chat();
            using (var context = new HotSaleDBEntities())
            {

                chat.user1 = context.users.ToList().SingleOrDefault(x => x.ID == UserOneID);
                chat.user2 = context.users.ToList().SingleOrDefault(x => x.ID == UserTwoID);
                context.chats.Add(chat);
                context.SaveChanges();
                context.users.ToList().SingleOrDefault(x => x.ID == UserOneID).chats.Add(chat);
                context.users.ToList().SingleOrDefault(x => x.ID == UserTwoID).chats.Add(chat);
                context.SaveChanges();

            }
            Chat Chat = new Chat();
            Chat.ID = chat.ID;
            Chat.UserFirst = new User();
            Chat.UserFirst.ID = chat.user1.ID;
            Chat.UserFirst.Name = chat.user1.Name;
            Chat.UserFirst.Surname = chat.user1.Surname;
            Chat.UserFirst.Avatar = chat.user1.Avatar;
            Chat.UserSecond = new User();
            Chat.UserSecond.ID = chat.user2.ID;
            Chat.UserSecond.Name = chat.user2.Name;
            Chat.UserSecond.Surname = chat.user2.Surname;
            Chat.UserSecond.Avatar = chat.user2.Avatar;
            Chat.Messages = new List<Messages>();

            return Chat;
        }
Пример #8
0
        public chat GetPostBuyer(int adId, int buyerId)
        {
            if (adId > 0 && buyerId > 0)
            {
                var chat = db.chat.Where(c => c.ad_id == adId && c.buyer_id == buyerId).FirstOrDefault();
                if (chat == null)
                {
                    var maxId = 1;
                    if (db.chat.Any())
                    {
                        maxId = db.chat.Max(c => c.chat_id) + 1;
                    }
                    var ad        = db.ad.Where(a => a.ad_id == adId).FirstOrDefault();
                    var seller_id = ad.user_id;
                    chat = new chat
                    {
                        chat_id   = maxId,
                        ad_id     = adId,
                        seller_id = seller_id,
                        buyer_id  = buyerId
                    };

                    db.chat.Add(chat);
                    db.SaveChanges();
                }

                return(chat);
            }
            return(null);
        }
Пример #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            chat chat = db.chat.Find(id);

            db.chat.Remove(chat);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #10
0
        private void ucChat_Click(object sender, EventArgs e)
        {
            ((Form)this.TopLevelControl).Hide();
            chat chForm = new chat(ContactID);

            chForm.Show();
            chForm.Text = SpokenBy.Text.EndsWith(":") ? SpokenBy.Text.Substring(0, spokenBy.Text.Length - 1) : SpokenBy.Text;
        }
Пример #11
0
 //退出聊天室删除一条聊天请求
 public int DelChatAsk(chat mychat)
 {
     SqlParameter[] parms =
     {
         data.MakeInParam("@Lauch_username",   SqlDbType.VarChar, 50, mychat.lauch_username),
         data.MakeInParam("@Invited_username", SqlDbType.VarChar, 50, mychat.invited_usrname),
     };
     return(data.RunProc("delete from chat_invite where lauch_username=@Lauch_username and invited_usrname=@Invited_username) ", parms));
 }
Пример #12
0
 //发起聊天时插入一条聊天请求
 public int InsertChatAsk(chat mychat)
 {
     SqlParameter[] parms =
     {
         data.MakeInParam("@Launch_username",  SqlDbType.VarChar, 50, mychat.lauch_username),
         data.MakeInParam("@Invited_username", SqlDbType.VarChar, 50, mychat.invited_usrname),
     };
     return(data.RunProc("insert into chat_invite(launch_username,invited_username) values(@Launch_username,@Invited_username) ", parms));
 }
Пример #13
0
        public override void initChatData(chat c)
        {
            mod_standard_chatdata chatData = c.getPluginData <mod_standard_chatdata>();

            if (chatData == null)
            {
                //Data doesnt exist, create, populate with sample data and register for saving
                chatData = new mod_standard_chatdata();
                c.addChatData(chatData);
            }
        }
Пример #14
0
 => new BasicWatchdog(
     chat,
     sessionControllerFactory,
     dmbFactory,
     sessionPersistor,
     JobManager,
     ServerControl,
     AsyncDelayer,
     diagnosticsIOManager,
     eventConsumer,
     LoggerFactory.CreateLogger <BasicWatchdog>(),
Пример #15
0
        }//добавляем задачу

        private bool CreatChat(int ID, string name)
        {
            chat           c  = new chat();
            ChatRepository _c = new ChatRepository();

            c.chatId   = ID;
            c.namechat = name;
            _c.Create(c);
            _c.Save();
            return(true);
        }//создание чата для задачи
Пример #16
0
 public ActionResult Edit([Bind(Include = "ID,userID,message,Timestamp")] chat chat)
 {
     if (ModelState.IsValid)
     {
         db.Entry(chat).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.userID = new SelectList(db.AspNetUsers, "Id", "Email", chat.userID);
     return(View(chat));
 }
Пример #17
0
        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);
            }
        }
Пример #18
0
        public ActionResult Create([Bind(Include = "ID,userID,message,Timestamp")] chat chat)
        {
            if (ModelState.IsValid)
            {
                db.chats.Add(chat);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.userID = new SelectList(db.AspNetUsers, "Id", "Email", chat.userID);
            return(View(chat));
        }
Пример #19
0
        private bool addQuote(List <mod_quote_quote_line> lines, chat c)
        {
            mod_quote_data localData = c.getPluginData <mod_quote_data>();

            if (!quoteExists(lines, c))
            {
                localData.multiquotes.Add(new mod_quote_multiquote(lines));
                Roboto.Settings.save();
                return(true);
            }
            return(false);
        }
Пример #20
0
 public ActionResult Edit([Bind(Include = "ID,gonderenID,alanID")] chat chat)
 {
     if (ModelState.IsValid)
     {
         db.Entry(chat).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     //ViewBag.alanID = new SelectList(db.hesap, "ID", "mail", chat.alanID);
     //ViewBag.ID = new SelectList(db.hesap, "ID", "mail", chat.ID);
     return(View(chat));
 }
Пример #21
0
 internal void validateChatData(chat chat)
 {
     if (pluginChatDataType != null)
     {
         RobotoModuleChatDataTemplate chatData = chat.getPluginData(pluginChatDataType);
         if (chatData == null || !chatData.isValid())
         {
             Console.WriteLine("chat data was invalid!");
             throw new InvalidOperationException("Chat Data was Invalid");
         }
     }
 }
Пример #22
0
        /// <summary>
        /// checks the players in the chat, if neccessary, for new achievs.
        /// </summary>
        /// <param name="c"></param>
        private void checkChat(chat c)
        {
            mod_steam_chat_data localData = c.getPluginData <mod_steam_chat_data>();

            if (localData != null)
            {
                foreach (mod_steam_player player in localData.players)
                {
                    player.checkAchievements();
                }
            }
        }
Пример #23
0
        public void loadData(user userlogin)
        {
            this.user = userlogin;
            chat chatserv = new chat();

            try
            {
                chatserv.getListChat("http://support.ekecompany.com/index.php", this.user, this.user.username, this.user.pass);
            }
            catch (Exception exception)
            {
            }
        }
Пример #24
0
        private bool quoteExists(List <mod_quote_quote_line> lines, chat c)
        {
            mod_quote_data localData = c.getPluginData <mod_quote_data>();

            foreach (mod_quote_multiquote q in localData.multiquotes)
            {
                if (q.lines == lines)
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #25
0
        public ActionResult Create([Bind(Include = "ID,gonderenID,alanID")] chat chat)
        {
            if (ModelState.IsValid)
            {
                db.chat.Add(chat);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //ViewBag.taraf1ID = new SelectList(db.hesap, "ID", "mail", chat.taraf1ID);
            //ViewBag.ID = new SelectList(db.hesap, "ID", "mail", chat.ID);
            return(View(chat));
        }
Пример #26
0
        public chat ToChat()
        {
            chat tmp = new chat
            {
                Message = msg,
                Time    = Ui.ToDateTime((time).ToString()),
                UID     = long.Parse(from.user_id),
                User    = from.user_name,
                Type    = (to == null ? "" : "pm")
            };

            return(tmp);
        }
Пример #27
0
 => new PosixWatchdog(
     chat,
     sessionControllerFactory,
     dmbFactory,
     sessionPersistor,
     JobManager,
     ServerControl,
     AsyncDelayer,
     diagnosticsIOManager,
     eventConsumer,
     gameIOManager,
     SymlinkFactory,
     LoggerFactory.CreateLogger <PosixWatchdog>(),
Пример #28
0
        private void button1_Click(object sender, EventArgs e)
        {
            chat chatserv = new chat();

            try
            {
                chatserv.login("http://support.ekecompany.com/index.php", this.user, this.username.Text, this.password.Text);
                this.Close();
            }
            catch (Exception exception)
            {
            }
        }
Пример #29
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;
            if (c != null) //Needs to be done in a chat!
            {
                if (m.text_msg.StartsWith("/birthday_add"))
                {
                    TelegramAPI.GetReply(m.chatID, "Whose birthday do you want to add?", m.message_id, true);
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/birthday_remove"))
                {
                    TelegramAPI.GetReply(m.chatID, "Whose birthday do you want to remove?", m.message_id, true);
                    processed = true;
                }
                else if (m.isReply && m.replyOrigMessage == "Whose birthday do you want to add?" && m.replyOrigUser == Roboto.Settings.botUserName)
                {
                    //reply to add word
                    TelegramAPI.GetReply(m.chatID, "What birthday does " + m.text_msg + " have? (DD-MON-YYYY format, e.g. 01-JAN-1900)", m.message_id, true);
                    processed = true;
                }

                else if (m.isReply && m.replyOrigMessage.StartsWith("What birthday does ") && m.replyOrigUser == Roboto.Settings.botUserName)
                {
                    string uname = m.replyOrigMessage.Substring(19);
                    uname = uname.Substring(0, uname.IndexOf(" have?"));
                    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);
                    }
                    else
                    {
                        Console.WriteLine("Failed to add birthday");
                        TelegramAPI.SendMessage(m.chatID, "Failed to add birthday");
                    }
                    processed = true;
                }

                else if (m.isReply && m.replyOrigMessage == "Whose birthday do you want to remove?" && m.replyOrigUser == Roboto.Settings.botUserName)
                {

                    bool success = removeBirthday(m.text_msg, c);
                    TelegramAPI.SendMessage(m.chatID, "Removed birthday for " + m.text_msg + " " + (success ? "successfully" : "but fell on my ass"));
                    processed = true;
                }
            }
            return processed;
        }
Пример #30
0
        public void send(string name, string message, string dateNow, string groupid)
        {
            string currentDate = GetNistTime().ToString("o");
            int    dialogid    = chatdt.chats.Where(x => x.roomid == groupid).Count();
            chat   chats       = new chat()
            {
                userid = name, dialog = message, chatTime = currentDate, roomid = groupid, seen = false, ID = 0, dialogid = dialogid + 1
            };

            chatdt.chats.Add(chats);
            chatdt.SaveChanges();
            Debug.WriteLine(currentDate);
            Clients.Group(groupid).addNewMessageToPage(name, message, currentDate);
        }
Пример #31
0
        // GET: chat/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            chat chat = db.chat.Find(id);

            if (chat == null)
            {
                return(HttpNotFound());
            }
            return(View(chat));
        }
Пример #32
0
 => new WindowsWatchdog(
     chat,
     sessionControllerFactory,
     dmbFactory,
     sessionPersistor,
     JobManager,
     ServerControl,
     AsyncDelayer,
     diagnosticsIOManager,
     eventConsumer,
     remoteDeploymentManagerFactory,
     gameIOManager,
     SymlinkFactory,
     LoggerFactory.CreateLogger <WindowsWatchdog>(),
Пример #33
0
        public ActionResult chat(string userName, string message)
        {
            chat ct = new chat();

            ct.userName      = Session["userNick"].ToString();
            ct.selectionCode = Session["userId"].ToString();
            ct.message       = message;
            ct.timeDate      = DateTime.Now.ToString();

            db.chats.Add(ct);
            db.SaveChanges();

            return(View());
        }
Пример #34
0
    //获取某一用户收到的聊天请求

    public DataSet GetChatAsk(chat mychat)
    {
        SqlParameter[] parms =
        {
            //data.MakeInParam("@UserName",SqlDbType.VarChar,50,user.username),
            //data.MakeInParam("@Email",SqlDbType.VarChar,50,user.email),
            //data.MakeInParam("@Lauch_username",SqlDbType.VarChar,50,mychat.lauch_username),
            data.MakeInParam("@Invited_username", SqlDbType.VarChar, 50, mychat.invited_usrname),
            //data.MakeInParam("@UserName",SqlDbType.Int,50,user.status),
            //data.MakeInParam("@UserName",SqlDbType.Int,50,user.grank),
            // data.MakeInParam("@UserName",SqlDbType.VarChar,50,user.sex),
        };
        //返回结果集的方式,使用data.Tables[0].Rows.Count取得行数判断是否登录成功
        return(data.RunProcReturn("select * from chat_invite where invited_username=@Invited_username", parms, "chat_invite"));
    }
Пример #35
0
        /// <summary>
        /// gets a FORMATTED string for the quote
        /// </summary>
        /// <returns></returns>
        private string getQuote(chat c)
        {
            mod_quote_data localData = c.getPluginData <mod_quote_data>();

            if (localData.multiquotes.Count > 0)
            {
                mod_quote_multiquote q = localData.multiquotes[settings.getRandom(localData.multiquotes.Count)];

                return(q.getText());
            }
            else
            {
                return("No quotes in DB");
            }
        }
Пример #36
0
        // GET: chats/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            chat chat = db.chats.Find(id);

            if (chat == null)
            {
                return(HttpNotFound());
            }
            ViewBag.userID = new SelectList(db.AspNetUsers, "Id", "Email", chat.userID);
            return(View(chat));
        }
Пример #37
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;

            if (m.text_msg.StartsWith("/help"))
            {
                TelegramAPI.SendMessage(m.chatID, getAllMethodDescriptions());
                processed = true;
            }
            else if (m.text_msg.StartsWith("/save"))
            {
                Roboto.Settings.save();
                TelegramAPI.SendMessage(m.chatID, "Saved settings");
            }
            //TODO - start, stop listening to chat.

            return processed;
        }
Пример #38
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;
            if (c != null)
            {
                mod_quote_data chatData = (mod_quote_data)c.getPluginData(typeof(mod_quote_data));

                if (m.text_msg.StartsWith("/quote_add"))
                {
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID, "Who is the quote by? Or enter 'cancel'", true, typeof(mod_quote), "WHO", -1, true);
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/quote_conv"))
                {
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID, "Enter the first speaker's name, a \\, then the text (e.g. Bob\\I like Bees).\n\rOr enter 'cancel' to cancel", true, typeof(mod_quote), "WHO_M", -1, true);
                    processed = true;
                }

                else if (m.text_msg.StartsWith("/quote_config"))
                {
                    List<string> options = new List<string>();
                    options.Add("Set Duration");
                    options.Add("Toggle automatic quotes");
                    string keyboard = TelegramAPI.createKeyboard(options, 1);
                    TelegramAPI.GetExpectedReply(c.chatID, m.userID,
                        "Quotes are currently " + (chatData.autoQuoteEnabled == true? "enabled" : "disabled")
                        + " and set to announce every " + chatData.autoQuoteHours.ToString() + " hours"
                        , false, typeof(mod_quote), "CONFIG", m.message_id, true, keyboard);
                }
                else if (m.text_msg.StartsWith("/quote"))
                {
                    TelegramAPI.SendMessage(m.chatID, getQuote(c), true, m.message_id);
                    processed = true;
                }
            }

            //also accept forwarded messages

            return processed;
        }
Пример #39
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;

            if (m.text_msg.StartsWith("/craft_add"))
            {
                TelegramAPI.GetExpectedReply(m.chatID, m.userID, "Enter the word to add", true, GetType(), "AddWord");
                processed = true;
            }
            else if (m.text_msg.StartsWith("/craft_remove"))
            {
                TelegramAPI.GetExpectedReply(m.chatID, m.userID, "Enter the word to remove", true, GetType(), "RemWord");
                processed = true;
            }
            else if (m.text_msg.StartsWith("/craft"))
            {
                TelegramAPI.SendMessage(m.chatID, craftWord());
                processed = true;
            }

            return processed;
        }
Пример #40
0
        public void SendMessage(chat.Message msg)
        {
            int size = msg.SerializedSize;

            byte[] buf = new byte[size + 4];

            buf[0] = (byte)((size >> 24) & 0x000000ff);
            buf[1] = (byte)((size >> 16) & 0x000000ff);
            buf[2] = (byte)((size >> 8) & 0x000000ff);
            buf[3] = (byte)((size) & 0x000000ff);

            pb.CodedOutputStream cos = pb.CodedOutputStream.CreateInstance(buf, 4, size);
            msg.WriteTo(cos);

            SendMessage(buf);
        }
Пример #41
0
        private void join_Click(object sender, EventArgs e)
        {
            try
               {
               string item = channelList.SelectedItem.ToString();
               Console.WriteLine(item);

               chat s = new chat(client, item);
               channels.Add(s);
               s.Show();
               client.joinChannel(item);
               }
               catch (Exception ex)
               {
               MessageBox.Show("Musisz wybrać kanał");
               }

               //tutaj do czatu
        }
Пример #42
0
    static void Xmpp_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
    {
        if (msg.HasTag(typeof(AgIXML)))
        {
            AgIXML agiMsg = msg.SelectSingleElement(typeof(AgIXML)) as AgIXML;
            agiMsg newMsg = new agiMsg();
            newMsg.ID = agiMsg.ID;
            newMsg.Type = agiMsg.Type;
            newMsg.Path = agiMsg.Path;
            newMsg.SessionID = agiMsg.SessionID;
            newMsg.SessionKey = agiMsg.SessionKey;
            newMsg.Data = agiMsg.Data;
            newMsg.Flags = agiMsg.Flags;

            switch (newMsg.Type)
            {
                case "tput":
                    xmppManager.world.agi.tput(newMsg);
                    break;
                case "rput":
                    xmppManager.world.agi.rput(newMsg);
                    break;
                case "tget":
                    xmppManager.world.agi.tget(newMsg);
                    break;
                case "rget":
                    xmppManager.world.agi.rget(newMsg);
                    break;
                case "tattach":
                    xmppManager.world.agi.tattach(newMsg);
                    break;
                case "rattach":
                    xmppManager.world.agi.rattach(newMsg);
                    break;
                case "tremove":
                    xmppManager.world.agi.tremove(newMsg);
                    break;
                case "rremove":
                    xmppManager.world.agi.rremove(newMsg);
                    break;
                case "tflush":
                    xmppManager.world.agi.tflush(newMsg);
                    break;
                case "rflush":
                    xmppManager.world.agi.rflush(newMsg);
                    break;
            }
        }

        if (msg.Body != null)
        {
             messages newMsg = new messages();
            newMsg.body = msg.Body;
            newMsg.from = msg.From.User;

            int count = 0;

            while (chats.Count != 0 && count < chats.Count)
            {
                if (chats.ElementAt(count).chatWith.userID == msg.From.User)
                {
                    chats.ElementAt(count).msgChain.Add(newMsg);
                    return;
                }
                count++;
            }

            chat newchat = new chat();
            newchat.msgChain.Add(newMsg);
            newchat.chatWith.userID = msg.From.User.ToString();
            chats.Add(newchat);
            Console.WriteLine(newMsg.body.ToString());
        }
    }
Пример #43
0
        /// <summary>
        /// Process chat messages
        /// </summary>
        /// <param name="m"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        public override bool chatEvent(message m, chat c = null)
        {
            //Various bits of setup before starting to process the message
            bool processed = false;

            if (c != null) //Setup needs to be done in a chat! Other replies will now have a chat object passed in here too!
            {
                //get current game data.
                mod_xyzzy_chatdata chatData = c.getPluginData<mod_xyzzy_chatdata>();

                if (chatData == null)
                {
                    log("Chatdata doesnt exist! creating.", logging.loglevel.high);
                    initChatData(c);
                    chatData = c.getPluginData<mod_xyzzy_chatdata>();

                    if (chatData == null)
                    {
                        log("Chatdata still doesnt exist! creating.", logging.loglevel.critical);
                    }
                }

                if (m.text_msg.StartsWith("/xyzzy_start") && chatData.status == xyzzy_Statuses.Stopped)
                {

                    Roboto.Settings.stats.logStat(new statItem("New Games Started", this.GetType()));
                    //Start a new game!

                    //try and send the opening message

                    //use defaults or configure game
                    string kb = TelegramAPI.createKeyboard(new List<string>() { "Use Defaults", "Configure Game", "Cancel" }, 2);

                    long messageID = TelegramAPI.GetExpectedReply(c.chatID, m.userID, "Do you want to start the game with the default settings, or set advanced optons first? You can change these options later with /xyzzy_settings", true, typeof(mod_xyzzy), "useDefaults",-1,false,kb);

                    if (messageID == long.MinValue)
                    {
                        //no private message session
                        TelegramAPI.SendMessage(m.chatID, m.userFullName + " needs to open a private chat to @" +
                            Roboto.Settings.botUserName + " to be able to start a game", false, -1, true);
                    }
                    else
                    {
                        //message went out successfully, start setting it up proper
                        chatData.reset();
                        //Roboto.Settings.clearExpectedReplies(c.chatID, typeof(mod_xyzzy)); //Cant do this, as clears the "how many questions" we just asked!
                        chatData.setStatus(xyzzy_Statuses.useDefaults);
                        //add the player that started the game
                        chatData.addPlayer(new mod_xyzzy_player(m.userFullName, m.userHandle, m.userID));

                        //send out invites
                        TelegramAPI.SendMessage(m.chatID, m.userFullName + " is starting a new game of xyzzy! Type /xyzzy_join to join. You can join / leave " +
                            "at any time - you will be included next time a question is asked. You will need to open a private chat to @" +
                            Roboto.Settings.botUserName + " if you haven't got one yet - unfortunately I am a stupid bot and can't do it myself :("
                            , false, -1, true);
                    }

                    //TODO - wrap the TelegramAPI calls into methods in the plugin and pluginData classes.

                }
                //Start but there is an existing game
                else if (m.text_msg.StartsWith("/xyzzy_start"))
                {
                    chatData.getStatus();
                    processed = true;
                }

                //player joining
                else if (m.text_msg.StartsWith("/xyzzy_join") && chatData.status != xyzzy_Statuses.Stopped)
                {
                    //TODO - try send a test message. If it fails, tell the user to open a 1:1 chat.
                    long i = -1;
                    try
                    {
                        i = TelegramAPI.SendMessage(m.userID, "You joined the xyzzy game in " + m.chatName);
                        if (i == -1)
                        {
                            TelegramAPI.SendMessage(m.chatID, "Sent " + m.userFullName + " a message, but I'm waiting for him to reply to another question. "
                                + m.userFullName + " is in, but will need to clear their PMs before they see any questions. ", false, m.message_id);

                        }
                        else if (i < 0)
                        {
                            TelegramAPI.SendMessage(m.chatID, "Couldn't add " + m.userFullName + " to the game, as I couldnt send them a message. "
                               + m.userFullName + " probably needs to open a chat session with me. "
                               + "Create a message session, then try /xyzzy_join again.", false, m.message_id);
                        }

                    }
                    catch
                    {
                        log("Error sending message!", logging.loglevel.high);
                    }

                    if (i != long.MinValue) //if we didnt get an error sending the message
                    {
                        bool added = chatData.addPlayer(new mod_xyzzy_player(m.userFullName, m.userHandle, m.userID));
                        if (added) { TelegramAPI.SendMessage(c.chatID, m.userFullName + " has joined the game"); }
                        else { TelegramAPI.SendMessage(c.chatID, m.userFullName + " is already in the game"); }
                    }
                    processed = true;
                }
                //Start but there is an existing game
                else if (m.text_msg.StartsWith("/xyzzy_join"))
                {
                    chatData.getStatus();
                    processed = true;
                }

                //player leaving
                else if (m.text_msg.StartsWith("/xyzzy_leave"))
                {
                    bool removed = chatData.removePlayer(m.userID);
                    //if (removed) { TelegramAPI.SendMessage(c.chatID, m.userFullName + " has left the game"); }
                    //else { TelegramAPI.SendMessage(c.chatID, m.userFullName + " isnt part of the game, and can't be removed!"); }
                    processed = true;
                }

                else if (m.text_msg.StartsWith("/xyzzy_status"))
                {
                    chatData.getStatus();
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/xyzzy_settings"))
                {
                    chatData.sendSettingsMessage(m);
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/xyzzy_get_settings"))
                {
                    chatData.sendSettingsMsgToChat();
                    processed = true;
                }

                /*Moved to the /xyzzy_settings command
                else if (m.text_msg.StartsWith("/xyzzy_setFilter"))
                {
                    chatData.sendSettingsMessage(m);
                    processed = true;
                }

                else if (m.text_msg.StartsWith("/xyzzy_filter"))
                {
                    string response = "The following pack filters are currently set. These can be changed when starting a new game : " + "\n\r" +
            chatData.getPackFilterStatus();
                    TelegramAPI.SendMessage(m.chatID, response, false, m.message_id);
                    processed = true;
                }
                //set the filter (inflight)
                else if (m.text_msg.StartsWith("/xyzzy_setFilter"))
                {
                    chatData.sendPackFilterMessage(m, 1);

                    processed = true;
                }
                //set the filter (inflight)
                else if (m.text_msg.StartsWith("/xyzzy_reDeal"))
                {
                    TelegramAPI.SendMessage(m.chatID, "Resetting everyone's cards, and shuffled the decks", false, m.message_id);
                    chatData.reDeal();

                    processed = true;
                }

                else if (m.text_msg.StartsWith("/xyzzy_reset"))
                {
                    chatData.resetScores();
                    TelegramAPI.SendMessage(m.chatID, "Scores have been reset!", false, m.message_id);
                    processed = true;
                }

                //inflite options
                else if (m.text_msg.StartsWith("/xyzzy_setTimeout"))
                {
                    chatData.askMaxTimeout(m.userID);
                }
                else if (m.text_msg.StartsWith("/xyzzy_setThrottle"))
                {
                    chatData.askMinTimeout(m.userID);
                }
                */
            }
            //has someone tried to do something unexpected in a private chat?
            else if (m.chatID == m.userID && m.text_msg.StartsWith("/xyzzy_"))
            {
                TelegramAPI.SendMessage(m.chatID, "To start a game, add me to a group chat, and type /xyzzy_start");
                processed = true;
            }

            return processed;
        }
Пример #44
0
 /// <summary>
 /// checks the players in the chat, if neccessary, for new achievs.
 /// </summary>
 /// <param name="c"></param>
 private void checkChat(chat c)
 {
     mod_steam_chat_data localData = c.getPluginData<mod_steam_chat_data>();
     if (localData != null)
     {
         foreach (mod_steam_player player in localData.players)
         {
             player.checkAchievements();
         }
     }
 }
Пример #45
0
 public override void initChatData(chat c)
 {
 }
Пример #46
0
        public override bool chatEvent(message m, chat c = null)
        {
            bool processed = false;

            if (m.text_msg.StartsWith("/help") && c != null && c.muted == false)
            {

                mod_standard_chatdata chatData = c.getPluginData<mod_standard_chatdata>();
                string openingMessage = "This is chat " + (c.chatTitle == null ? "" : c.chatTitle) + " (" + c.chatID + "). " +"\n\r";
                if (chatData.quietHoursStartTime != TimeSpan.MinValue && chatData.quietHoursEndTime != TimeSpan.MinValue)
                {
                    openingMessage += "Quiet time set between " + chatData.quietHoursStartTime.ToString("c") + " and " + chatData.quietHoursEndTime.ToString("c") + ". \n\r";
                }

                TelegramAPI.SendMessage(m.chatID, openingMessage +  getAllMethodDescriptions());
                processed = true;
            }
            else if (m.text_msg.StartsWith("/save"))
            {
                Roboto.Settings.save();
                TelegramAPI.SendMessage(m.chatID, "Saved settings");
                processed = true;
            }
            else if (m.text_msg.StartsWith("/stop") && c != null)
            {
                c.muted = true;
                TelegramAPI.SendMessage(m.chatID, "I am now ignoring all messages in this chat until I get a /start command. ");
                //TODO - make sure we abandon any games

                processed = true;
            }
            else if (m.text_msg.StartsWith("/start") && c != null && c.muted == true)
            {
                c.muted = false;
                TelegramAPI.SendMessage(m.chatID, "I am listening for messages again. Type /help for a list of commands." + "\n\r" + getAllWelcomeDescriptions());
                processed = true;
            }
            else if (m.text_msg.StartsWith("/start"))
            {
                //a default /start message where we arent on pause. Might be in group or private chat.
                TelegramAPI.SendMessage(m.chatID, getAllWelcomeDescriptions());

            }

            else if (m.text_msg.StartsWith("/background"))
            {
                //kick off the background loop.
                Roboto.Settings.backgroundProcessing(true);
            }

            else if (m.text_msg.StartsWith("/setquiethours"))
            {
                TelegramAPI.GetExpectedReply(m.chatID, m.userID, "Enter the start time for the quiet hours, cancel, or disable. This should be in the format hh:mm:ss (e.g. 23:00:00)", true, this.GetType(), "setQuietHours");
                processed = true;
            }

            else if (m.text_msg.StartsWith("/stats"))
            {
                TimeSpan uptime = DateTime.Now.Subtract(Roboto.startTime);

                String statstxt = "I is *@" + Roboto.Settings.botUserName + "*" + "\n\r" +
                    "Uptime: " + uptime.Days.ToString() + " days, " + uptime.Hours.ToString() + " hours and " + uptime.Minutes.ToString() + " minutes." + "\n\r" +
                    "I currently know about " + Roboto.Settings.chatData.Count().ToString() + " chats." + "\n\r" +
                    "The following plugins are currently loaded:" + "\n\r";

                foreach (RobotoModuleTemplate plugin in settings.plugins)
                {
                    statstxt += "*" + plugin.GetType().ToString() + "*" + "\n\r";
                    statstxt += plugin.getStats() + "\n\r";
                }

                TelegramAPI.SendMessage(m.chatID, statstxt, true);
                processed = true;
            }
            else if (m.text_msg.StartsWith("/statgraph"))
            {
                string[] argsList = m.text_msg.Split(" ".ToCharArray(), 2);
                Stream image;
                //Work out args and get our image
                if (argsList.Length > 1)
                {
                    string args = argsList[1];
                    image = Roboto.Settings.stats.generateImage(argsList[1].Split("|"[0]).ToList());
                }
                else
                {
                    image = Roboto.Settings.stats.generateImage(new List<string>());
                }

                //Sending image...
                if (image != null)
                {
                    TelegramAPI.SendPhoto(m.chatID, "Stats", image, "StatsGraph.jpg", "application/octet-stream", m.message_id, false);
                }
                else
                {
                    TelegramAPI.SendMessage(m.chatID, "No statistics were found that matched your input, sorry!");
                }
                processed = true;

                //TODO - keyboard for stats?
            }

                return processed;
        }
Пример #47
0
 private void OnPlayerChat(chat.Arg arg)
 {
     if (rustWeb != null)
         rustWeb.OnPlayerChat(arg);
 }
Пример #48
0
 void OnMessage(chat.Message msg)
 {
     if( msg.HasNotification )
     {
         if (msg.Notification.HasWelcome)
         {
             this.Title = msg.Notification.Welcome.Text.ToStringUtf8();
         }else if( msg.Notification.HasFriend )
         {
             var name = msg.Notification.Friend.Name.ToStringUtf8();
             if( msg.Notification.Friend.Online )
             {
                 my_friends.Add(name);
             }
             else
             {
                 my_friends.Remove(name);
             }
         }
         else if (msg.Notification.HasMsg)
         {
             var txtMsg = new TextMessage(msg.Notification.Msg);
             text_messages.Add(txtMsg);
         }
     }
 }
Пример #49
0
 public TextMessage( chat.MessageNotification msgNotify)
 {
     Sender = msgNotify.Sender.ToStringUtf8();
     Timestamp = msgNotify.Timestamp;
     Text = msgNotify.Text.ToStringUtf8();
 }
Пример #50
0
 public override void initChatData(chat c)
 {
     //no specific data, as the enabled flag is on the core chat object.
 }
Пример #51
0
        /// <summary>
        /// Process chat messages
        /// </summary>
        /// <param name="m"></param>
        /// <param name="c"></param>
        /// <returns></returns>
        public override bool chatEvent(message m, chat c = null)
        {
            //Various bits of setup before starting to process the message
            bool processed = false;
            mod_xyzzy_expectedReply expectedInReplyTo = null;
            if (m.text_msg == "bip")
            {
                int i = 1;
            }

            if (c == null && m.isReply)
            {
                //any non-chat messages should only be in reply to messages that we have logged. Find the chatID of the message, and get the chat object
                foreach (mod_xyzzy_expectedReply testReply in localData.expectedReplies)
                {
                    if (testReply.messageID == m.replyMessageID)
                    {
                        //get the chat & reply objects.
                        expectedInReplyTo = testReply;
                        c = Roboto.Settings.getChat(testReply.chatID);
                    }
                }
            }

              if (c == null)
            {
                //except for this stupid thing, where if you reply to a message in a private chat, it doesnt give the original ID. So guess if it is or not.
                //TODO - will f**k up playuing in multiple games.
                if (expectedInReplyTo == null)
                {
                    foreach (mod_xyzzy_expectedReply testReply in localData.expectedReplies)
                    {
                        if (testReply.playerID == m.userID)
                        {
                            //get the chat & reply objects.
                            expectedInReplyTo = testReply;
                            c = Roboto.Settings.getChat(testReply.chatID);
                        }
                    }
                }
            }

            if (c != null) //Setup needs to be done in a chat! Other replies will now have a chat object passed in here too!
            {
                //get current game data.
                mod_xyzzy_data chatData = c.getPluginData<mod_xyzzy_data>();

                if (m.isReply && m.replyOrigMessage == "Which player do you want to kick" && m.replyOrigUser == Roboto.Settings.botUserName)
                {
                    mod_xyzzy_player p = chatData.getPlayer(m.text_msg);
                    if (p != null)
                    {
                        chatData.players.Remove(p);
                        TelegramAPI.SendMessage(m.chatID, "Kicked " + p.name, false, m.message_id, true);
                    }
                    chatData.check();

                    processed = true;
                }

                if (m.text_msg.StartsWith("/xyzzy_start") && chatData.status == mod_xyzzy_data.statusTypes.Stopped)
                {
                    //Start a new game!
                    chatData.reset();
                    localData.clearExpectedReplies(c.chatID);
                    chatData.status = mod_xyzzy_data.statusTypes.SetGameLength;
                    //add the player that started the game
                    chatData.addPlayer(new mod_xyzzy_player(m.userFullName, m.userID));

                    //send out invites
                    TelegramAPI.GetReply(m.chatID, m.userFullName + " is starting a new game of xyzzy! Type /xyzzy_join to join. You can join / leave " +
                        "at any time - you will be included next time a question is asked. You will need to open a private chat to " +
                        Roboto.Settings.botUserName + " if you haven't got one yet - unfortunately I am a stupid bot and can't do it myself :("
                        , -1, true);

                    //confirm number of questions
                    int nrQuestionID = TelegramAPI.GetReply(m.userID, "How many questions do you want the round to last for (-1 for infinite)", -1, true);
                    localData.expectedReplies.Add(new mod_xyzzy_expectedReply(nrQuestionID, m.userID, c.chatID, "")); //this will last until the game is started.

                }

                //Set up the game, once we get a reply from the user.
                else if (chatData.status == mod_xyzzy_data.statusTypes.SetGameLength && expectedInReplyTo != null)
                {
                    int questions;

                    if (int.TryParse(m.text_msg, out questions) && questions >= -1)
                    {
                        chatData.enteredQuestionCount = questions;
                        //next, ask which packs they want:
                        chatData.sendPackFilterMessage(m);
                        chatData.status = mod_xyzzy_data.statusTypes.setPackFilter;
                    }
                    else
                    {
                        TelegramAPI.GetReply(m.chatID, "Thats not a valid number", m.message_id, true);
                        TelegramAPI.GetReply(m.chatID, "How many questions do you want the round to last for? -1 for infinite", m.message_id, true);
                    }
                }

                //Set up the game filter, once we get a reply from the user.
                else if (chatData.status == mod_xyzzy_data.statusTypes.setPackFilter && expectedInReplyTo != null)
                {
                    if (m.text_msg != "Continue")
                    {
                        chatData.setPackFilter(m);
                        chatData.sendPackFilterMessage(m);
                    }
                    else if (chatData.packFilter.Count == 0)
                    {
                        chatData.sendPackFilterMessage(m);
                    }
                    else
                    {

                        chatData.addQuestions();

                        List<mod_xyzzy_card> answers = new List<mod_xyzzy_card>();
                        foreach (mod_xyzzy_card a in localData.answers)
                        {
                            if (chatData.packEnabled(a.category)) { answers.Add(a); }
                        }
                        //TODO - shuffle the list
                        foreach (mod_xyzzy_card answer in answers)
                        {
                            chatData.remainingAnswers.Add(answer.uniqueID);
                        }

                        //tell the player they can start when they want
                        string keyboard = TelegramAPI.createKeyboard(new List<string> { "start" },1);
                        int expectedMessageID = TelegramAPI.GetReply(m.userID, "OK, to start the game once enough players have joined reply to this with \"start\". You'll be sent a message when a user joins.", -1, true, keyboard);
                        chatData.status = mod_xyzzy_data.statusTypes.Invites;
                    }
                }

                //start the game proper
                else if (chatData.status == mod_xyzzy_data.statusTypes.Invites && expectedInReplyTo != null && m.text_msg == "start" )
                {
                    localData.clearExpectedReplies(c.chatID);
                    if (chatData.players.Count > 0) //TODO - should be min 2
                    {
                        chatData.askQuestion();
                    }
                    else
                    {
                        TelegramAPI.SendMessage(m.chatID, "Not enough players");
                    }
                    processed = true;
                }

                //A player answering the question
                else if (chatData.status == mod_xyzzy_data.statusTypes.Question && expectedInReplyTo != null)
                {
                    bool answerAccepted = chatData.logAnswer(m.userID, m.text_msg);
                    /*if (answerAccepted) - covered in the logAnswer step
                    {
                        //no longer expecting a reply from this player
                        if (chatData.allPlayersAnswered())
                        {
                            chatData.beginJudging();
                        }
                    }
                    */
                }

                //A judges response
                else if (chatData.status == mod_xyzzy_data.statusTypes.Judging && expectedInReplyTo != null)
                {
                    bool success = chatData.judgesResponse(m.text_msg);
                    if (success)
                    {
                        //no longer expecting a reply from this player
                        localData.expectedReplies.Remove(expectedInReplyTo);
                    }
                }
                //player joining
                else if (m.text_msg.StartsWith("/xyzzy_join"))
                {
                    //TODO - try send a test message. If it fails, tell the user to open a 1:1 chat.
                    int i = -1;
                    try
                    {
                        i = TelegramAPI.SendMessage(m.userID, "You joined the xyzzy game in " + m.chatName);
                    }
                    catch
                    {
                        TelegramAPI.SendMessage(m.chatID, "Couldn't add " + m.userFullName + " to the game, as I couldnt send them a message. "
                            + m.userFullName + " probably needs to open a chat session with me. "
                            + "Create a message session, then try /xyzzy_join again. Asshole.", false, m.message_id);
                    }

                    if (i != -1)
                    {
                        bool added = chatData.addPlayer(new mod_xyzzy_player(m.userFullName, m.userID));
                        if (added) { TelegramAPI.SendMessage(c.chatID, m.userFullName + " has joined the game"); }
                        else { TelegramAPI.SendMessage(c.chatID, m.userFullName + " is already in the game"); }
                    }
                    processed = true;
                }
                //player leaving
                else if (m.text_msg.StartsWith("/xyzzy_leave"))
                {
                    bool removed = chatData.removePlayer(m.userID);
                    if (removed) { TelegramAPI.SendMessage(c.chatID, m.userFullName + " has left the game"); }
                    else { TelegramAPI.SendMessage(c.chatID, m.userFullName + " isnt part of the game, and can't be removed!"); }
                    processed = true;
                }
                //player kicked
                else if (m.text_msg.StartsWith("/xyzzy_kick"))
                {
                    List<string> players = new List<string>();
                    foreach (mod_xyzzy_player p in chatData.players) {players.Add(p.name);}
                    string keyboard = TelegramAPI.createKeyboard(players,2);
                    TelegramAPI.GetReply(m.chatID, "Which player do you want to kick", m.message_id, true, keyboard);
                    processed = true;
                }
                //player kicked
                else if (m.text_msg.StartsWith("/xyzzy_abandon") && chatData.status != mod_xyzzy_data.statusTypes.Stopped)
                {
                    chatData.status = mod_xyzzy_data.statusTypes.Stopped;
                    localData.clearExpectedReplies(c.chatID);
                    TelegramAPI.SendMessage(c.chatID, "Game abandoned. type /xyzzy_start to start a new game.");
                    processed = true;
                }
                //extend a game
                else if (m.text_msg.StartsWith("/xyzzy_extend"))
                {
                    chatData.addQuestions();

                    TelegramAPI.SendMessage(c.chatID, "Added additional cards to the game!");
                    if (chatData.status == mod_xyzzy_data.statusTypes.Stopped)
                    {
                        chatData.askQuestion();
                    }

                    processed = true;
                }

                //debug question
                else if (m.text_msg.StartsWith("/xyzzy_question") && chatData.status != mod_xyzzy_data.statusTypes.Stopped)
                {
                    //TODO - DEBUG ONLY
                    chatData.askQuestion();
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/xyzzy_status"))
                {
                    string response = "The current status of the game is " + chatData.status.ToString();
                    if (chatData.status != mod_xyzzy_data.statusTypes.Stopped)
                    {
                        response += " with " + chatData.remainingQuestions.Count.ToString() + " questions remaining. Say /xyzzy_join to join. The following players are currently playing: \n\r";
                        foreach (mod_xyzzy_player p in chatData.players)
                        {
                            response += p.name + " - " + p.wins.ToString() + " points. \n\r";
                        }

                        switch (chatData.status)
                        {
                            case mod_xyzzy_data.statusTypes.Question:
                                response += "The current question is : " + "\n\r" +
                                    localData.getQuestionCard(chatData.currentQuestion).text + "\n\r" +
                                    "The following responses are outstanding :";
                                foreach (mod_xyzzy_expectedReply r in localData.expectedReplies)
                                {
                                    if (r.chatID == c.chatID)
                                    {
                                        mod_xyzzy_player p = chatData.getPlayer(r.playerID);
                                        if (p != null) { response += " " + p.name; }
                                    }
                                }
                                break;

                            case mod_xyzzy_data.statusTypes.Judging:
                                response += "Waiting for " + chatData.players[chatData.lastPlayerAsked].name + " to judge";
                                break;
                        }
                    }

                    TelegramAPI.SendMessage(m.chatID, response, false, m.message_id,true);
                    chatData.check();
                    processed = true;
                }
                else if (m.text_msg.StartsWith("/xyzzy_filter"))
                {
                    string response = "The following pack filters are currently set. These can be changed when starting a new game : " + "\n\r" +
            chatData.getPackFilterStatus();
                    TelegramAPI.SendMessage(m.chatID, response, false, m.message_id);
                    processed = true;
                }

            }

            return processed;
        }
Пример #52
0
        /// <summary>
        /// gets a FORMATTED string for the quote
        /// </summary>
        /// <returns></returns>
        private string getQuote(chat c)
        {
            mod_quote_data localData = c.getPluginData<mod_quote_data>();
            if (localData.multiquotes.Count > 0)
            {

                mod_quote_multiquote q = localData.multiquotes[settings.getRandom(localData.multiquotes.Count)];

                return (q.getText());

            }
            else
            {
                return "No quotes in DB";
            }
        }
Пример #53
0
 public void addBirthday(mod_birthday_birthday birthday, chat c)
 {
     mod_birthday_data localData = c.getPluginData<mod_birthday_data>();
     localData.birthdays.Add(birthday);
 }
Пример #54
0
 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;
 }
Пример #55
0
        private bool addQuote(List<mod_quote_quote_line> lines, chat c)
        {
            mod_quote_data localData = c.getPluginData<mod_quote_data>();

            if (!quoteExists(lines, c))
            {
                localData.multiquotes.Add(new mod_quote_multiquote(lines));
                Roboto.Settings.save();
                return true;
            }
            return false;
        }
Пример #56
0
        public override void initChatData(chat c)
        {
            mod_quote_data chatData = c.getPluginData<mod_quote_data>();

            if (chatData == null)
            {
                //Data doesnt exist, create, populate with sample data and register for saving
                chatData = new mod_quote_data();
                c.addChatData(chatData);
            }
            else
            {
                //migrate any old chats to multi_quotes
                //TODO - remove this once all migrated
                #pragma warning disable 612, 618
                foreach (mod_quote_quote q in chatData.quotes)
                {
                    //create a single line quote in multiquotes

                    mod_quote_multiquote mq = new mod_quote_multiquote(new List<mod_quote_quote_line>() { new mod_quote_quote_line(q.by, q.text) });
                    mq.on = q.on;
                    chatData.multiquotes.Add(mq);
                    log("Migrated quote for chat " + chatData.chatID + " to multiquote");
                }
                if (chatData.quotes.Count > 0)
                {
                    log("Migrated " + chatData.quotes.Count + " quotes for chat " + chatData.chatID);
                    chatData.quotes.Clear();
                }
                #pragma warning restore 612, 618

            }
        }
Пример #57
0
 private bool quoteExists(List<mod_quote_quote_line> lines, chat c)
 {
     mod_quote_data localData = c.getPluginData<mod_quote_data>();
     foreach (mod_quote_multiquote q in localData.multiquotes)
     {
         if (q.lines == lines)
         {
             return true;
         }
     }
     return false;
 }