/// <summary> /// Generate a simple answer from the json template of this dialog. /// </summary> /// <param name="stepContext">the waterfall step context</param> /// <param name="cancellationToken">the cancellation token</param> /// <returns></returns> protected async Task <DialogTurnResult> SimpleAnswer(WaterfallStepContext stepContext, CancellationToken cancellationToken) { string json = MiscExtensions.LoadEmbeddedResource(_smallTalkPath + "." + $"{_top}.json"); List <string> answers = json == null ? new List <string>() : JsonConvert.DeserializeObject <List <string> >(json); await TheBot.SendMessage(GetSimpleAnswer(answers), stepContext.Context); return(await ProceedWithDialog(stepContext)); }
private void CheckKeyDown(object sender, EventArgs e) { if (!MiscExtensions.ApplicationHasFocus()) { if (Keybinds.IsKeyDown(toggleRecording)) { ToggleRecording(); } } }
public override object TransformOutput(object obj, MemberInfo member, int i) { if (member.Name == "CustomAttachedObject") { return(obj?.ToString() ?? ""); } if (obj is Stopwatch s) { return(s.Elapsed.TotalSeconds); } return(MiscExtensions.MapSystemNumericsValueToVVVV(obj)); }
public override Type TransformType(Type original, MemberInfo member) { if (original == typeof(object)) { return(typeof(string)); } if (original.Is(typeof(Stopwatch))) { return(typeof(double)); } return(MiscExtensions.MapSystemNumericsTypeToVVVV(original)); }
private async Task <DialogTurnResult> ClassifySmallTalk(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var top = TheBot.Result.GetTopScoringIntent().Item1.Substring("st_".Length); if (MiscExtensions.LoadEmbeddedResource(SmallTalkPath + "." + $"{top}.json") == null) { await TheBot.SendMessage($"Ich habe noch nicht gelernt auf {top} zu antworten.", stepContext.Context); } else { List <string> answers = FindSpecificAnswers(top); await TheBot.SendMessage(GetAnswer(answers), stepContext.Context); } return(await ProceedWithDialog(stepContext)); }
public static async Task Main() { try { MiscExtensions.SetupApplicationInformation(); var applicationOptions = MiscExtensions.VerifyOptions(); await Host.CreateDefaultBuilder() .ConfigureAppConfiguration(builder => { var sources = builder.Sources.OfType <JsonConfigurationSource>().ToArray(); foreach (var source in sources) { builder.Sources.Remove(source); } builder.SetBasePath(Directory.GetCurrentDirectory()); builder.AddJsonFile(ApplicationOptions.FILE_NAME, false, true); }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseUrls($"http://{applicationOptions.Url}"); webBuilder.UseStartup <Startup>(); }) .ConfigureLogging(logging => { logging.SetMinimumLevel(applicationOptions.Logging.DefaultLevel); logging.ClearProviders(); logging.AddProvider(new LoggerProvider(applicationOptions.Logging)); }) .ConfigureServices((context, collection) => { collection.AddConnections(); collection.AddControllers(); collection.AddHttpClient(); collection.AddMemoryCache(cacheOptions => { cacheOptions.ExpirationScanFrequency = TimeSpan.FromSeconds(30); cacheOptions.CompactionPercentage = 0.5; }); collection.AddResponseCaching(cachingOptions => { cachingOptions.SizeLimit = 5; }); collection.AddResponseCompression(); collection.Configure <ApplicationOptions>(context.Configuration); collection.AddScoped <ProviderFilterAttribute>(); collection.AddSingleton <DyscClient>(); }) .RunConsoleAsync(); } catch (Exception exception) { Console.WriteLine(exception); Console.ReadKey(); } }
public virtual void Draw() { if (!Visible) { return; } var res = UIMenu.GetScreenResolutionMantainRatio(); if (UseDynamicPositionment) { SafeSize = new PointF(300, 240); TopLeft = new PointF(SafeSize.X, SafeSize.Y); BottomRight = new PointF((int)res.Width - SafeSize.X, (int)res.Height - SafeSize.Y); } var rectSize = new SizeF(BottomRight.SubtractPoints(TopLeft)); DrawInstructionalButtons?.Invoke(this, EventArgs.Empty); if (DrawBg) { new UIResRectangle(TopLeft, rectSize, Color.FromArgb((Focused || !FadeInWhenFocused) ? 200 : 120, 0, 0, 0)).Draw(); var tileSize = 100; RockstarTile.Size = new SizeF(tileSize, tileSize); var cols = (int)rectSize.Width / tileSize; var fils = 4; for (int i = 0; i < cols * fils; i++) { RockstarTile.Position = TopLeft.AddPoints(new PointF(tileSize * (i % cols), tileSize * (i / cols))); RockstarTile.Color = Color.FromArgb((int)MiscExtensions.LinearFloatLerp(40, 0, i / cols, fils), 255, 255, 255); RockstarTile.Draw(); } } }
/// <summary> /// Find answers based on the topics. /// </summary> /// <param name="top">the topic</param> /// <returns>a list of answer templates</returns> protected virtual List <string> FindSpecificAnswers(string top) { List <string> files = Assembly.GetEntryAssembly().GetManifestResourceNames().Where(s => s.StartsWith(SmallTalkPath)) .Select(s => s.Substring(SmallTalkPath.Length + 1)) .Select(f => Path.GetFileNameWithoutExtension(f)).Where(f => f.StartsWith(top)).ToList(); if (!files.Any()) { throw new FileNotFoundException($"No file found for {top}"); } if (files.Count == 1) { string data = MiscExtensions.LoadEmbeddedResource(SmallTalkPath + "." + $"{files[0]}.json"); return(JsonConvert.DeserializeObject <List <string> >(data)); } List <string> entities = files.Where(f => f.StartsWith($"{top}_")).Select(f => f.Split('_', 2)[1]).ToList(); // Assume List Entity Name to be "E_{topic}" if (!TheBot.Result.Entities.TryGetValue($"E_{top}", out List <IEntity> foundEntities)) { string data = MiscExtensions.LoadEmbeddedResource(SmallTalkPath + "." + $"{top}.json"); return(JsonConvert.DeserializeObject <List <string> >(data)); } // Assume List Entity var roots = foundEntities.Where(e => e.EType == EntityType.Group).Cast <GroupEntity>().Select(e => e.Shape); List <string> paths = entities.Where(e => roots.Contains(e)).Select(e => SmallTalkPath + "." + $"{top}_{e}.json").ToList(); if (!paths.Any()) { string data = MiscExtensions.LoadEmbeddedResource(SmallTalkPath + "." + $"{top}.json"); return(JsonConvert.DeserializeObject <List <string> >(data)); } return(paths.SelectMany(p => JsonConvert.DeserializeObject <List <string> >(MiscExtensions.LoadEmbeddedResource(p))).ToList()); }
public void ClampTest() { Assert.IsTrue(MiscExtensions.Clamp(10, 0, 20) == 10 && MiscExtensions.Clamp(10, 15, 20) == 15 && MiscExtensions.Clamp(10, 0, 5) == 5); }
public void ClampAngleTest() { Assert.IsTrue(MiscExtensions.ClampAngle(420) >= 0 && MiscExtensions.ClampAngle(420) <= 360); }
public void AbsTest() { Assert.IsTrue(MiscExtensions.Abs(-69) == 69); }
public static bool IsSubsampledY(this WICJpegYCrCbSubsamplingOption o) => MiscExtensions.IsSubsampledY((ChromaSubsampleMode)o);
public void Tick() { if (!Main.IsOnServer()) { return; } var timePassed = Math.Min(DateTime.Now.Subtract(_focusStart).TotalMilliseconds, DateTime.Now.Subtract(_lastMsg).TotalMilliseconds); int alpha = 100; if (timePassed > 60000 && !_isFocused) { alpha = (int)MiscExtensions.QuadraticEasingLerp(100f, 0f, (int)Math.Min(timePassed - 60000, 2000), 2000); } if (timePassed < 300 && _lastFadedOut) { alpha = (int)MiscExtensions.QuadraticEasingLerp(0f, 100f, (int)Math.Min(timePassed, 300), 300); } var textAlpha = (alpha / 100f) * 126 + 126; var c = 0; if (_messages.Any()) { for (int indx = Math.Min(_messagesPerPage + _pagingIndex, _messages.Count - 1); indx >= (_messages.Count <= _messagesPerPage ? 0 : _pagingIndex); indx--) { var msg = _messages[indx]; Point position = Main.PlayerSettings.ScaleChatWithSafezone ? UIMenu.GetSafezoneBounds() + new Size(0, 25 * c) : new Point(0, 25 * c); string output = msg.Item1; var res = GTA.UI.Screen.Resolution; int length = NativeUI.StringMeasurer.MeasureString(output); while (length > res.Width - 10 - position.X && output.Length > 10) { output = output.Substring(0, Math.Max(10, output.Length - 10)); length = NativeUI.StringMeasurer.MeasureString(output); } new UIResText(output, position, 0.45f, Color.FromArgb((int)textAlpha, msg.Item2)) { Outline = true, }.Draw(); c++; } } if (_pagingIndex != 0 && _messages.Count > _messagesPerPage) { Point start = UIMenu.GetSafezoneBounds(); if (!Main.PlayerSettings.ScaleChatWithSafezone) { start = new Point(); } start = new Point(start.X - 15, start.Y); var chatHeight = 25 * (_messagesPerPage + 1); var availableChoices = _messages.Count - _messagesPerPage; var barHeight = (1f / availableChoices) * chatHeight; new UIResRectangle(start, new Size(10, chatHeight), Color.FromArgb(50, 0, 0, 0)).Draw(); new UIResRectangle(start + new Size(0, (int)(chatHeight - chatHeight * ((_pagingIndex + 1) / (float)availableChoices))), new Size(10, (int)barHeight), Color.FromArgb(150, 0, 0, 0)).Draw(); } if (!Main.CanOpenChatbox) { IsFocused = false; } if (!IsFocused) { return; } DrawChatboxInput(); Game.DisableControlThisFrame(0, Control.NextCamera); Game.DisableAllControlsThisFrame(0); }
public void Tick() { if (!Main.IsOnServer()) { return; } var timePassed = Math.Min(DateTime.Now.Subtract(_focusStart).TotalMilliseconds, DateTime.Now.Subtract(_lastMsg).TotalMilliseconds); int alpha = 100; if (timePassed > 60000 && !_isFocused) { alpha = (int)MiscExtensions.QuadraticEasingLerp(100f, 0f, (int)Math.Min(timePassed - 60000, 2000), 2000); } if (timePassed < 300 && _lastFadedOut) { alpha = (int)MiscExtensions.QuadraticEasingLerp(0f, 100f, (int)Math.Min(timePassed, 300), 300); } var pos = GetInputboxPos(Main.PlayerSettings.ScaleChatWithSafezone); _mainScaleform.Render2DScreenSpace(new PointF(pos.X, pos.Y), new PointF(UI.WIDTH, UI.HEIGHT)); var textAlpha = (alpha / 100f) * 126 + 126; var c = 0; if (_messages.Any()) { for (int indx = Math.Min(_messagesPerPage + _pagingIndex, _messages.Count - 1); indx >= (_messages.Count <= _messagesPerPage ? 0 : _pagingIndex); indx--) { var msg = _messages[indx]; string output = msg.Item1; var limit = UIMenu.GetScreenResolutionMantainRatio().Width - UIMenu.GetSafezoneBounds().X; while (StringMeasurer.MeasureString(output) > limit) { output = output.Substring(0, output.Length - 5); } if (Main.PlayerSettings.ScaleChatWithSafezone) { new UIResText(output, UIMenu.GetSafezoneBounds() + new Size(0, 25 * c), 0.35f, Color.FromArgb((int)textAlpha, msg.Item2)) { Outline = true, }.Draw(); } else { new UIResText(output, new Point(0, 25 * c), 0.35f, Color.FromArgb((int)textAlpha, msg.Item2)) { Outline = true, }.Draw(); } c++; } } if (_pagingIndex != 0 && _messages.Count > _messagesPerPage) { Point start = UIMenu.GetSafezoneBounds(); if (!Main.PlayerSettings.ScaleChatWithSafezone) { start = new Point(); } start = new Point(start.X - 15, start.Y); var chatHeight = 25 * (_messagesPerPage + 1); var availableChoices = _messages.Count - _messagesPerPage; var barHeight = (1f / availableChoices) * chatHeight; new UIResRectangle(start, new Size(10, chatHeight), Color.FromArgb(50, 0, 0, 0)).Draw(); new UIResRectangle(start + new Size(0, (int)(chatHeight - chatHeight * ((_pagingIndex + 1) / (float)availableChoices))), new Size(10, (int)barHeight), Color.FromArgb(150, 0, 0, 0)).Draw(); } if (!IsFocused) { return; } if (!Main.CanOpenChatbox) { IsFocused = false; } Game.DisableControlThisFrame(0, Control.NextCamera); Game.DisableAllControlsThisFrame(0); }
/// <summary> /// Transform a property to a different value /// </summary> /// <param name="obj">Original value of the property</param> /// <param name="member">Property info</param> /// <param name="i">Current slice</param> /// <returns>The resulting transformed object</returns> public virtual object TransformInput(object obj, PropertyInfo member, int i) { return(MiscExtensions.MapVVVVValueToSystemNumerics(obj)); }
public Type TransformType(Type original, MemberInfo member) { return(MiscExtensions.MapSystemNumericsTypeToVVVV(original)); }
/// <summary> /// Creates the analyzer. /// </summary> /// <param name="lang">Defines the language.</param> /// <exception cref="ArgumentException">unsupported language.</exception> public RegexQuestionAnalyzer(Language lang) { if (!Configs.Contains(lang)) { throw new ArgumentException("Your Language is not supported."); } _map = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(MiscExtensions.LoadEmbeddedResource($"Framework.DialogAnalyzer.QuestionTypes_{Maps[lang]}.json")); }
/// <summary> /// Transform the type a property to a different one /// </summary> /// <param name="original">Original type of the property</param> /// <param name="member">Property info</param> /// <returns>The resulting transformed type</returns> public virtual Type TransformType(Type original, PropertyInfo member) { return(MiscExtensions.MapSystemNumericsTypeToVVVV(original)); }
/// <summary> /// Transform the default value of the property to a different value /// </summary> /// <param name="obj">Original value of the property</param> /// <param name="member">Property info</param> /// <param name="i">Current slice</param> /// <returns>The resulting transformed object</returns> public virtual object TransformDefaultValue(object obj, PropertyInfo member) { return(MiscExtensions.MapSystemNumericsValueToVVVV(obj)); }
public object TransformOutput(object obj, MemberInfo member, int i) { return(MiscExtensions.MapSystemNumericsValueToVVVV(obj)); }
public void Tick() { if (!Main.IsOnServer()) { return; } var timePassed = Math.Min(DateTime.Now.Subtract(_focusStart).TotalMilliseconds, DateTime.Now.Subtract(_lastMsg).TotalMilliseconds); int alpha = 100; if (timePassed > 60000 && !_isFocused) { alpha = (int)MiscExtensions.QuadraticEasingLerp(100f, 0f, (int)Math.Min(timePassed - 60000, 2000), 2000); } if (timePassed < 300 && _lastFadedOut) { alpha = (int)MiscExtensions.QuadraticEasingLerp(0f, 100f, (int)Math.Min(timePassed, 300), 300); } var pos = GetInputboxPos(Main.PlayerSettings.ScaleChatWithSafezone); _mainScaleform.Render2DScreenSpace(new PointF(pos.X, pos.Y), new PointF(UI.WIDTH, UI.HEIGHT)); var textAlpha = (alpha / 100f) * 126 + 126; var c = 0; foreach (var msg in _messages) { string output = msg.Item1; var limit = UIMenu.GetScreenResolutionMaintainRatio().Width - UIMenu.GetSafezoneBounds().X; while (StringMeasurer.MeasureString(output) > limit) { output = output.Substring(0, output.Length - 5); } if (Main.PlayerSettings.ScaleChatWithSafezone) { new UIResText(output, UIMenu.GetSafezoneBounds() + new Size(0, 25 * c), 0.35f, Color.FromArgb((int)textAlpha, msg.Item2)) { Outline = true, }.Draw(); } else { new UIResText(output, new Point(0, 25 * c), 0.35f, Color.FromArgb((int)textAlpha, msg.Item2)) { Outline = true, }.Draw(); } c++; } if (!IsFocused) { return; } Game.DisableControlThisFrame(0, Control.NextCamera); Game.DisableAllControlsThisFrame(0); Function.Call(Hash.DISABLE_ALL_CONTROL_ACTIONS, 0); }