Skip to content

Commit

Permalink
Fix Couldn't resolve username @name and add option to disable web s…
Browse files Browse the repository at this point in the history
…erver run (Liminiens#34)

* Update .net sdk

* Add listen endpoint to settings

* Disable azure webserver

* Update docs

* Fix username searching

* Revert sdk version

* Replace invariant string comparison with StringComparison.InvariantCultureIgnoreCase

* Replace RunAzureWebServer with DisableAzureWebServer

With such change no config changes will be required on server
  • Loading branch information
YogurtTheHorse authored Oct 21, 2020
1 parent 07b408c commit 8d29618
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ 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,
"Username": "User",
"Password": "Secrete"
},
"ChatsToMonitor": [
"Sample",
"Text"
"@Sample",
"@Text"
],
"AllowedUsers": [
"Pasha",
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Grinder/Datastore.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Grinder

open System
open FSharp.Control.Tasks.V2
open Microsoft.EntityFrameworkCore
open Grinder.DataAccess
Expand Down Expand Up @@ -28,7 +29,7 @@ module Datastore =
use context = new GrinderContext()
let! user =
context.Users
.FirstOrDefaultAsync(fun u -> u.Username = username.TrimStart('@'))
.FirstOrDefaultAsync(fun u -> u.Username.Equals(username.TrimStart('@'), StringComparison.InvariantCultureIgnoreCase))
return user
|> Option.ofObj
|> Option.fold (fun _ u -> UserIdFound u.UserId) UserIdNotFound
Expand Down
28 changes: 16 additions & 12 deletions src/Grinder/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Program =
AllowedUsers: string array
ChannelId: int64
AdminUserId: int64
DisableAzureWebServer: bool
}

[<CLIMutable>]
Expand Down Expand Up @@ -172,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("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();
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/")
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
1 change: 1 addition & 0 deletions src/Grinder/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Token": "REPLACEME",
"ChannelId": 0,
"AdminUserId": 0,
"DisableAzureWebServer": true,
// uncomment if you need proxy
// "Socks5Proxy": {
// "Hostname": "REPLACEME",
Expand Down

0 comments on commit 8d29618

Please sign in to comment.