private List <DiscordOverwriteBuilder> CreatePermissions(DiscordGuild guild, DiscordRole allowedRole, DiscordRole deniedRole) { var permissions = new List <DiscordOverwriteBuilder> (); var adminRole = guild.Roles.Values.Where(role => role.Name.Equals("smashfest-admin")).FirstOrDefault(); if (adminRole != null) { var adminPermissions = new DiscordOverwriteBuilder(); adminPermissions.For(adminRole); adminPermissions.Allow(Permissions.SendMessages); adminPermissions.Allow(Permissions.AccessChannels); adminPermissions.Allow(Permissions.PrioritySpeaker); permissions.Add(adminPermissions); } Console.WriteLine($"allowed: {allowedRole.Name}"); DiscordOverwriteBuilder allowed = new DiscordOverwriteBuilder(); allowed.For(allowedRole); allowed.Allow(Permissions.SendMessages); allowed.Allow(Permissions.AccessChannels); allowed.Allow(Permissions.ReadMessageHistory); permissions.Add(allowed); Console.WriteLine($"denied: {deniedRole.Name}"); DiscordOverwriteBuilder denied = new DiscordOverwriteBuilder(); denied.For(deniedRole); denied.Deny(Permissions.SendMessages); denied.Deny(Permissions.AccessChannels); denied.Deny(Permissions.ReadMessageHistory); permissions.Add(denied); return(permissions); }
private List <DiscordOverwriteBuilder> GetOverwrites(List <DiscordMember> v, DiscordGuild guild, DiscordMember owner) { v.Add(owner); List <DiscordOverwriteBuilder> res = new List <DiscordOverwriteBuilder>(); //@everyone - READ FALSE, WRITE FALSE DiscordOverwriteBuilder v1 = new DiscordOverwriteBuilder(); v1.For(guild.EveryoneRole); v1.Deny(Permissions.AccessChannels); v1.Deny(Permissions.SendMessages); res.Add(v1); //Frozen - WRITE FALSE DiscordOverwriteBuilder v7 = new DiscordOverwriteBuilder(); v7.For(Dependencies.Settings.FrozenPlayerRole); v7.Deny(Permissions.SendMessages); res.Add(v7); //Participant - WRITE TRUE DiscordOverwriteBuilder v2 = new DiscordOverwriteBuilder(); v2.For(Dependencies.Settings.AliveParticipantRole); v2.Allow(Permissions.SendMessages); res.Add(v2); //Dead - Read TRUE, Write FALSE DiscordOverwriteBuilder v3 = new DiscordOverwriteBuilder(); v3.For(Dependencies.Settings.DeadParticipantRole); v3.Allow(Permissions.AccessChannels); v3.Deny(Permissions.SendMessages); res.Add(v3); //GM - Read TRUE, Write True DiscordOverwriteBuilder v4 = new DiscordOverwriteBuilder(); v4.For(Dependencies.Settings.GameMasterRole); v4.Allow(Permissions.SendMessages); v4.Allow(Permissions.AccessChannels); res.Add(v4); foreach (var v5 in v) { DiscordOverwriteBuilder v6 = new DiscordOverwriteBuilder(); v6.For(v5); v6.Allow(Permissions.AccessChannels); res.Add(v6); } return(res); }
/// <summary> /// Gets all channels, members in them and set's up event handlers /// </summary> /// <param name="guild"></param> /// <returns></returns> internal async Task Initialize(DiscordGuild guild) { //DebugLogWriteLine($"Initiating {guild} GuildTask... "); //Init guild Guild = guild; GuildId = guild.Id; SecretRoomOverwriteBuilder = new DiscordOverwriteBuilder(); SecretRoomOverwriteBuilder.For(Guild.EveryoneRole); SecretRoomOverwriteBuilder.Deny(Permissions.AccessChannels); //PersonalChannelOverwriteBuilder = new DiscordOverwriteBuilder(); //PersonalChannelOverwriteBuilder.Allow(Permissions.AccessChannels); LogChannel = guild.GetChannel(LogChannelId); if (LogChannel != null) { LogMessage = await LogChannel.SendMessageAsync($"Begin of log {DateTime.Now.ToString()}\n"); } //Init RootCategory Guild.Channels.TryGetValue(DateCategoryId, out DiscordChannel cat); if (cat == null) { string m = $"Initialize failed. No Category found on + {DateCategoryId}"; //DebugLogWriteLine(m); throw new Exception(m); } DateRootCategory = cat; Guild.Channels.TryGetValue(DateSecretCategoryId, out DiscordChannel secCat); DateSecretCategory = secCat; //DebugLogWrite("Initiating voice channels... "); //VoiceChannels DateVoiceLobbies.Clear(); SecretRooms.Clear(); DateVoiceLobbies.AddRange(GetVoiceLobbies()); SecretRooms.AddRange(GetSecretRooms()); await VoiceChannelsInitAsync().ConfigureAwait(false); if (DateVoiceLobbies.Count == 0 || DateVoiceLobbies.All(c => c.Users.Count() > 0)) { await AddLastEmptyVoiceLobby().ConfigureAwait(false); } //DebugLogWrite("Initiating Emojis... "); //GetEmojis MaleEmoji = DiscordEmoji.FromUnicode(DateBot.Instance.Client, MaleEmojiId); FemaleEmoji = DiscordEmoji.FromUnicode(DateBot.Instance.Client, FemaleEmojiId); OptionEmojis.Clear(); OptionEmojis.AddRange(OptionEmojiIds.Select(id => DiscordEmoji.FromUnicode(DateBot.Instance.Client, id))); LikeEmoji = DiscordEmoji.FromUnicode(DateBot.Instance.Client, LikeEmojiId); DisLikeEmoji = DiscordEmoji.FromUnicode(DateBot.Instance.Client, DisLikeEmojiId); TimeEmoji = DiscordEmoji.FromUnicode(DateBot.Instance.Client, TimeEmojiId); CancelLikeEmoji = DiscordEmoji.FromUnicode(DateBot.Instance.Client, CancelLikeEmojiId); //DebugLogWrite("Initiating Users in lobbies... "); //Check and add users in lobbies foreach (var u in UsersInLobbies.ToArray()) { AddOrGetUserState(u).LastEnteredLobbyTime = DateTime.Now; } //DebugLogWrite("Initiating Welcome message... "); //Check for welcome message TODO add option emojis DateTextChannel = Guild.GetChannel(DateTextChannelId); await WelcomeMessageInit().ConfigureAwait(false); _ = PrivateControlsMessageInit().ConfigureAwait(false); //UpdateTimer = new Timer(TimeSpan.FromSeconds(30).TotalMilliseconds) { AutoReset = true }; //UpdateTimer.Elapsed += UpdateTimer_Elapsed; //UpdateTimer.Start(); //DebugLogWrite("finished"); InitTask = null; Initialized = true; if (UsersInLobbies.Count > 0) { TryStartMatchingTask(); } }