Exemplo n.º 1
0
 /// <summary>
 /// 添加回复内容
 /// </summary>
 /// <param name="modal"></param>
 /// <returns></returns>
 public static AutoReply AddNewAutoReplyInfo(AutoReply modal)
 {
     using (EFDbContext db = new EFDbContext())
     {
         var entiy = db.AutoReply.Add(modal);
         int row   = db.SaveChanges();
         return(entiy);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 更新回复命令
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public int UpdateAutoReplyInfo(string data)
        {
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(data));
            DataContractJsonSerializer djs = new DataContractJsonSerializer(typeof(AutoReply));
            AutoReply bs = (AutoReply)djs.ReadObject(ms);

            bs.ModifiedTime = DateTime.Now;
            return(wcApi.AutoReplyBLL.UpdateAutoReplyInfo(bs));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 添加回复命令
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public JsonResult AddNewAutoReplyInfo(string question, string replaycontent)
        {
            AutoReply bs = new AutoReply();

            bs.Question     = question;
            bs.ReplyContent = replaycontent;
            bs.Flag         = 0;
            bs.CreatedTime  = DateTime.Now;
            var p = wcApi.AutoReplyBLL.AddNewAutoReplyInfo(bs);

            return(Json(new { status = 1, data = p }));
        }
        public AutoReply ConvertToEntity()
        {
            var entity = new AutoReply();

            entity.Id              = Id;
            entity.AppId           = AppId;
            entity.Name            = Name;
            entity.Description     = Description;
            entity.PrimaryType     = KeywordType;
            entity.CreatedUserID   = CreatedUserID;
            entity.CreatedUserName = CreatedUserName;
            entity.CreatedDate     = CreatedDate;
            entity.UpdatedUserID   = UpdatedUserID;
            entity.UpdatedUserName = UpdatedUserName;
            entity.UpdatedDate     = UpdatedDate;
            return(entity);
        }
Exemplo n.º 5
0
        private async Task OnMessageReceivedAsync(SocketMessage message)
        {
            InternalStatistics.IncrementEvent("MessageReceived");

            if (!TryParseMessage(message, out SocketUserMessage userMessage))
            {
                return;
            }

            var context = new SocketCommandContext(Client, userMessage);

            if (context.IsPrivate)
            {
                return;
            }

            int argPos = 0;

            if (userMessage.HasStringPrefix(Config.CommandPrefix, ref argPos) || userMessage.HasMentionPrefix(Client.CurrentUser, ref argPos))
            {
                await Commands.ExecuteAsync(context, userMessage.Content.Substring(argPos), Services).ConfigureAwait(false);

                if (context.Guild != null)
                {
                    EmoteChain.CleanupAsync((SocketGuildChannel)context.Channel);
                }
            }
            else
            {
                if (context.Guild != null)
                {
                    UserService.IncrementMessage(context.User as SocketGuildUser, context.Guild, context.Channel as SocketGuildChannel);
                    await AutoReply.TryReplyAsync(context.Guild, userMessage).ConfigureAwait(false);
                }

                await EmoteChain.ProcessChainAsync(context).ConfigureAwait(false);

                EmoteStats.AnylyzeMessageAndIncrementValues(context);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the current status of listener
        /// </summary>
        /// <returns></returns>
        public bool StartListener()
        {
            if (IsListening)
            {
                return(IsListening);
            }
            IPAddress serverIP = IPAddress.Parse(Services.CommonUtility.GetIPAddress());

            listener = new TcpListener(serverIP, Port);

            try
            {
                listener.Start();
                IsListening = true;
            }
            catch (Exception ex)
            {
                IsListening = false;
                ExceptionHandler?.Invoke(null, ex);
                return(IsListening);
            }

            Task.Run(async() =>
            {
                while (IsListening)
                {
                    try
                    {
                        ReplyPacket replyPacket = new ReplyPacket()
                        {
                            IsSentAndReplyReceived = true
                        };
                        TcpClient clientTCP    = await listener.AcceptTcpClientAsync().ConfigureAwait(false);
                        replyPacket.PortSender = ((IPEndPoint)clientTCP.Client.RemoteEndPoint).Port;
                        replyPacket.IPSender   = ((IPEndPoint)clientTCP.Client.RemoteEndPoint).Address.ToString();
                        if (ReceiveFromThisIPAddressList.Count > 0)
                        {
                            bool isProcessingRequired = false;
                            foreach (var ipAcceptable in ReceiveFromThisIPAddressList)
                            {
                                if (ipAcceptable == replyPacket.IPSender)
                                {
                                    isProcessingRequired = true;
                                    break;
                                }
                            }
                            if (!isProcessingRequired)
                            {
                                continue;
                            }
                        }

                        int length;
                        NetworkStream stream     = clientTCP.GetStream();
                        List <byte> singlePacket = new List <byte>();
                        var byteArray            = new byte[1024];
                        while ((length = stream.Read(byteArray, 0, byteArray.Length)) != 0)
                        {
                            var copy = new byte[length];
                            Array.Copy(byteArray, 0, copy, 0, length);
                            singlePacket.AddRange(copy);
                        }
                        replyPacket.SetReply(singlePacket);
                        DataEvent?.Invoke(this, replyPacket);
                        if (IsAutoReplying)
                        {
                            await stream.WriteAsync(AutoReply?.ToArray(), 0, AutoReply.Count).ConfigureAwait(false);
                            stream.Flush();
                        }
                        stream.Close();
                        clientTCP.Close();
                    }
                    catch (Exception ex)
                    {
                        ExceptionHandler?.Invoke(this, ex);
                    }
                }
                listener.Server.Close();
            });
            return(IsListening);
        }
 internal static CfAutoReply FromAutoReplay(AutoReply source)
 {
     return(source == null ? null : new CfAutoReply(source.Number, source.Keyword, source.Match, source.Message, source.id));
 }
Exemplo n.º 8
0
        private async Task OnMessageReceivedAsync(SocketMessage message)
        {
            CalledEventStats.Increment("MessageReceived");

            var messageStopwatch = new Stopwatch();

            messageStopwatch.Start();

            try
            {
                if (!TryParseMessage(message, out SocketUserMessage userMessage))
                {
                    return;
                }

                var commandStopwatch = new Stopwatch();
                var context          = new SocketCommandContext(Client, userMessage);

                if (message.Channel is IPrivateChannel && !Config.IsUserBotAdmin(userMessage.Author.Id))
                {
                    return;
                }

                int argPos = 0;
                if (userMessage.HasStringPrefix(Config.CommandPrefix, ref argPos) || userMessage.HasMentionPrefix(Client.CurrentUser, ref argPos))
                {
                    await LogCommandAsync(userMessage, context, argPos).ConfigureAwait(false);

                    commandStopwatch.Start();
                    var result = await Commands.ExecuteAsync(context, userMessage.Content.Substring(argPos), Services).ConfigureAwait(false);

                    commandStopwatch.Stop();

                    if (!result.IsSuccess && result.Error != null)
                    {
                        switch (result.Error.Value)
                        {
                        case CommandError.UnknownCommand: return;

                        case CommandError.UnmetPrecondition:
                        case CommandError.ParseFailed:
                            await context.Channel.SendMessageAsync(result.ErrorReason.PreventMassTags()).ConfigureAwait(false);

                            break;

                        case CommandError.BadArgCount:
                            await SendCommandHelp(context, argPos).ConfigureAwait(false);

                            break;

                        default:
                            throw new BotException(result);
                        }
                    }

                    var command = message.Content.Split(' ')[0];
                    Statistics.LogCall(command, commandStopwatch.ElapsedMilliseconds);
                    await EmoteChain.CleanupAsync(context.Channel, true).ConfigureAwait(false);
                }
                else
                {
                    await ChannelStats.IncrementCounterAsync(userMessage.Channel).ConfigureAwait(false);

                    await AutoReply.TryReplyAsync(userMessage).ConfigureAwait(false);

                    await EmoteChain.ProcessChainAsync(context).ConfigureAwait(false);

                    await EmoteStats.AnylyzeMessageAndIncrementValuesAsync(context).ConfigureAwait(false);
                }
            }
            finally
            {
                messageStopwatch.Stop();
                Statistics.ComputeAvgReact(messageStopwatch.ElapsedMilliseconds);
            }
        }
 public AutoReplyQueryResult(long totalResult, AutoReply[] cfAutoReply)
 {
     TotalResults = totalResult;
     AutoReply = cfAutoReply;
 }