public override void Load() { // get owner string OwnerString = Bot.Owner + ":"; // tie into the chat event so we can detect messages sent to us RegisterEvent(dAmnPacketType.Chat, new BotServerPacketEvent(ChatReceived)); // register our commands CommandHelp help = new CommandHelp( "Controls settings for the AI chat bot.", "ai status - lists chatrooms and their ai settings<br />" + "ai (#room | all) respond [on | off] - responds even when user with same username is present. Is off by default<br />" + "<b>Example:<b> !ai all respond on - turns respond on for all rooms"); RegisterCommand("ai", new BotCommandEvent(AIHandler), help, PrivClass.Owner); // load our settings LoadSettings(); }
public override CommandResultCode Execute(IExecutionContext context, CommandArguments args) { if (args.Count > 1) return CommandResultCode.SyntaxError; string commandName = null; if (args.MoveNext()) commandName = args.Current; // nothing given: provide generic help. Application.Error.WriteLine(); int maxPad = 0; if (commandName == null) { ICollection<Command> commands = Application.Commands.RegisteredCommands; // process the command groups first... Dictionary<string, List<CommandHelp>> groups = new Dictionary<string, List<CommandHelp>>(); foreach (Command command in commands) { string groupName = command.GroupName; if (groupName == null || groupName.Length == 0) groupName = "commands"; List<CommandHelp> list; if (!groups.TryGetValue(groupName, out list)) { list = new List<CommandHelp>(); groups[groupName] = list; } CommandHelp commandHelp = new CommandHelp(); StringBuilder cmdPrint = new StringBuilder(" "); string[] aliases = command.Aliases; cmdPrint.Append(command.Name); if (aliases != null && aliases.Length > 0) { cmdPrint.Append(" | "); for (int i = 0; i < aliases.Length; i++) { if (i != 0) cmdPrint.Append(" | "); cmdPrint.Append(aliases[i]); } } commandHelp.Name = cmdPrint.ToString(); string description = command.ShortDescription; if (description == null) { // no description ... try to get the groups description... } commandHelp.Description = description; maxPad = Math.Max(maxPad, cmdPrint.Length); list.Add(commandHelp); } foreach (KeyValuePair<string, List<CommandHelp>> entry in groups) { string groupName = entry.Key; Application.Error.Write(groupName); Application.Error.Write(":"); Application.Error.WriteLine(); List<CommandHelp> commandList = entry.Value; foreach (CommandHelp command in commandList) { Application.Error.Write(" "); Application.Error.Write(command.Name); if (command.Description != null) { for (int i = 0; i < maxPad - command.Name.Length; ++i) Application.Error.Write(" "); Application.Error.Write(" : "); Application.Error.Write(command.Description); } Application.Error.WriteLine(); } } } else { CommandDispatcher disp = Application.Commands; string cmdString = disp.CompleteCommandName(commandName); Command c = disp.GetCommand(cmdString); if (c == null) { Application.Error.WriteLine("Help: unknown command '" + cmdString + "'"); Application.Error.WriteLine(); return CommandResultCode.ExecutionFailed; } WriteDescription(c); } Application.Error.WriteLine(); return CommandResultCode.Success; }
public ToolModule() : base("Tool") { //数据库表 Get["/TableList"] = r => { ViewBag.TableList = JsonConvert.SerializeObject(TableListService.GetAllTable()); return(View["TableList"]); }; //CronExpress表达式生成器FGZDZDZDZDZDZDZ Get["/CronExpress"] = r => { return(View["CronExpress"]); }; //命令行执行工具 Get["/CommandLine"] = r => { return(View["CommandLine"]); }; //系统日志 Get["/SysLog"] = r => { return(View["SysLog"]); }; //异常信息 Get["/ExceptionLog"] = r => { return(View["ExceptionLog", LogHelper.GetExceptionMsg()]); }; #region "接口" //生成实体代码 Post["/QuickCode"] = r => { string strTableList = Request.Form["TableList"]; if (string.IsNullOrEmpty(strTableList)) { return(null); } string FileName = string.Format("EntityCode-{0}.zip", DateTime.Now.ToString("yyyyMMddHHmmss")); var res = new Response() { Contents = stream => { EntityCodeHelper.QuickCode(TableListService.GetTableInfo(strTableList.Split(',')), stream); }, ContentType = MimeHelper.GetMineType(FileName), StatusCode = HttpStatusCode.OK, Headers = new Dictionary <string, string> { { "Content-Disposition", string.Format("attachment;filename={0}", System.Web.HttpUtility.UrlPathEncode(FileName)) } } }; return(res); }; //计算表达式最近五次运行时间 Get["/CalcRunTime"] = r => { string CronExpressionString = Request.Query["CronExpression"]; if (string.IsNullOrEmpty(CronExpressionString)) { return("[]"); } else { JsonSerializerSettings setting = new JsonSerializerSettings(); setting.DateFormatString = "yyyy-MM-dd HH:mm:ss"; return(JsonConvert.SerializeObject(QuartzHelper.GetTaskeFireTime(CronExpressionString, 5), setting)); } }; //获取命令行返回结果 Post["/Cmd"] = r => { string strCmd = Request.Form["cmd"]; return(CommandHelp.ExcuteCommad(strCmd)); }; //删除异常消息 Get["/DeleteException"] = r => { string type = Request.Query["Type"]; string Index = Request.Query["Index"]; if ("Delete".Equals(type, StringComparison.CurrentCultureIgnoreCase)) { long key; if (long.TryParse(Index, out key)) { LogHelper.RemoveExceptionMsg(key); } } else if ("Clear".Equals(type, StringComparison.CurrentCultureIgnoreCase)) { LogHelper.ClearExceptionMsg(); } return(string.Empty); }; #endregion }
static void Main(string[] args) { AdminRun.Run(); if (!SetConsoleCtrlHandler(cancelHandler, true)) { Console.WriteLine("程序监听系统按键异常"); } try { //1.MEF初始化 MefConfig.Init(); //2.数据库初始化连接 ConfigInit.InitConfig(); //3.系统参数配置初始化 ConfigManager configManager = MefConfig.TryResolve <ConfigManager>(); configManager.Init(); Console.Title = SystemConfig.ProgramName; Console.CursorVisible = false; //隐藏光标 //4.任务启动 QuartzHelper.InitScheduler(); QuartzHelper.StartScheduler(); //5.加载SQL信息到缓存中 XmlCommandManager.LoadCommnads(SysConfig.XmlCommandFolder); //开发时监听资源文件变化,用于实时更新 DevelperHelper.WatcherResourceChange(); //测试dapper orm框架 //DapperDemoService.Test(); //启动站点 using (NancyHost host = Startup.Start(SystemConfig.WebPort)) { //调用系统默认的浏览器 string url = string.Format("http://127.0.0.1:{0}", SystemConfig.WebPort); Process.Start(url); Console.WriteLine("系统已启动,当前监听站点地址:{0}", url); try { //4.消息队列启动 RabbitMQClient.InitClient(); } catch (Exception ex) { Console.WriteLine(ex); } //5.系统命令初始化 CommandHelp.Init(); } } catch (Exception ex) { Console.WriteLine(ex); } Console.Read(); }
private static void WriteManual(bool includeValues = false, Filter?filter = null) { IEnumerable <Command> commands = LoadCommands(); var writer = new ConsoleHelpWriter(new HelpWriterOptions(filter: filter)); IEnumerable <CommandHelp> commandHelps = commands.Select(f => CommandHelp.Create(f, filter: filter)) .Where(f => f.Arguments.Any() || f.Options.Any()) .ToImmutableArray(); ImmutableArray <CommandItem> commandItems = HelpProvider.GetCommandItems(commandHelps.Select(f => f.Command)); ImmutableArray <OptionValueList> values = ImmutableArray <OptionValueList> .Empty; if (commandItems.Any()) { values = HelpProvider.GetOptionValues( commandHelps.SelectMany(f => f.Command.Options), OptionValueProviders.Providers, filter); var commandsHelp = new CommandsHelp(commandItems, values); writer.WriteCommands(commandsHelp); foreach (CommandHelp commandHelp in commandHelps) { WriteSeparator(); WriteLine(); WriteLine($"Command: {commandHelp.Name}"); WriteLine(); string description = commandHelp.Description; if (!string.IsNullOrEmpty(description)) { WriteLine(description); WriteLine(); } writer.WriteCommand(commandHelp); } if (includeValues) { WriteSeparator(); } } else { WriteLine(); WriteLine("No command found"); if (includeValues) { values = HelpProvider.GetOptionValues( commands.Select(f => CommandHelp.Create(f)).SelectMany(f => f.Command.Options), OptionValueProviders.Providers, filter); } } if (includeValues) { writer.WriteValues(values); }
/// <summary> /// Updates the help text for a registered command. /// </summary> /// <param name="commandName">Command name to update.</param> /// <param name="help">Help text for the command.</param> protected void RegisterCommandHelp(string commandName, CommandHelp help) { Bot.UpdateCommandHelp(commandName, help); }
/// <summary> /// This method lets you tie into a command that is received from a user. There are no /// preset commands. Any new commands are registered with this method. Only one method /// can be mapped for one command. /// </summary> /// <param name="commandName">Command name to register for.</param> /// <param name="commandMethod">Method that will be executed when command is encountered.</param> /// <param name="help">Help text for command.</param> /// <param name="defaultPrivClassName">Name of the default priv class to use for this command.</param> protected void RegisterCommand(string commandName, BotCommandEvent commandMethod, CommandHelp help, string defaultPrivClassName) { Bot.AddCommandListener(commandName, this, commandMethod, help, defaultPrivClassName); }
/// <summary> /// This method lets you tie into a command that is received from a user. There are no /// preset commands. Any new commands are registered with this method. Only one method /// can be mapped for one command. /// </summary> /// <param name="commandName">Command name to register for.</param> /// <param name="commandMethod">Method that will be executed when command is encountered.</param> /// <param name="help">Help text for command.</param> /// <param name="privClass">The priv class.</param> protected void RegisterCommand(string commandName, BotCommandEvent commandMethod, CommandHelp help, PrivClass privClass) { RegisterCommand(commandName, commandMethod, help, privClass.Name); }
public override CommandResultCode Execute(IExecutionContext context, CommandArguments args) { if (args.Count > 1) { return(CommandResultCode.SyntaxError); } string commandName = null; if (args.MoveNext()) { commandName = args.Current; } // nothing given: provide generic help. Application.Error.WriteLine(); int maxPad = 0; if (commandName == null) { ICollection <Command> commands = Application.Commands.RegisteredCommands; // process the command groups first... Dictionary <string, List <CommandHelp> > groups = new Dictionary <string, List <CommandHelp> >(); foreach (Command command in commands) { string groupName = command.GroupName; if (groupName == null || groupName.Length == 0) { groupName = "commands"; } List <CommandHelp> list; if (!groups.TryGetValue(groupName, out list)) { list = new List <CommandHelp>(); groups[groupName] = list; } CommandHelp commandHelp = new CommandHelp(); StringBuilder cmdPrint = new StringBuilder(" "); string[] aliases = command.Aliases; cmdPrint.Append(command.Name); if (aliases != null && aliases.Length > 0) { cmdPrint.Append(" | "); for (int i = 0; i < aliases.Length; i++) { if (i != 0) { cmdPrint.Append(" | "); } cmdPrint.Append(aliases[i]); } } commandHelp.Name = cmdPrint.ToString(); string description = command.ShortDescription; if (description == null) { // no description ... try to get the groups description... } commandHelp.Description = description; maxPad = Math.Max(maxPad, cmdPrint.Length); list.Add(commandHelp); } foreach (KeyValuePair <string, List <CommandHelp> > entry in groups) { string groupName = entry.Key; Application.Error.Write(groupName); Application.Error.Write(":"); Application.Error.WriteLine(); List <CommandHelp> commandList = entry.Value; foreach (CommandHelp command in commandList) { Application.Error.Write(" "); Application.Error.Write(command.Name); if (command.Description != null) { for (int i = 0; i < maxPad - command.Name.Length; ++i) { Application.Error.Write(" "); } Application.Error.Write(" : "); Application.Error.Write(command.Description); } Application.Error.WriteLine(); } } } else { CommandDispatcher disp = Application.Commands; string cmdString = disp.CompleteCommandName(commandName); Command c = disp.GetCommand(cmdString); if (c == null) { Application.Error.WriteLine("Help: unknown command '" + cmdString + "'"); Application.Error.WriteLine(); return(CommandResultCode.ExecutionFailed); } WriteDescription(c); } Application.Error.WriteLine(); return(CommandResultCode.Success); }