Example #1
0
        /// <summary>
        /// 穷人榜
        /// </summary>
        /// <returns></returns>
        public string showPoorest()
        {
            try
            {
                StringBuilder sb     = new StringBuilder();
                int           maxnum = 10;
                var           users  = this.users.Values.ToList();
                users.Sort((left, right) =>
                {
                    return(left.Money.CompareTo(right.Money));
                });

                sb.Append("穷 人 榜 \r\n");
                for (int i = 0; i < Math.Min(users.Count, maxnum); i++)
                {
                    sb.Append($"{i + 1}:{getQQNick(users[i].UserId)},{users[i].Money}枚\r\n");
                }
                return(sb.ToString());
            }
            catch (Exception ex)
            {
                FileIOActor.log(ex);
                return("");
            }
        }
Example #2
0
 public void init(sendQQGroupMsgHandler _showScene, getQQNickHandler _getQQNick, BTCActor _btc, string _path)
 {
     outputMessage = _showScene;
     getQQNick     = _getQQNick;
     btc           = _btc;
     path          = _path;
     lock (matchMutex)
     {
         try
         {
             var lines = FileIOActor.readLines(path + userinfoFile);
             foreach (var line in lines)
             {
                 RHUser user = new RHUser(line);
                 users[user.userid] = user;
             }
             lines = FileIOActor.readLines(path + horseinfoFile);
             foreach (var line in lines)
             {
                 RHHorse horse = new RHHorse(line);
                 horses[horse.name] = horse;
             }
         }
         catch (Exception e)
         {
             FileIOActor.log(e.Message + "\r\n" + e.StackTrace);
         }
     }
 }
Example #3
0
        public void init(string path)
        {
            try
            {
                this.path = path;


                var lines1 = FileIOActor.readLines(path + repfile);
                foreach (var line in lines1)
                {
                    var items = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    if (items.Length >= 2)
                    {
                        var r1 = items[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        replaces[items[0]] = r1.ToList();
                        foreach (var sr in r1)
                        {
                            replacesC[sr] = items[0];
                        }
                    }
                }

                var lines2 = FileIOActor.readLines(path + expfile);
                foreach (var line in lines2)
                {
                    var items = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                    exps.Add(items);
                }
            }
            catch (Exception e)
            {
                FileIOActor.log(e.Message + "\r\n" + e.StackTrace);
            }
        }
        public void init(string _path)
        {
            try
            {
                path = _path;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                parser.init(path);

                var lines = FileIOActor.readLines(path + imageWords);
                foreach (var line in lines)
                {
                    var items = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (items.Length >= 2)
                    {
                        baiduWordReplaceDict[items[0]] = items[1];
                    }
                }

                cookie = File.ReadAllText(path + cookief, Encoding.UTF8);
            }catch (Exception ex)
            {
                FileIOActor.log(ex);
            }
        }
 public bool videoCmd(long group, string cmd)
 {
     try
     {
         if (!servers.ContainsKey(group))
         {
             servers[group] = new MWServer(this, group);
         }
         if (cmd.StartsWith("播放"))
         {
             cmd = cmd.Substring(2).Trim();
             if (!servers[group].playVideo(cmd))
             {
                 outputMessage(group, -1, $"没有名为{cmd}的视频。");
             }
             return(true);
         }
         if (cmd == "停止")
         {
             servers[group].stopVideo();
             outputMessage(group, -1, "已停止播放视频。");
             return(true);
         }
     }
     catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
     return(false);
 }
        /// <summary>
        /// 保存抽卡结果
        /// </summary>
        public void savePlayData()
        {
            lock (dcardMutex)
            {
                try
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var user in users.Values)
                    {
                        sb.Append(user.ToString() + "\r\n");
                    }
                    File.WriteAllText(path + dcardPath + userf, sb.ToString(), Encoding.UTF8);

                    sb = new StringBuilder();
                    foreach (var server in servers.Values)
                    {
                        sb.Append(server.ToString() + "\r\n");
                    }
                    File.WriteAllText(path + dcardPath + dcardserverf, sb.ToString(), Encoding.UTF8);
                }
                catch (Exception ex)
                {
                    FileIOActor.log(ex);
                }
            }
        }
        /// <summary>
        /// 保存(新增的)卡片信息
        /// </summary>
        public void saveCardsData()
        {
            lock (dcardMutex)
            {
                try
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var pool in pools.Values)
                    {
                        sb.Append(pool.ToString() + "\r\n");
                    }
                    File.WriteAllText(path + dcardPath + poolf, sb.ToString(), Encoding.UTF8);

                    sb = new StringBuilder();
                    foreach (var card in cards.Values)
                    {
                        sb.Append(card.ToString() + "\r\n");
                    }
                    File.WriteAllText(path + dcardPath + cardf, sb.ToString(), Encoding.UTF8);
                }
                catch (Exception ex)
                {
                    FileIOActor.log(ex);
                }
            }
        }
