/// <summary> /// Returns whether the specified voice channel is managed by the bot /// </summary> /// <param name="vc">VC to check</param> /// <returns>If the VC is a temporary VC managed by the bot</returns> public bool IsVcManaged(IVoiceChannel vc) { var guild = vc.Guild; var props = SpService.GetProperties(guild.Id); return(vc.CategoryId == props.TempVoiceCategoryId); }
/// <summary> /// Sets if a VC should be NSFW or not /// </summary> /// <param name="vc">VC to modify</param> /// <param name="nsfw">If the VC should be nsfw</param> public async Task SetVcNsfw(IVoiceChannel vc, bool nsfw) { var props = SpService.GetProperties(vc.GuildId); var newPerm = nsfw ? PermValue.Allow : PermValue.Inherit; var nsfwRole = vc.Guild.GetRole(props.NsfwRoleId); var perms = vc.GetPermissionOverwrite(nsfwRole) ?? OverwritePermissions.InheritAll; await vc.AddPermissionOverwriteAsync(nsfwRole, perms.Modify(viewChannel: newPerm, connect: newPerm)).ConfigureAwait(false); }
/// <summary> /// Checks if a VC is NSFW /// </summary> /// <param name="vc"></param> /// <returns></returns> public bool IsVcNsfw(IVoiceChannel vc) { var props = SpService.GetProperties(vc.GuildId); if (props.NsfwRoleId == 0) { return(false); } var isPrivate = !IsVcPublic(vc); var perms = vc.GetPermissionOverwrite(vc.Guild.GetRole(props.NsfwRoleId)) ?? OverwritePermissions.InheritAll; return(isPrivate && (perms.ViewChannel == PermValue.Allow && perms.Connect == PermValue.Allow)); }
public async Task UserVoiceStateUpdated(SocketUser user, SocketVoiceState before, SocketVoiceState after) { var guild = (after.VoiceChannel != null ? after : before).VoiceChannel.Guild; if (before.VoiceChannel?.Id == after.VoiceChannel?.Id) { return; } var props = SpService.GetProperties(guild.Id); var guildUser = guild.GetUser(user.Id); if (guildUser == null) { return; } var name = (!string.IsNullOrEmpty(guildUser.Nickname)) ? guildUser.Nickname : user.Username; // If the user switched to a 'create vc' channel if (after.VoiceChannel != null && after.VoiceChannel.Id == props.TempVoiceCreateChannelId) { if (!await DoSpamChecks(guildUser, props, guild).ConfigureAwait(false)) { return; } Logger.LogInformation("Creating vc in {guildName} for {name}", guild.Name, $"{guildUser.Username}#{guildUser.Discriminator}"); var newVoiceChannel = await guild.CreateVoiceChannelAsync(name + "'s Voice Chat", (properties) => properties.CategoryId = props.TempVoiceCategoryId) .ConfigureAwait(false); if (!props.SimpleTempVc) { var perms = GetOwnerPermissions(newVoiceChannel); await newVoiceChannel.AddPermissionOverwriteAsync(user, perms).ConfigureAwait(false); } await guildUser.ModifyAsync(vcUser => vcUser.Channel = newVoiceChannel).ConfigureAwait(false); } await RemoveOldVc(before, props).ConfigureAwait(false); await ChangeOwnerIfCreatorLeft(before, props, user, guildUser).ConfigureAwait(false); }
public ActionResult Index() { SetCurrentSpCulture(); ErrorModel errorModel; var blogUrl = Request.QueryString["blogUrl"]; if (string.IsNullOrWhiteSpace(blogUrl) || blogUrl.Equals(Viewer.BlogUrlDefaultValue)) { errorModel = new ErrorModel { ErrorMessage = Viewer.BlogUrlError }; return(View("Error", errorModel)); } else { const string Layouts15Text = "_layouts/15"; if (blogUrl.Contains(Layouts15Text)) { var indexOfLayouts15 = blogUrl.IndexOf(Layouts15Text); blogUrl = blogUrl.Substring(0, indexOfLayouts15); } } var numberOfEntries = int.Parse(Request.QueryString["numberOfEntries"]); if (numberOfEntries < 0) { errorModel = new ErrorModel { ErrorMessage = Viewer.NumberOfEntriesError }; return(View("Error", errorModel)); } var bodyMaxLength = int.Parse(Request.QueryString["entriesBodyMaxLength"]); if (bodyMaxLength < 0) { errorModel = new ErrorModel { ErrorMessage = Viewer.EntriesBodyMaxLengthError }; return(View("Error", errorModel)); } try { var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); var spService = new SpService(spContext); var viewerModel = spService.GetEntriesFrom(blogUrl, numberOfEntries, bodyMaxLength); return(View(viewerModel)); } catch (ServerUnauthorizedAccessException) { errorModel = new ErrorModel { ErrorMessage = Viewer.UnauthorizedError }; } catch (ServerException) { var errorMessage = string.Format(Viewer.NotBlogError, Viewer.BlogListTitle); errorModel = new ErrorModel { ErrorMessage = errorMessage }; } catch (Exception exception) { errorModel = new ErrorModel { ErrorMessage = exception.Message }; } return(View("Error", errorModel)); }
public async Task UserVoiceStateUpdated(SocketUser user, SocketVoiceState before, SocketVoiceState after) { SocketGuild guild; if (after.VoiceChannel != null) { guild = after.VoiceChannel.Guild; } else { guild = before.VoiceChannel.Guild; } var serverProperties = SpService.GetProperties(guild.Id); var guildUser = guild.GetUser(user.Id); if (guildUser == null) { return; } var name = !(string.IsNullOrEmpty(guildUser.Nickname)) ? guildUser.Nickname : user.Username; //If the vc they switched to is a "create vc" one if (after.VoiceChannel != null && after.VoiceChannel.Id == serverProperties.TempVoiceCreateChannelId) { if (spamProtectionDictionary.ContainsKey(guildUser)) { if (spamProtectionCountDictionary[guildUser] > 4) { if (DateTimeOffset.Now.ToUnixTimeSeconds() - spamProtectionDictionary[guildUser] < 60) { await guildUser.AddRoleAsync(guild.GetRole(serverProperties.SpamRoleId)); await Logger.Log(new LogMessage(LogSeverity.Warning, "ChannelMaker", "Giving spamrole to " + name + " for spamming VC creation")); var logChannel = Client.GetChannel(serverProperties.LogChannelId) as ITextChannel; await logChannel.SendMessageAsync(guildUser.Mention + " was spamming VC creation, giving spam role."); await RemoveOldVc(before, serverProperties); await guildUser.ModifyAsync(vcUser => { vcUser.Channel = null; }); return; } spamProtectionCountDictionary[guildUser] = 0; } } spamProtectionDictionary[guildUser] = DateTimeOffset.Now.ToUnixTimeSeconds(); if (!spamProtectionCountDictionary.ContainsKey(guildUser)) { spamProtectionCountDictionary[guildUser] = 1; } else { spamProtectionCountDictionary[guildUser]++; } await Logger.Log(new LogMessage(LogSeverity.Info, "ChannelMaker", "Creating VC for " + name)); var newVoiceChannel = await after.VoiceChannel.Guild.CreateVoiceChannelAsync(name + "'s Voice Chat", (properties) => { properties.CategoryId = serverProperties.TempVoiceCategoryId; }); await guildUser.ModifyAsync(vcUser => { vcUser.Channel = newVoiceChannel; }); } await RenameVcIfCreatorLeft(before, serverProperties, user, guildUser); await RemoveOldVc(before, serverProperties); }