diff --git a/.gitignore b/.gitignore index c7ad158..a9bd15c 100644 --- a/.gitignore +++ b/.gitignore @@ -561,4 +561,5 @@ dist .history .ionide -# End of https://www.toptal.com/developers/gitignore/api/csharp,fsharp,node,visualstudiocode \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/csharp,fsharp,node,visualstudiocode +Keroosha.SilencerBot/token diff --git a/Keroosha.SilencerBot/Database.fs b/Keroosha.SilencerBot/Database.fs index 5ced8ac..d9af61a 100644 --- a/Keroosha.SilencerBot/Database.fs +++ b/Keroosha.SilencerBot/Database.fs @@ -44,6 +44,7 @@ let migrateApp (connectionString: string) = use serviceProvider = ServiceCollection() .AddFluentMigratorCore() + .AddLogging(fun x -> x.AddFluentMigratorConsole() |> ignore) .ConfigureRunner(fun x -> x.AddPostgres() .WithMigrationsIn(typeof.Assembly) @@ -51,12 +52,12 @@ let migrateApp (connectionString: string) = ) .BuildServiceProvider(false) use scope = serviceProvider.CreateScope() - serviceProvider.GetRequiredService().MigrateUp() + scope.ServiceProvider.GetRequiredService().MigrateUp() let createContext (connectionString: string) = new DbContext(connectionString, PostgreSQLTools.GetDataProvider()) -[] +[] type InitialMigration() = inherit AutoReversingMigration() override this.Up() = diff --git a/Keroosha.SilencerBot/Keroosha.SilencerBot.fsproj b/Keroosha.SilencerBot/Keroosha.SilencerBot.fsproj index 7dabb0d..90dd9be 100644 --- a/Keroosha.SilencerBot/Keroosha.SilencerBot.fsproj +++ b/Keroosha.SilencerBot/Keroosha.SilencerBot.fsproj @@ -1,4 +1,4 @@ - + Exe diff --git a/Keroosha.SilencerBot/Program.fs b/Keroosha.SilencerBot/Program.fs index eb83363..976c127 100644 --- a/Keroosha.SilencerBot/Program.fs +++ b/Keroosha.SilencerBot/Program.fs @@ -11,13 +11,14 @@ let config = Env.createConfig "SILENCER_BOT_CONFIG_PATH" let botConfig = Config.defaultConfig |> Config.withReadTokenFromFile let ctxFactory = fun () -> Database.createContext <| config.connectionString -Console.CancelKeyPress |> Event.add (fun _ -> Environment.Exit <| 0) Database.migrateApp config.connectionString let botInbox = createBotInbox <| (botConfig, ctxFactory) let handleUpdate (ctx: UpdateContext) = resolveUpdate ctx |> botInbox.Post +Console.CancelKeyPress |> Event.add (fun _ -> Environment.Exit <| 0) + async { let! _ = Api.makeRequestAsync botConfig <| Api.deleteWebhookBase() return! startBot botConfig handleUpdate None diff --git a/Keroosha.SilencerBot/Telegram.fs b/Keroosha.SilencerBot/Telegram.fs index 19f2e06..46467df 100644 --- a/Keroosha.SilencerBot/Telegram.fs +++ b/Keroosha.SilencerBot/Telegram.fs @@ -20,7 +20,7 @@ let isVoiceRemoveAction(update: Update) = let resolveUpdate (ctx: UpdateContext) = match ctx.Update with | x when isVoiceRemoveAction x -> - VoiceRemove { fileId = x.Message.Value.Audio.Value.FileId; chatId = x.Message.Value.Chat.Id } + VoiceRemove { fileId = x.Message.Value.Audio.Value.FileId; chatId = x.Message.Value.Chat.Id } | _ -> Unknown let createBotInbox (cfg: BotConfig, db: unit -> DbContext) = MailboxProcessor.Start(fun (inbox) -> diff --git a/Keroosha.SilencerBot/config.example.json b/Keroosha.SilencerBot/config.example.json index 9cf4472..cb82363 100644 --- a/Keroosha.SilencerBot/config.example.json +++ b/Keroosha.SilencerBot/config.example.json @@ -1,3 +1,4 @@ { - "ConnectionString": "Server=127.0.0.1;User id=postgres;password=postgres;database=silencer-bot" + "connectionString": "Server=127.0.0.1;User id=postgres;password=postgres;database=silencer-bot", + "tempSavePath": "/tmp" } \ No newline at end of file