From dcd74c8667f93b0360b42a0f157ed992aa62e693 Mon Sep 17 00:00:00 2001 From: Ronny Gunawan <3048897+ronnygunawan@users.noreply.github.com> Date: Tue, 31 Oct 2023 19:44:53 +0700 Subject: [PATCH] Fix JS syntax highlighting --- BotNet.Services/BotCommands/Exec.cs | 6 +++--- BotNet/Bot/UpdateHandler.cs | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/BotNet.Services/BotCommands/Exec.cs b/BotNet.Services/BotCommands/Exec.cs index 18eba71..13d5d35 100644 --- a/BotNet.Services/BotCommands/Exec.cs +++ b/BotNet.Services/BotCommands/Exec.cs @@ -15,7 +15,7 @@ namespace BotNet.Services.BotCommands { public static class Exec { private static DateTimeOffset _skipPestoUntil = DateTimeOffset.Now; - public static async Task ExecAsync(ITelegramBotClient botClient, IServiceProvider serviceProvider, Message message, string language, CancellationToken cancellationToken) { + public static async Task ExecAsync(ITelegramBotClient botClient, IServiceProvider serviceProvider, Message message, string language, string highlightLanguage, CancellationToken cancellationToken) { if (message.Entities?.FirstOrDefault() is { Type: MessageEntityType.BotCommand, Offset: 0, Length: int commandLength } && message.Text![commandLength..].Trim() is string commandArgument) { if (commandArgument.Length > 0) { @@ -48,7 +48,7 @@ await botClient.SendTextMessageAsync( } else { await botClient.SendTextMessageAsync( chatId: message.Chat.Id, - text: $"Code:\n```{language}\n{MarkdownV2Sanitizer.Sanitize(commandArgument)}\n```\n\nOutput:\n```\n{MarkdownV2Sanitizer.Sanitize(result.Run.Output)}\n```", + text: $"Code:\n```{highlightLanguage}\n{MarkdownV2Sanitizer.Sanitize(commandArgument)}\n```\nOutput:\n```\n{MarkdownV2Sanitizer.Sanitize(result.Run.Output)}\n```", parseMode: ParseMode.MarkdownV2, replyToMessageId: message.MessageId, cancellationToken: cancellationToken); @@ -99,7 +99,7 @@ await botClient.SendTextMessageAsync( } else { await botClient.SendTextMessageAsync( chatId: message.Chat.Id, - text: $"Code:\n```{language}\n{MarkdownV2Sanitizer.Sanitize(repliedToMessage)}\n```\n\nOutput:\n```\n{MarkdownV2Sanitizer.Sanitize(result.Run.Output)}\n```", + text: $"Code:\n```{highlightLanguage}\n{MarkdownV2Sanitizer.Sanitize(repliedToMessage)}\n```\nOutput:\n```\n{MarkdownV2Sanitizer.Sanitize(result.Run.Output)}\n```", parseMode: ParseMode.MarkdownV2, replyToMessageId: message.ReplyToMessage.MessageId, cancellationToken: cancellationToken); diff --git a/BotNet/Bot/UpdateHandler.cs b/BotNet/Bot/UpdateHandler.cs index 168f373..3749d43 100644 --- a/BotNet/Bot/UpdateHandler.cs +++ b/BotNet/Bot/UpdateHandler.cs @@ -211,31 +211,31 @@ await _clusterClient.GetGrain(sentMessage.MessageId).Track case "/scala": case "/swift": case "/julia": - await Exec.ExecAsync(botClient, _serviceProvider, update.Message, command.ToLowerInvariant()[1..], cancellationToken); + await Exec.ExecAsync(botClient, _serviceProvider, update.Message, command.ToLowerInvariant()[1..], command.ToLowerInvariant()[1..], cancellationToken); break; case "/sqlite3": - await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "SQLite3", cancellationToken); + await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "SQLite3", "sqlite3", cancellationToken); break; case "/commonlisp": - await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "CommonLisp", cancellationToken); + await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "CommonLisp", "cl", cancellationToken); break; case "/cpp": - await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "C++", cancellationToken); + await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "C++", "cpp", cancellationToken); break; case "/cs": - await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "csharp.net", cancellationToken); + await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "csharp.net", "csharp", cancellationToken); break; case "/fs": - await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "fsharp.net", cancellationToken); + await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "fsharp.net", "fsharp", cancellationToken); break; case "/js": - await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "JavaScript", cancellationToken); + await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "JavaScript", "js", cancellationToken); break; case "/ts": - await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "TypeScript", cancellationToken); + await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "TypeScript", "ts", cancellationToken); break; case "/vb": - await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "basic.net", cancellationToken); + await Exec.ExecAsync(botClient, _serviceProvider, update.Message, "basic.net", "vbnet", cancellationToken); break; case "/pop": await botClient.SendTextMessageAsync(