示例#1
0
        public Task OnMessage(SocketMessage msg)
        {
            if (msg.Channel.GetType() == typeof(SocketDMChannel))
            {
                return(Task.CompletedTask);
            }

            var userMsg = msg as SocketUserMessage;
            var _       = Task.Run(async() =>
            {
                try
                {
                    // handle announcement messages
                    await PublishAnnouncementMessages(userMsg);

                    if (msg == null || msg.Author.IsBot)
                    {
                        return;
                    }
                    var channel = msg.Channel as ITextChannel;

                    bool messageTriggeredRaidProtection = _raidProtectionService.CheckMessage(new FloofDataContext(), msg).Result;
                    if (messageTriggeredRaidProtection)
                    {
                        await msg.DeleteAsync();
                        return;
                    }

                    string randomResponse = RandomResponseGenerator.GenerateResponse(userMsg);
                    if (!string.IsNullOrEmpty(randomResponse))
                    {
                        await msg.Channel.SendMessageAsync(randomResponse);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Error with the on message event handler: " + ex);
                    return;
                }
            });

            return(Task.CompletedTask);
        }
示例#2
0
        public Task OnMessage(SocketMessage msg)
        {
            var userMsg = msg as SocketUserMessage;
            int argPos  = 0;
            var _       = Task.Run(async() =>
            {
                try
                {
                    if (msg == null || msg.Author.IsBot)
                    {
                        return;
                    }
                    var channel     = msg.Channel as ITextChannel;
                    string content  = msg.Content;
                    bool hasBadWord = _wordFilterService.hasFilteredWord(new FloofDataContext(), msg.Content, channel.Guild.Id, msg.Channel.Id);
                    if (hasBadWord)
                    {
                        await HandleBadMessage(msg.Author, msg);
                    }
                    else if (userMsg.HasMentionPrefix(_client.CurrentUser, ref argPos) && content.EndsWith("?"))
                    {
                        string eightBallResponse = Floofbot.Modules.Helpers.EightBall.GetRandomResponse();
                        await channel.SendMessageAsync($"> {content}\n{eightBallResponse}");
                    }
                    else
                    {
                        string randomResponse = RandomResponseGenerator.GenerateResponse(userMsg);
                        if (!string.IsNullOrEmpty(randomResponse))
                        {
                            await channel.SendMessageAsync(randomResponse);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Error with the on message event handler: " + ex);
                    return;
                }
            });

            return(Task.CompletedTask);
        }