示例#1
0
        private async Task HandleCommandAsync(SocketMessage s)
        {
            var msg = (SocketUserMessage)s;

            if (msg == null)
            {
                return;
            }
            var context = new SocketCommandContext(_client, msg);

            if (context.User.IsBot)
            {
                return;
            }

            // if it's a dm, skip the methods in the region #trivial
            if (context.IsPrivate)
            {
                goto TrivialEnd;
            }

            #region Trivial
            // Leveling up
            Leveling.UserSentMessage(context);
            #endregion

TrivialEnd:
            var argPos = 0;
            // NOTE: ToString() can cause issues by spitting out the type instead of the char
            if (!msg.HasStringPrefix(Config.bot.cmdPrefix.ToString(), ref argPos))
            {
                MessageReceievedEventArgs e = new MessageReceievedEventArgs {
                    Msg = msg
                };
                OnMessageReceived(e);
            }

            if ((msg.HasStringPrefix(Config.bot.cmdPrefix.ToString(), ref argPos) ||
                 msg.HasMentionPrefix(_client.CurrentUser, ref argPos)) && !context.IsPrivate)
            {
                var result = await _service.ExecuteAsync(context, argPos);

                if (!result.IsSuccess /*&& result.Error != CommandError.UnknownCommand*/)
                {
                    Console.WriteLine(result.ErrorReason);
                }
            }
        }
示例#2
0
 protected virtual void OnMessageReceived(MessageReceievedEventArgs e)
 {
     MessageReceived?.Invoke(this, e);
 }