Example #8
0
        /// <summary>
        /// 安全修改货币数目
        /// </summary>
        /// <param name="money"></param>
        public long addMoney(long money)
        {
            try
            {
                lock (moneyMutex)
                {
                    long realMoney = money;
                    if (money >= 0 && Money >= 0)
                    {
                        realMoney = Math.Min(money, long.MaxValue - Money);
                    }
                    else if (money <= 0 && Money <= 0)
                    {
                        realMoney = Math.Max(money, long.MinValue - Money);
                    }

                    _wallet.money += realMoney;

                    if (realMoney != money)
                    {
                        FileIOActor.log($"{UserId}的{BTCActor.unitName}溢出,{_wallet.money}+{money}");
                    }

                    return(realMoney);
                }
            }
            catch (Exception ex)
            {
                FileIOActor.log(ex);
            }
            return(0);
        }
Example #9
0
        public void begin(int _roadnum, int _roadlen)
        {
            try
            {
                if (status != RHStatus.None)
                {
                    return;
                }
                //horses = _horses;
                //showScene = handle;
                //getQQNick = getqq;
                roadnum = _roadnum;
                roadlen = _roadlen;
                roads.Clear();
                bets.Clear();
                initHorses(ra.horses.Values.ToList());
                status           = RHStatus.Bet;
                nowTime          = 0;
                skillDescription = "";


                raceLoopThread = new Thread(raceLoop);
                run            = true;
                raceLoopThread.Start();
            }
            catch (Exception ex)
            {
                FileIOActor.log(ex);
            }
        }
        public bool deleteCards(MWServer server, MWUser user, string cname, int maxnum)
        {
            try
            {
                if (maxnum <= 0)
                {
                    return(false);
                }
                List <MWItem> deleteItems = new List <MWItem>();
                foreach (var card in user.cards)
                {
                    if (card.name == cname)
                    {
                        deleteItems.Add(card);
                        if (deleteItems.Count >= maxnum)
                        {
                            break;
                        }
                    }
                }
                int  dnum   = deleteItems.Count;
                uint dmoney = 0;
                foreach (var item in deleteItems)
                {
                    dmoney += user.deleteCard(item);
                }

                string res = "";
                if (dnum <= 0)
                {
                    // no cards
                    res = $"你手里没有 {cname} 卡";
                }
                else
                {
                    btc.getUser(user.userid).addMoney(dmoney);
                    if (dnum < maxnum)
                    {
                        res = $"你卖掉了全部{dnum}张 {cname} 卡,获得{dmoney}{BTCActor.unitName}";
                    }
                    else
                    {
                        res = $"你卖掉了{dnum}张 {cname} 卡,获得{dmoney}{BTCActor.unitName}";
                    }
                }
                outputMessage(server.group, user.userid, res.Trim());
                savePlayData();
            }
            catch (Exception ex)
            {
                FileIOActor.log(ex);
                return(false);
            }
            return(true);
        }
