public async Task MoveToNewRoomAsync(params SocketGuildUser[] users) { RestVoiceChannel voiceChannel = await Context.Guild.CreateVoiceChannelAsync("Breakout room", x => x.CategoryId = _session.DatingCategory.Id); foreach (var user in users) { await voiceChannel.AddPermissionOverwriteAsync(user, Overwrites.ConnectVoice); await user.ModifyAsync(u => u.Channel = voiceChannel); } }
private async Task UserVoiceUpdated(SocketUser arg1, SocketVoiceState arg2, SocketVoiceState arg3) { if (arg1 is SocketGuildUser user) { var chnl = user.VoiceChannel; if (chnl != null && chnl.Id == config.SetupChannelId) { if (chnl.Category is SocketCategoryChannel cat) { if (cat.Channels.Count - 1 >= config.MaxRentedVCs) { await user.ModifyAsync(prop => { prop.Channel = null; }); } else { RestVoiceChannel vc = await chnl.Guild.CreateVoiceChannelAsync(user.Username, prop => { prop.CategoryId = config.CategoryId; }); OverwritePermissions creatorperms = OverwritePermissions.DenyAll(vc); creatorperms = creatorperms.Modify(viewChannel: PermValue.Allow, manageChannel: PermValue.Allow, manageRoles: PermValue.Allow, useVoiceActivation: PermValue.Allow, prioritySpeaker: PermValue.Allow, connect: PermValue.Allow, stream: PermValue.Allow, speak: PermValue.Allow); await vc.AddPermissionOverwriteAsync(user, creatorperms); await user.ModifyAsync(prop => { prop.Channel = vc; }); } } } if (arg2.VoiceChannel != null && arg2.VoiceChannel.CategoryId == config.CategoryId && arg2.VoiceChannel.Id != config.SetupChannelId && arg2.VoiceChannel.Users.Count == 0) { await arg2.VoiceChannel.DeleteAsync(); } if (arg3.VoiceChannel != null && arg3.VoiceChannel.CategoryId == config.CategoryId && arg3.VoiceChannel.Id != config.SetupChannelId && arg3.VoiceChannel.Users.Count == 0) { await arg3.VoiceChannel.DeleteAsync(); } } }
public async Task <string> Load(CustomVC vc) { if (await IsActive(vc)) { return(":x: Custom VC is already loaded."); } using MySqlConnection connection = MySQL.MySQL.getConnection(); string query = $"SELECT ChannelID FROM CustomVCs WHERE UserID={vc.UserID}"; ulong channelid = await connection.ExecuteScalarAsync <ulong>(query); SocketGuildUser user = Constants.IGuilds.Jordan(_client).GetUser(vc.UserID); RestVoiceChannel voice = await Constants.IGuilds.Jordan(_client).CreateVoiceChannelAsync($"{user.Username}'s VC", x => { x.CategoryId = Data.GetChnlId("Voice Booth", MySQL.ChannelType.CategoryChannel); if (vc.Slots != 0) { x.UserLimit = vc.Slots; } else { x.UserLimit = null; } x.Bitrate = vc.Bitrate; }); query = $"UPDATE CustomVCs SET ChannelID={voice.Id} WHERE UserID={vc.UserID}"; await connection.ExecuteAsync(query); OverwritePermissions perms = new OverwritePermissions( muteMembers: PermValue.Allow, deafenMembers: PermValue.Allow, moveMembers: PermValue.Allow ); await voice.AddPermissionOverwriteAsync(user, perms); return(":white_check_mark: Loaded Custom VC."); }
private async Task OnReactionAdded(Cacheable <IUserMessage, ulong> cache, ISocketMessageChannel channel, SocketReaction reaction) { IGuildChannel guildChannel = channel as IGuildChannel; SocketGuild guild = guildChannel.Guild as SocketGuild; //GlobalUtils.client.Guilds.FirstOrDefault(); SocketUser user = GlobalUtils.client.GetUser(reaction.UserId); SocketGuildUser guser = guild.GetUser(user.Id); if (user.IsBot) { return; // Task.CompletedTask; } // add vote Console.WriteLine($"Emoji added: {reaction.Emote.Name}"); if (pendingGames.ContainsKey(reaction.MessageId) && reaction.Emote.Name == "\u2705") { pendingGames[reaction.MessageId].votes++; if (pendingGames[reaction.MessageId].votes >= voteThreshold || user.Id == 346219993437831182) { Console.WriteLine("Adding game: " + pendingGames[reaction.MessageId].game); // add the game now! RestRole gRole = await guild.CreateRoleAsync(pendingGames[reaction.MessageId].game); Console.WriteLine("Game Role: " + gRole.Name); RestTextChannel txtChan = await guild.CreateTextChannelAsync(pendingGames[reaction.MessageId].game, x => { x.CategoryId = gamesText.Id; }); Console.WriteLine("Text Channel: " + txtChan.Name); await txtChan.AddPermissionOverwriteAsync(gRole, permissions); RestVoiceChannel voiceChan = await guild.CreateVoiceChannelAsync(pendingGames[reaction.MessageId].game, x => { x.CategoryId = gamesVoice.Id; }); Console.WriteLine("Voice Channel: " + voiceChan.Name); await voiceChan.AddPermissionOverwriteAsync(gRole, permissions); games.Add(new GameInfo(pendingGames[reaction.MessageId].game, txtChan.Id, voiceChan.Id)); // remove poll message, add new game announcement and remove pending game ISocketMessageChannel chan = gameChannel as ISocketMessageChannel; await chan.DeleteMessageAsync(reaction.MessageId); EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle("New Game Added"); embed.WithDescription($"`{pendingGames[reaction.MessageId].game}`\n"); embed.WithColor(GlobalUtils.color); await chan.SendMessageAsync("", false, embed.Build()); pendingGames.Remove(reaction.MessageId); UpdateOrAddRoleMessage(); } } Console.WriteLine($"Emoji added: {reaction.MessageId} == {roleMessageId} : {reaction.MessageId == roleMessageId}"); Console.WriteLine("Add Game Role: " + guser.Nickname); if (reaction.MessageId == roleMessageId) { // they reacted to the correct role message Console.WriteLine("Add Game Role: " + guser.Nickname); for (int i = 0; i < games.Count && i < GlobalUtils.menu_emoji.Count <string>(); i++) { if (GlobalUtils.menu_emoji[i] == reaction.Emote.Name) { Console.WriteLine("Emoji Found"); var result = from a in guild.Roles where a.Name == games[i].game select a; SocketRole role = result.FirstOrDefault(); Console.WriteLine("Role: " + role.Name); await guser.AddRoleAsync(role); } } } Console.WriteLine("what?!"); Save(); }
public List <Command> Init(IValkyrjaClient iClient) { this.Client = iClient as ValkyrjaClient; List <Command> commands = new List <Command>(); this.Client.Events.MessageReceived += OnMessageReceived; // !tempChannel Command newCommand = new Command("tempChannel"); newCommand.Type = CommandType.Standard; newCommand.Description = "Creates a temporary voice channel. This channel will be destroyed when it becomes empty, with grace period of three minutes since it's creation."; newCommand.ManPage = new ManPage("[userLimit] <channelName>", "`[userLimit]` - Optional user limit.\n\n`<channelName>` - Name of the new temporary voice channel."); newCommand.RequiredPermissions = PermissionType.ServerOwner | PermissionType.Admin | PermissionType.Moderator | PermissionType.SubModerator; newCommand.OnExecute += async e => { if (e.Server.Config.TempChannelCategoryId == 0) { await e.SendReplySafe("This command has to be configured on the config page (\"other\" section) <https://valkyrja.app/config>"); return; } if (string.IsNullOrWhiteSpace(e.TrimmedMessage)) { await e.SendReplySafe($"Usage: `{e.Server.Config.CommandPrefix}tempChannel <name>` or `{e.Server.Config.CommandPrefix}tempChannel [userLimit] <name>`"); return; } int limit = 0; bool limited = int.TryParse(e.MessageArgs[0], out limit); StringBuilder name = new StringBuilder(); for (int i = limited ? 1 : 0; i < e.MessageArgs.Length; i++) { name.Append(e.MessageArgs[i]); name.Append(" "); } string responseString = string.Format(TempChannelConfirmString, name.ToString()); try { RestVoiceChannel tempChannel = null; if (limited) { tempChannel = await e.Server.Guild.CreateVoiceChannelAsync(name.ToString(), c => { c.CategoryId = e.Server.Config.TempChannelCategoryId; c.UserLimit = limit; }); } else { tempChannel = await e.Server.Guild.CreateVoiceChannelAsync(name.ToString(), c => c.CategoryId = e.Server.Config.TempChannelCategoryId); } if (e.Server.Config.TempChannelGiveAdmin) { await tempChannel.AddPermissionOverwriteAsync(e.Message.Author, new OverwritePermissions(manageChannel : PermValue.Allow, manageRoles : PermValue.Allow, moveMembers : PermValue.Allow, muteMembers : PermValue.Allow, deafenMembers : PermValue.Allow)); } ServerContext dbContext = ServerContext.Create(this.Client.DbConnectionString); ChannelConfig channel = dbContext.Channels.AsQueryable().FirstOrDefault(c => c.ServerId == e.Server.Id && c.ChannelId == tempChannel.Id); if (channel == null) { channel = new ChannelConfig { ServerId = e.Server.Id, ChannelId = tempChannel.Id }; dbContext.Channels.Add(channel); } channel.Temporary = true; dbContext.SaveChanges(); dbContext.Dispose(); } catch (HttpException exception) { await e.Server.HandleHttpException(exception, $"This happened in <#{e.Channel.Id}> when trying to create a temporary channel."); } catch (Exception exception) { await this.Client.LogException(exception, e); responseString = string.Format(ErrorUnknownString, this.Client.GlobalConfig.AdminUserId); } await e.SendReplySafe(responseString); }; commands.Add(newCommand); commands.Add(newCommand.CreateAlias("tmp")); commands.Add(newCommand.CreateAlias("tc")); // !mentionRole newCommand = new Command("mentionRole"); newCommand.Type = CommandType.Standard; newCommand.Description = "Mention a role with a message. Use with the name of the role as the first parameter and the message will be the rest."; newCommand.ManPage = new ManPage("<roleName> <message text>", "`<roleName>` - Name of the role to be mentioned with a ping.\n\n`<message text>` - Text that will be said with the role mention."); newCommand.DeleteRequest = true; newCommand.RequiredPermissions = PermissionType.ServerOwner | PermissionType.Admin; newCommand.OnExecute += async e => { if (!e.Server.Guild.CurrentUser.GuildPermissions.ManageRoles) { await e.SendReplySafe(ErrorPermissionsString); return; } if (e.MessageArgs == null || e.MessageArgs.Length < 2) { await e.SendReplySafe($"Usage: `{e.Server.Config.CommandPrefix}{e.CommandId} <roleName> <message text>`"); return; } IEnumerable <SocketRole> foundRoles = null; if (!(foundRoles = e.Server.Guild.Roles.Where(r => r.Name == e.MessageArgs[0])).Any() && !(foundRoles = e.Server.Guild.Roles.Where(r => r.Name.ToLower() == e.MessageArgs[0].ToLower())).Any() && !(foundRoles = e.Server.Guild.Roles.Where(r => r.Name.ToLower().Contains(e.MessageArgs[0].ToLower()))).Any()) { await e.SendReplySafe(ErrorRoleNotFound); return; } if (foundRoles.Count() > 1) { await e.SendReplySafe(ErrorTooManyFound); return; } SocketRole role = foundRoles.First(); string message = e.TrimmedMessage.Substring(e.TrimmedMessage.IndexOf(e.MessageArgs[1])); await role.ModifyAsync(r => r.Mentionable = true); await Task.Delay(100); await e.SendReplySafe($"{role.Mention} {message}", allowedMentions : new AllowedMentions(AllowedMentionTypes.Users | AllowedMentionTypes.Everyone | AllowedMentionTypes.Roles)); await Task.Delay(100); await role.ModifyAsync(r => r.Mentionable = false); }; commands.Add(newCommand); commands.Add(newCommand.CreateAlias("announce")); // !cheatsheet newCommand = new Command("cheatsheet"); newCommand.Type = CommandType.Standard; newCommand.Description = "Send an embed cheatsheet with various moderation commands."; newCommand.ManPage = new ManPage("", ""); newCommand.RequiredPermissions = PermissionType.ServerOwner | PermissionType.Admin; newCommand.OnExecute += async e => { EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.WithTitle("Moderation commands").WithColor(16711816).WithFields( new EmbedFieldBuilder().WithName($"`{e.Server.Config.CommandPrefix}op`").WithValue("Distinguish yourself as a moderator when addressing people, and allow the use of `!mute`, `!kick` & `!ban` commands."), new EmbedFieldBuilder().WithName($"`{e.Server.Config.CommandPrefix}mute @user(s) duration`").WithValue("Mute mentioned user(s) for `duration` (use `m`, `h` and `d`, e.g. 1h15m. This will effectively move them to the `#chill-zone` channel."), new EmbedFieldBuilder().WithName($"`{e.Server.Config.CommandPrefix}kick @user(s) reason`").WithValue("Kick mentioned `@users` (or IDs) with specific `reason`."), new EmbedFieldBuilder().WithName($"`{e.Server.Config.CommandPrefix}ban @user(s) duration reason`").WithValue("Ban mentioned `@users` (or IDs) for `duration` (use `h` and `d`, e.g. 1d12h, or zero `0d` for permanent) with specific `reason`."), new EmbedFieldBuilder().WithName("`reason`").WithValue("Reason parameter of the above `kick` and `ban` commands is stored in the database as a _warning_ and also PMed to the user. Please provide proper descriptions."), new EmbedFieldBuilder().WithName($"`{e.Server.Config.CommandPrefix}issueWarning @user(s) message`").WithValue("The same as `addWarning`, but also PM this message to the user(s)"), new EmbedFieldBuilder().WithName($"`{e.Server.Config.CommandPrefix}addWarning @user(s) message`").WithValue("Add a `message` to the database, taking notes of peoples naughty actions."), new EmbedFieldBuilder().WithName($"`{e.Server.Config.CommandPrefix}removeWarning @user`").WithValue("Remove the last added warning from the `@user` (or ID)"), new EmbedFieldBuilder().WithName($"`{e.Server.Config.CommandPrefix}whois @user`").WithValue("Search for a `@user` (or ID, or name) who is present on the server."), new EmbedFieldBuilder().WithName($"`{e.Server.Config.CommandPrefix}find expression`").WithValue("Search for a user using more complex search through all the past nicknames, etc... This will also go through people who are not on the server anymore."), new EmbedFieldBuilder().WithName($"`whois/find`").WithValue("Both whois and find commands will return information about the user, when was their account created, when did they join, their past names and nicknames, and all the previous warnings and bans.") ); RestUserMessage msg = await e.Channel.SendMessageAsync(embed : embedBuilder.Build()); await msg.PinAsync(); embedBuilder = new EmbedBuilder(); embedBuilder.WithTitle("Moderation guidelines").WithColor(16711816).WithDescription("for implementing the [theory](http://rhea-ayase.eu/articles/2017-04/Moderation-guidelines) in real situations.\n") .WithFields( new EmbedFieldBuilder().WithName("__Talking to people__").WithValue("~"), new EmbedFieldBuilder().WithName("Don't use threats.").WithValue("a) **Imposed consequences** - what you can do with your power (kick, ban,...) These are direct threats, avoid them.\nb) **Natural consequences** - implied effects of members actions. These can include \"the community is growing to dislike you,\" or \"see you as racist,\" etc..."), new EmbedFieldBuilder().WithName("Identify what is the underlying problem.").WithValue("a) **Motivation problem** - the member is not motivated to behave in acceptable manner - is a troll or otherwise enjoys being mean to people.\nb) **Ability problem** - the member may be direct without \"filters\" and their conversation often comes off as offensive while they just state things the way they see them: http://www.mit.edu/~jcb/tact.html"), new EmbedFieldBuilder().WithName("Conversation should follow:").WithValue("1) **Explain** the current situation / problem.\n2) **Establish safety** - you're not trying to ban them or discourage them from participating.\n3) **Call to action** - make sure to end the conversation with an agreement about what steps will be taken towards improvement.\n"), new EmbedFieldBuilder().WithName("__Taking action__").WithValue("~"), new EmbedFieldBuilder().WithName("Always log every action").WithValue("with `warnings`, and always check every member and their history."), new EmbedFieldBuilder().WithName("Contents of our channels should not be disrespectful towards anyone, think about minorities.").WithValue("a) Discussion topic going wild, the use of racial/homophobic or other improper language should be pointed out with an explanation that it is not cool towards minorities within our community.\nb) A member being plain disrespectful on purpose... Mute them, see their reaction to moderation talk and act on it."), new EmbedFieldBuilder().WithName("Posting or even spamming inappropriate content").WithValue("should result in immediate mute and only then followed by explaining correct behavior based on all of the above points."), new EmbedFieldBuilder().WithName("Repeated offense").WithValue("a) 1d ban, 3d ban, 7d ban - are your options depending on how severe it is.\nb) Permanent ban should be brought up for discussion with the rest of the team."), new EmbedFieldBuilder().WithName("Member is disrespectful to the authority.").WithValue("If you get into conflict yourself, someone is disrespectful to you as a moderator, trolling and challenging your authority - step back and ask for help, mention `@Staff` in the mod channel, and let 3rd party deal with it.") ); msg = await e.Channel.SendMessageAsync(embed : embedBuilder.Build()); await msg.PinAsync(); }; commands.Add(newCommand); // !embed newCommand = new Command("embed"); newCommand.Type = CommandType.Standard; newCommand.Description = "Build an embed. Use without arguments for help."; newCommand.ManPage = new ManPage("<options>", "Use any combination of:\n" + "`--channel ` - Channel where to send the embed.\n" + "`--edit <msgId>` - Replace a MessageId with a new embed (use after --channel)\n" + "`--title ` - Title\n" + "`--description ` - Description\n" + "`--footer ` - Footer\n" + "`--color ` - #rrggbb hex color used for the embed stripe.\n" + "`--image ` - URL of a Hjuge image in the bottom.\n" + "`--thumbnail ` - URL of a smol image on the side.\n" + "`--fieldName ` - Create a new field with specified name.\n" + "`--fieldValue ` - Text value of a field - has to follow a name.\n" + "`--fieldInline ` - Use to set the field as inline.\n" + "Where you can repeat the field* options multiple times."); newCommand.RequiredPermissions = PermissionType.ServerOwner | PermissionType.Admin; newCommand.OnExecute += async e => { await this.Client.SendEmbedFromCli(e); }; commands.Add(newCommand); // !addEmoji newCommand = new Command("addEmoji"); newCommand.Type = CommandType.Standard; newCommand.Description = "Add an emoji reaction to a message."; newCommand.ManPage = new ManPage("<messageId> <emojis>", "`<messageId>` - ID of the message (in the current channel)\n\n`<emojis>` - Emojis that will be added as a reaction."); newCommand.RequiredPermissions = PermissionType.ServerOwner | PermissionType.Admin; newCommand.OnExecute += async e => { if (e.MessageArgs == null || e.MessageArgs.Length < 2 || !guid.TryParse(e.MessageArgs[0], out guid messageId)) { await e.SendReplySafe("Invalid parameters:\n" + e.Command.ManPage.ToString(e.Server.Config.CommandPrefix + e.CommandId)); return; } List <IEmote> emotes = new List <IEmote>(); for (int i = 1; i < e.MessageArgs.Length; i++) { if (Emote.TryParse(e.MessageArgs[i], out Emote emote)) { emotes.Add(emote); } else { emotes.Add(new Emoji(e.MessageArgs[i])); } } if (!emotes.Any()) { await e.SendReplySafe("No emotes found:\n" + e.Command.ManPage.ToString(e.Server.Config.CommandPrefix + e.CommandId)); return; } string response = "K."; try { IMessage msg = await e.Channel.GetMessageAsync(messageId); switch (msg) { case RestUserMessage message: await message.AddReactionsAsync(emotes.ToArray()); break; case SocketUserMessage message: await message.AddReactionsAsync(emotes.ToArray()); break; default: response = "Failed to fetch a message with that ID. Did you use this command in a correct channel?"; break; } } catch (Exception) { response = "You've dun goof'd, eh?"; } await e.SendReplySafe(response); }; commands.Add(newCommand); return(commands); }
private async Task MessageReceived(SocketMessage arg) { if (!sentMessages.Contains(arg) && arg.Author.Id != _c.CurrentUser.Id) { sentMessages.Add(arg); if (arg.Channel.Id == 759102103200989254) { string content = arg.Content; await arg.DeleteAsync(); int section; if (int.TryParse(content, out section)) { if (section <= 72 && section >= 2 && section % 10 != 0) { bool found = false; foreach (SocketRole role in _c.GetGuild(759101634948890645).Roles) { if (role.Name == "Lab " + section) { found = true; } } if (!found) { Log("Role doesn't exist for section " + section + ", creating..."); RestRole role = await _c.GetGuild(759101634948890645).CreateRoleAsync("Lab " + section, null, null, false, null); Log("Created role with id " + role.Id); await(arg.Author as IGuildUser).AddRoleAsync(role); Log("Adding " + role.Name + " to " + arg.Author.Username); // Check for already-existing channel. If there isn't one, create one. found = false; foreach (ITextChannel channel in _c.GetGuild(759101634948890645).TextChannels) { if (channel.Name == "lab-" + section) { found = true; } } if (!found) { RestTextChannel tc = await _c.GetGuild(759101634948890645).CreateTextChannelAsync("lab-" + section, (a) => { a.CategoryId = 759102041309708370; }); RestVoiceChannel vc = await _c.GetGuild(759101634948890645).CreateVoiceChannelAsync("- Lab " + section + " -", (a) => { a.CategoryId = 759102041309708370; }); OverwritePermissions allow_perms = new OverwritePermissions(connect: PermValue.Allow, viewChannel: PermValue.Allow, sendMessages: PermValue.Allow, readMessageHistory: PermValue.Allow, speak: PermValue.Allow); OverwritePermissions deny_perms = new OverwritePermissions(connect: PermValue.Deny, viewChannel: PermValue.Deny, sendMessages: PermValue.Deny, readMessageHistory: PermValue.Deny, speak: PermValue.Deny); await vc.AddPermissionOverwriteAsync(role, allow_perms); await vc.AddPermissionOverwriteAsync(_c.GetGuild(759101634948890645).EveryoneRole, deny_perms); await tc.AddPermissionOverwriteAsync(role, allow_perms); await tc.AddPermissionOverwriteAsync(_c.GetGuild(759101634948890645).EveryoneRole, deny_perms); } } foreach (SocketRole role in _c.GetGuild(759101634948890645).Roles) { if (role.Name.ToLower().Contains("lab ") && role.Name != "Lab " + section) { await(arg.Author as IGuildUser).RemoveRoleAsync(role); } else if (role.Name.ToLower() == "student") { await(arg.Author as IGuildUser).AddRoleAsync(role); Log("Adding " + role.Name + " to " + arg.Author.Username); } else if (role.Name == "Lab " + section) { await(arg.Author as IGuildUser).AddRoleAsync(role); Log("Adding " + role.Name + " to " + arg.Author.Username); // Check for already-existing channel. If there isn't one, create one. found = false; foreach (ITextChannel channel in _c.GetGuild(759101634948890645).TextChannels) { if (channel.Name == "lab-" + section) { found = true; } } if (!found) { RestTextChannel tc = await _c.GetGuild(759101634948890645).CreateTextChannelAsync("lab-" + section, (a) => { a.CategoryId = 759102041309708370; }); RestVoiceChannel vc = await _c.GetGuild(759101634948890645).CreateVoiceChannelAsync("- Lab " + section + " -", (a) => { a.CategoryId = 759102041309708370; }); OverwritePermissions allow_perms = new OverwritePermissions(connect: PermValue.Allow, viewChannel: PermValue.Allow, sendMessages: PermValue.Allow, readMessageHistory: PermValue.Allow, speak: PermValue.Allow); OverwritePermissions deny_perms = new OverwritePermissions(connect: PermValue.Deny, viewChannel: PermValue.Deny, sendMessages: PermValue.Deny, readMessageHistory: PermValue.Deny, speak: PermValue.Deny); await vc.AddPermissionOverwriteAsync(role, allow_perms); await vc.AddPermissionOverwriteAsync(_c.GetGuild(759101634948890645).EveryoneRole, deny_perms); await tc.AddPermissionOverwriteAsync(role, allow_perms); await tc.AddPermissionOverwriteAsync(_c.GetGuild(759101634948890645).EveryoneRole, deny_perms); } } } } } } else if (arg.Channel.Id == 762877768315830273) { string content = arg.Content; await arg.DeleteAsync(); int section; if (int.TryParse(content, out section)) { if (section >= 1 && section <= 70 && (section % 10 == 0 || section == 1)) { bool found = false; foreach (SocketRole role in _c.GetGuild(759101634948890645).Roles) { if (role.Name == "Lecture " + section) { found = true; } } if (!found) { Log("Role doesn't exist for section " + section + ", creating..."); RestRole role = await _c.GetGuild(759101634948890645).CreateRoleAsync("Lecture " + section, null, null, false, null); Log("Created role with id " + role.Id); await(arg.Author as IGuildUser).AddRoleAsync(role); Log("Adding " + role.Name + " to " + arg.Author.Username); // Check for already-existing channel. If there isn't one, create one. found = false; foreach (ITextChannel channel in _c.GetGuild(759101634948890645).TextChannels) { if (channel.Topic == "Section " + (section == 1 ? "001" : "0" + section)) { found = true; } } if (!found) { RestTextChannel tc = await _c.GetGuild(759101634948890645).CreateTextChannelAsync("lecture-chat", (a) => { a.CategoryId = 759103059695239240; a.Topic = "Section " + (section == 1 ? "001" : "0" + section); }); RestVoiceChannel vc = await _c.GetGuild(759101634948890645).CreateVoiceChannelAsync("- Lecture Chat (0" + (section == 1 ? "01" : section + "") + ")" + " -", (a) => { a.CategoryId = 759103059695239240; }); OverwritePermissions allow_perms = new OverwritePermissions(connect: PermValue.Allow, viewChannel: PermValue.Allow, sendMessages: PermValue.Allow, readMessageHistory: PermValue.Allow, speak: PermValue.Allow); OverwritePermissions deny_perms = new OverwritePermissions(connect: PermValue.Deny, viewChannel: PermValue.Deny, sendMessages: PermValue.Deny, readMessageHistory: PermValue.Deny, speak: PermValue.Deny); await vc.AddPermissionOverwriteAsync(role, allow_perms); await vc.AddPermissionOverwriteAsync(_c.GetGuild(759101634948890645).EveryoneRole, deny_perms); await tc.AddPermissionOverwriteAsync(role, allow_perms); await tc.AddPermissionOverwriteAsync(_c.GetGuild(759101634948890645).EveryoneRole, deny_perms); } } foreach (SocketRole role in _c.GetGuild(759101634948890645).Roles) { if (role.Name.ToLower().Contains("lecture ") && role.Name != "Lecture " + section) { await(arg.Author as IGuildUser).RemoveRoleAsync(role); } else if (role.Name.ToLower() == "student") { await(arg.Author as IGuildUser).AddRoleAsync(role); Log("Adding " + role.Name + " to " + arg.Author.Username); } else if (role.Name == "Lecture " + section) { await(arg.Author as IGuildUser).AddRoleAsync(role); Log("Adding " + role.Name + " to " + arg.Author.Username); // Check for already-existing channel. If there isn't one, create one. found = false; foreach (ITextChannel channel in _c.GetGuild(759101634948890645).TextChannels) { if (channel.Topic == "Section " + (section == 1 ? "001" : "0" + section)) { found = true; } } if (!found) { RestTextChannel tc = await _c.GetGuild(759101634948890645).CreateTextChannelAsync("lecture-chat", (a) => { a.CategoryId = 759103059695239240; a.Topic = "Section " + (section == 1 ? "001" : "0" + section); }); RestVoiceChannel vc = await _c.GetGuild(759101634948890645).CreateVoiceChannelAsync("- Lecture Chat (0" + (section == 1 ? "01" : section + "") + ")" + " -", (a) => { a.CategoryId = 759103059695239240; }); OverwritePermissions allow_perms = new OverwritePermissions(connect: PermValue.Allow, viewChannel: PermValue.Allow, sendMessages: PermValue.Allow, readMessageHistory: PermValue.Allow, speak: PermValue.Allow); OverwritePermissions deny_perms = new OverwritePermissions(connect: PermValue.Deny, viewChannel: PermValue.Deny, sendMessages: PermValue.Deny, readMessageHistory: PermValue.Deny, speak: PermValue.Deny); await vc.AddPermissionOverwriteAsync(role, allow_perms); await vc.AddPermissionOverwriteAsync(_c.GetGuild(759101634948890645).EveryoneRole, deny_perms); await tc.AddPermissionOverwriteAsync(role, allow_perms); await tc.AddPermissionOverwriteAsync(_c.GetGuild(759101634948890645).EveryoneRole, deny_perms); } } } } } } } }