Exemplo n.º 1
0
        public async Task UnmuteAsync(
            [Summary("The user to unmute.")] SocketGuildUser user = null,
            [Summary("The reason for the unmute.")][Remainder]
            string reason = "A moderator has taken mercy on you by lifting the mute.")
        {
            if (user != null)
            {
                if (await _mute.UnmuteAsync(user, (SocketGuildUser)Context.User, reason))
                {
                    await ReplyAsync($"Unmuted {user}.");
                }
                else
                {
                    await ReplyAsync($"Failed to unmute {user} because the user isn't muted.");
                }
            }
            else
            {
                string reply = null;

                foreach (Mute mute in await DataBaseUtil.GetActiveMutesAsync())
                {
                    //TODO: Move this to >MuteHistory. It is only here because I'm too lazy and this was easier...
                    reply += $"Name: {mute.Username}\nMuted at: {mute.Timestamp:yyyy-MM-ddTHH:mm:ssZ}\n" +
                             $"Duration: {mute.Duration?.ToString() ?? "indefinite"}\nReason: {mute.Reason ?? "None"}\n" +
                             $"Expires at: {mute.Timestamp.AddMinutes(mute.Duration ?? 0)}";
                }

                if (reply == null)
                {
                    reply = "No mutes found!";
                }

                await ReplyAsync($"Current Mutes: {reply}");
            }

            await DataBaseUtil.AddCommandAsync("Unmute", Context);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks for expired or manually removed mutes and appropriately unmutes users.
        /// </summary>
        /// <returns>No object or value is returned by this method when it completes.</returns>
        private async Task CheckMutesAsync()
        {
            SocketGuild guild = _client.Guilds.FirstOrDefault();

            if (guild == null)
            {
                return;
            }

            foreach (Mute mute in await DataBaseUtil.GetActiveMutesAsync())
            {
                SocketGuildUser user = guild.GetUser(mute.UserId);

                if (user == null)
                {
                    // TODO: Handle this better so it does not spam each mute cycle.
                    // await _data.ChannelLog($"Failure Unmuting {mute.Username}", "User not found.");

                    continue;
                }

                if (mute.CheckExpired())
                {
                    await UnmuteAsync(user, _client.CurrentUser, "The mute expired.");

                    await Task.Delay(1000);

                    continue;
                }

                if (!user.Roles.Contains(_data.MuteRole))
                {
                    await user.AddRoleAsync(_data.MuteRole);

                    await Task.Delay(1000);
                }
            }
        }