protected override void Invoking(MessageReceivedEventArgs e, PlainText appName, PlainText operationText, ComplexMessage elements) { try { var config = Configuration.AppStatusConfig; var app = AppUtilities.GetApps(e.Source, e.Subject).Where(x => x.Name.ToLower() == appName.Content.ToLower()).Single(); bool?operation = operationText.Content.ToLower().ToBool("on", "off"); if (app.CanDisable) { if (operation.HasValue) { config.Config[e.Source.ToString(true)][app.Name] = operation.Value; e.Reply($"已{(operation.Value ? "启用" : "停用")}应用 {app.DisplayName}({app.Name}) ✧(≖ ◡ ≖✿ "); config.Save(); } } else { e.Reply($"该应用 {app.DisplayName}({app.Name})不允许被启用/停用 o(゚Д゚)っ!"); } } catch (InvalidOperationException) { e.Reply($"应用 {appName} 不存在 (•́へ•́╬)"); } }
protected override void Invoking(MessageReceivedEventArgs e, PlainText plainText, ComplexMessage elements) { var apps = AppUtilities.GetApps(e.Source, e.Subject); if (int.TryParse(plainText, out int pageIndex)) { var appInfos = apps.Select(GetAppInfo).OrderBy(x => x); int pageCount = (int)Math.Ceiling((float)appInfos.Count() / MaxCount); if (pageIndex > 0 && pageIndex <= pageCount) { int start = (pageIndex - 1) * MaxCount; int count = pageIndex < pageCount ? MaxCount : appInfos.Count() - start; var appInfosSplit = appInfos.Skip(start).Take(count); e.Source.Send($"帮助菜单 (第 {pageIndex} 页 / 共 {pageCount} 页):\n\n" + string.Join("\n", appInfosSplit)); } else if (pageIndex < 1) { e.Reply($"页数不能小于等于 0 (T▽T)"); } else if (pageIndex > pageCount) { e.Reply($"帮助菜单仅有 {pageCount} 页 |ω・`)"); } } else { try { var app = apps.Where(x => x.Name.ToLower() == plainText.Content.ToLower()).Single(); e.Source.Send(GetAppInfo(app) + ":\n" + string.Join("\n", app.Features.Where(f => f.Usage != null).Select(f => f.Usage))); } catch (InvalidOperationException) { e.Reply($"应用 {plainText} 不存在 (•́へ•́╬)"); } } string GetAppInfo(AppBase app) => $"{(app.IsEnabled(e.Source) ? string.Empty : "【已停用】")}{app.DisplayName} ({app.Name})"; }