public Task SetChannelPermissions(Channel channel, Role role, ChannelPermissions allow = null, ChannelPermissions deny = null) { if (channel == null) throw new ArgumentNullException(nameof(channel)); if (role == null) throw new ArgumentNullException(nameof(role)); CheckReady(); return SetChannelPermissions(channel, role?.Id, PermissionTarget.Role, allow, deny); }
public Task SetChannelPermissions(Channel channel, Role role, DualChannelPermissions permissions = null) { if (channel == null) throw new ArgumentNullException(nameof(channel)); if (role == null) throw new ArgumentNullException(nameof(role)); CheckReady(); return SetChannelPermissions(channel, role?.Id, PermissionTarget.Role, permissions?.Allow, permissions?.Deny); }
public Task RemoveChannelPermissions(Channel channel, Role role) { if (channel == null) throw new ArgumentNullException(nameof(channel)); if (role == null) throw new ArgumentNullException(nameof(role)); CheckReady(); return RemoveChannelPermissions(channel, role?.Id, PermissionTarget.Role); }
private async Task <bool> addToRole(Discord.Role role, Discord.User target, MessageEventArgs e) { try { await target.AddRoles(role); } catch (Exception) { await e.Channel.SendMessage(SystemMessages.MESSAGE_ROLESETEXCEPTION); return(true); } return(true); }
private async Task <Discord.Role> addToRole(string roleName, ServerPermissions permissions, Discord.User target, MessageEventArgs e) { Discord.Role newrole = null; try { newrole = await e.Server.CreateRole(roleName, permissions); await target.AddRoles(newrole); } catch (Exception) { await newrole.Delete(); await e.Channel.SendMessage(SystemMessages.MESSAGE_ROLESETEXCEPTION); return(null); } return(newrole); }
public void GetMasteryPoints() { commands.CreateCommand("Mastery") .Do(async(e) => { string returnstring = ""; SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext()); Summoner summoner = null; try { DataLibary.Models.User user = new UserRepo(new UserContext()).GetUserByDiscord(e.User.Id); summoner = new SummonerAPI().GetSummoner( new SummonerRepo(new SummonerContext()).GetSummonerByUserId(user), ToolKit.LeagueAndDatabase.GetRegionFromDatabaseId( new RegionRepo(new RegionContext()).GetRegionId(user) )); } catch { } if (settingsRepo.MasteryPointsByAccount(e.Server.Id)) { if (summoner != null) { int points = new MasteryAPI().GetPoints(summoner, new ChampionAPI().GetChampion(settingsRepo.GetChampionId(e.Server.Id), RiotSharp.Region.eune)); Discord.Role r = e.Server.GetRole(settingsRepo.GetRoleByPoints(e.Server.Id, points)); await e.User.AddRoles(r); returnstring = Eng_Default.RoleHasBeenGiven(r.Name); } else { returnstring = Eng_Default.RegisterAccount(); } } else { returnstring = Eng_Default.ServerDoesNotAllow(); } await e.Channel.SendMessage(returnstring); }); }
public void UniversalRole() { commands.CreateCommand("Roles") .Parameter("Parameter", ParameterType.Unparsed) .Do(async(e) => { string returnstring; ServerRepo serverRepo = new ServerRepo(new ServerContext()); SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext()); if (serverRepo.IsServerVerified(e.Server.Id)) { try { Discord.Role r = RoleSearch(e.Server, e.GetArg("Parameter").ToLower()); if (!settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id)) { await e.User.AddRoles(r); returnstring = Eng_Default.RoleHasBeenGiven(r.Name); } else { returnstring = Eng_Default.RoleHasBeenDisabled(); } } catch { returnstring = Eng_Default.RoleNotFound(e.GetArg("Parameter")); } } else { returnstring = Eng_Default.ServerIsNotVerified(); } await e.Channel.SendMessage(returnstring); }); }
public bool CanRun(Command command, User user, Channel channel, out string error) { error = String.Empty; if (NadekoBot.IsUserBlacklisted(user.Id) || (!channel.IsPrivate && (NadekoBot.IsServerBlacklisted(channel.Server.Id) || NadekoBot.IsChannelBlacklisted(channel.Id)))) { return(false); } if (timeBlackList.ContainsKey(user)) { return(false); } if (channel.IsPrivate) { return(false); } timeBlackList.TryAdd(user, DateTime.Now); try { //is it a permission command? // if it is, check if the user has the correct role // if yes return true, if no return false if (command.Category == "Permissions") { Discord.Role role = null; try { role = PermissionHelper.ValidateRole(user.Server, PermissionsHandler.GetServerPermissionsRoleName(user.Server)); } catch { } if (user.Server.Owner.Id == user.Id || (role != null && user.HasRole(role))) { return(true); } ServerPermissions perms; PermissionsHandler.PermissionsDict.TryGetValue(user.Server.Id, out perms); throw new Exception($"You don't have the necessary role (**{(perms?.PermissionsControllerRole ?? "Nadeko")}**) to change permissions."); } var permissionType = PermissionsHandler.GetPermissionBanType(command, user, channel); string msg; switch (permissionType) { case PermissionsHandler.PermissionBanType.None: return(true); case PermissionsHandler.PermissionBanType.ServerBanCommand: msg = $"**{command.Text}** command has been banned from use on this **server**."; break; case PermissionsHandler.PermissionBanType.ServerBanModule: msg = $"**{command.Category}** module has been banned from use on this **server**."; break; case PermissionsHandler.PermissionBanType.ChannelBanCommand: msg = $"**{command.Text}** command has been banned from use on this **channel**."; break; case PermissionsHandler.PermissionBanType.ChannelBanModule: msg = $"**{command.Category}** module has been banned from use on this **channel**."; break; case PermissionsHandler.PermissionBanType.RoleBanCommand: msg = $"You do not have a **role** which permits you the usage of **{command.Text}** command."; break; case PermissionsHandler.PermissionBanType.RoleBanModule: msg = $"You do not have a **role** which permits you the usage of **{command.Category}** module."; break; case PermissionsHandler.PermissionBanType.UserBanCommand: msg = $"{user.Mention}, You have been banned from using **{command.Text}** command."; break; case PermissionsHandler.PermissionBanType.UserBanModule: msg = $"{user.Mention}, You have been banned from using **{command.Category}** module."; break; default: return(true); } if (PermissionsHandler.PermissionsDict[user.Server.Id].Verbose) //if verbose - print errors { error = msg; } return(false); } catch (Exception ex) { if (PermissionsHandler.PermissionsDict[user.Server.Id].Verbose) //if verbose - print errors { error = ex.Message; } return(false); } }
internal Role Clone() { var result = new Role(); _cloner(this, result); return result; }
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); } }
public RoleEventArgs(Role role) { Role = role; }
public void AddObject(Discord.Role role) { Role = role; }
internal RoleEventArgs(Role role) { Role = role; }
public Task RemoveChannelRolePermissions(Channel channel, Role role) => RemoveChannelPermissions(channel, role?.Id, PermissionTarget.Role);
public Task RemoveChannelRolePermissions(string channelId, Role role) => RemoveChannelPermissions(_channels[channelId], role?.Id, PermissionTarget.Role);
public Task SetChannelRolePermissions(Channel channel, Role role, PackedChannelPermissions allow = null, PackedChannelPermissions deny = null) => SetChannelPermissions(channel, role?.Id, PermissionTarget.Role, allow, deny);
public Task SetChannelRolePermissions(string channelId, Role role, PackedChannelPermissions allow = null, PackedChannelPermissions deny = null) => SetChannelPermissions(_channels[channelId], role?.Id, PermissionTarget.Role, allow, deny);
public static void SetRoleCommandPermission(Role role, string commandName, bool value) { var server = role.Server; if (!_permissionsDict.ContainsKey(server)) { _permissionsDict.TryAdd(server, new ServerPermissions(server.Id, server.Name)); } if (!_permissionsDict[server].RolePermissions.ContainsKey(role.Id)) _permissionsDict[server].RolePermissions.Add(role.Id, new Permissions(role.Name)); var commands = _permissionsDict[server].RolePermissions[role.Id].commands; if (commands.ContainsKey(commandName)) commands[commandName] = value; else commands.Add(commandName, value); WriteServerToJson(server); }
public static void SetRoleModulePermission(Role role, string moduleName, bool value) { var server = role.Server; if (!_permissionsDict.ContainsKey(server)) { _permissionsDict.TryAdd(server, new ServerPermissions(server.Id, server.Name)); } if (!_permissionsDict[server].RolePermissions.ContainsKey(role.Id)) _permissionsDict[server].RolePermissions.Add(role.Id, new Permissions(role.Name)); var modules = _permissionsDict[server].RolePermissions[role.Id].modules; if (modules.ContainsKey(moduleName)) modules[moduleName] = value; else modules.Add(moduleName, value); WriteServerToJson(server); }
public bool HasRole(Role role) { if (role == null) throw new ArgumentNullException(nameof(role)); return _roles.ContainsKey(role.Id); }
public Task EditRole(Role role, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null) => EditRole(role.ServerId, role.Id, name: name, permissions: permissions, color: color, hoist: hoist, position: position);
internal void Update(APIMessage model) { var channel = Channel; var server = channel.Server; if (model.Attachments != null) { Attachments = model.Attachments .Select(x => new Attachment() { Id = x.Id, Url = x.Url, ProxyUrl = x.ProxyUrl, Width = x.Width, Height = x.Height, Size = x.Size, Filename = x.Filename }) .ToArray(); } if (model.Embeds != null) { Embeds = model.Embeds.Select(x => { EmbedLink author = null, provider = null; File thumbnail = null; if (x.Author != null) author = new EmbedLink { Url = x.Author.Url, Name = x.Author.Name }; if (x.Provider != null) provider = new EmbedLink { Url = x.Provider.Url, Name = x.Provider.Name }; if (x.Thumbnail != null) thumbnail = new File { Url = x.Thumbnail.Url, ProxyUrl = x.Thumbnail.ProxyUrl, Width = x.Thumbnail.Width, Height = x.Thumbnail.Height }; return new Embed { Url = x.Url, Type = x.Type, Title = x.Title, Description = x.Description, Author = author, Provider = provider, Thumbnail = thumbnail }; }).ToArray(); } if (model.IsTextToSpeech != null) IsTTS = model.IsTextToSpeech.Value; if (model.Timestamp != null) Timestamp = model.Timestamp.Value; if (model.EditedTimestamp != null) EditedTimestamp = model.EditedTimestamp; if (model.Mentions != null) { MentionedUsers = model.Mentions .Select(x => Channel.GetUser(x.Id)) .Where(x => x != null) .ToArray(); } if (model.IsMentioningEveryone != null) { if (model.IsMentioningEveryone.Value && User != null && User.GetPermissions(channel).MentionEveryone) MentionedRoles = new Role[] { Server.EveryoneRole }; else MentionedRoles = new Role[0]; } if (model.Content != null) { string text = model.Content; RawText = text; //var mentionedUsers = new List<User>(); var mentionedChannels = new List<Channel>(); //var mentionedRoles = new List<Role>(); text = CleanUserMentions(Channel, text/*, mentionedUsers*/); if (server != null) { text = CleanChannelMentions(Channel, text, mentionedChannels); //text = CleanRoleMentions(_client, User, channel, text, mentionedRoles); } Text = text; //MentionedUsers = mentionedUsers; MentionedChannels = mentionedChannels; //MentionedRoles = mentionedRoles; } }
private void RaiseRoleUpdated(Role role) { if (_config.EnableDebug) RaiseOnDebugMessage(DebugMessageType.Event, $"RoleUpdated {role.Name} ({role.Id}) in {role.Server?.Name} ({role.ServerId})"); if (RoleUpdated != null) RoleUpdated(this, new RoleEventArgs(role)); }
private void RaiseRoleUpdated(Role role) { if (RoleUpdated != null) RaiseEvent(nameof(RoleUpdated), () => RoleUpdated(this, new RoleEventArgs(role))); }
internal void AddRole(Role role) { if (_roles.TryAdd(role.Id, role)) { if (role.Id == Id) EveryoneRole = role; } }
public Discord.Role RoleSearch(Discord.Server server, string parameter) { Discord.Role r = null; SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext()); if (settingsRepo.RankByParameter(server.Id) == true) { List <string> filter = new List <string>(); if (settingsRepo.RankCommandType(server.Id) == CommandType.Basic) { filter = Ranks.BasicRanks(); } else if (settingsRepo.RankCommandType(server.Id) == CommandType.PerQueue) { filter = Ranks.QueueRanks(); } foreach (string rank in filter) { if (parameter.ToLower() == rank.ToLower()) { try { return(server.GetRole(settingsRepo.GetOverride(rank, server.Id))); } catch { return(server.FindRoles(rank, false).First()); } } } } if (settingsRepo.RoleByParameter(server.Id)) { List <string> filter = new List <string>(); if (settingsRepo.RoleCommandType(server.Id) == CommandType.Basic) { filter = DataLibary.Models.Roles.NormalRoles(); } else if (settingsRepo.RoleCommandType(server.Id) == CommandType.Main) { filter = DataLibary.Models.Roles.MainRoles(); } else if (settingsRepo.RoleCommandType(server.Id) == CommandType.Mains) { filter = DataLibary.Models.Roles.MainsRoles(); } foreach (string role in filter) { if (role.ToLower().Contains(parameter.ToLower())) { try { ulong id = settingsRepo.GetOverride(role.ToLower(), server.Id); r = server.GetRole(id); if (r == null) { throw new Exception(); } } catch { return(server.FindRoles(role, false).First()); } } } } if (settingsRepo.RegionByParameter(server.Id)) { foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions()) { if (parameter.ToLower() == region.ToLower()) { try { return(server.GetRole(settingsRepo.GetOverride(region.ToLower(), server.Id))); } catch { var temp = server.FindRoles(region, false).First(); if (settingsRepo.IsRoleDisabled(temp.Name.ToLower(), server.Id)) { } else { return(temp); } } } } } foreach (string role in settingsRepo.GetAllOverrides(server.Id)) { var temp = server.GetRole(Convert.ToUInt64(role.Substring(role.IndexOf(":") + 1, role.Length - role.IndexOf(":") - 1))); if (parameter.ToLower() == temp.Name.ToLower() || parameter.ToLower() == role.Split(':').First().ToLower()) { return(temp); } } return(r); }
public bool CanRun(Command command, User user, Channel channel, out string error) { error = String.Empty; if (channel.IsPrivate || channel.Server == null) { return(command.Category == "Help"); } if (ConfigHandler.IsUserBlacklisted(user.Id) || (!channel.IsPrivate && (ConfigHandler.IsServerBlacklisted(channel.Server.Id) || ConfigHandler.IsChannelBlacklisted(channel.Id)))) { return(false); } if (timeBlackList.ContainsKey(user)) { return(false); } timeBlackList.TryAdd(user, DateTime.Now); try { //is it a permission command? // if it is, check if the user has the correct role // if yes return true, if no return false if (command.Category == "Permissions") { Discord.Role role = null; try { role = PermissionHelper.ValidateRole(user.Server, PermissionsHandler.GetServerPermissionsRoleName(user.Server)); } catch { } if (user.Server.Owner.Id == user.Id || (role != null && user.HasRole(role))) { return(true); } ServerPermissions perms; PermissionsHandler.PermissionsDict.TryGetValue(user.Server.Id, out perms); throw new Exception($"You don't have the necessary role (**{(perms?.PermissionsControllerRole ?? "Nadeko")}**) to change permissions."); } var permissionType = PermissionsHandler.GetPermissionBanType(command, user, channel); string msg; if (permissionType == PermissionsHandler.PermissionBanType.ServerBanModule && command.Category.ToLower() == "nsfw") { msg = $"**{command.Category}** module has been banned from use on this **server**.\nNSFW module is disabled by default. Server owner can type `;sm nsfw enable` to enable it."; } else { switch (permissionType) { case PermissionsHandler.PermissionBanType.None: return(true); case PermissionsHandler.PermissionBanType.ServerBanCommand: msg = $"**{command.Text}** command has been banned from use on this **server**."; break; case PermissionsHandler.PermissionBanType.ServerBanModule: msg = $"**{command.Category}** module has been banned from use on this **server**."; break; case PermissionsHandler.PermissionBanType.ChannelBanCommand: msg = $"**{command.Text}** command has been banned from use on this **channel**."; break; case PermissionsHandler.PermissionBanType.ChannelBanModule: msg = $"**{command.Category}** module has been banned from use on this **channel**."; break; case PermissionsHandler.PermissionBanType.RoleBanCommand: msg = $"You do not have a **role** which permits you the usage of **{command.Text}** command."; break; case PermissionsHandler.PermissionBanType.RoleBanModule: msg = $"You do not have a **role** which permits you the usage of **{command.Category}** module."; break; case PermissionsHandler.PermissionBanType.UserBanCommand: msg = $"{user.Mention}, You have been banned from using **{command.Text}** command."; break; case PermissionsHandler.PermissionBanType.UserBanModule: msg = $"{user.Mention}, You have been banned from using **{command.Category}** module."; break; default: return(true); } } if (PermissionsHandler.PermissionsDict[user.Server.Id].Verbose) //if verbose - print errors { error = msg; } return(false); } catch (Exception ex) { Console.WriteLine($"Exception in canrun: {ex}"); try { ServerPermissions perms; if (PermissionsHandler.PermissionsDict.TryGetValue(user.Server.Id, out perms) && perms.Verbose) { //if verbose - print errors error = ex.Message; } } catch (Exception ex2) { Console.WriteLine($"SERIOUS PERMISSION ERROR {ex2}\n\nUser:{user} Server: {user?.Server?.Name}/{user?.Server?.Id}"); } return(false); } }
public void GetRegion() { commands.CreateCommand("region") .Parameter("region", ParameterType.Unparsed) .Do(async(e) => { try { new RoleManagementTrigger(BotUser, commands).OverrideDeletion(e.Server); } catch { } string returnstring = "error"; if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id)) { string command = ""; try { command = e.GetArg("region").Substring(0, e.GetArg("region").IndexOf(" ")).ToLower(); } catch { } SettingsRepo settingsRepo = (new SettingsRepo(new SettingsContext())); if (e.GetArg("region").ToLower() == "help" || e.GetArg("region") == "?") { if (settingsRepo.RegionByAccount(e.Server.Id) == true || settingsRepo.RegionByParameter(e.Server.Id) == true) { returnstring = "You can use the -Region command to assign a region role to yourself."; if (settingsRepo.RegionByAccount(e.Server.Id) == true) { returnstring += "\nYou can use *-Region* to get your region based on your bound League of Legends account."; } if (settingsRepo.RegionByParameter(e.Server.Id) == true) { returnstring += "\nYou can use *-Region <League Region>* to assign a region to yourself.\nUse *-Region list* to see all the regions on this server."; } } else { returnstring = Eng_Default.ServerDoesNotAllow(); } } else if (command == "remove" || command == "delete") { foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions()) { if (region.ToLower() == e.GetArg("region").Split(' ').Last().ToLower()) { try { ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id); await e.User.RemoveRoles(e.Server.GetRole(id)); returnstring = Eng_Default.RoleHasBeenRemoved(region); await e.User.RemoveRoles(e.Server.FindRoles(region.ToLower(), false).First()); returnstring = Eng_Default.RoleHasBeenRemoved(region); } catch { } } } try { foreach (string role in settingsRepo.GetAllOverrides(e.Server.Id)) { var replacement = e.Server.GetRole(Convert.ToUInt64(role.Split(':').Last())); if (e.GetArg("region").Substring(e.GetArg("region").IndexOf(" ") + 1, e.GetArg("region").Length - e.GetArg("region").IndexOf(" ") - 1).ToLower() == replacement.Name.ToLower()) { await e.User.RemoveRoles(replacement); returnstring = Eng_Default.RoleHasBeenRemoved(role); } } } catch { } } else if (e.GetArg("region").ToLower() == "list") { if (settingsRepo.RegionByParameter(e.Server.Id) == true || settingsRepo.RegionByAccount(e.Server.Id) == true) { returnstring = "Assignable regions on this server:\n```"; List <string> overrides = new List <string>(); try { overrides = settingsRepo.GetAllOverrides(e.Server.Id); } catch { } foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions()) { bool found = false; if (overrides != null) { foreach (string over in overrides) { if (region.ToLower() == over.Substring(0, over.IndexOf(":")).ToLower()) { returnstring += "\n- " + e.Server.GetRole(Convert.ToUInt64(over.Substring(over.IndexOf(":") + 1, over.Length - over.IndexOf(":") - 1))).Name; found = true; } } } if (found == false) { returnstring += "\n- " + region; } } returnstring += "```"; } else { returnstring = Eng_Default.ServerDoesNotAllow(); } } else { if (settingsRepo.RegionByAccount(e.Server.Id) == true && e.GetArg("region") == "") { Summoner summoner = null; try { DataLibary.Models.User user = new UserRepo(new UserContext()).GetUserByDiscord(e.User.Id); summoner = new SummonerAPI().GetSummoner( new SummonerRepo(new SummonerContext()).GetSummonerByUserId(user), ToolKit.LeagueAndDatabase.GetRegionFromDatabaseId( new RegionRepo(new RegionContext()).GetRegionId(user) )); } catch { returnstring = Eng_Default.RegisterAccount(); } //summoner will be null when the item does not excist within the database. //This is only done so there will be a proper returnmessage send to the user. if (summoner != null) { foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions()) { if (region.ToLower() == summoner.Region.ToString().ToLower()) { try { await e.User.AddRoles( e.Server.GetRole(settingsRepo.GetOverride(region.ToLower(), e.Server.Id))); returnstring = Eng_Default.RoleHasBeenGiven(region); } catch { await e.User.AddRoles(e.Server.FindRoles(region, false).First()); returnstring = Eng_Default.RoleHasBeenGiven(region); } } } } } else if (e.GetArg("region") == "" && settingsRepo.RegionByAccount(e.Server.Id) == false) { returnstring = Eng_Default.ServerDoesNotAllow(); } else if (settingsRepo.RegionByParameter(e.Server.Id) == true) { bool found = false; foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions()) { if (e.GetArg("region").ToLower() == region.ToLower()) { try { Discord.Role r = e.Server.GetRole(settingsRepo.GetOverride(region.ToLower(), e.Server.Id)); if (settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id)) { returnstring = Eng_Default.RoleHasBeenDisabled(); } else { await e.User.AddRoles(r); returnstring = Eng_Default.RoleHasBeenGiven(r.Name); } found = true; } catch { Discord.Role r = e.Server.FindRoles(region, false).First(); if (settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id)) { returnstring = Eng_Default.RoleHasBeenDisabled(); } else { await e.User.AddRoles(r); returnstring = Eng_Default.RoleHasBeenGiven(r.Name); } found = true; } } } foreach (string role in settingsRepo.GetAllOverrides(e.Server.Id)) { var replacement = e.Server.GetRole(Convert.ToUInt64(role.Substring(role.IndexOf(":") + 1, role.Length - role.IndexOf(":") - 1))); if (e.GetArg("region").ToLower() == replacement.Name.ToLower()) { await e.User.AddRoles(replacement); returnstring = Eng_Default.RoleHasBeenGiven(role); found = true; } } if (found == false) { returnstring = Eng_Default.RoleNotFound(e.GetArg("region")); } } else { returnstring = Eng_Default.ServerDoesNotAllow(); } } } else { returnstring = Eng_Default.ServerIsNotVerified(); } await e.Channel.SendMessage(returnstring); }); }
public static async Task SetRoleModulePermission(Role role, string moduleName, bool value) { var server = role.Server; var serverPerms = PermissionsDict.GetOrAdd(server.Id, new ServerPermissions(server.Id, server.Name)); if (!serverPerms.RolePermissions.ContainsKey(role.Id)) serverPerms.RolePermissions.Add(role.Id, new Permissions(role.Name)); var modules = serverPerms.RolePermissions[role.Id].Modules; if (modules.ContainsKey(moduleName)) modules[moduleName] = value; else modules.TryAdd(moduleName, value); await WriteServerToJson(serverPerms).ConfigureAwait(false); }
public void AdminMastery() { commands.CreateCommand("ConfigMastery") .Parameter("CommandType") .Parameter("Parameter", ParameterType.Optional) .Parameter("Points", ParameterType.Optional) .Do(async(e) => { string returnstring = ""; SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext()); ServerRepo serverRepo = new ServerRepo(new ServerContext()); if (serverRepo.IsServerVerified(e.Server.Id) && serverRepo.IsAdmin(e.User.Id, e.Server.Id)) { if (e.GetArg("CommandType") == "?" || e.GetArg("CommandType").ToLower() == "help") { returnstring = "**This command can be used to configure the Mastery Point system on your server.**" + "\nUse *-ConfigMastery champion <champion>* to set a champion for your server:" + "\nExample: -ConfigMastery champion Thresh" + "\n\nUse *-ConfigMastery list* to get a list of all the roles you have set up." + "\n\nUse *-ConfigMastery add <RoleName> <Amount>* to add a rank to the system:" + "\nExample: -ConfigMastery add \"1 Million\" 1000000" + "\n\nUse *-ConfigMastery remove <Points>* to remove a milestone rank:" + "\nExample: -ConfigMastery remove 1000000"; } else if (e.GetArg("CommandType").ToLower() == "champion") { try { settingsRepo.SetChampionId(e.Server.Id, new ChampionAPI().GetChampionId(e.GetArg("Parameter").ToString())); returnstring = "Champion set to " + e.GetArg("Parameter"); } catch { returnstring = "Did not find champion called " + e.GetArg("Parameter"); } } else if (e.GetArg("CommandType").ToLower() == "list") { try { returnstring = "Server looks at mastery points for " + new ChampionAPI().GetChampionName( settingsRepo.GetChampionId(e.Server.Id)); returnstring += "\nRoles for this server: ```"; foreach (string line in settingsRepo.GetAllMasteryRoles(e.Server.Id)) { returnstring += "\n" + line.Split(':').First() + " points uses role: " + e.Server.GetRole(Convert.ToUInt64(line.Split(':').Last())).Name; } returnstring += "\n```"; } catch { returnstring = "No champion or role found, please set this up first!"; } } else if (e.GetArg("CommandType").ToLower() == "add") { try { Discord.Role r = e.Server.FindRoles(e.GetArg("Parameter"), false).First(); settingsRepo.SetRoleByPoints(r.Id, e.Server.Id, Convert.ToInt32(e.GetArg("Points"))); returnstring = "Added to the list!"; } catch { returnstring = "Failed to add, role not found."; } } else if (e.GetArg("CommandType").ToLower() == "remove") { try { settingsRepo.RemoveRoleByPoints(e.Server.Id, Convert.ToInt32(e.GetArg("Parameter"))); returnstring = "Removed the role with the points " + e.GetArg("Parameter"); } catch { returnstring = "Failed to remove the role with points " + e.GetArg("Parameter"); } } } await e.Channel.SendMessage(returnstring); }); }
public bool CanRun(Command command, User user, Channel channel, out string error) { error = null; if (channel.IsPrivate) { return(true); } try { //is it a permission command? // if it is, check if the user has the correct role // if yes return true, if no return false if (command.Category == "Permissions") { Discord.Role role = null; try { role = PermissionHelper.ValidateRole(user.Server, PermissionsHandler.GetServerPermissionsRoleName(user.Server)); } catch { } if (user.Server.Owner.Id == user.Id || (role != null && user.HasRole(role))) { return(true); } throw new Exception($"You don't have the necessary role (**{PermissionsHandler._permissionsDict[user.Server].PermissionsControllerRole}**) to change permissions."); } var permissionType = PermissionsHandler.GetPermissionBanType(command, user, channel); string msg; switch (permissionType) { case PermissionsHandler.PermissionBanType.None: return(true); case PermissionsHandler.PermissionBanType.ServerBanCommand: msg = $"**{command.Text}** command has been banned from use on this **server**."; break; case PermissionsHandler.PermissionBanType.ServerBanModule: msg = $"**{command.Category}** module has been banned from use on this **server**."; break; case PermissionsHandler.PermissionBanType.ChannelBanCommand: msg = $"**{command.Text}** command has been banned from use on this **channel**."; break; case PermissionsHandler.PermissionBanType.ChannelBanModule: msg = $"**{command.Category}** module has been banned from use on this **channel**."; break; case PermissionsHandler.PermissionBanType.RoleBanCommand: msg = $"You do not have a **role** which permits you the usage of **{command.Text}** command."; break; case PermissionsHandler.PermissionBanType.RoleBanModule: msg = $"You do not have a **role** which permits you the usage of **{command.Category}** module."; break; case PermissionsHandler.PermissionBanType.UserBanCommand: msg = $"{user.Mention}, You have been banned from using **{command.Text}** command."; break; case PermissionsHandler.PermissionBanType.UserBanModule: msg = $"{user.Mention}, You have been banned from using **{command.Category}** module."; break; default: return(true); } if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors { Task.Run(() => channel.SendMessage(msg)); } return(false); } catch (Exception ex) { if (PermissionsHandler._permissionsDict[user.Server].Verbose) //if verbose - print errors { Task.Run(() => channel.SendMessage(ex.Message)); } return(false); } }
public Task SetChannelRolePermissions(string channelId, Role role, PackedPermissions allow, PackedPermissions deny) => SetChannelPermissions(channelId, role?.Id, "role", allow, deny);
internal void RemoveRole(Role role) { if (_roles.TryRemove(role.Id, out role)) { if (role.Id == Id) EveryoneRole = null; } }
public async void GetRoles(Discord.Server server, Discord.User discorduser) { SettingsRepo settingsRepo = new SettingsRepo(new SettingsContext()); Summoner summoner = null; try { DataLibary.Models.User user = new UserRepo(new UserContext()).GetUserByDiscord(discorduser.Id); summoner = new SummonerAPI().GetSummoner( new SummonerRepo(new SummonerContext()).GetSummonerByUserId(user), ToolKit.LeagueAndDatabase.GetRegionFromDatabaseId( new RegionRepo(new RegionContext()).GetRegionId(user) )); } catch { } if (settingsRepo.RankByAccount(server.Id) == true) { //summoner will be null when the item does not excist within the database. //This is only done so there will be a proper returnmessage send to the user. if (summoner != null) { if (settingsRepo.RankCommandType(server.Id) == CommandType.Basic) { try { string rank = new RankAPI().GetRankingSimple(summoner, Queue.RankedSolo5x5); try { await discorduser.AddRoles( server.GetRole(settingsRepo.GetOverride(rank.ToLower(), server.Id))); } catch { await discorduser.AddRoles(server.FindRoles(rank, false).First()); } } catch { } } else if (settingsRepo.RankCommandType(server.Id) == CommandType.Division) { try { string rank = new RankAPI().GetRankingHarder(summoner, Queue.RankedSolo5x5) .ToLower(); try { await discorduser.AddRoles( server.GetRole(settingsRepo.GetOverride(rank, server.Id))); } catch { await discorduser.AddRoles(server.FindRoles(rank, false).First()); } } catch { } } else if (settingsRepo.RankCommandType(server.Id) == CommandType.PerQueue) { //Each of these can fail when someone does not have this rank, therefore this isn't in one big Try because it could fail halfway. try { string rank = "Solo " + new RankAPI().GetRankingSimple(summoner, Queue.RankedSolo5x5); try { await discorduser.AddRoles( server.GetRole(settingsRepo.GetOverride(rank, server.Id))); } catch { await discorduser.AddRoles(server.FindRoles(rank, false).First()); } } catch { Console.WriteLine(discorduser.Name + "doesn't have a soloq rank"); } try { string rank = "Flex " + new RankAPI().GetRankingSimple(summoner, Queue.RankedFlexSR); try { await discorduser.AddRoles( server.GetRole(settingsRepo.GetOverride(rank, server.Id))); } catch { await discorduser.AddRoles(server.FindRoles(rank, false).First()); } } catch { Console.WriteLine(discorduser.Name + "doesn't have a flex rank"); } try { string rank = "3v3 " + new RankAPI().GetRankingSimple(summoner, Queue.RankedFlexTT); try { await discorduser.AddRoles( server.GetRole(settingsRepo.GetOverride(rank, server.Id))); } catch { await discorduser.AddRoles(server.FindRoles(rank, false).First()); } } catch { Console.WriteLine(discorduser.Name + "doesn't have a 3v3 rank"); } } } } if (settingsRepo.RegionByAccount(server.Id) && summoner != null) { //summoner will be null when the item does not excist within the database. //This is only done so there will be a proper returnmessage send to the user. foreach (string region in new RegionRepo(new RegionContext()).GetAllRegions()) { if (region.ToLower() == summoner.Region.ToString().ToLower()) { try { await discorduser.AddRoles( server.GetRole(settingsRepo.GetOverride(region.ToLower(), server.Id))); } catch { await discorduser.AddRoles(server.FindRoles(region, false).First()); } } } } if (settingsRepo.RoleByAccount(server.Id) && summoner != null) { List <string> filter = new List <string>(); if (settingsRepo.RoleCommandType(server.Id) == CommandType.Basic) { filter = DataLibary.Models.Roles.NormalRoles(); } else if (settingsRepo.RoleCommandType(server.Id) == CommandType.Main) { filter = DataLibary.Models.Roles.MainRoles(); } else if (settingsRepo.RoleCommandType(server.Id) == CommandType.Mains) { filter = DataLibary.Models.Roles.MainsRoles(); } try { string mainrole = new RoleAPI().GetRole(summoner); foreach (string role in filter) { if (role.Contains(mainrole)) { try { ulong id = settingsRepo.GetOverride(role.ToLower(), server.Id); await discorduser.AddRoles(server.GetRole(id)); } catch { await discorduser.AddRoles(server.FindRoles(role, false).First()); } } } } catch { Console.WriteLine("Error in roles"); } } if (settingsRepo.MasteryPointsByAccount(server.Id) && summoner != null) { int points = new MasteryAPI().GetPoints(summoner, new ChampionAPI().GetChampion(settingsRepo.GetChampionId(server.Id), RiotSharp.Region.eune)); Discord.Role r = server.GetRole(settingsRepo.GetRoleByPoints(server.Id, points)); await discorduser.AddRoles(r); } }
public Task RemoveChannelRolePermissions(Channel channel, Role role) => RemoveChannelPermissions(channel?.Id, role?.Id);
internal static async Task CopyRolePermissions(Role fromRole, Role toRole) { var server = fromRole.Server; var serverPerms = PermissionsDict.GetOrAdd(server.Id, new ServerPermissions(server.Id, server.Name)); var from = GetRolePermissionsById(server, fromRole.Id); if (from == null) serverPerms.RolePermissions.Add(fromRole.Id, from = new Permissions(fromRole.Name)); var to = GetRolePermissionsById(server, toRole.Id); if (to == null) serverPerms.RolePermissions.Add(toRole.Id, to = new Permissions(toRole.Name)); to.CopyFrom(from); await WriteServerToJson(serverPerms).ConfigureAwait(false); }
public Task RemoveChannelRolePermissions(string channelId, Role role) => RemoveChannelPermissions(channelId, role?.Id);
public static async Task SetRoleCommandPermission(Role role, string commandName, bool value) { var server = role.Server; var serverPerms = PermissionsDict.GetOrAdd(server.Id, new ServerPermissions(server.Id, server.Name)); if (!serverPerms.RolePermissions.ContainsKey(role.Id)) serverPerms.RolePermissions.Add(role.Id, new Permissions(role.Name)); var commands = serverPerms.RolePermissions[role.Id].Commands; if (commands.ContainsKey(commandName)) commands[commandName] = value; else commands.TryAdd(commandName, value); await WriteServerToJson(serverPerms).ConfigureAwait(false); }
public Task EditRole(Role role, string newName) => EditRole(role?.ServerId, role?.Id, newName);
public Task DeleteRole(Role role) => DeleteRole(role?.ServerId, role?.Id);
public bool CanRun(Command command, User user, Channel channel, out string error) { error = String.Empty; if (!MidnightBot.Ready) { return(false); } if (channel.IsPrivate) { return(true); } if (ConfigHandler.IsUserBlacklisted(user.Id) || (!channel.IsPrivate && (ConfigHandler.IsServerBlacklisted(channel.Server.Id) || ConfigHandler.IsChannelBlacklisted(channel.Id)))) { return(false); } if (timeBlackList.Contains(user.Id)) { return(false); } if (!channel.IsPrivate && !channel.Server.CurrentUser.GetPermissions(channel).SendMessages) { return(false); } timeBlackList.Add(user.Id); ServerPermissions perms; PermissionsHandler.PermissionsDict.TryGetValue(user.Server.Id, out perms); AddUserCooldown(user.Server.Id, user.Id, command.Text.ToLower()); if (!MidnightBot.IsOwner(user.Id) && commandCooldowns.Keys.Contains(user.Server.Id + ":" + command.Text.ToLower())) { if (perms?.Verbose == true) { error = $"{user.Mention} Du hast einen Cooldown auf diesem Befehl."; } return(false); } try { //is it a permission command? // if it is, check if the user has the correct role // if yes return true, if no return false if (command.Category == "Permissions") { Discord.Role role = null; try { role = PermissionHelper.ValidateRole(user.Server, PermissionsHandler.GetServerPermissionsRoleName(user.Server)); } catch { } if (user.Server.Owner.Id == user.Id || (role != null && user.HasRole(role)) || MidnightBot.IsOwner(user.Id)) { return(true); } throw new Exception($"Du hast nicht die benötigte Rolle (**{(perms?.PermissionsControllerRole ?? "Admin")}**) um die Berechtigungen zu ändern."); } var permissionType = PermissionsHandler.GetPermissionBanType(command, user, channel); string msg; if (permissionType == PermissionsHandler.PermissionBanType.ServerBanModule && command.Category.ToLower() == "nsfw") { msg = $"**{command.Category}** Modul wurde gebannt von diesem **server**.\nNSFW Modul ist standardmäßig deaktiviert. Der Server-Owner kann `;sm nsfw enable` eingeben, um es zu aktivieren."; } else { switch (permissionType) { case PermissionsHandler.PermissionBanType.None: return(true); case PermissionsHandler.PermissionBanType.ServerBanCommand: msg = $"Befehl **{command.Text}** wurde gebannt von diesem **Server**."; break; case PermissionsHandler.PermissionBanType.ServerBanModule: msg = $"Modul **{command.Category}** wurde gebannt von diesem **Server**."; break; case PermissionsHandler.PermissionBanType.ChannelBanCommand: msg = $"Befehl **{command.Text}** wurde gebannt von diesem **Channel**."; break; case PermissionsHandler.PermissionBanType.ChannelBanModule: msg = $"Modul **{command.Category}** wurde gebannt von diesem **Channel**."; break; case PermissionsHandler.PermissionBanType.RoleBanCommand: msg = $"Du hast nicht die benötigte **Rolle** welche dich zur Benutzung vom **{command.Text}** Befehl berechtigt."; break; case PermissionsHandler.PermissionBanType.RoleBanModule: msg = $"Du hast keine **Rolle** welche dich zur Benutzung vom **{command.Category}** Modul berechtigt."; break; case PermissionsHandler.PermissionBanType.UserBanCommand: msg = $"{user.Mention}, Du wurdest gebannt von der Benutzung des **{command.Text}** Befehls."; break; case PermissionsHandler.PermissionBanType.UserBanModule: msg = $"{user.Mention}, Du wurdest gebannt von der Benutzung des **{command.Category}** Modules."; break; default: return(true); } } if (PermissionsHandler.PermissionsDict[user.Server.Id].Verbose) //if verbose - print errors { error = msg; } return(false); } catch (Exception ex) { Console.WriteLine($"Exception in canrun: {ex}"); try { if (perms != null && perms.Verbose) { //if verbose - print errors error = ex.Message; } } catch (Exception ex2) { Console.WriteLine($"SERIOUS PERMISSION ERROR {ex2}\n\nUser:{user} Server: {user?.Server?.Name}/{user?.Server?.Id}"); } return(false); } }
public void GetRank() { commands.CreateCommand("Rank") .Parameter("rank", ParameterType.Unparsed) .Do(async(e) => { string returnstring = "error"; if (new ServerRepo(new ServerContext()).IsServerVerified(e.Server.Id)) { try { new RoleManagementTrigger(BotUser, commands).OverrideDeletion(e.Server); } catch { } SettingsRepo settingsRepo = (new SettingsRepo(new SettingsContext())); if (e.GetArg("rank").Split(' ').First() == "delete" || e.GetArg("rank").Split(' ').First() == "remove") { foreach (string region in Ranks.BasicRanks()) { if (region.ToLower() == e.GetArg("rank") .Substring(e.GetArg("rank").IndexOf(" ") + 1, e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1) .ToLower()) { try { ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id); await e.User.RemoveRoles(e.Server.GetRole(id), e.Server.FindRoles(region.ToLower(), false).First()); returnstring = Eng_Default.RoleHasBeenRemoved(region); } catch { } } } foreach (string region in Ranks.QueueRanks()) { if (region.ToLower() == e.GetArg("rank") .Substring(e.GetArg("rank").IndexOf(" ") + 1, e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1) .ToLower()) { try { ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id); await e.User.RemoveRoles(e.Server.GetRole(id), e.Server.FindRoles(region.ToLower(), false).First()); returnstring = Eng_Default.RoleHasBeenRemoved(region); } catch { } } } foreach (string region in Ranks.DivisionRanks()) { if (region.ToLower() == e.GetArg("rank") .Substring(e.GetArg("rank").IndexOf(" ") + 1, e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1) .ToLower()) { try { ulong id = settingsRepo.GetOverride(region.ToLower(), e.Server.Id); await e.User.RemoveRoles(e.Server.GetRole(id), e.Server.FindRoles(region.ToLower(), false).First()); returnstring = Eng_Default.RoleHasBeenRemoved(region); } catch { } } } try { foreach (string role in settingsRepo.GetAllOverrides(e.Server.Id)) { var replacement = e.Server.GetRole(Convert.ToUInt64(role.Split(':').Last())); if ( e.GetArg("rank") .Substring(e.GetArg("rank").IndexOf(" ") + 1, e.GetArg("rank").Length - e.GetArg("rank").IndexOf(" ") - 1) .ToLower() == replacement.Name.ToLower()) { await e.User.RemoveRoles(replacement); returnstring = Eng_Default.RoleHasBeenRemoved(role); } } } catch { } } else if (e.GetArg("rank").ToLower() == "list") { if (settingsRepo.RankByAccount(e.Server.Id) == true || settingsRepo.RankByParameter(e.Server.Id) == true) { returnstring = "Assignable roles on this server:"; if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Basic) { foreach (string r in Ranks.BasicRanks()) { returnstring += "\n- " + r; } } else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.PerQueue) { foreach (string r in Ranks.QueueRanks()) { returnstring += "\n- " + r; } } else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Division) { foreach (string r in Ranks.BasicRanks()) { returnstring += "\n- " + r + " V to I"; } } } else { returnstring = Eng_Default.ServerDoesNotAllow(); } } else if (e.GetArg("rank") == "?" || e.GetArg("rank").ToLower() == "help") { returnstring = "Use the base command -rank to get a rank assigned as your role."; if (settingsRepo.RankByAccount(e.Server.Id) == true) { returnstring += "\nYou can use *-Rank* to get your ranks based on bound league of legends account."; } if (settingsRepo.RankByParameter(e.Server.Id) == true) { returnstring += "\nYou can use *-Rank <League rank>* to get a role based on your input"; returnstring += "\nRoles you can get on this server are:"; if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Basic) { foreach (string r in Ranks.BasicRanks()) { returnstring += "\n- " + r; } } else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.PerQueue) { foreach (string r in Ranks.QueueRanks()) { returnstring += "\n- " + r; } } else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Division) { foreach (string r in Ranks.BasicRanks()) { returnstring += "\n- " + r + " V to I"; } } } } else { if (e.GetArg("rank") == "") { //Checks if gettings ranks by account is disabled (Unsure why someone would disable this but hey ¯\_(ツ)_/¯ someone might want so) if (settingsRepo.RankByAccount(e.Server.Id) == true) { Summoner summoner = null; try { DataLibary.Models.User user = new UserRepo(new UserContext()).GetUserByDiscord(e.User.Id); summoner = new SummonerAPI().GetSummoner( new SummonerRepo(new SummonerContext()).GetSummonerByUserId(user), ToolKit.LeagueAndDatabase.GetRegionFromDatabaseId( new RegionRepo(new RegionContext()).GetRegionId(user) )); } catch { returnstring = Eng_Default.RegisterAccount(); } //summoner will be null when the item does not excist within the database. //This is only done so there will be a proper returnmessage send to the user. if (summoner != null) { if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Basic) { string rank = new RankAPI().GetRankingSimple(summoner, Queue.RankedSolo5x5); try { await e.User.AddRoles( e.Server.GetRole(settingsRepo.GetOverride(rank.ToLower(), e.Server.Id))); } catch { await e.User.AddRoles(e.Server.FindRoles(rank, false).First()); } returnstring = Eng_Default.RoleHasBeenGiven(rank); } else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Division) { string rank = new RankAPI().GetRankingHarder(summoner, Queue.RankedSolo5x5) .ToLower(); try { await e.User.AddRoles( e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id))); } catch { await e.User.AddRoles(e.Server.FindRoles(rank, false).First()); } returnstring = Eng_Default.RoleHasBeenGiven(rank); } else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.PerQueue) { //Each of these can fail when someone does not have this rank, therefore this isn't in one big Try because it could fail halfway. try { string rank = "Solo " + new RankAPI().GetRankingSimple(summoner, Queue.RankedSolo5x5); try { await e.User.AddRoles( e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id))); } catch { await e.User.AddRoles(e.Server.FindRoles(rank, false).First()); } } catch { Console.WriteLine(e.User.Name + "doesn't have a soloq rank"); } try { string rank = "Flex " + new RankAPI().GetRankingSimple(summoner, Queue.RankedFlexSR); try { await e.User.AddRoles( e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id))); } catch { await e.User.AddRoles(e.Server.FindRoles(rank, false).First()); } } catch { Console.WriteLine(e.User.Name + "doesn't have a flex rank"); } try { string rank = "3v3 " + new RankAPI().GetRankingSimple(summoner, Queue.RankedFlexTT); try { await e.User.AddRoles( e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id))); } catch { await e.User.AddRoles(e.Server.FindRoles(rank, false).First()); } } catch { Console.WriteLine(e.User.Name + "doesn't have a 3v3 rank"); } returnstring = Eng_Default.RolesHaveBeenGiven(); } } } else { returnstring = Eng_Default.ServerDoesNotAllow(); } } else { //Check settings and give ranks according to the parameter if (settingsRepo.RankByParameter(e.Server.Id) == true) { bool found = false; List <string> filter = new List <string>(); if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.Basic) { filter = Ranks.BasicRanks(); } else if (settingsRepo.RankCommandType(e.Server.Id) == CommandType.PerQueue) { filter = Ranks.QueueRanks(); } foreach (string rank in filter) { if (e.GetArg("rank").ToLower() == rank.ToLower()) { try { Discord.Role r = e.Server.GetRole(settingsRepo.GetOverride(rank, e.Server.Id)); if (!settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id)) { await e.User.AddRoles(r); returnstring = Eng_Default.RoleHasBeenGiven(r.Name); } else { returnstring = Eng_Default.RoleHasBeenDisabled(); } } catch { Discord.Role r = e.Server.FindRoles(rank, false).First(); if (!settingsRepo.IsRoleDisabled(r.Name.ToLower(), e.Server.Id)) { await e.User.AddRoles(r); returnstring = Eng_Default.RoleHasBeenGiven(r.Name); } else { returnstring = Eng_Default.RoleHasBeenDisabled(); } } found = true; } } if (found == false) { returnstring = Eng_Default.RoleNotFound(e.GetArg("rank")); } } else { returnstring = Eng_Default.ServerDoesNotAllow(); } } } } else { returnstring = Eng_Default.ServerIsNotVerified(); } await e.Channel.SendMessage(returnstring); }); }
public RoleUpdatedEventArgs(Role before, Role after) { Before = before; After = after; }