コード例 #1
0
        public async Task Unmute(IGuildUser userToUnmute, [Remainder] string reason = "No reason.")
        {
            var mutedRoleId = GuildRepository.FetchGuild(Context.Guild.Id).MutedRoleId;

            if (userToUnmute.RoleIds.All(x => x != mutedRoleId))
            {
                throw new Exception("You cannot unmute a user who isn't muted.");
            }
            await ModuleMethods.InformSubjectAsync(Context.User, "Unmute", userToUnmute, reason);

            await userToUnmute.RemoveRoleAsync(Context.Guild.GetRole(mutedRoleId));

            MuteRepository.RemoveMute(userToUnmute.Id, Context.Guild.Id);
            await Logger.ModLog(Context, "Unmute", new Color(12, 255, 129), reason, userToUnmute);

            await ReplyAsync($"{Context.User.Mention} has successfully unmuted {userToUnmute.Mention}!");
        }
コード例 #2
0
 private void AutoUnmute()
 {
     Timer t = new Timer(async method =>
     {
         foreach (Mute mute in await(await DEABot.Mutes.FindAsync("")).ToListAsync())
         {
             if (DateTime.UtcNow.Subtract(mute.MutedAt).TotalMilliseconds > mute.MuteLength)
             {
                 var guild = _client.GetGuild(mute.GuildId);
                 if (guild != null && guild.GetUser(mute.UserId) != null)
                 {
                     var guildData = GuildRepository.FetchGuild(guild.Id);
                     var mutedRole = guild.GetRole(guildData.MutedRoleId);
                     if (mutedRole != null && guild.GetUser(mute.UserId).Roles.Any(x => x.Id == mutedRole.Id))
                     {
                         var channel = guild.GetTextChannel(guildData.ModLogId);
                         if (channel != null && guild.CurrentUser.GuildPermissions.EmbedLinks &&
                             (guild.CurrentUser as IGuildUser).GetPermissions(channel as SocketTextChannel).SendMessages &&
                             (guild.CurrentUser as IGuildUser).GetPermissions(channel as SocketTextChannel).EmbedLinks)
                         {
                             await guild.GetUser(mute.UserId).RemoveRoleAsync(mutedRole);
                             var footer = new EmbedFooterBuilder()
                             {
                                 IconUrl = "http://i.imgur.com/BQZJAqT.png",
                                 Text    = $"Case #{guildData.CaseNumber}"
                             };
                             var builder = new EmbedBuilder()
                             {
                                 Color       = new Color(12, 255, 129),
                                 Description = $"**Action:** Automatic Unmute\n**User:** {guild.GetUser(mute.UserId)} ({guild.GetUser(mute.UserId).Id})",
                                 Footer      = footer
                             }.WithCurrentTimestamp();
                             GuildRepository.Modify(DEABot.GuildUpdateBuilder.Set(x => x.CaseNumber, ++guildData.CaseNumber), guild.Id);
                             await channel.SendMessageAsync("", embed: builder);
                         }
                     }
                 }
                 MuteRepository.RemoveMute(mute.UserId, mute.GuildId);
             }
         }
     },
                         null,
                         Config.AUTO_UNMUTE_COOLDOWN,
                         Timeout.Infinite);
 }