Exemplo n.º 1
0
        //Discordにリプライがきたときのイベント
        private void replayEventProcess(object sender, EventArgs e)
        {
            if (e is DiscordReceive)
            {
                DiscordReceive data = e as DiscordReceive;

                foreach (string s in cancelword) //キャンセルが出た時
                {
                    if (s == data.content)
                    {
                        //キャンセルが出た時
                        cancelEvent?.Invoke(this, data);
                        return;
                    }
                }

                foreach (string s in listwords)  //参加者の問い合わせが来た時
                {
                    if (s == data.content)
                    {
                        showMember?.Invoke(this, data);
                        return;
                    }
                }

                foreach (string s in joinwords)  //参加する場合
                {
                    if (s == data.content)
                    {
                        //参加クラス未定で参加
                        DiscordJoinArg join = new DiscordJoinArg(data.message, client.CurrentUser.Id, JobClass.None, JobClass.None);
                        joinEvent(this, join);
                        return;
                    }
                }

                //参加クラスを定義した場合の処理
                string   content    = data.content.Replace(" ", " "); //全角スペースを半角スペースに変換
                string[] splitedStr = content.Split(' ');
                string   note       = "";                             //備考

                if (splitedStr.Length > 1)
                {
                    note = splitedStr[1];
                }

                (JobClass mainclass, JobClass subClass) = myFunction.convertJobClass(splitedStr[0]);

                if ((mainclass != JobClass.None && subClass != JobClass.None) || (mainclass == JobClass.Hr)) //メインクラスもサブクラスも定義されてる場合
                {
                    DiscordJoinArg join = new DiscordJoinArg(data.message, client.CurrentUser.Id, mainclass, subClass, note);
                    joinEvent(this, join);
                    return;
                }

                //なにもない場合にはリプライイベント
                replayEvent?.Invoke(this, data);
            }
        }
        //戻り値はUPDATEかどうか
        public bool addMember(IjoinArg member)
        {
            (int key, bool memberd) = isMemberd(member);
            List <NpgsqlParameter> parm = new List <NpgsqlParameter>();
            string que = "";

            if (!memberd)   //初めて追加
            {
                que = string.Format("INSERT INTO {0} (ID,name,tag,mainclass,subclass,note,jointime) VALUES (:id,:author,:tag,:main,:sub,:note,'{1}');", tablename, DateTime.Now.ToString());


                parm.Add(new NpgsqlParameter("id", NpgsqlDbType.Integer));
                parm.Add(new NpgsqlParameter("author", NpgsqlDbType.Text));
                parm.Add(new NpgsqlParameter("main", NpgsqlDbType.Integer));
                parm.Add(new NpgsqlParameter("sub", NpgsqlDbType.Integer));
                parm.Add(new NpgsqlParameter("note", NpgsqlDbType.Text));
                parm.Add(new NpgsqlParameter("tag", NpgsqlDbType.Text));

                parm[0].Value = id;
                parm[1].Value = member.getName();
                parm[2].Value = (int)member.getMainclass();
                parm[3].Value = (int)member.getSubclass();
                parm[4].Value = member.getNote();

                if (member is DiscordJoinArg)
                {
                    DiscordJoinArg disc = member as DiscordJoinArg;
                    parm[5].Value = disc.getID();
                }
                else
                {
                    parm[5].Value = "";
                }

                id++;

                logOutput.writeLog("{0}が参加しました。", member.getName());
            }
            else
            {
                if (member.getNote() == "")   //備考の更新がないとき
                {
                    /*
                     * que = string.Format("UPDATE {0} SET mainclass = {1},subclass = {2} WHERE id = {3};",
                     *          tablename,
                     *          member.mainClass,
                     *          member.subClass,
                     *          id);
                     */

                    que = string.Format("UPDATE {0} SET mainclass = :main ,subclass = :sub WHERE id = :id;", tablename);

                    /*
                     * parm.Add(new NpgsqlParameter("id", DbType.Int32) { Value = key });
                     * parm.Add(new NpgsqlParameter("main", DbType.Int32) { Value = member.mainClass });
                     * parm.Add(new NpgsqlParameter("sub", DbType.Int32) { Value = member.subClass });
                     */

                    parm.Add(new NpgsqlParameter("id", NpgsqlDbType.Integer));
                    parm.Add(new NpgsqlParameter("main", NpgsqlDbType.Integer));
                    parm.Add(new NpgsqlParameter("sub", NpgsqlDbType.Integer));

                    parm[0].Value = key;
                    parm[1].Value = (int)member.getMainclass();
                    parm[2].Value = (int)member.getSubclass();
                }
                else
                {
                    /*
                     * que = string.Format("UPDATE {0} SET mainclass = {1},subclass = {2} ,note = {3} WHERE id = {4};",
                     *          tablename,
                     *          member.mainClass,
                     *          member.subClass,
                     *          member.content,
                     *          id);
                     */
                    que = string.Format("UPDATE {0} SET mainclass = :main ,subclass = :sub,note = :note WHERE id = :id;", tablename);

                    /*
                     * parm.Add(new NpgsqlParameter("id", DbType.Int32) { Value = key });
                     * parm.Add(new NpgsqlParameter("main", DbType.Int32) { Value = member.mainClass });
                     * parm.Add(new NpgsqlParameter("sub", DbType.Int32) { Value = member.subClass });
                     * parm.Add(new NpgsqlParameter("note", DbType.String) { Value = member.content });
                     */

                    parm.Add(new NpgsqlParameter("id", NpgsqlDbType.Integer));
                    parm.Add(new NpgsqlParameter("main", NpgsqlDbType.Integer));
                    parm.Add(new NpgsqlParameter("sub", NpgsqlDbType.Integer));
                    parm.Add(new NpgsqlParameter("note", NpgsqlDbType.Text));

                    parm[0].Value = key;
                    parm[1].Value = (int)member.getMainclass();
                    parm[2].Value = (int)member.getSubclass();
                    parm[3].Value = member.getNote();
                }

                logOutput.writeLog("{0}を変更しました。", member.getName());
            }

            //command(que);

            List <object> outputobj = new List <object>();

            foreach (NpgsqlParameter p in parm)
            {
                outputobj.Add(p);
            }

            ListParamCommand(que, outputobj);

            return(memberd);
        }