Example #11
0
 public string showBigWinner()
 {
     try
     {
         StringBuilder sb    = new StringBuilder();
         var           users = this.users.Values.ToList();
         users.Sort((left, right) =>
         {
             if (left.getWinPercent() < right.getWinPercent())
             {
                 return(1);
             }
             else if (left.getWinPercent() == right.getWinPercent())
             {
                 if (left.getPlayTime() < right.getPlayTime())
                 {
                     return(1);
                 }
                 else if (left.getPlayTime() > right.getPlayTime())
                 {
                     return(-1);
                 }
                 else
                 {
                     return(0);
                 }
             }
             else
             {
                 return(-1);
             }
         });
         sb.Append("赛 🐎 胜 率 榜 \r\n");
         int   showtime = 0;
         int   index    = 0;
         int   maxnum   = 10;
         ulong mintime  = 5;
         while (showtime < maxnum && index < users.Count)
         {
             ulong playtime = users[index].wintime + users[index].losetime;
             if (playtime > mintime)
             {
                 sb.Append($"{showtime + 1}:{getQQNick(users[index].userid)},{Math.Round(users[index].getWinPercent(), 2)}%({users[index].wintime}/{playtime})\r\n");
                 showtime += 1;
             }
             index += 1;
         }
         return(sb.ToString());
     }catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
     return("");
     //save();
 }
        public void init(string path)
        {
            this.path = path;
            var lines = FileIOActor.readLines(path + nameDictName);

            nameDict = new Dictionary <string, string>();
            foreach (var line in lines)
            {
                var items = line.Split('\t');
                if (items.Length >= 2)
                {
                    nameDict[items[0]] = items[1];
                }
            }

            var lines2 = FileIOActor.readLines(path + roomDictName);

            roomDict = new Dictionary <string, string>();
            foreach (var line in lines2)
            {
                var items = line.Split('\t');
                if (items.Length >= 2)
                {
                    roomDict[items[0]] = items[1];
                }
            }

            var lines3 = FileIOActor.readLines(path + areaDictName);

            areas = new Dictionary <string, int[]>();
            foreach (var line in lines3)
            {
                var items = line.Split('\t');
                if (items.Length >= 3)
                {
                    try
                    {
                        areas[items[0]] = new int[] { int.Parse(items[1]), int.Parse(items[2]) };
                    }
                    catch { }
                }
            }

            var lines4 = FileIOActor.readLines(path + shiquName);

            foreach (var line in lines4)
            {
                var items1 = line.Trim().Split(':');
                if (items1.Length == 2)
                {
                    var items2 = items1[1].Split('\t');
                    shiqus[double.Parse(items1[0])] = items2;
                }
            }
        }
Example #13
0
 /// <summary>
 /// 设置钱数。覆盖原有钱数,请谨慎。
 /// </summary>
 /// <param name="money"></param>
 public void setMoney(long money)
 {
     try
     {
         _wallet.money = money;
     }
     catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
 }
Example #14
0
 public override string ToString()
 {
     try
     {
         return($"{uid}\t{sum}\t{Configs.toTimestamp(lastGetTime)}");
     }
     catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
     return("");
 }
        public bool deleteCardsByQuality(MWServer server, MWUser user, ulong maxquality)
        {
            try
            {
                if (maxquality <= 0)
                {
                    return(false);
                }
                Dictionary <string, List <MWItem> > deleteItems = new Dictionary <string, List <MWItem> >();
                foreach (var card in user.cards)
                {
                    if (card.quality <= maxquality)
                    {
                        if (!deleteItems.ContainsKey(card.name))
                        {
                            deleteItems[card.name] = new List <MWItem>();
                        }
                        deleteItems[card.name].Add(card);
                    }
                }
                uint   dmoney = 0;
                string res    = "";
                if (deleteItems.Count <= 0)
                {
                    // no cards
                    res = $"你手里没有 {maxquality}星或以下卡片";
                }
                else
                {
                    res = $"你卖掉了";
                    foreach (var itemp in deleteItems)
                    {
                        foreach (var item in itemp.Value)
                        {
                            dmoney += user.deleteCard(item);
                        }
                        res += $"{itemp.Value.Count}张{itemp.Key},";
                    }

                    btc.getUser(user.userid).addMoney(dmoney);
                    res += $"获得{dmoney}{BTCActor.unitName}";
                }
                outputMessage(server.group, user.userid, res.Trim());
                savePlayData();
            }
            catch (Exception ex)
            {
                FileIOActor.log(ex);
                return(false);
            }
            return(true);
        }
        public void init(string path)
        {
            rand      = new Random();
            this.path = path;
            var    lines     = FileIOActor.readLines(path + zhouyiName);
            string nowGuaNum = "";
            int    nowline   = 0;

            string[] items;
            foreach (var line in lines)
            {
                nowline += 1;
                if (line.StartsWith("0") || line.StartsWith("1"))
                {
                    nowGuaNum        = line.Trim();
                    guaci[nowGuaNum] = new string[7];
                    yaoci[nowGuaNum] = new string[6, 4];
                    nowline          = 0;
                }
                else
                {
                    if (nowline == 1)
                    {
                        items = line.Trim().Split(' ');
                        guaci[nowGuaNum][0] = items[0];
                        guaci[nowGuaNum][1] = items[1];
                        guaci[nowGuaNum][2] = items[2];
                    }
                    else if (nowline == 2)
                    {
                        guaci[nowGuaNum][3] = line.Trim().Substring(guaci[nowGuaNum][0].Length + 1);
                    }
                    else if (nowline == 3)
                    {
                        guaci[nowGuaNum][4] = line.Trim().Substring(3);
                    }
                    else if (nowline == 4)
                    {
                        guaci[nowGuaNum][5] = line.Trim().Substring(3);
                    }
                    else if (nowline == 5)
                    {
                        guaci[nowGuaNum][6] = line.Trim().Substring(3);
                    }
                    else if (nowline >= 6)
                    {
                        yaoci[nowGuaNum][(nowline - 6) / 4, (nowline - 6) % 4] = line.Trim().Substring(3);
                    }
                }
            }
        }
