Example #1
0
        private string AddReplyToDatabase(string from, string trigger, string reply)
        {
            //Ignore all Twitch commands.
            if (reply.StartsWith("/timeout") || reply.StartsWith("/ban") ||
                reply.StartsWith("/unban") || reply.StartsWith("/slow") ||
                reply.StartsWith("/slowoff") || reply.StartsWith("/subscribers") ||
                reply.StartsWith("/subscribersoff") || reply.StartsWith("/clear") ||
                reply.StartsWith("/mod") || reply.StartsWith("/unmod") ||
                reply.StartsWith("/r9kbeta") || reply.StartsWith("/r9kbetaoff") ||
                reply.StartsWith("/commercial") || reply.StartsWith("/mods"))
            {
                return(DefaultReplies.Angry());
            }


            var data = new Dictionary <string, string>();

            data["addedBy"] = from;
            data["trigger"] = trigger;
            data["reply"]   = reply;

            var ok = Tables["reply"].Insert(data);

            if (!ok)
            {
                return(DefaultReplies.Error());
            }

            var entry     = Tables["reply"].GetLatestEntry();
            var tomeReply = CreateReply(entry);

            _chat.ReplyCache.Add(tomeReply);

            return(DefaultReplies.Confirmation());
        }
Example #2
0
        private string AddQuoteToDatabase(string from, string user, string search)
        {
            //Get the latest message from user containing the search string.
            var userMessage = _chat.ReceivedMessages.Search(user, search);

            if (userMessage == null)
            {
                return(DefaultReplies.Error());
            }

            var data = new Dictionary <string, string>();

            data["addedBy"] = from;
            data["trigger"] = user;
            data["reply"]   = userMessage.Message;

            var ok = _tables["quote"].Insert(data);

            if (!ok)
            {
                return(DefaultReplies.Error());
            }

            var entry = _tables["quote"].GetLatestEntry();
            var reply = CreateReply(entry);

            _chat.ReplyCache.Add(reply);

            return(DefaultReplies.Confirmation());
        }
        private string GetTableEntry(string tableName, string id)
        {
            if (!Tables.ContainsKey(tableName))
            {
                return("Type not found. Choose from: 'command', 'reply', or 'quote'.");
            }

            var table = Tables[tableName];
            var entry = table.GetById(id);

            if (entry == null)
            {
                return(DefaultReplies.Error());
            }

            tableName = char.ToUpper(tableName[0]) + tableName.Substring(1);
            var message = "That was " + tableName + " #" + id + "( ";

            foreach (var column in entry.Columns)
            {
                message += column.Key + " : " + column.Value + ", ";
            }
            message  = message.Substring(0, message.Length - 2);
            message += " )";

            return(message);
        }
Example #4
0
        private string EditEntry(string tableName, string id, string toReplace, string replaceWith)
        {
            if (!Tables.ContainsKey(tableName))
            {
                return("/me :: Type not found. Choose from: 'command' or 'reply'.");
            }

            var table = Tables[tableName];
            var entry = table.GetById(id);

            var message    = entry.Columns["reply"];
            var newMessage = message.Replace(toReplace, replaceWith);

            // "reply" is the name of the column we want to edit.
            var ok = table.Update(id, "reply", newMessage);

            if (!ok)
            {
                return(DefaultReplies.Error());
            }

            entry.Columns["reply"] = newMessage;
            var tomeReply = CreateReply(tableName, entry);

            _chat.ReplyCache.Add(tomeReply);

            return("Edited: " + tomeReply.InfoMessage);
        }
Example #5
0
        private string AddVoteToDatabase(string from, string name, int count)
        {
            var entryList = _tables["vote"].SearchBy("name", name);

            if (entryList == null)
            {
                return(DefaultReplies.Denial());
            }
            var entry = entryList.FirstOrDefault();

            if (entry == null)
            {
                return(DefaultReplies.Denial());
            }

            //If an entry is defined as 'votable', deny.
            if (entry.Columns["vote"] != "False")
            {
                return(DefaultReplies.Denial());
            }

            var userList = _tables["dragon"].SearchBy("user", from);

            if (userList == null)
            {
                return(DefaultReplies.Denial());
            }
            var user = entryList.FirstOrDefault();

            if (user == null)
            {
                return(DefaultReplies.Denial());
            }

            //If user has less coins than he wants to enter, deny.
            var newCoins = int.Parse(user.Columns["coins"]);

            if (newCoins < count)
            {
                return(DefaultReplies.Denial());
            }

            var currentCount = int.Parse(entry.Columns["count"]);
            var newCount     = currentCount + count;

            var ok = _tables["vote"].Update(entry.Columns["id"], "count", newCount.ToString(CultureInfo.InvariantCulture));

            if (!ok)
            {
                return(DefaultReplies.Error());
            }
            ok = _tables["dragon"].Update(user.Columns["dragonId"], "coins", newCoins.ToString(CultureInfo.InvariantCulture));
            if (!ok)
            {
                return(DefaultReplies.Error());
            }

            return(DefaultReplies.Confirmation());
        }
        public void Execute(UserMessage userMessage)
        {
            Match match = Regex.Match(userMessage.Message, RegexString);

            string description = match.Groups[1].ToString();

            HighlightIn30Minutes(userMessage.From.Nick, DateTime.Now.ToString("t"), description);
            _chat.SendMessage(userMessage.Channel.Name, DefaultReplies.Confirmation());
        }
Example #7
0
        private string DeleteEntryFromDatabase(string tableName, string id)
        {
            if (!_tables.ContainsKey(tableName))
            {
                return("Type not found. Choose from: 'command', 'reply', or 'quote'.");
            }

            var table = _tables[tableName];
            var ok    = table.Delete(id);

            if (!ok)
            {
                return(DefaultReplies.Error());
            }

            tableName = char.ToUpper(tableName[0]) + tableName.Substring(1);
            return(tableName + " #" + id + " has been deleted.");
        }
        private string AddQuoteToDatabase(string from, string message)
        {
            var data = new Dictionary <string, string>();

            data["addedBy"] = from;
            data["trigger"] = _user;
            data["reply"]   = message;

            var ok = Tables["quote"].Insert(data);

            if (!ok)
            {
                return(DefaultReplies.Error());
            }

            var entry = Tables["quote"].GetLatestEntry();
            var reply = CreateReply(entry);

            _chat.ReplyCache.Add(reply);
            return(DefaultReplies.Confirmation());
        }
Example #9
0
        private string AddCommandToDatabase(string from, string trigger, string reply)
        {
            //Create data to be added into the database
            var data = new Dictionary <string, string>();

            data["addedBy"] = from;
            data["trigger"] = trigger.ToLower();
            data["reply"]   = reply;

            var ok = _commandTable.Insert(data);

            if (!ok)
            {
                return(DefaultReplies.Error());
            }

            //Create TomeMessage to log in the history.
            var entry     = _commandTable.GetLatestEntry();
            var tomeReply = CreateReply(entry);

            _chat.ReplyCache.Add(tomeReply);

            return("Command !" + trigger + " has been created succesfully.");
        }