//Begins the application process. async internal static Task Apply(CommandEventArgs e) { Channel userchannel = null; var userchannelList = e.Server.AllChannels.Where(ch => ch.Name == e.User.Name); if (userchannelList.Count() > 0) { userchannel = userchannelList.First(); } if (userchannel != null) { RuntimeStatics.ActiveChannels[userchannel] = 0; await userchannel.DeleteMessages(userchannel.Messages.ToArray()); await BeginApplication(e, userchannel); } else { //why the f**k does this exist var userpermission = new ChannelPermissionOverrides(PermValue.Deny, PermValue.Deny, PermValue.Allow, PermValue.Allow, PermValue.Deny, PermValue.Allow, PermValue.Allow, PermValue.Allow, PermValue.Allow); var everyonepermission = new ChannelPermissionOverrides(PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny); userchannel = await e.Server.CreateChannel(e.User.Name, ChannelType.Text); await userchannel.AddPermissionsRule(e.Server.GetRole(Program.Guild.EveryoneID), everyonepermission); await userchannel.AddPermissionsRule(e.User, userpermission); await userchannel.AddPermissionsRule(e.Server.GetRole(Program.Guild.OfficerID), userpermission); RuntimeStatics.ActiveChannels.Add(userchannel, 0); await Apply(e); } }
public async Task Test_Affect_Permissions_Invalid_Channel() { var channel = await _testServer.CreateChannel($"test_{_random.Next()}", ChannelType.Text); var user = _testServer.GetUser(_targetBot.CurrentUser.Id); var perms = new ChannelPermissionOverrides(sendMessages: PermValue.Deny); await channel.Delete(); await channel.AddPermissionsRule(user, perms); }
public async Task Test_AddGet_PermissionsRule() { var channel = await _testServer.CreateChannel($"test_{_random.Next()}", ChannelType.Text); var user = _testServer.GetUser(_targetBot.CurrentUser.Id); var perms = new ChannelPermissionOverrides(sendMessages: PermValue.Deny); await channel.AddPermissionsRule(user, perms); var resultPerms = channel.GetPermissionsRule(user); Assert.IsNotNull(resultPerms, "Perms retrieved from server were null."); }
public async Task Test_Permissions_Event() { var channel = await _testServer.CreateChannel($"test_{_random.Next()}", ChannelType.Text); var user = _testServer.GetUser(_targetBot.CurrentUser.Id); var perms = new ChannelPermissionOverrides(sendMessages: PermValue.Deny); AssertEvent <ChannelUpdatedEventArgs> ("ChannelUpdatedEvent never fired.", async() => await channel.AddPermissionsRule(user, perms), x => _targetBot.ChannelUpdated += x, x => _targetBot.ChannelUpdated -= x, (s, e) => e.After.PermissionOverwrites.Count() != e.Before.PermissionOverwrites.Count()); }
public async Task Test_AddRemove_PermissionsRule() { var channel = await _testServer.CreateChannel($"test_{_random.Next()}", ChannelType.Text); var user = _testServer.GetUser(_targetBot.CurrentUser.Id); var perms = new ChannelPermissionOverrides(sendMessages: PermValue.Deny); await channel.AddPermissionsRule(user, perms); await channel.RemovePermissionsRule(user); await Task.Delay(200); Assert.AreEqual(PermValue.Inherit, channel.GetPermissionsRule(user).SendMessages); }
private async void parseInput(string input, MessageEventArgs e) { string[] toParse = input.Split(' '); string command = toParse[0]; int inputLen = toParse.Length; Server server = e.Server; if (e.Channel.IsPrivate) { return; } else if (command == "") { return; } else if (inputLen == 1) { if (command == Constants.COMMAND_HELP) { await e.Channel.SendMessage("Testing Testing 1 2 3"); } else if (command == Constants.COMMAND_DEVTESTNEWLINE) { string sentence = "```"; for (int i = 0; i < 5; i++) { sentence += i + ") " + "Satsuo" + "\n"; } sentence += "```"; await e.Channel.SendMessage(sentence); } else if (command == Constants.COMMAND_LISTUSERS) { foreach (Discord.User user in e.Channel.Users) { //TODO: Check for users in a voice channel and only list those await e.Channel.SendMessage(user.ToString()); await user.SendMessage("Will this work?"); } } else if (command == Constants.COMMAND_GITHUB) { await e.Channel.SendMessage(Constants.URL_GITHUB); } else if (command == Constants.COMMAND_LISTSERVERSWITHGAMES) { if (!PartyGames.Any()) { await e.Channel.SendMessage("No server is running a game right now!"); } else { for (int i = 0; i < PartyGames.Count(); i++) { Game game = PartyGames.ElementAt(i); await e.Channel.SendMessage("Server " + game.getGameServerID().ToString() + " running game type " + game.getGameType() + " on text channel " + game.getTextChannelID().ToString() + " and on voice channel " + game.getVoiceChannelID().ToString()); } } } else if (command == Constants.COMMAND_JOINPARTYGAME) { Game game = ServerStartingGame(server); if (game != null) { if (game.playerAlreadyJoined(e.User)) { await e.Channel.SendMessage(SystemMessages.MESSAGE_GAMEALREADYJOINED); } else { bool added = await addToRole(game.getPlayerRole(), e.User, e); if (added) { game.addPlayer(e.User); await e.Channel.SendMessage(e.User.NicknameMention + " has joined the " + game.getGameType() + " game. Click " + client.GetChannel(game.getTextChannelID()).Mention + " to enter the text channel."); } } } else { await e.Channel.SendMessage(SystemMessages.MESSAGE_GAMESTARTEDORNONE); } } else if (command == Constants.COMMAND_LEAVEPARTYGAME) { Game game = ServerStartingGame(server); if (game != null) { if (game.playerAlreadyJoined(e.User)) { game.removePlayer(e.User); await e.Channel.SendMessage(e.User.NicknameMention + " has left the " + game.getGameType() + " game."); } else { await e.Channel.SendMessage("You haven't even joined the game!"); } } else { await e.Channel.SendMessage(SystemMessages.MESSAGE_GAMESTARTEDNOLEAVE); } } else if (commandRollDice(command)) { string value = command.Remove(0, 2); if (isValidDiceRoll(value)) { int rollValue = getDiceRoll(value); await e.Channel.SendMessage(e.User.Mention + " rolled a d" + value + " and got: " + rollValue); return; } else { await e.Channel.SendMessage("USAGE: !d#, where # is between 1-" + Int32.MaxValue + "."); return; } } //The Secret Santa module else if (command == Constants.COMMAND_STARTSECRETSANTA) { if (secretSanta == null) { secretSanta = new SecretSanta(server, client); await e.Channel.SendMessage("The Secret Santa module has been initialized!"); } } } else if (inputLen > 1) { if (command == Constants.COMMAND_SETGAME) { string game = input.Remove(0, Constants.COMMAND_SETGAME.Length + 1); client.SetGame(game); } else if (command == Constants.COMMAND_CREATECHANNEL) { string channelname = input.Remove(0, Constants.COMMAND_CREATECHANNEL.Length + 1); await createNewChannel(channelname, ChannelType.Text, e); } else if (command == Constants.COMMAND_TTS) { string message = input.Remove(0, Constants.COMMAND_TTS.Length + 1); await e.Channel.SendTTSMessage(message); } else if (command == Constants.COMMAND_SETROLE) { string rolename = input.Remove(0, Constants.COMMAND_SETROLE.Length + 1); ServerPermissions permissions = new ServerPermissions(true); try { await addToRole(rolename, permissions, e.User, e); } catch (Exception) { return; } } else if (command == Constants.COMMAND_STARTDND) { if (!isHostingGame) { Discord.Channel text, voice = null; Discord.Role gamerole = null; string channelname = input.Remove(0, Constants.COMMAND_STARTDND.Length + 1); ServerPermissions permissions = new ServerPermissions(); gamerole = await addToRole(Constants.GAME_DNDGAME, permissions, e.User, e); if (gamerole != null) { text = await createNewChannel(channelname, ChannelType.Text, e); if (text != null) { isHostingGame = true; voice = await createNewChannel(channelname + " Voice", ChannelType.Voice, e); ChannelPermissionOverrides memberPermOverride = new ChannelPermissionOverrides(PermValue.Deny, PermValue.Deny, PermValue.Allow, PermValue.Allow, PermValue.Allow, PermValue.Deny, PermValue.Allow, PermValue.Deny, PermValue.Allow, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny); ChannelPermissionOverrides everyonePermOverride = new ChannelPermissionOverrides(PermValue.Deny, PermValue.Deny, PermValue.Allow, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny); await text.AddPermissionsRule(gamerole, memberPermOverride); await text.AddPermissionsRule(e.Server.EveryoneRole, everyonePermOverride); Game DnDGame = new DnDGame(server, text, voice, e.Channel, gamerole, client, e.User.Id); DnDGame.addPlayer(e.User); PartyGames.Add(DnDGame); await setChannelToTop(text); await setChannelToTop(voice); await e.Channel.SendMessage(DnDGame.getGameType() + SystemMessages.MESSAGE_GAMECREATED + text.Mention); Console.WriteLine("Game was created at server: " + server.Id); } else { await gamerole.Delete(); } } } else { Console.WriteLine(SystemMessages.MESSAGE_GAMEHASSTARTED); } } else if (command == Constants.COMMAND_STARTRESISTANCE) { bool createGame = false; if (!PartyGames.Any()) { createGame = true; } Game game = null; if (!createGame && PartyGames.Any()) { int i = 0; bool found = false; while (i < PartyGames.Count()) { game = PartyGames.ElementAt(i); if (game.getGameServerID() == server.Id) { found = true; } i++; } createGame = found ? false : true; } if (createGame && !isHostingGame) { Discord.Channel text, voice = null; Discord.Role gamerole = null; string channelname = input.Remove(0, Constants.COMMAND_STARTRESISTANCE.Length + 1); ServerPermissions permissions = new ServerPermissions(); gamerole = await addToRole(Constants.GAME_RESISTANCE, permissions, e.User, e); if (gamerole != null) { text = await createNewChannel(channelname, ChannelType.Text, e); if (text != null) { isHostingGame = true; voice = await createNewChannel(channelname + " Voice", ChannelType.Voice, e); ChannelPermissionOverrides memberPermOverride = new ChannelPermissionOverrides(PermValue.Deny, PermValue.Deny, PermValue.Allow, PermValue.Allow, PermValue.Allow, PermValue.Deny, PermValue.Allow, PermValue.Deny, PermValue.Allow, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny); ChannelPermissionOverrides everyonePermOverride = new ChannelPermissionOverrides(PermValue.Deny, PermValue.Deny, PermValue.Allow, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny, PermValue.Deny); await text.AddPermissionsRule(gamerole, memberPermOverride); await text.AddPermissionsRule(e.Server.EveryoneRole, everyonePermOverride); Game resistanceGame = new ResistanceGame(server, text, voice, e.Channel, gamerole, client, e.User.Id); resistanceGame.addPlayer(e.User); PartyGames.Add(resistanceGame); await setChannelToTop(text); await setChannelToTop(voice); await e.Channel.SendMessage(resistanceGame.getGameType() + SystemMessages.MESSAGE_GAMECREATED + text.Mention); Console.WriteLine("Game was created at server: " + server.Id); } else { await gamerole.Delete(); } } } else { Console.WriteLine(SystemMessages.MESSAGE_GAMEHASSTARTED); } } else if (command == Constants.COMMAND_FLOODMESSAGE) { int repeat; if (Int32.TryParse(toParse[1], out repeat)) { string message = input.Remove(0, Constants.COMMAND_FLOODMESSAGE.Length + toParse[1].Length + 2); for (int i = 0; i < repeat; i++) { await e.Channel.SendMessage(message); } } else { await e.Channel.SendMessage("Invalid use of command, nerd"); } } } if (Constants.TESTBUILD) { await e.Channel.SendMessage("Length of input: " + inputLen); } }
static async Task AddRoomCmd(CommandEventArgs args) { bool isSecret; string privacyArg = args.GetArg("privacy"); string roomName = args.GetArg("roomName"); if (privacyArg == null || privacyArg == "public") { isSecret = false; } else if (privacyArg == "secret") { isSecret = true; } else { await args.Channel.SendMessage("L'argument \"privacy\" doit être soit \"public\" ou \"secret\""); return; } if (roomName == null) { await args.Channel.SendMessage("Vous devez spécifier un nom."); } else { Role botRole = null; Role everyoneRole = args.Server.EveryoneRole; ChannelPermissionOverrides botPermission = new ChannelPermissionOverrides( readMessages: PermValue.Allow, sendMessages: PermValue.Allow, manageChannel: PermValue.Allow ); ChannelPermissionOverrides notAllowedPermission = new ChannelPermissionOverrides( readMessages: PermValue.Deny ); foreach (Role r in args.Server.Roles) { if (r.Name == "Bot") { botRole = r; break; } } if (botRole == null) { throw new Exception("Le rôle de Bot n'a pas été trouvé"); } Channel newChannel = await args.Server.CreateChannel(roomName, ChannelType.Text); await newChannel.AddPermissionsRule(botRole, botPermission); await newChannel.AddPermissionsRule(args.User, botPermission); BotDebug.Log("Le channel " + roomName + " à été créé par " + args.User.Name, "ServerManagement", ConsoleColor.Yellow); if (isSecret) { await newChannel.AddPermissionsRule(everyoneRole, notAllowedPermission); } await newChannel.SendMessage(args.User.Mention + ", votre nouveau salon à été créé, vous pouvez en modifier les permissions.\n" + "Prenez notes que les administrateurs ont toujours accès à ce salon."); } }
public static Task SetChannelPermissions(this DiscordClient client, Channel channel, Role role, ChannelPermissionOverrides permissions) { if (channel == null) { throw new ArgumentNullException(nameof(channel)); } return(channel.AddPermissionsRule(role, permissions)); }
public static Task SetChannelPermissions(this DiscordClient client, Channel channel, Role role, ChannelPermissionOverrides permissions) { if (channel == null) throw new ArgumentNullException(nameof(channel)); return channel.AddPermissionsRule(role, permissions); }