Example #17
0
 /// <summary>
 /// 写资金变动日志
 /// </summary>
 /// <param name="record"></param>
 void writeRecord(BTCRecord record)
 {
     lock (recordMutex)
     {
         try
         {
             FileIOActor.appendLine(path + recordf, record.ToString());
         }
         catch (Exception ex)
         {
             FileIOActor.log(ex);
         }
     }
 }
Example #18
0
 /// <summary>
 /// 转换时间为unix时间戳
 /// </summary>
 /// <param name="date">需要传递UTC时间,避免时区误差,例:DataTime.UTCNow</param>
 /// <returns></returns>
 public static double toTimestamp(DateTime date)
 {
     try
     {
         DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
         TimeSpan diff          = date - dateTimeStart;
         return(Math.Floor(diff.TotalSeconds));
     }
     catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
     return(0);
 }
Example #19
0
        /// <summary>
        /// 转账
        /// </summary>
        /// <param name="fromqq"></param>
        /// <param name="targetqq"></param>
        /// <param name="money"></param>
        /// <returns></returns>
        public string transMoney(long fromqq, long targetqq, long money)
        {
            string res = "";

            try
            {
                var user1 = getUser(fromqq);
                var user2 = getUser(targetqq);
                if (user1 == null || user2 == null)
                {
                    return($"用户{targetqq}没有{unitName}账户");
                }
                if (money <= 0)
                {
                    return($"只允许正向转账");
                }
                if (user1.Money < money)
                {
                    return($"您的余额不足。当前余额{user1.Money}{unitName}");
                }

                res = $"您向{user2.UserId}发起转账{money}枚{BTCActor.unitName},";


                long realMoney = user2.addMoney(money);

                if (realMoney != money)
                {
                    if (realMoney == 0)
                    {
                        res += $"但对方钱包满了,没转成。";
                    }
                    else
                    {
                        //  上溢
                        res += $"由于对方钱包已满,仅成功转账{realMoney}枚。";
                    }
                }
                user1.addMoney(-1 * realMoney);
                writeRecord(new BTCRecord(fromqq, targetqq, realMoney, "转账", realMoney == money ? "成功" : "成功。达到钱包上限"));
                res += $"余额{user1.Money}{unitName}";
                save();
            }
            catch (Exception ex)
            {
                FileIOActor.log(ex);
                res += $"转账系统被橄榄了,你钱没了!请带截图联系bot作者";
            }
            return(res);
        }
Example #20
0
 public bool personIs(long user, string state)
 {
     try
     {
         if (personLevel.ContainsKey(user))
         {
             return(personLevel[user].Contains(state));
         }
     }
     catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
     return(false);
 }
Example #21
0
 public static DateTime toDateTime(string timeStamp)
 {
     try
     {
         DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
         long     lTime         = long.Parse(timeStamp + "0000000");
         TimeSpan toNow         = new TimeSpan(lTime);
         return(dateTimeStart.Add(toNow));
     }
     catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
     return(DateTime.Now);
 }
        /// <summary>
        /// 从万恶的百度知道的答案中删掉那些万恶的图片格式的文字。嗯。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        private string replaceImageWords(string str)
        {
            try
            {
                foreach (var key in baiduWordReplaceDict.Keys)
                {
                    str = str.Replace($"<img class=\"word-replace\" src=\"https://zhidao.baidu.com/api/getdecpic?picenc={key}\">", baiduWordReplaceDict[key]);
                }
            }
            catch (Exception e)
            {
                FileIOActor.log(e.Message + "\r\n" + e.StackTrace);
            }

            return(str);
        }
Example #23
0
 public void parse(string line)
 {
     try
     {
         var items = line.Trim().Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
         if (items.Length >= 2)
         {
             uid   = long.Parse(items[0]);
             money = long.Parse(items[1]);
         }
     }
     catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
 }
Example #24
0
 public void personDeleteTag(long user, string state)
 {
     try
     {
         if (!personLevel.ContainsKey(user))
         {
             return;
         }
         personLevel[user].Remove(state.Trim());
         save();
     }
     catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
 }
