/******************************************************** * Creates Public Anon Channel * ********************************************************/ public async Task CreatePublicAnonChannel(SocketGuild guild) { var everyoneRole = guild.Roles.FirstOrDefault(x => x.IsEveryone); Console.WriteLine($"Creating PublicChannel for Guild {guild.Name}"); var text = await guild.CreateTextChannelAsync("Anon"); ICategoryChannel category = guild.CategoryChannels.FirstOrDefault(x => x.Id == CatagoryID); //if catagory exits make a new one if (category == null) { category = await guild.CreateCategoryChannelAsync("Anonyomus Channels"); await category.AddPermissionOverwriteAsync(everyoneRole, PermissionsDenyAll); } await text.AddPermissionOverwriteAsync(everyoneRole, PermissionsReadOnly); await text.ModifyAsync(x => x.CategoryId = category.Id); var message = await text.SendMessageAsync($"**Welcome to {guild.Name}'s Anonamus Channel!**\n\n" + "This channel allows all the users on the server to see the anonamous chat without being in it." + "The bot grabs all messages sent by users and sends them to everyone elses channel. " + "Becouse the bot posts the message you don't know who sent the message.\n\n" + "You can view the source code at https://github.com/doc543/AnonBot \n"); await message.PinAsync(); Console.WriteLine("Created Text Channel: " + CatagoryID.ToString()); }
public async Task <RuntimeResult> Setup(int count = 3) { IRole role = Context.Guild.Roles.FirstOrDefault(x => x.Name == TTTService.RoleName); if (role == null) { role = await Context.Guild.CreateRoleAsync(TTTService.RoleName, isMentionable : false); } var existing = Context.Guild.VoiceChannels.Count(x => x.Name.StartsWith("ttt-")); ICategoryChannel category = Context.Guild.CategoryChannels.FirstOrDefault(x => x.Name == "TTT"); if (category == null) { category = await Context.Guild.CreateCategoryChannelAsync("TTT"); await category.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, Program.NoPerms); await category.AddPermissionOverwriteAsync(role, Program.ReadPerms); } for (int i = 0; i < (count * count); i++) { IVoiceChannel vc = Context.Guild.VoiceChannels.FirstOrDefault(x => x.Name.StartsWith($"ttt-{i}")); if (vc == null) { vc = await Context.Guild.CreateVoiceChannelAsync($"ttt-{i}", x => { x.CategoryId = category.Id; }); } var invites = await vc.GetInvitesAsync(); IInvite invite = invites.FirstOrDefault(); if (invite == null) { invite = await vc.CreateInviteAsync(maxAge : null, maxUses : 1, isTemporary : true); } await vc.ModifyAsync(x => x.Name = $"ttt-{i}-{invite.Code}"); } return(Success("Server has been setup for tic tac toe.")); }
public async Task ArchiveProject() { ICategoryChannel ProjectsCategory = CommandHelper.FindCategory(Context.Guild.CategoryChannels, Strings.ProjectCategoryName); ICategoryChannel ArchiveCategory = CommandHelper.FindCategory(Context.Guild.CategoryChannels, Strings.ArchiveCategoryName); if (((ITextChannel)Context.Channel).CategoryId != ProjectsCategory.Id) { await ReplyAsync("This channel is not a project channel!"); return; } if (ArchiveCategory is null) //Create the category { ArchiveCategory = await Context.Guild.CreateCategoryChannelAsync(Strings.ArchiveCategoryName); await ArchiveCategory.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, new OverwritePermissions(sendMessages : PermValue.Deny)); } await((IGuildChannel)Context.Channel).ModifyAsync(delegate(GuildChannelProperties ac) { ac.CategoryId = ArchiveCategory.Id; }); List <ITextChannel> channels = new List <ITextChannel>(Context.Guild.TextChannels); channels.RemoveAll(x => x.CategoryId != ArchiveCategory.Id); channels.Add((ITextChannel)Context.Channel); await CommandHelper.OrderChannels(channels, ArchiveCategory.Id); IRole ProjectRole = CommandHelper.FindRole(Context.Guild.Roles, Context.Channel.Name); IRole ProjectManagerRole = CommandHelper.FindRole(Context.Guild.Roles, $"{Context.Channel.Name}-Manager"); await Context.Guild.GetRole(ProjectRole.Id).DeleteAsync(); await Context.Guild.GetRole(ProjectManagerRole.Id).DeleteAsync(); await ReplyAsync("Archived project and cleared role!"); await((IGuildChannel)Context.Channel).AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, (OverwritePermissions)ArchiveCategory.GetPermissionOverwrite(Context.Guild.EveryoneRole)); }
/* ************************************************************** * Create Anon Channel * 1. Creates a new channgel named after the user * 2. Checks if a catagory is made if not creates one and sets permissions * 4. Sets permissions on channel so the user can only see that channel * 5. Send Welcome message and pins it. * ****************************************************************/ public async Task CreateAnonChannel(SocketGuildUser user) { var everyoneRole = user.Guild.Roles.FirstOrDefault(x => x.IsEveryone); Console.WriteLine($"Creating Channel for {user.Username}! for Guild {user.Guild.Name}"); //create text channel var text = await user.Guild.CreateTextChannelAsync(user.Id.ToString()); //find catagory named whatever ICategoryChannel category = user.Guild.CategoryChannels.FirstOrDefault(x => x.Id == CatagoryID); //if catagory exits make a new one if (category == null) { category = await user.Guild.CreateCategoryChannelAsync("Annoyamus Channels"); await category.AddPermissionOverwriteAsync(everyoneRole, PermissionsDenyAll); } await text.ModifyAsync(x => x.CategoryId = category.Id); await text.AddPermissionOverwriteAsync(everyoneRole, PermissionsDenyAll); await text.AddPermissionOverwriteAsync(user, PermissionsAnnChannel); var msg = await text.SendMessageAsync($"**Welcome {user.Mention} to {user.Guild.Name}!**\n\n" + "Everyone on this server is in a channel by themselves and the bot. " + "The bot grabs all messages sent by users and sends them to everyone elses channel. " + "Becouse the bot posts the message you don't know who sent the message.\n\n" + "This bot does not log anything. You can view the source code at https://github.com/doc543/AnonBot \n" + "Use \"\\help\" - Brings up help text."); await msg.PinAsync(); Console.WriteLine("Created Text Channel: " + CatagoryID.ToString()); }
public async Task Challenge(SocketGuildUser user = null) { // Create SocketGuildUser objects SocketGuildUser author = (Context.Message.Author as SocketGuildUser); // Creating objects string type1, type2; type1 = Convert.ToString(provider.GetFieldAwonaByID("type", Convert.ToString(author.Id), "discord_id", "users")); type2 = Convert.ToString(provider.GetFieldAwonaByID("type", Convert.ToString(user.Id), "discord_id", "users")); Archetype player1 = subcommand.CreateClass(type1, author); Archetype player2 = subcommand.CreateClass(type2, user); // If created successfully if (player1 == null) { await ReplyAsync("Ошибка при создании первого игрока"); return; } else if (player2 == null) { await ReplyAsync("Ошибка при создании второго игрока"); return; } await ReplyAsync(":white_check_mark: Создаю каналы..."); ulong context_id = Context.Channel.Id; ulong channel_id = 823844887787077682; string answer = ""; if (!subcommand.ValidChecker(user, author, ref answer, channel_id, context_id)) { await ReplyAsync(answer); return; } // // Get everyone role, create new role, create permissions, set roles // // Create user name and author name string authorname, username; authorname = Context.Message.Author.Username; username = user.Username; // Create Roles IRole everyone = Context.Guild.EveryoneRole; IRole publicrole = await Context.Guild.CreateRoleAsync($"{authorname}-vs-{username}", null, new Color(0xf5fffa), false, null); IRole firstplayer = await Context.Guild.CreateRoleAsync($"{authorname}#{authorname.Length}", null, new Color(0xf5fffa), false, null); IRole secondplayer = await Context.Guild.CreateRoleAsync($"{username}#{username.Length}", null, new Color(0xf5fffa), false, null); // Create Permissions OverwritePermissions noView = new OverwritePermissions(viewChannel: PermValue.Deny); OverwritePermissions yesView = new OverwritePermissions(viewChannel: PermValue.Allow); // Add roles to first and second player await(Context.User as IGuildUser).AddRoleAsync(publicrole); await(Context.User as IGuildUser).AddRoleAsync(firstplayer); await(user as IGuildUser).AddRoleAsync(publicrole); await(user as IGuildUser).AddRoleAsync(secondplayer); // // Create category, set permissions, create two channels // // Create category and set permissions ICategoryChannel category = await Context.Guild.CreateCategoryChannelAsync($"{authorname}-vs-{username}"); await category.AddPermissionOverwriteAsync(everyone, noView); await category.AddPermissionOverwriteAsync(firstplayer, yesView); await category.AddPermissionOverwriteAsync(secondplayer, yesView); // Create channel 1 ITextChannel authorchannel = await Context.Guild.CreateTextChannelAsync($"{authorname}-challenge"); await authorchannel.AddPermissionOverwriteAsync(everyone, noView); await authorchannel.AddPermissionOverwriteAsync(firstplayer, yesView); await authorchannel.ModifyAsync(x => x.CategoryId = category.Id); // Create channel 2 ITextChannel userchannel = await Context.Guild.CreateTextChannelAsync($"{username}-challenge"); await userchannel.AddPermissionOverwriteAsync(everyone, noView); await userchannel.AddPermissionOverwriteAsync(secondplayer, yesView); await userchannel.ModifyAsync(x => x.CategoryId = category.Id); // // Fight category // // Start message provider.ExecuteSQL($"INSERT INTO duel VALUES (\"{authorname}-vs-{username}\", \"{authorname}\", \"{username}\", {author.Id}, {user.Id}, {authorchannel.Id}, {userchannel.Id}, \"Sleep\", \"Sleep\", {player1.Health}, {player2.Health}, false, false)"); FightHandler fightHandler = new FightHandler(); await fightHandler.StartMessage(author, user, userchannel, authorchannel); await ReplyAsync(":white_check_mark: Бой начат, каналы созданы"); fightHandler.FightLoop(author, user, player1, player2, category, authorchannel, userchannel, publicrole, firstplayer, secondplayer); }
/// <summary> /// Create a Category using the channel using roles provided /// </summary> public static async Task CreateCategory(CommandContext Context, string Category, [Optional] List <Permissions> Roles, [Optional] int?Position) { // Get the list of Categories IReadOnlyCollection <IGuildChannel> categories = await Context.Guild.GetCategoriesAsync(); // Check if the Category exists bool exists = false; ICategoryChannel newcategory = null; foreach (var categoryname in categories) { if (categoryname.Name.ToString().ToLower().Trim() == Category.ToString().ToLower().Trim()) { // If the channel exists exit newcategory = categoryname as ICategoryChannel; exists = true; break; } } // Create the Category if (exists == false) { newcategory = await Context.Guild.CreateCategoryAsync(Category); } // Wait for Category to Generate await Task.Delay(1000); if (newcategory != null) { // Check if we are passing roles if (Roles != null) { // Parse in the roles to add them to the channel foreach (Permissions role in Roles) { // Before we go any further let's see if the role already exists // If the role exists exit the task foreach (Discord.IRole existingrole in Context.Guild.Roles) { // Compare the list of roles in the discord with the Role if (existingrole.Name.ToLower().Trim() == role.Role.ToLower().Trim()) { // Add the selected roles to the channel using inhert as its base await newcategory.AddPermissionOverwriteAsync(existingrole, role.ChannelPermType); break; } } } // Remove the everyone permission if it's not in the list bool permfound = false; foreach (Permissions perm in Roles) { if (perm.Role.ToLower().Contains("everyone") == true) { permfound = true; break; } } if (permfound == false) { foreach (Discord.IRole existingrole in Context.Guild.Roles) { // Compare the list of roles in the discord with the Role if (existingrole.Name.ToLower() == "@everyone") { OverwritePermissions denypermissions = new OverwritePermissions(createInstantInvite: PermValue.Deny, manageChannel: PermValue.Deny, addReactions: PermValue.Deny, viewChannel: PermValue.Deny, sendMessages: PermValue.Deny, sendTTSMessages: PermValue.Deny, manageMessages: PermValue.Deny, embedLinks: PermValue.Deny, attachFiles: PermValue.Deny, readMessageHistory: PermValue.Deny, mentionEveryone: PermValue.Deny, useExternalEmojis: PermValue.Deny, connect: PermValue.Deny, speak: PermValue.Deny, muteMembers: PermValue.Deny, deafenMembers: PermValue.Deny, moveMembers: PermValue.Deny, useVoiceActivation: PermValue.Deny, manageRoles: PermValue.Deny, manageWebhooks: PermValue.Deny); // Remove Everyones permissions await newcategory.AddPermissionOverwriteAsync(existingrole, denypermissions); break; } } } } // Check if a position was provided if (Position != null) { // Update its position await newcategory.ModifyAsync(x => { x.Position = Position.Value; }); } } }