Пример #1
0
        public async Task HandleCommandAsync(SocketMessage messageParam)
        {
            string userName    = "";
            string channelName = "";
            string guildName   = "";
            int    argPos      = 0;

            try {
                DatabaseUtils.ChangeCollection("userData");
                var   msg    = messageParam as SocketUserMessage;
                ulong userId = msg.Author.Id;
                userName    = GetUserName(msg.Author);
                channelName = msg.Channel?.Name ?? "NULL";
                var context = new CommandContext(client, msg);
                guildName = context.Guild?.Name ?? "NULL";
                var channelID = msg.Channel.Id;
                await Logger.Log(new LogMessage(LogSeverity.Info, $"{GetType().Name}.HandleCommandAsync", $"HandleCommandAsync G: {guildName} C: {channelName} User: {userName}  Msg: {msg}"));

                var guildUsers = await context.Guild.GetUsersAsync();

                if (!msg.Author.IsBot)
                {
                    DatabaseUtils.IncrementDocument(userId, "numberOfMessages", 1);
                    DatabaseUtils.IncrementDocument(userId, "experience", msg.Content.Length);
                    await RoleUtils.MessageCountRoles(msg.Author, channelID);

                    await RoleUtils.DateJoinedRoles(msg.Author, channelID);

                    await PointLeader.CheckForNewLeader(guildUsers, channelID);
                }
                if (msg.Author.Id == 181240813492109312 || msg.Author.Id == 195567858133106697)
                {
                    if (msg.MentionedUsers.ToList().Count >= 1)
                    {
                        await RoleUtils.GiveRoleToUser(msg.MentionedUsers.FirstOrDefault() as SocketGuildUser, "???", msg.Channel.Id);
                    }
                }

                if (msg == null)
                {
                    return;
                }
                else if (msg.HasStringPrefix(CommandPrefix, ref argPos))
                {
                    var result = await commands.ExecuteAsync(context, argPos, null);

                    if (!result.IsSuccess)                     // If execution failed, reply with the error message.
                    {
                        string message = "Command Failed: " + msg;
                        await Logger.Log(new LogMessage(LogSeverity.Error, $"{GetType().Name}.HandleCommandAsync", message));

                        await context.Channel.SendMessageAsync(message);
                    }
                }
            } catch (Exception e) {
                await Logger.Log(new LogMessage(LogSeverity.Error, $"{GetType().Name}.HandleCommandAsync", $"G:{guildName} C:{channelName} U:{userName} Unexpected Exception {e}", e));
            }
        }