Example #1
0
        private async Task HandleTimeoutUser(SocketMessage message)
        {
            await message.DeleteAsync();

            int timeRemaining = Timewatch.GetRemainingTime(_timedOutUsers[message.Author]);
            await message.Author.SendMessageAsync(string.Format("You're on a timeout for {0} more seconds.", timeRemaining));
        }
Example #2
0
        private async Task HandleCommand(Command command)
        {
            switch (command.CommandType)
            {
            case CommandType.AddAdmin:

                foreach (CommandArgument argument in command.Arguments)
                {
                    if (argument.IsUserMention)
                    {
                        SocketUser userToAdd = argument.MentionedUser;
                        await Log("Adding admin: " + userToAdd.Username);

                        _admins.Add(userToAdd);
                    }
                }

                break;

            case CommandType.RemoveAdmin:

                foreach (CommandArgument argument in command.Arguments)
                {
                    if (argument.IsUserMention)
                    {
                        SocketUser userToRemove = argument.MentionedUser;
                        await Log("Removing admin: " + userToRemove.Username);

                        _admins.Remove(userToRemove);
                    }
                }

                break;

            case CommandType.AddBlacklist:

                foreach (CommandArgument argument in command.Arguments)
                {
                    if (argument.IsUserMention)
                    {
                        _blacklistedUsers.Add(argument.MentionedUser);
                    }
                }

                break;

            case CommandType.RemoveBlacklist:

                foreach (CommandArgument argument in command.Arguments)
                {
                    if (argument.IsUserMention)
                    {
                        _blacklistedUsers.Remove(argument.MentionedUser);
                    }
                }

                break;

            case CommandType.AddFilter:

                _filteredWords.Add(command.Arguments[0].Argument);

                break;

            case CommandType.RemoveFilter:

                _filteredWords.Remove(command.Arguments[0].Argument);

                break;

            case CommandType.AddTimeout:

                double timeoutDurationInSeconds;
                if (double.TryParse(command.Arguments[1].Argument, out timeoutDurationInSeconds))
                {
                    SocketUser mentionedUser = command.Arguments[0].MentionedUser;
                    if (mentionedUser == null)
                    {
                        return;
                    }

                    Action removeTimedOutUser = async() => await RemoveTimeout(mentionedUser);

                    string id = Timewatch.AddTimer(timeoutDurationInSeconds, removeTimedOutUser);

                    await AddTimeout(mentionedUser, id);

                    await Log(string.Format("Adding timeout of {0} seconds to {1}", timeoutDurationInSeconds, mentionedUser.Username));
                }

                break;

            case CommandType.RemoveTimeout:

                if (command.Arguments[0].IsUserMention)
                {
                    await Log("Removing timeout: " + command.Arguments[0].MentionedUser.Username);

                    Timewatch.RemoveTimer(_timedOutUsers[command.Arguments[0].MentionedUser]);
                    _timedOutUsers.Remove(command.Arguments[0].MentionedUser);
                }

                break;

            case CommandType.SetTimeoutRole:

                if (command.Arguments[0].IsRoleMention)
                {
                    await Log("Setting timeout role: " + command.Arguments[0].MentionedRole.Name);

                    _timeOutRole = command.Arguments[0].MentionedRole;
                }

                break;

            case CommandType.ListAdmins:

                StringBuilder adminOutput = new StringBuilder("Admins:\n");
                await Log("Admins:");

                foreach (SocketUser admin in _admins)
                {
                    await Log(admin.Username);

                    adminOutput.Append(admin.Username).Append("\n");
                }

                await command.OriginalMessage.Channel.SendMessageAsync(adminOutput.ToString());

                break;

            case CommandType.ListBlacklist:

                StringBuilder blacklistedUsersOutput = new StringBuilder("Blacklist:\n");

                await Log("Blacklist:");

                foreach (SocketUser blacklistedUser in _blacklistedUsers)
                {
                    string output = string.Format("Name: {0}, ID: {1}", blacklistedUser.Username, blacklistedUser.Id);
                    await Log(output);

                    blacklistedUsersOutput.Append(output).Append("\n");
                }

                await command.OriginalMessage.Channel.SendMessageAsync(blacklistedUsersOutput.ToString());

                break;

            case CommandType.ListFilter:

                StringBuilder filteredWordsOutput = new StringBuilder("Filtered Words:\n");

                await Log("Filtered words:");

                foreach (string filteredWord in _filteredWords)
                {
                    filteredWordsOutput.Append(filteredWord).Append("\n");
                    await Log(filteredWord);
                }

                await command.OriginalMessage.Channel.SendMessageAsync(filteredWordsOutput.ToString());

                break;

            case CommandType.AuditLogTarget:

                foreach (CommandArgument argument in command.Arguments)
                {
                    if (argument.IsChannelMention)
                    {
                        if (argument.MentionedChannel is ISocketMessageChannel)
                        {
                            _auditLogChannel = argument.MentionedChannel as ISocketMessageChannel;
                        }

                        break;
                    }
                }

                break;

            case CommandType.ToggleAuditLog:

                _auditLogMode = !_auditLogMode;

                break;

            case CommandType.GetID:

                await Log("Author ID: " + command.Author.Id);

                await Log("ID's in order of @:");

                if (command.Arguments == null || command.Arguments.Count == 0)
                {
                    return;
                }

                foreach (CommandArgument arg in command.Arguments)
                {
                    if (arg.MentionedUser != null)
                    {
                        await Log("ID: " + arg.MentionedUser.Id);
                    }
                }

                break;

            case CommandType.Cleanup:

                var channel  = command.OriginalMessage.Channel;
                var messages = await channel.GetMessagesAsync().FlattenAsync();

                foreach (IMessage messageInChannel in messages)
                {
                    if (messageInChannel.Content.StartsWith(_botPrefix))
                    {
                        await messageInChannel.DeleteAsync();
                    }
                }

                await Log("Finished cleanup");

                await channel.SendMessageAsync("Cleanup complete.");

                break;

            case CommandType.Help:

                LogHelp(command.OriginalMessage.Channel);

                break;

            case CommandType.None:

                return;

                break;
            }
        }