Ejemplo n.º 1
0
        /// <summary>
        /// 打印日志到酷Q日志,并向指定QQ通知
        /// </summary>
        /// <param name="log">日志信息</param>
        /// <param name="level">日志等级</param>
        /// <param name="noticeQqs">被通知的QQ(或更多人)</param>
        /// <param name="needMinimumLevel">多严重才会被通知</param>
        public static void Log(string log, int level, long[] noticeQqs, int needMinimumLevel)
        {
            CoolQLogLevel cqll      = CoolQLogLevel.None;
            string        levelName = "";

            switch (level)
            {
            case INFO:
                cqll      = CoolQLogLevel.Info;
                levelName = "Chika.Info(日志)";
                break;

            case DONE:
                cqll      = CoolQLogLevel.InfoSuccess;
                levelName = "Chika.Done(完成)";
                break;

            case DEBUG:
                cqll      = CoolQLogLevel.Debug;
                levelName = "Chika.Debug(调试)";
                break;

            case WARN:
                cqll      = CoolQLogLevel.Warning;
                levelName = "Chika.Warn(警告)";
                break;

            case ERROR:
                cqll      = CoolQLogLevel.Error;
                levelName = "Chika.Error(错误)";
                break;

            case FEATURE:
                cqll      = CoolQLogLevel.Fatal;
                levelName = "Chika.Feature(特性(呸)严重BUG)";
                break;
            }

            CoolApiExtensions.AddLog(
                MainPlugin.CoolQApi,
                cqll,
                log
                );

            if (level >= needMinimumLevel)
            {
                for (int i = 0; i < noticeQqs.Length; i++)
                {
                    MainPlugin.CoolQApi.SendPrivateMsg(noticeQqs[i], "【千歌日志提醒】\n[等级] " + levelName + "\n" + log);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取群成员,并缓存
        /// </summary>
        /// <param name="api"></param>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public static List <GroupMemberInfoWithBocai> GetGroupMemberListAndCache(ICoolQApi api, long groupId)
        {
            List <GroupMemberInfoWithBocai>                        list   = new List <GroupMemberInfoWithBocai>();
            Dictionary <long, GroupMemberInfoWithBocai>            keyVal = new Dictionary <long, GroupMemberInfoWithBocai>();
            ModelWithSourceString <IEnumerable <GroupMemberInfo> > result = CoolApiExtensions.GetGroupMemberList(api, groupId);
            IEnumerable <GroupMemberInfo> iterator = result.Model;

            if (iterator != null)
            {
                foreach (GroupMemberInfo memberInfo in iterator)
                {
                    GroupMemberInfoWithBocai groupMemberInfoWithBocai = new GroupMemberInfoWithBocai(memberInfo, list.Count);

                    //增加短名字
                    //===================2018-02===================
                    string shortName = "";// Regex.Replace(g.NickName, @"\[[^\]]*?\]", "");
                    shortName = function.filtetStingSpecial(groupMemberInfoWithBocai.GroupMemberBaseInfo.NickName);
                    //===================2018-02===================


                    shortName = shortName.Replace("'", "").Replace("/", "").Replace("\\", "").Replace("\"", "").Replace(".", "");
                    bool isHanzi = false;
                    for (int ii = 0; ii < shortName.Length; ii++)
                    {
                        if ((int)shortName[ii] > 127)
                        {
                            //是汉字
                            isHanzi = true;
                            break;
                        }
                    }
                    if (isHanzi)
                    {
                        shortName = shortName.Length > 2 ? shortName.Substring(0, 2) : shortName;
                    }
                    else
                    {
                        shortName = shortName.Length > 4 ? shortName.Substring(0, 4) : shortName;
                    }

                    groupMemberInfoWithBocai.NickNameShort = shortName;

                    list.Add(groupMemberInfoWithBocai);
                    keyVal.Add(memberInfo.Number, groupMemberInfoWithBocai);
                }
            }

            CacheData.GroupMemberInfoList = list;
            CacheData.GroupMemberInfoDic  = keyVal;
            return(list);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 打印日志到酷Q日志
        /// </summary>
        /// <param name="log">日志信息</param>
        /// <param name="level">日志等级</param>
        public static void Log(string log, int level)
        {
            CoolQLogLevel cqll = CoolQLogLevel.None;

            switch (level)
            {
            case INFO:
                cqll = CoolQLogLevel.Info;
                break;

            case DONE:
                cqll = CoolQLogLevel.InfoSuccess;
                break;

            case DEBUG:
                cqll = CoolQLogLevel.Debug;
                break;

            case WARN:
                cqll = CoolQLogLevel.Warning;
                break;

            case ERROR:
                cqll = CoolQLogLevel.Error;
                break;

            case FEATURE:
                cqll = CoolQLogLevel.Fatal;
                break;
            }

            CoolApiExtensions.AddLog(
                MainPlugin.CoolQApi,
                cqll,
                log
                );
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 开始处理
        /// </summary>
        /// <returns></returns>
        public int Run()
        {
            try
            {
                // 全群发送同一条信息
                if (Msg.IndexOf("#全群通知") == 0)
                {
                    if (Sender.QQ == -10000)
                    {
                        IEnumerable <GroupInfo> groups = ExtrasCoolApiExtensions.GetGroupList(MainPlugin.CoolQApi);
                        string Broadcast = Msg.Replace("#全群通知", "");
                        foreach (GroupInfo group in groups)
                        {
                            User system = new User(-100000, new UserSource(UserSource.GroupMessage, new Group(group.GroupNumber), 0));
                            system.Send(Broadcast);
                        }
                        return(1);
                    }
                }

                // 强制回收垃圾
                if (Msg.IndexOf("#回收垃圾") == 0)
                {
                    if (Sender.QQ == 1813274096)
                    {
                        GC.Collect();
                        Sender.Send("void GC.Collect();成功");
                        return(1);
                    }
                }

                // 强制重新载入全部用户
                if (Msg.IndexOf("#重载用户") == 0)
                {
                    if (Sender.QQ == 1813274096)
                    {
                        IEnumerable <GroupInfo> info = ExtrasCoolApiExtensions.GetGroupList(MainPlugin.CoolQApi);
                        int groups = 0, users = 0;
                        foreach (GroupInfo inf in info)
                        {
                            Group gp = new Group(inf.GroupNumber);
                            ModelWithSourceString <IEnumerable <GroupMemberInfo> > members = CoolApiExtensions.GetGroupMemberList(MainPlugin.CoolQApi, inf.GroupNumber);
                            foreach (GroupMemberInfo i in members.Model)
                            {
                                User usr = new User(i.Number, new UserSource(UserSource.GroupMessage, new Group(gp.QQId), 0));
                                users++;
                            }
                            groups++;
                        }
                        GC.Collect();
                        Sender.Send("已经重新载入了" + groups + "个群," + users + "个QQ。");
                        return(1);
                    }
                }

                // 如果被封禁则不处理
                if (Sender.Source.Group != null)
                {
                    if (Sender.Source.Group.IsBaned)
                    {
                        return(1);
                    }
                }
                if (Sender.IsBaned)
                {
                    return(1);
                }
                // 你群如果关了千歌不处理
                if (Sender.Source.Group != null)
                {
                    if (!Sender.Source.Group.IsEnable)
                    {
                        if (rcc(Msg) != "开千歌")
                        {
                            return(1);
                        }
                    }
                }

                // 菜单
                if (Menu.AutoSend(rcc(Msg), Sender) != 0)
                {
                    return(1);
                }

                // 开启千歌
                if (rcc(Msg) == "开千歌")
                {
                    ModelWithSourceString <GroupMemberInfo> info = CoolApiExtensions.GetGroupMemberInfoV2(MainPlugin.CoolQApi, Sender.Source.Group.QQId, Sender.QQ, false);
                    if (info.Model.Authority == "群主" || info.Model.Authority == "管理员" || Sender.QQ == 1813274096)
                    {
                        Sender.Send(Sender.AT + "千歌已开启");
                        Sender.Source.Group.IsEnable = true;
                        return(1);
                    }
                    else
                    {
                        Sender.Send(Sender.AT + "请管理员来进行操作");
                        return(1);
                    }
                }

                // 关闭千歌
                if (rcc(Msg) == "关千歌")
                {
                    ModelWithSourceString <GroupMemberInfo> info = CoolApiExtensions.GetGroupMemberInfoV2(MainPlugin.CoolQApi, Sender.Source.Group.QQId, Sender.QQ, false);
                    if (info.Model.Authority == "群主" || info.Model.Authority == "管理员" || Sender.QQ == 1813274096)
                    {
                        Sender.Send(Sender.AT + "千歌已关闭");
                        Sender.Source.Group.IsEnable = false;
                        return(1);
                    }
                    else
                    {
                        Sender.Send(Sender.AT + "请管理员来进行操作");
                        return(1);
                    }
                }

                // 群状态
                if (Sender.Source.Group != null)
                {
                    if (rcc(Msg) == "群状态")
                    {
                        Status.Auto3(Sender.Source.Group);
                    }
                }

                // 蜜柑商店
                if (MardarinStore.Auto(Sender, rcc(Msg)) != 0)
                {
                    return(1);
                }

                // 小游戏
                if (MiniGame.Auto(Sender, rcc(Msg)) != 0)
                {
                    return(1);
                }

                // 签到
                if (rcc(Msg) == "签到")
                {
                    return(new Checkin(Sender).Check());
                }

                // 抛锦球
                if (ThrowBall.Auto(Sender, rcc(Msg)) == 1)
                {
                    return(1);
                }

                // 状态
                if (rcc(Msg) == "状态")
                {
                    return(Status.Auto(Sender));
                }
                if (rcc(Msg) == "我的状态")
                {
                    return(Status.Auto2(Sender));
                }

                // 档线
                if (rcc(Msg) == "档线")
                {
                    return(Yohane.StopLine.Auto(Sender));
                }

                // 转账
                if (Transfer.Auto(Sender, rcc(Msg)) == 1)
                {
                    return(1);
                }

                // "Sudo"
                if (Sender.QQ == 1813274096)
                {
                    if (rcc(Msg).IndexOf("sudo") == 0)
                    {
                        string[] parm = Msg.Split('|');
                        if (parm.Length >= 3)
                        {
                            int num = 0;
                            int.TryParse(parm[1], out num);
                            Command cmd = new Command(parm[2], new User(num, Sender.Source), TimeStampHelper.ConvertDateTimeInt(DateTime.Now).ToString());
                            return(cmd.Run());
                        }
                    }
                }

                // 抽卡
                if (ScoutSimulator.Msg.Auto(Sender, rcc(Msg)) != 0)
                {
                    return(1);
                }

                // 抽奖
                if (Lottery.Auto(Sender, rcc(Msg)) != 0)
                {
                    return(1);
                }

                // 鸽服号状态
                if (SIF.CN.Status.Auto(Sender, rcc(Msg)) != 0)
                {
                    return(1);
                }

                // 算运势
                if (rcc(Msg) == "算运势")
                {
                    return(Divination.Auto(Sender));
                }

                // 点歌
                if (rcc(Msg).IndexOf("网易点歌") == 0)
                {
                    return(ChooseSong.Choose.Auto(Sender, rcc(Msg)));
                }

                // 算日美ID
                #region

                /*long getRF_id = 0;
                 * if (Msg.Length == 12)
                 * {
                 *  if (long.TryParse(Msg.Replace("算账号",""), out getRF_id) == true)
                 *  {
                 *      getRF_id = getRF_id * 526850996;
                 *      getRF_id = getRF_id % 999999937;
                 *      Sender.Send(Sender.AT + "Uid: " + Msg.Replace("算账号", "") + "\n" +
                 *          "Id: " + getRF_id);
                 *      return 1;
                 *  }
                 *  else
                 *  {
                 *      MessageSendHelper.Send(Sender, " × 计算失败!以下是狗开发的一点人生经验:\n - 不支持国服\n - 文本格式不对\n - 数值转换错误");
                 *      return 1;
                 *  }
                 * }
                 * else
                 * {
                 *  MessageSendHelper.Send(Sender, " × 计算失败!以下是狗开发的一点人生经验:\n - 不支持国服\n - 文本格式不对\n - 未知");
                 *  return 1;
                 * }*/

                #endregion

                // 聊天解析Beta
                if (Chat.Msg.Auto(Sender, Msg) != 0)
                {
                    return(1);
                }
            }
            catch (Exception ex)
            {
                Logger.Log
                    ("Ex:" + ex.Message, Logger.WARN, new long[] { }, 0);
                Sender.Send("ChikaBot Test System\n错误信息 " + ex.Message + "\n错误来源 " + ex.Source + "\n错误堆叠 " + ex.StackTrace);
                //ExceptionReportHelper.Send("消息处理", Sender, ex, Msg);
                //Sender.Send(" × 千歌酱出了一个Bug, 暂时不能陪你玩了...\n   错误类型:" + ex.GetType().ToString());
            }


            return(0);
        }
Ejemplo n.º 5
0
        public static int Auto(User Sender, string Msg)
        {
            if (Msg == "抛锦球")
            {
                if (Sender.Source.Group == null)
                {
                    Sender.Send("请在群内使用");
                    return(1);
                }

                if (Sender.RandomBanCard < 1)
                {
                    Sender.Send("锦球卡不足!请购买!\nP.S 你可以在抽奖卡池,积分商店购买到。");
                    return(1);
                }

                Sender.RandomBanCard--;

                ModelWithSourceString <IEnumerable <GroupMemberInfo> > model =
                    CoolApiExtensions.GetGroupMemberList(MainPlugin.CoolQApi, Sender.Source.Group.QQId);

                List <GroupMemberInfo> members = new List <GroupMemberInfo>();

                foreach (GroupMemberInfo info in model.Model)
                {
                    if (info.Authority != "群主")
                    {
                        if (info.Authority != "管理员")
                        {
                            members.Add(info);
                        }
                    }
                }

                long   banQQIndexOfMembers = members[new Random().Next(0, members.Count)].Number;
                int    banTimeBySecond     = new Random().Next(60, 600);
                string banTimeStr          = banTimeBySecond + "s";
                MainPlugin.CoolQApi.SetGroupBan(Sender.Source.Group.QQId, banQQIndexOfMembers, banTimeBySecond);
                User BanUser = new User(banQQIndexOfMembers, Sender.Source);
                Sender.Send("恭喜" + BanUser.AT + "被" + Sender.AT + "砸中!禁言" + banTimeStr + "!");
                return(1);
            }
            else if (Msg.IndexOf("抛锦球") == 0)
            {
                if (Sender.Source.Group == null)
                {
                    Sender.Send("请在群内使用");
                    return(1);
                }

                if (Sender.AtBanCard < 1)
                {
                    Sender.Send("锦球卡不足!请购买!\nP.S 你可以在抽奖卡池,积分商店购买到。");
                    return(1);
                }
                if (Msg.IndexOf("[cq:at,qq=") == -1 && Msg.IndexOf("]") == -1)
                {
                    Sender.Send(Sender.AT + "请@你想禁言谁");
                    return(1);
                }
                string msg   = Msg.Replace("抛锦球", "");
                long   banQQ = 0;
                string obj   = msg.Substring(
                    msg.IndexOf("[cq:at,qq=") + 10,
                    msg.Length - 11 - msg.Substring(msg.IndexOf("]"), msg.Length - msg.IndexOf("]")).Length + 1
                    );
                long.TryParse(obj, out banQQ);
                msg = msg.Replace("[cq:at,qq=" + obj + "]", "");
                if (msg.Replace(" ", "") != "")
                {
                    Sender.Send(Sender.AT + "抛锦球的格式为 /抛锦球[@一个人]\n[@一个人]为选填项");
                    return(1);
                }
                User banUser = new User(banQQ, Sender.Source);
                ModelWithSourceString <GroupMemberInfo> banUserInfo = CoolApiExtensions.GetGroupMemberInfoV2(MainPlugin.CoolQApi, Sender.Source.Group.QQId, banUser.QQ, false);
                if (banUserInfo.Model.Authority == "群主" || banUserInfo.Model.Authority == "管理员")
                {
                    Sender.Send(Sender.AT + "你@的人太强大了,千歌不能砸中他!");
                    return(1);
                }
                Sender.AtBanCard--;
                int banTimeBySecond = new Random().Next(60, 600);
                int sec = 0, min = 0;
                min = (int)(sec / 60);
                sec = sec % 60;
                string banTimeStr = banTimeBySecond + "s";
                MainPlugin.CoolQApi.SetGroupBan(Sender.Source.Group.QQId, banUser.QQ, banTimeBySecond);
                Sender.Send("恭喜" + banUser.AT + "被" + Sender.AT + "砸中!禁言" + banTimeStr + "!");
                return(1);
            }
            else
            {
                return(0);
            }
        }