Example #25
0
 /// <summary>
 /// 获取用户,如果不存在,就为该号码开户
 /// </summary>
 /// <param name="uid"></param>
 /// <returns></returns>
 public BTCUser getUser(long uid)
 {
     if (!users.ContainsKey(uid))
     {
         try
         {
             users[uid] = new BTCUser(uid);
         }
         catch (Exception ex)
         {
             FileIOActor.log(ex);
             users[uid] = null;
         }
     }
     return(users[uid]);
 }
Example #26
0
 public void groupDeleteTag(long group, string state)
 {
     try
     {
         if (!groupLevel.ContainsKey(group))
         {
             return;
         }
         groupLevel[group].Remove(state.Trim());
         save();
     }
     catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
 }
        /// <summary>
        /// 在百度知道查询答案。
        /// </summary>
        /// <param name="sentence">要查询的句子</param>
        /// <param name="num">获取的答案数</param>
        /// <returns></returns>
        public string[] getBaiduZhidaoAnswers(string sentence, int num = 10)
        {
            List <string> res = new List <string>();

            try
            {
                string url  = $"https://zhidao.baidu.com/search?word={WebConnectActor.UrlEncode(sentence)}";
                string html = WebConnectActor.getData(url, Encoding.GetEncoding("gb2312"), cookie);
                //FileIOActor.log(url);
                //FileIOActor.log(html);

                HtmlDocument hdoc = new HtmlDocument();
                hdoc.LoadHtml(html);
                HtmlNode favurl = null;
                try
                {
                    var node = hdoc.DocumentNode.SelectSingleNode("//dt[@class=\"dt mb-8\"]");
                    if (node != null)
                    {
                        favurl = node.ChildNodes[1];
                    }
                }
                catch (Exception ex) { FileIOActor.log(ex); }

                var urls = hdoc.DocumentNode.SelectNodes("//a[@class=\"ti\"]");
                if (favurl != null)
                {
                    urls.Insert(0, favurl);
                }
                foreach (var aurl in urls)
                {
                    string dw       = ItemParser.removeBlank(aurl.GetAttributeValue("href", ""), true);
                    var    areslist = getBaiduZhidaoAnswersByUrl(dw);
                    if (areslist.Length > 0)
                    {
                        res.Add(areslist[0].Trim());
                    }
                    if (res.Count > num)
                    {
                        break;
                    }
                }
            }
            catch (Exception ex) { FileIOActor.log(ex); }

            return(res.ToArray());
        }
Example #28
0
 public void parse(string line)
 {
     try
     {
         var items = line.Trim().Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
         if (items.Length >= 3)
         {
             uid         = long.Parse(items[0]);
             sum         = long.Parse(items[1]);
             lastGetTime = Configs.toDateTime(items[2]);// DateTime.ParseExact(items[2], "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture);
         }
     }
     catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
 }
Example #29
0
 public void parse(string line)
 {
     try
     {
         var items = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
         if (items.Length >= 4)
         {
             userid   = long.Parse(items[0]);
             hrmoney  = ulong.Parse(items[1]);
             wintime  = ulong.Parse(items[2]);
             losetime = ulong.Parse(items[3]);
         }
     }
     catch (Exception ex)
     {
         FileIOActor.log(ex);
     }
 }
        /// <summary>
        /// 获取翻译结果
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        public string Translation(string src, string to = "简体中文", string from = "自动")
        {
            InitTkk();
            string tk  = GetTK(src);
            string url = $"{getTranslateUrl(from, to)}&tk={tk}&q={UrlEncode(src)}";
            //FileIOActor.log(url);
            //return url;
            string httpresult = WebConnectActor.getData(url, Encoding.UTF8, "", true);

            FileIOActor.log(httpresult);
            try
            {
                string res = "";
                JArray jo  = (JArray)JsonConvert.DeserializeObject(httpresult);
                //JObject jo = JObject.Parse(httpresult);
                //FileIOActor.log(jo[0].ToString());
                int resnum = jo[0].Count();
                if (resnum >= 1)
                {
                    foreach (var item in jo[0])
                    {
                        //FileIOActor.log(item.ToString());
                        //FileIOActor.log(item[0].ToString());
                        res += item[0].ToString() + Environment.NewLine;
                    }
                }
                return(res.Trim());
            }
            catch (Exception e)
            {
                FileIOActor.log(e.Message + "\r\n" + e.StackTrace);
            }


            ////正则获取结果集
            //int begin = httpresult.IndexOf("[[[\"") + 4;
            //int end = httpresult.IndexOf("\",\"");
            //try
            //{
            //    httpresult = httpresult.Substring(begin, end - begin);
            //}
            //catch { }
            return(httpresult);
        }