public bool CommandHasLevel(Types.CommandLevel level, MethodInfo methodInfo) { if (methodInfo == null) { return(false); //TODO: This shouldn't happen, ever. } var attributes = Attribute.GetCustomAttributes(methodInfo); return(attributes.Any(at => at is CommandUserLevel && ((CommandUserLevel)at).Level <= level)); }
public void UpdateCommandLevel(string command, Types.CommandLevel level) { string sql = "UPDATE '" + _channel + "_commands' SET command_name = '" + EscapeString(command) + "', command_level = '" + level + "' WHERE command_name = '" + EscapeString(command) + "';"; using (_dbCommand = new SQLiteCommand(sql, _dbConnection)) { _dbCommand.ExecuteNonQuery(); } }
public void AddCommand(string command, string response, Types.CommandLevel level) { string sql = "INSERT OR IGNORE INTO '" + _channel + "_commands' (command_name, command_level, command_response) VALUES ('" + EscapeString(command) + "', '" + level + "', '" + EscapeString(response) + "');"; using (_dbCommand = new SQLiteCommand(sql, _dbConnection)) { _dbCommand.ExecuteNonQuery(); } }
// This is a positional argument public CommandUserLevel(Types.CommandLevel level) { Level = level; }
// This is a positional argument public CommandUserLevel(Types.CommandLevel level) { Level = level; }
public CustomCommand(string displayName, string commandResponse, Types.CommandLevel commandLevel) { this.CommandResponse = commandResponse; this.CommandLevel = commandLevel; this.DisplayName = displayName; }
public CustomCommand(string displayName, string commandResponse, Types.CommandLevel commandLevel) { this.CommandResponse = commandResponse; this.CommandLevel = commandLevel; this.DisplayName = displayName; }
public void ExecuteCommand(string user, Types.UserLevel userLevel, string commandName, string[] paramStrings) { Types.CommandLevel level = GetCommandLevel(userLevel); bool isAlias; commandName = commandName.ToLower(); bool isOther = true; CommandBase cmd = InternalCommands["other"]; if (CommandGroupExists(commandName, out isAlias)) { cmd = isAlias ? CommandAliases[commandName] : InternalCommands[commandName]; isOther = false; } var methods = cmd.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); if (!isOther || methods.Any(m => m.Name.ToLower() == commandName)) { string subCommandName = isOther ? commandName : "default"; bool isDefault = true; if (!isOther && paramStrings.Length > 0) { isDefault = false; subCommandName = paramStrings[0]; } List <MethodInfo> foundMethods = methods.Where(method => method.Name.ToLower() == subCommandName.ToLower()).ToList(); if (foundMethods.Count == 0) { if (!isDefault) { subCommandName = "default"; isDefault = true; foundMethods = methods.Where(method => method.Name.ToLower() == subCommandName.ToLower()).ToList(); } } else { if (!isDefault) { string[] newParams = new string[paramStrings.Length - 1]; for (int i = 1; i < paramStrings.Length; i++) { newParams[i - 1] = paramStrings[i]; } paramStrings = newParams; } } if (foundMethods.Count != 0) { bool succes = false; foreach (var methodInfo in foundMethods) { if (CommandHasLevel(level, methodInfo)) { object[] paramObject = GetParamObject(methodInfo, userLevel, user, paramStrings); if (paramObject != null && CommandCheckParams(methodInfo, paramObject)) { succes = true; methodInfo.Invoke(cmd, paramObject); } } } if (!succes) { if (isOther || !isDefault) { string usage = null; foreach (var method in foundMethods) { if (CommandHasLevel(level, method)) { usage = GetCommandUsage(method); break; } } if (usage != null) { Program.Irc.SendMessage(String.Format(Resources.CommandUsage, usage, user)); } } } } } else { commandName = commandName.ToLower(); if (CustomCommandExists(commandName)) { if (CustomCommandHasLevel(level, commandName)) { Program.Irc.SendMessage(GetCustomCommandResponse(commandName, paramStrings, user)); } } } }
private bool CustomCommandHasLevel(Types.CommandLevel level, string commandName) { return(CustomCommands[commandName].CommandLevel <= level); }