Ejemplo n.º 1
0
        /// <summary>
        /// 式をDBに登録する
        /// </summary>
        /// <param name="expr">式</param>
        /// <param name="with_save">保存するか</param>
        /// <param name="force">強制的に変更するか</param>
        /// <returns>計算結果</returns>
        public int?set(string expr, bool with_save = true, bool force = false)
        {
            if (!isValid(expr))
            {
                return(null);
            }
            var _rat = rat.eval(expr);

            if (_rat.Denominator != 1)
            {
                return(null);
            }
            var n = (int)_rat.Numerator;

            if (!force && hdb.map.ContainsKey(n) && !set_cost(expr, hdb.map[n]))
            {
                return(null);
            }
            hdb.map[n] = expr;
            if (with_save)
            {
                JsonMgr <HanshinDB> .Save(hdb, filename);
            }
            return(n);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// DBから指定された式を消去する
 /// </summary>
 /// <param name="n">消す数字</param>
 /// <param name="with_save">保存するか (default: true)</param>
 /// <returns>消去できたらTrue</returns>
 public bool delete(int n, bool with_save = true)
 {
     if (hdb.map.ContainsKey(n))
     {
         hdb.map.Remove(n);
         if (with_save)
         {
             JsonMgr <HanshinDB> .Save(hdb, filename);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 阪神算
        /// </summary>
        public Hanshin(string _filename = "hanshin.json")
        {
            filename = _filename;
            if (System.IO.File.Exists(filename))
            {
                hdb = JsonMgr <HanshinDB> .Load(filename);
            }
            else
            {
                hdb          = new HanshinDB();
                hdb.map      = new Dictionary <int, string>();
                hdb.map[334] = "334";
                hdb.map[29]  = "33-4";
                JsonMgr <HanshinDB> .Save(hdb, filename);
            }

            rat = new RatEvaluator();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Slack
        /// </summary>
        public SlackBot(string filename = "config.json")
        {
            if (System.IO.File.Exists(filename))
            {
                conf = JsonMgr <Config> .Load(filename);
            }
            else
            {
                var _conf = new Config();
                _conf.token              = "<YOUR BOT TOKEN HERE>";
                _conf.next_procon        = DateTime.MinValue;
                _conf.procon_notice_time = 0;
                _conf.manager_ids        = new List <string>()
                {
                    "<MANAGER USERNAME HERE>"
                };
                _conf.channels = new List <string>()
                {
                    "<CHANNEL HERE (without #)>"
                };
                _conf.procon_notice_channels = new List <string>()
                {
                    "<PROCON NOTICE CHANNEL HERE (without #)>"
                };

                JsonMgr <Config> .Save(_conf, filename);

                throw new Exception(string.Format("{0}を設定してください。", filename));
            }

            client = new SlackSocketClient(conf.token);

            channel_ids = new List <string>();
            core        = new BotCore(conf);
            IsConnected = false;

            // プロコン残り日数表通知用
            timer_procon          = new System.Timers.Timer();
            timer_procon.Interval = 1000;
            timer_procon.Elapsed += Timer_procon_Elapsed;
        }