Exemple #1
0
 /// <summary>
 /// 获取用户信息
 /// </summary>
 /// <param name="uin"></param>
 /// <param name="group"></param>
 /// <returns></returns>
 private Sender FetchPersonalSender(string uin, string group)
 {
     var sender = RunTime.Senders.FirstOrDefault(p => p.uin == uin);
     var name = RunTime.NickNames.FirstOrDefault(p => p.group == group && p.uin == uin);
     if (sender == null)
     {
         sender = new Sender { uin = uin, type = SenderType.Custom };
     }
     sender.name = name == null ? "大姐姐" : name.name;
     if (RunTime.FriendMasks.ContainsKey(uin))
     {
         sender.name = RunTime.FriendMasks[sender.uin];
     }
     return sender;
 }
Exemple #2
0
 public void Reply(string message, Sender sender)
 {
     var type = Analyse(message);
     //判断是否有权限    
     var flag = CheckPermission(sender);
     var result = "";
     switch (type)
     {
         case MessageType.Teach:
             result = flag ? TeachAction(message) : ConstString("NoThanks");
             break;
         case MessageType.Regex:
             result = flag ? RegexAction(message) : ConstString("NoThanks");
             break;
         case MessageType.Delete:
             result = flag ? DeleteAction(message) : ConstString("NoThanks");
             break;
         case MessageType.Set:
             result = flag ? SetAction(message) : ConstString("NoThanks");
             break;
         case MessageType.Test:
             result = flag ? TestAction(message) : ConstString("NoThanks");
             break;
         case MessageType.Scheme:
             result = flag ? SchemeAction(sender.name) : ConstString("NoThanks");
             break;
         case MessageType.Ext:
             result = flag ? ExtAction(message) : ConstString("NoThanks");
             break;
         case MessageType.Push:
             result = flag ? PushAction(message, sender.name) : ConstString("NoThanks");
             break;
         case MessageType.Chat:
             result = ChatAction(message) ?? ConstString("Require");
             break;
     }
     //处理占位符
     var msgs = HandlePlaceHolder(result, sender.name);
     foreach (var msg in msgs)
     {
         Thread.Sleep(500);
         RunTime.Net.SendMessage(sender.uin, msg);
     }
 }
Exemple #3
0
 public void Reply(string message, Sender sender, GroupSender groupSender)
 {
     //群聊不处理50字以上
     if (message.Length > 50) return;
     var type = Analyse(message);
     //判断是否有权限    
     var flag = CheckPermission(sender);
     var result = "";
     switch (type)
     {
         case MessageType.Teach:
             result = flag ? TeachAction(message) : ConstString("NoThanks");
             AddAttention(sender, 2);
             break;
         case MessageType.Regex:
             result = flag ? RegexAction(message) : ConstString("NoThanks");
             AddAttention(sender, 2);
             break;
         case MessageType.Delete:
             result = flag ? DeleteAction(message) : ConstString("NoThanks");
             AddAttention(sender, 2);
             break;
         case MessageType.Set:
             result = flag ? SetAction(message) : ConstString("NoThanks");
             AddAttention(sender, 2);
             break;
         case MessageType.Test:
             result = flag ? TestAction(message) : ConstString("NoThanks");
             AddAttention(sender, 2);
             break;
         case MessageType.Scheme:
             result = flag ? SchemeAction(sender.name) : ConstString("NoThanks");
             AddAttention(sender, 2);
             break;
         case MessageType.Ext:
             result = flag ? ExtAction(message) : ConstString("NoThanks");
             AddAttention(sender, 2);
             break;
         case MessageType.Push:
             result = flag ? PushAction(message, sender.name) : ConstString("NoThanks");
             AddAttention(sender, 2);
             break;
         case MessageType.Chat:
             flag = message.Contains(Settings.NekoName) || RandomAttention(sender);
             LoseAttention(sender);
             if (flag)
             {
                 result = ChatAction(message);
                 AddAttention(sender, 2);
                 if (groupSender.type == GroupSenderType.Master && String.IsNullOrEmpty(result))
                 {
                     result = ConstString("Require");
                 }
             }
             break;
     }
     //在没有权限的群里 而且词库没有相关信息 不做回答
     if (string.IsNullOrEmpty(result)) return;
     //处理占位符
     var msgs = HandlePlaceHolder(result, sender.name);
     foreach (var msg in msgs)
     {
         Thread.Sleep(500);
         RunTime.Net.SendGroupMsg(groupSender.uin, msg);
     }
 }
Exemple #4
0
 /// <summary>
 /// 加关注(最高5点关注)
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="degree"></param>
 public void AddAttention(Sender sender, int degree)
 {
     for (var i = 0; i < degree; i++)
     {
         if (RunTime.Attention.Count(p => p == sender.uin) == 5) break;
         RunTime.Attention.Add(sender.uin);
     }
 }
Exemple #5
0
 /// <summary>
 /// 检查是否有命令权限
 /// </summary>
 /// <param name="groupSender"></param>
 /// <param name="sender"></param>
 /// <returns></returns>
 public bool CheckPermission(Sender sender, GroupSender groupSender)
 {
     return (sender.type == SenderType.Master) || (groupSender.type == GroupSenderType.Master);
 }
Exemple #6
0
 /// <summary>
 /// 检查是否有命令权限
 /// </summary>
 /// <param name="sender"></param>
 /// <returns></returns>
 public bool CheckPermission(Sender sender)
 {
     return (sender.type == SenderType.Master);
 }
Exemple #7
0
 /// <summary>
 /// 是否随机插话
 /// </summary>
 /// <param name="sender"></param>
 /// <returns></returns>
 public bool RandomAttention(Sender sender)
 {
     double rate = 0d;
     switch (sender.type)
     {
         case SenderType.Master:
             rate = Settings.MasterRate;
             break;
         case SenderType.Friend:
             rate = Settings.FriendRate;
             break;
         case SenderType.Custom:
             rate = Settings.CustomRate;
             break;
     }
     if (RunTime.Attention.Any(p => p == sender.uin))
     {
         rate += 0.5;
     }
     return new Random().NextDouble() < rate;
 }
Exemple #8
0
 /// <summary>
 /// 失去关注
 /// </summary>
 /// <param name="sender"></param>
 public void LoseAttention(Sender sender)
 {
     RunTime.Attention.Remove(sender.uin);
 }