Exemple #1
0
        private void Unmute(object stateObj)
        {
            Task.Run(async() =>
            {
                List <Mute> collection = null;

                try
                {
                    collection = await _muteRepository.AllAsync();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }

                foreach (var mute in collection)
                {
                    if (DateTime.Now.Subtract(mute.MutedAt).TotalMilliseconds <= mute.MuteLength)
                    {
                        return;
                    }

                    try
                    {
                        var guild = await(_client as IDiscordClient).GetGuildAsync(mute.GuildId);

                        var user = await guild.GetUserAsync(mute.UserId);

                        var dbGuild = await _guildRepository.GetGuildAsync(guild.Id);

                        var mutedRole = guild.GetRole(dbGuild.MutedRoleId);

                        await user.RemoveRoleAsync(mutedRole);

                        await _moderationService.ModLogAsync(dbGuild, guild, "Auto unmute", Configuration.UnmuteColor, string.Empty, null, user);

                        await Task.Delay(500);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.StackTrace);
                    }
                    finally
                    {
                        await _muteRepository.DeleteAsync(mute);
                    }
                }
            });
        }
Exemple #2
0
        private void Unmute(object stateObj)
        {
            Task.Run(async() =>
            {
                Logger.Log(LogSeverity.Debug, $"Timers", "Auto Unmute");

                List <Mute> collection = null;

                try
                {
                    collection = await _muteRepo.AllAsync();
                }
                catch (Exception e)
                {
                    Logger.Log(LogSeverity.Error, "Attempting to all async the mute repo.", e.StackTrace);
                }

                if (collection == null)
                {
                    Logger.Log(LogSeverity.Error, "Collection is null", $"Stopping Auto Unmute");
                    return;
                }

                Logger.Log(LogSeverity.Debug, "Successfully loaded collection", $"Collection count: {collection.Count}");

                foreach (var mute in collection)
                {
                    if (DateTime.UtcNow.Subtract(mute.MutedAt).TotalMilliseconds <= mute.MuteLength)
                    {
                        return;
                    }

                    Logger.Log(LogSeverity.Debug, "Mute is passed it's length", $"More information soon...");

                    try
                    {
                        var guild = await(_client as IDiscordClient).GetGuildAsync(mute.GuildId);

                        Logger.Log(LogSeverity.Debug, "Mute Guild:", guild.Name + $" ({mute.GuildId})");

                        var user = await guild.GetUserAsync(mute.UserId);

                        Logger.Log(LogSeverity.Debug, "Mute User:"******"{user} ({mute.UserId})");

                        var dbGuild = await _guildRepo.GetGuildAsync(guild.Id);

                        Logger.Log(LogSeverity.Debug, "DbGuild Fetched", $"Mod Log Channel Id: {dbGuild.ModLogChannelId}");

                        var mutedRole = guild.GetRole(dbGuild.MutedRoleId);

                        Logger.Log(LogSeverity.Debug, "Muted role fetched", mutedRole.Name + $" ({mutedRole.Id})");

                        await user.RemoveRoleAsync(mutedRole);

                        Logger.Log(LogSeverity.Debug, "Successfully removed a role", $"Mute: {mute}");

                        var result = await _moderationService.TryModLogAsync(dbGuild, guild, "Automatic Unmute", new Color(12, 255, 129), string.Empty, null, user);

                        Logger.Log(LogSeverity.Debug, "Mod log attempt", $"Succes: {result}");

                        await Task.Delay(500);
                    }
                    catch (Exception e)
                    {
                        Logger.Log(LogSeverity.Error, "Auto Unmute role removal", e.StackTrace);
                    }
                    finally
                    {
                        await _muteRepo.DeleteAsync(mute);
                        Logger.Log(LogSeverity.Debug, "Mute entry deleted", "Passed it's length");
                    }
                }
            });
        }