Esempio n. 1
0
        public async Task UnmuteUser(IGuildUser usr, MuteType type = MuteType.All)
        {
            if (type == MuteType.All)
            {
                StopUnmuteTimer(usr.GuildId, usr.Id);
                try { await usr.ModifyAsync(x => x.Mute = false).ConfigureAwait(false); } catch { }
                try { await usr.RemoveRoleAsync(await GetMuteRole(usr.Guild)).ConfigureAwait(false); } catch { /*ignore*/ }
                using (var uow = _db.UnitOfWork)
                {
                    var config = uow.GuildConfigs.For(usr.Guild.Id, set => set.Include(gc => gc.MutedUsers)
                                                      .Include(gc => gc.UnmuteTimers));
                    config.MutedUsers.Remove(new MutedUserId()
                    {
                        UserId = usr.Id
                    });
                    if (MutedUsers.TryGetValue(usr.Guild.Id, out ConcurrentHashSet <ulong> muted))
                    {
                        muted.TryRemove(usr.Id);
                    }

                    config.UnmuteTimers.RemoveWhere(x => x.UserId == usr.Id);

                    await uow.CompleteAsync().ConfigureAwait(false);
                }
                UserUnmuted(usr, MuteType.All);
            }
            else if (type == MuteType.Voice)
            {
                await usr.ModifyAsync(x => x.Mute = false).ConfigureAwait(false);

                UserUnmuted(usr, MuteType.Voice);
            }
            else if (type == MuteType.Chat)
            {
                await usr.RemoveRoleAsync(await GetMuteRole(usr.Guild).ConfigureAwait(false)).ConfigureAwait(false);

                UserUnmuted(usr, MuteType.Chat);
            }
        }