From 124b150b2a0a9ac8a3b1f483efc81116afee3ca6 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Tue, 20 Oct 2020 17:34:27 +0300 Subject: [PATCH 1/8] Update .net sdk --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index d0bfd1d..e73a5fd 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "3.1.300" + "version": "3.1.403" } } \ No newline at end of file From 0667bb14c524f1a35055f0f7572050653f46f9c0 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Tue, 20 Oct 2020 17:43:23 +0300 Subject: [PATCH 2/8] Add listen endpoint to settings --- src/Grinder/Program.fs | 3 ++- src/Grinder/appsettings.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Grinder/Program.fs b/src/Grinder/Program.fs index db29908..bd7c308 100644 --- a/src/Grinder/Program.fs +++ b/src/Grinder/Program.fs @@ -36,6 +36,7 @@ module Program = AllowedUsers: string array ChannelId: int64 AdminUserId: int64 + ListenEndpoint: string } [] @@ -174,7 +175,7 @@ module Program = // Needed for azure web app deploy check. We have to response with anything on port 80 use listener = new HttpListener() - listener.Prefixes.Add("http://*:80/") + listener.Prefixes.Add(config.ListenEndpoint) listener.Start() let buffer = System.Text.Encoding.UTF8.GetBytes "OK" diff --git a/src/Grinder/appsettings.json b/src/Grinder/appsettings.json index 2b88449..6c2f933 100644 --- a/src/Grinder/appsettings.json +++ b/src/Grinder/appsettings.json @@ -3,6 +3,7 @@ "Token": "REPLACEME", "ChannelId": 0, "AdminUserId": 0, + "ListenEndpoint": "http://*:80/", // uncomment if you need proxy // "Socks5Proxy": { // "Hostname": "REPLACEME", From 722ce135de3a50646cb8b3d5fa631695e9914d09 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Tue, 20 Oct 2020 17:47:08 +0300 Subject: [PATCH 3/8] Disable azure webserver --- src/Grinder/Program.fs | 29 ++++++++++++++++------------- src/Grinder/appsettings.json | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Grinder/Program.fs b/src/Grinder/Program.fs index bd7c308..5c49f8d 100644 --- a/src/Grinder/Program.fs +++ b/src/Grinder/Program.fs @@ -36,7 +36,7 @@ module Program = AllowedUsers: string array ChannelId: int64 AdminUserId: int64 - ListenEndpoint: string + RunAzureWebServer: bool } [] @@ -173,18 +173,21 @@ module Program = printfn "Bot started" - // Needed for azure web app deploy check. We have to response with anything on port 80 - use listener = new HttpListener() - listener.Prefixes.Add(config.ListenEndpoint) - listener.Start() - - let buffer = System.Text.Encoding.UTF8.GetBytes "OK" - - while true do - let ctx = listener.GetContext() - let output = ctx.Response.OutputStream - output.Write(buffer, 0, buffer.Length) - output.Close(); + if config.RunAzureWebServer then + // Needed for azure web app deploy check. We have to response with anything on port 80 + use listener = new HttpListener() + listener.Prefixes.Add("http://*:80/") + listener.Start() + + let buffer = System.Text.Encoding.UTF8.GetBytes "OK" + + while true do + let ctx = listener.GetContext() + let output = ctx.Response.OutputStream + output.Write(buffer, 0, buffer.Length) + output.Close() + else + Console.ReadLine () |> ignore printfn "Bot exited" 0 // return an integer exit code \ No newline at end of file diff --git a/src/Grinder/appsettings.json b/src/Grinder/appsettings.json index 6c2f933..166ba99 100644 --- a/src/Grinder/appsettings.json +++ b/src/Grinder/appsettings.json @@ -3,7 +3,7 @@ "Token": "REPLACEME", "ChannelId": 0, "AdminUserId": 0, - "ListenEndpoint": "http://*:80/", + "RunAzureWebServer": true, // uncomment if you need proxy // "Socks5Proxy": { // "Hostname": "REPLACEME", From e2cc90f3c43e89e570f3057a0ab261b7b2e17637 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Tue, 20 Oct 2020 18:14:36 +0300 Subject: [PATCH 4/8] Update docs --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 68d6130..c3440cc 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ You can choose two ways to configure grinder but keep in mind about configuratio "Token": "test", "ChannelId": 111, "AdminUserId": 123, + "RunAzureWebServer": true, "Socks5Proxy": { "Hostname": "Hostme", "Port": 1337, @@ -71,8 +72,8 @@ You can choose two ways to configure grinder but keep in mind about configuratio "Password": "Secrete" }, "ChatsToMonitor": [ - "Sample", - "Text" + "@Sample", + "@Text" ], "AllowedUsers": [ "Pasha", @@ -102,8 +103,8 @@ Grinder_Bot__AllowedUsers__0=Pasha Grinder_Bot__AllowedUsers__1=Technique #ChatsToMonitor - chats where bot will read messages and replies -Grinder_Bot__ChatsToMonitor__0=Sample -Grinder_Bot__ChatsToMonitor__1=Text +Grinder_Bot__ChatsToMonitor__0=@Sample +Grinder_Bot__ChatsToMonitor__1=@Text #AdminUserId - telegram user id who will be able to send private messages to bot Grinder_Bot__AdminUserId=123 From 55d12857e4f6f7c9b63a62fe038b3a90ffb6e462 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Tue, 20 Oct 2020 18:14:53 +0300 Subject: [PATCH 5/8] Fix username searching --- src/Grinder/Datastore.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Grinder/Datastore.fs b/src/Grinder/Datastore.fs index 9a9e30d..795e54d 100644 --- a/src/Grinder/Datastore.fs +++ b/src/Grinder/Datastore.fs @@ -28,7 +28,7 @@ module Datastore = use context = new GrinderContext() let! user = context.Users - .FirstOrDefaultAsync(fun u -> u.Username = username.TrimStart('@')) + .FirstOrDefaultAsync(fun u -> u.Username.ToLower() = username.TrimStart('@').ToLower()) return user |> Option.ofObj |> Option.fold (fun _ u -> UserIdFound u.UserId) UserIdNotFound From 14f6f62f007eb2385caa699114ac57e6eb7a697a Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Tue, 20 Oct 2020 18:21:36 +0300 Subject: [PATCH 6/8] Revert sdk version --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index e73a5fd..d0bfd1d 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "3.1.403" + "version": "3.1.300" } } \ No newline at end of file From 829f19892650cbeb160fc00b3153298b66577e21 Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Tue, 20 Oct 2020 18:30:38 +0300 Subject: [PATCH 7/8] Replace invariant string comparison with StringComparison.InvariantCultureIgnoreCase --- src/Grinder/Datastore.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Grinder/Datastore.fs b/src/Grinder/Datastore.fs index 795e54d..f1046c2 100644 --- a/src/Grinder/Datastore.fs +++ b/src/Grinder/Datastore.fs @@ -1,5 +1,6 @@ namespace Grinder +open System open FSharp.Control.Tasks.V2 open Microsoft.EntityFrameworkCore open Grinder.DataAccess @@ -28,7 +29,7 @@ module Datastore = use context = new GrinderContext() let! user = context.Users - .FirstOrDefaultAsync(fun u -> u.Username.ToLower() = username.TrimStart('@').ToLower()) + .FirstOrDefaultAsync(fun u -> u.Username.Equals(username.TrimStart('@'), StringComparison.InvariantCultureIgnoreCase)) return user |> Option.ofObj |> Option.fold (fun _ u -> UserIdFound u.UserId) UserIdNotFound From 3e7e15122f84fd220af7419982c119a3d900ba0c Mon Sep 17 00:00:00 2001 From: YogurtTheHorse Date: Tue, 20 Oct 2020 18:37:13 +0300 Subject: [PATCH 8/8] Replace RunAzureWebServer with DisableAzureWebServer With such change no config changes will be required on server --- src/Grinder/Program.fs | 4 ++-- src/Grinder/appsettings.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Grinder/Program.fs b/src/Grinder/Program.fs index 5c49f8d..73e9106 100644 --- a/src/Grinder/Program.fs +++ b/src/Grinder/Program.fs @@ -36,7 +36,7 @@ module Program = AllowedUsers: string array ChannelId: int64 AdminUserId: int64 - RunAzureWebServer: bool + DisableAzureWebServer: bool } [] @@ -173,7 +173,7 @@ module Program = printfn "Bot started" - if config.RunAzureWebServer then + if not config.DisableAzureWebServer then // Needed for azure web app deploy check. We have to response with anything on port 80 use listener = new HttpListener() listener.Prefixes.Add("http://*:80/") diff --git a/src/Grinder/appsettings.json b/src/Grinder/appsettings.json index 166ba99..1e1c731 100644 --- a/src/Grinder/appsettings.json +++ b/src/Grinder/appsettings.json @@ -3,7 +3,7 @@ "Token": "REPLACEME", "ChannelId": 0, "AdminUserId": 0, - "RunAzureWebServer": true, + "DisableAzureWebServer": true, // uncomment if you need proxy // "Socks5Proxy": { // "Hostname": "REPLACEME",