コード例 #1
0
ファイル: DataUtils.cs プロジェクト: rexyrex/RexBot-2.0
        //return content from dictionary
        public static string getFromRexDB(string username, string id)
        {
            string res = string.Empty;

            if (rexDB.ContainsKey(username) && rexDB[username].ContainsKey(id))
            {
                res = rexDB[username][id];
                if (MasterUtils.ContainsAny(res, GlobalVars.REXDB_DISALLOWED_FUNCTIONS))
                {
                    res = "Guys I suck! hahaha... Just report me please haha!";
                }
            }
            else
            {
                res = "You have nothing stored here";
            }
            return(res);
        }
コード例 #2
0
ファイル: DataUtils.cs プロジェクト: rexyrex/RexBot-2.0
        //Add line to file + update current dictionary
        //File wont delete existing id's
        //Load process will simply overwrite so most recent pair survives
        public static void writeToRexDB(string userName, string id, string content)
        {
            if (MasterUtils.ContainsAny(content, new string[] { "!meme" }) && content.Count(x => x == '(') == 3)
            {
                int    bracketCount = 0;
                string type         = string.Empty;
                string topText      = string.Empty;
                string botText      = string.Empty;

                for (int i = 0; i < content.Length; i++)
                {
                    if (content[i] == '(' || content[i] == ')')
                    {
                        bracketCount++;
                    }
                    if (bracketCount == 3)
                    {
                        if (content[i] != '(')
                        {
                            topText += content[i];
                        }
                    }
                    if (bracketCount == 5)
                    {
                        if (content[i] != '(')
                        {
                            botText += content[i];
                        }
                    }
                    if (bracketCount == 1)
                    {
                        if (content[i] != ')' && content[i] != '(')
                        {
                            type += content[i];
                        }
                    }
                }
                topText = MasterUtils.processTextForMeme(topText);
                botText = MasterUtils.processTextForMeme(botText);
                string final = "https://memegen.link/" + type + "/" + topText + "/" + botText + ".jpg";
                content = final;
            }

            if (!rexDB.ContainsKey(userName))
            {
                rexDB[userName] = new Dictionary <string, string>();
            }

            if (MasterUtils.ContainsAny(content, GlobalVars.REXDB_DISALLOWED_FUNCTIONS))
            {
                content = "Guys I suck! hahaha... Just report me please haha!";
            }

            if (rexDB[userName].ContainsKey(id))
            {
                rexDB[userName][id] = content;
            }
            else
            {
                rexDB[userName].Add(id, content);
            }

            using (StreamWriter sw = File.AppendText(textPath + "rexdb.txt"))
            {
                sw.WriteLine(userName + 'ㄱ' + id + 'ㄱ' + content);
            }
        }