Initial commit
This commit is contained in:
		
						commit
						0663a2b94e
					
				
					 10 changed files with 358 additions and 0 deletions
				
			
		
							
								
								
									
										238
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										238
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,238 @@
 | 
			
		|||
# Created by https://www.toptal.com/developers/gitignore/api/fsharp,node,rider
 | 
			
		||||
# Edit at https://www.toptal.com/developers/gitignore?templates=fsharp,node,rider
 | 
			
		||||
 | 
			
		||||
### fsharp ###
 | 
			
		||||
lib/debug
 | 
			
		||||
lib/release
 | 
			
		||||
Debug
 | 
			
		||||
*.suo
 | 
			
		||||
*.user
 | 
			
		||||
obj
 | 
			
		||||
bin
 | 
			
		||||
/build/
 | 
			
		||||
*.exe
 | 
			
		||||
!.paket/paket.bootstrapper.exe
 | 
			
		||||
.ionide/
 | 
			
		||||
.fake
 | 
			
		||||
 | 
			
		||||
### Node ###
 | 
			
		||||
# Logs
 | 
			
		||||
logs
 | 
			
		||||
*.log
 | 
			
		||||
npm-debug.log*
 | 
			
		||||
yarn-debug.log*
 | 
			
		||||
yarn-error.log*
 | 
			
		||||
lerna-debug.log*
 | 
			
		||||
.pnpm-debug.log*
 | 
			
		||||
 | 
			
		||||
# Diagnostic reports (https://nodejs.org/api/report.html)
 | 
			
		||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
 | 
			
		||||
 | 
			
		||||
# Runtime data
 | 
			
		||||
pids
 | 
			
		||||
*.pid
 | 
			
		||||
*.seed
 | 
			
		||||
*.pid.lock
 | 
			
		||||
 | 
			
		||||
# Directory for instrumented libs generated by jscoverage/JSCover
 | 
			
		||||
lib-cov
 | 
			
		||||
 | 
			
		||||
# Coverage directory used by tools like istanbul
 | 
			
		||||
coverage
 | 
			
		||||
*.lcov
 | 
			
		||||
 | 
			
		||||
# nyc test coverage
 | 
			
		||||
.nyc_output
 | 
			
		||||
 | 
			
		||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
 | 
			
		||||
.grunt
 | 
			
		||||
 | 
			
		||||
# Bower dependency directory (https://bower.io/)
 | 
			
		||||
bower_components
 | 
			
		||||
 | 
			
		||||
# node-waf configuration
 | 
			
		||||
.lock-wscript
 | 
			
		||||
 | 
			
		||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
 | 
			
		||||
build/Release
 | 
			
		||||
 | 
			
		||||
# Dependency directories
 | 
			
		||||
node_modules/
 | 
			
		||||
jspm_packages/
 | 
			
		||||
 | 
			
		||||
# Snowpack dependency directory (https://snowpack.dev/)
 | 
			
		||||
web_modules/
 | 
			
		||||
 | 
			
		||||
# TypeScript cache
 | 
			
		||||
*.tsbuildinfo
 | 
			
		||||
 | 
			
		||||
# Optional npm cache directory
 | 
			
		||||
.npm
 | 
			
		||||
 | 
			
		||||
# Optional eslint cache
 | 
			
		||||
.eslintcache
 | 
			
		||||
 | 
			
		||||
# Optional stylelint cache
 | 
			
		||||
.stylelintcache
 | 
			
		||||
 | 
			
		||||
# Microbundle cache
 | 
			
		||||
.rpt2_cache/
 | 
			
		||||
.rts2_cache_cjs/
 | 
			
		||||
.rts2_cache_es/
 | 
			
		||||
.rts2_cache_umd/
 | 
			
		||||
 | 
			
		||||
# Optional REPL history
 | 
			
		||||
.node_repl_history
 | 
			
		||||
 | 
			
		||||
# Output of 'npm pack'
 | 
			
		||||
*.tgz
 | 
			
		||||
 | 
			
		||||
# Yarn Integrity file
 | 
			
		||||
.yarn-integrity
 | 
			
		||||
 | 
			
		||||
# dotenv environment variable files
 | 
			
		||||
.env
 | 
			
		||||
.env.development.local
 | 
			
		||||
.env.test.local
 | 
			
		||||
.env.production.local
 | 
			
		||||
.env.local
 | 
			
		||||
 | 
			
		||||
# parcel-bundler cache (https://parceljs.org/)
 | 
			
		||||
.cache
 | 
			
		||||
.parcel-cache
 | 
			
		||||
 | 
			
		||||
# Next.js build output
 | 
			
		||||
.next
 | 
			
		||||
out
 | 
			
		||||
 | 
			
		||||
# Nuxt.js build / generate output
 | 
			
		||||
.nuxt
 | 
			
		||||
dist
 | 
			
		||||
 | 
			
		||||
# Gatsby files
 | 
			
		||||
.cache/
 | 
			
		||||
# Comment in the public line in if your project uses Gatsby and not Next.js
 | 
			
		||||
# https://nextjs.org/blog/next-9-1#public-directory-support
 | 
			
		||||
# public
 | 
			
		||||
 | 
			
		||||
# vuepress build output
 | 
			
		||||
.vuepress/dist
 | 
			
		||||
 | 
			
		||||
# vuepress v2.x temp and cache directory
 | 
			
		||||
.temp
 | 
			
		||||
 | 
			
		||||
# Docusaurus cache and generated files
 | 
			
		||||
.docusaurus
 | 
			
		||||
 | 
			
		||||
# Serverless directories
 | 
			
		||||
.serverless/
 | 
			
		||||
 | 
			
		||||
# FuseBox cache
 | 
			
		||||
.fusebox/
 | 
			
		||||
 | 
			
		||||
# DynamoDB Local files
 | 
			
		||||
.dynamodb/
 | 
			
		||||
 | 
			
		||||
# TernJS port file
 | 
			
		||||
.tern-port
 | 
			
		||||
 | 
			
		||||
# Stores VSCode versions used for testing VSCode extensions
 | 
			
		||||
.vscode-test
 | 
			
		||||
 | 
			
		||||
# yarn v2
 | 
			
		||||
.yarn/cache
 | 
			
		||||
.yarn/unplugged
 | 
			
		||||
.yarn/build-state.yml
 | 
			
		||||
.yarn/install-state.gz
 | 
			
		||||
.pnp.*
 | 
			
		||||
 | 
			
		||||
### Node Patch ###
 | 
			
		||||
# Serverless Webpack directories
 | 
			
		||||
.webpack/
 | 
			
		||||
 | 
			
		||||
# Optional stylelint cache
 | 
			
		||||
 | 
			
		||||
# SvelteKit build / generate output
 | 
			
		||||
.svelte-kit
 | 
			
		||||
 | 
			
		||||
### Rider ###
 | 
			
		||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
 | 
			
		||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
 | 
			
		||||
 | 
			
		||||
# User-specific stuff
 | 
			
		||||
.idea/**/workspace.xml
 | 
			
		||||
.idea/**/tasks.xml
 | 
			
		||||
.idea/**/usage.statistics.xml
 | 
			
		||||
.idea/**/dictionaries
 | 
			
		||||
.idea/**/shelf
 | 
			
		||||
 | 
			
		||||
# AWS User-specific
 | 
			
		||||
.idea/**/aws.xml
 | 
			
		||||
 | 
			
		||||
# Generated files
 | 
			
		||||
.idea/**/contentModel.xml
 | 
			
		||||
 | 
			
		||||
# Sensitive or high-churn files
 | 
			
		||||
.idea/**/dataSources/
 | 
			
		||||
.idea/**/dataSources.ids
 | 
			
		||||
.idea/**/dataSources.local.xml
 | 
			
		||||
.idea/**/sqlDataSources.xml
 | 
			
		||||
.idea/**/dynamic.xml
 | 
			
		||||
.idea/**/uiDesigner.xml
 | 
			
		||||
.idea/**/dbnavigator.xml
 | 
			
		||||
 | 
			
		||||
# Gradle
 | 
			
		||||
.idea/**/gradle.xml
 | 
			
		||||
.idea/**/libraries
 | 
			
		||||
 | 
			
		||||
# Gradle and Maven with auto-import
 | 
			
		||||
# When using Gradle or Maven with auto-import, you should exclude module files,
 | 
			
		||||
# since they will be recreated, and may cause churn.  Uncomment if using
 | 
			
		||||
# auto-import.
 | 
			
		||||
# .idea/artifacts
 | 
			
		||||
# .idea/compiler.xml
 | 
			
		||||
# .idea/jarRepositories.xml
 | 
			
		||||
# .idea/modules.xml
 | 
			
		||||
# .idea/*.iml
 | 
			
		||||
# .idea/modules
 | 
			
		||||
# *.iml
 | 
			
		||||
# *.ipr
 | 
			
		||||
 | 
			
		||||
# CMake
 | 
			
		||||
cmake-build-*/
 | 
			
		||||
 | 
			
		||||
# Mongo Explorer plugin
 | 
			
		||||
.idea/**/mongoSettings.xml
 | 
			
		||||
 | 
			
		||||
# File-based project format
 | 
			
		||||
*.iws
 | 
			
		||||
 | 
			
		||||
# IntelliJ
 | 
			
		||||
out/
 | 
			
		||||
 | 
			
		||||
# mpeltonen/sbt-idea plugin
 | 
			
		||||
.idea_modules/
 | 
			
		||||
 | 
			
		||||
# JIRA plugin
 | 
			
		||||
atlassian-ide-plugin.xml
 | 
			
		||||
 | 
			
		||||
# Cursive Clojure plugin
 | 
			
		||||
.idea/replstate.xml
 | 
			
		||||
 | 
			
		||||
# SonarLint plugin
 | 
			
		||||
.idea/sonarlint/
 | 
			
		||||
 | 
			
		||||
# Crashlytics plugin (for Android Studio and IntelliJ)
 | 
			
		||||
com_crashlytics_export_strings.xml
 | 
			
		||||
crashlytics.properties
 | 
			
		||||
crashlytics-build.properties
 | 
			
		||||
fabric.properties
 | 
			
		||||
 | 
			
		||||
# Editor-based Rest Client
 | 
			
		||||
.idea/httpRequests
 | 
			
		||||
 | 
			
		||||
# Android studio 3.1+ serialized cache file
 | 
			
		||||
.idea/caches/build_file_checksums.ser
 | 
			
		||||
 | 
			
		||||
# End of https://www.toptal.com/developers/gitignore/api/fsharp,node,rider
 | 
			
		||||
PublishHelperBot/config.dev.json
 | 
			
		||||
							
								
								
									
										10
									
								
								.idea/.idea.PublishHelperBot/.idea/.gitignore
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								.idea/.idea.PublishHelperBot/.idea/.gitignore
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,10 @@
 | 
			
		|||
# Default ignored files
 | 
			
		||||
/shelf/
 | 
			
		||||
/workspace.xml
 | 
			
		||||
# Rider ignored files
 | 
			
		||||
/modules.xml
 | 
			
		||||
/projectSettingsUpdater.xml
 | 
			
		||||
/.idea.PublishHelperBot.iml
 | 
			
		||||
/contentModel.xml
 | 
			
		||||
# Editor-based HTTP Client requests
 | 
			
		||||
/httpRequests/
 | 
			
		||||
							
								
								
									
										4
									
								
								.idea/.idea.PublishHelperBot/.idea/encodings.xml
									
										
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.idea/.idea.PublishHelperBot/.idea/encodings.xml
									
										
									
										generated
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										8
									
								
								.idea/.idea.PublishHelperBot/.idea/indexLayout.xml
									
										
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.idea/.idea.PublishHelperBot/.idea/indexLayout.xml
									
										
									
										generated
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="UserContentModel">
 | 
			
		||||
    <attachedFolders />
 | 
			
		||||
    <explicitIncludes />
 | 
			
		||||
    <explicitExcludes />
 | 
			
		||||
  </component>
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										7
									
								
								.idea/.idea.PublishHelperBot/.idea/vcs.xml
									
										
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								.idea/.idea.PublishHelperBot/.idea/vcs.xml
									
										
									
										generated
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="VcsDirectoryMappings">
 | 
			
		||||
    <mapping directory="$PROJECT_DIR$/.." vcs="Git" />
 | 
			
		||||
    <mapping directory="$PROJECT_DIR$" vcs="Git" />
 | 
			
		||||
  </component>
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										16
									
								
								PublishHelperBot.sln
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								PublishHelperBot.sln
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
 | 
			
		||||
Microsoft Visual Studio Solution File, Format Version 12.00
 | 
			
		||||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PublishHelperBot", "PublishHelperBot\PublishHelperBot.fsproj", "{B6A593C7-C2A8-483C-B3A5-F943B59ABEF2}"
 | 
			
		||||
EndProject
 | 
			
		||||
Global
 | 
			
		||||
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 | 
			
		||||
		Debug|Any CPU = Debug|Any CPU
 | 
			
		||||
		Release|Any CPU = Release|Any CPU
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 | 
			
		||||
		{B6A593C7-C2A8-483C-B3A5-F943B59ABEF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 | 
			
		||||
		{B6A593C7-C2A8-483C-B3A5-F943B59ABEF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
 | 
			
		||||
		{B6A593C7-C2A8-483C-B3A5-F943B59ABEF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
 | 
			
		||||
		{B6A593C7-C2A8-483C-B3A5-F943B59ABEF2}.Release|Any CPU.Build.0 = Release|Any CPU
 | 
			
		||||
	EndGlobalSection
 | 
			
		||||
EndGlobal
 | 
			
		||||
							
								
								
									
										51
									
								
								PublishHelperBot/Program.fs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								PublishHelperBot/Program.fs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,51 @@
 | 
			
		|||
// For more information see https://aka.ms/fsharp-console-apps
 | 
			
		||||
 | 
			
		||||
open System
 | 
			
		||||
open System.IO
 | 
			
		||||
open System.Net.Http
 | 
			
		||||
open System.Threading
 | 
			
		||||
open System.Threading.Tasks
 | 
			
		||||
open Microsoft.FSharp.Control
 | 
			
		||||
open Newtonsoft.Json
 | 
			
		||||
open Telegram.Bot
 | 
			
		||||
open Telegram.Bot.Polling
 | 
			
		||||
open Telegram.Bot.Types
 | 
			
		||||
open Telegram.Bot.Types.Enums
 | 
			
		||||
 | 
			
		||||
type BotConfig = {
 | 
			
		||||
  token: string
 | 
			
		||||
  chanelId: int64
 | 
			
		||||
  adminChatId: int64
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
let ReadConfig =
 | 
			
		||||
  File.ReadAllText >> JsonConvert.DeserializeObject<BotConfig>
 | 
			
		||||
 | 
			
		||||
let CreateConfig (name: string) =
 | 
			
		||||
  match Environment.GetEnvironmentVariable(name) with
 | 
			
		||||
  | null ->  raise <| ApplicationException("Missing config path env")
 | 
			
		||||
  | path  -> ReadConfig <| path
 | 
			
		||||
 | 
			
		||||
let CreateBot (config: BotConfig, http: HttpClient) =
 | 
			
		||||
  TelegramBotClient(config.token, http)
 | 
			
		||||
 | 
			
		||||
let config = CreateConfig <| "SBPB_CONFIG_PATH";
 | 
			
		||||
let botClient = CreateBot <| (config, new HttpClient())
 | 
			
		||||
 | 
			
		||||
let shouldReply (u: Update) =
 | 
			
		||||
  u.Type = UpdateType.Message && u.Message.Chat.Id = config.adminChatId
 | 
			
		||||
 | 
			
		||||
let updateHandle (bc: ITelegramBotClient) (u: Update) (ct: CancellationToken): Task =
 | 
			
		||||
  match u with
 | 
			
		||||
  | _ when shouldReply u -> bc.SendTextMessageAsync(config.chanelId, u.Message.Text, cancellationToken = ct)
 | 
			
		||||
  | _ -> Task.CompletedTask
 | 
			
		||||
 | 
			
		||||
let handlePollingError (bc: ITelegramBotClient) (e: Exception) (t: CancellationToken) =
 | 
			
		||||
  printfn $"{e.Message}\n{e.StackTrace}"
 | 
			
		||||
  Task.CompletedTask
 | 
			
		||||
  
 | 
			
		||||
let receiverOptions = ReceiverOptions(AllowedUpdates = Array.zeroCreate<UpdateType> 0) 
 | 
			
		||||
 | 
			
		||||
botClient.StartReceiving(updateHandle,handlePollingError,receiverOptions)
 | 
			
		||||
 | 
			
		||||
Console.ReadKey() |> ignore
 | 
			
		||||
							
								
								
									
										18
									
								
								PublishHelperBot/PublishHelperBot.fsproj
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								PublishHelperBot/PublishHelperBot.fsproj
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,18 @@
 | 
			
		|||
<Project Sdk="Microsoft.NET.Sdk">
 | 
			
		||||
 | 
			
		||||
    <PropertyGroup>
 | 
			
		||||
        <OutputType>Exe</OutputType>
 | 
			
		||||
        <TargetFramework>net7.0</TargetFramework>
 | 
			
		||||
    </PropertyGroup>
 | 
			
		||||
 | 
			
		||||
    <ItemGroup>
 | 
			
		||||
        <PackageReference Include="Telegram.Bot" Version="18.0.0" />
 | 
			
		||||
    </ItemGroup>
 | 
			
		||||
    
 | 
			
		||||
    <ItemGroup>
 | 
			
		||||
        <Compile Include="Program.fs" />
 | 
			
		||||
        <Content Include="config.dev.json" />
 | 
			
		||||
        <Content Include="config.example.json" />
 | 
			
		||||
    </ItemGroup>
 | 
			
		||||
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										5
									
								
								PublishHelperBot/config.example.json
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								PublishHelperBot/config.example.json
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
{
 | 
			
		||||
  "token": "abba",
 | 
			
		||||
  "chanelId": "123123123",
 | 
			
		||||
  "adminChatId": "123123123"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								README.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								README.md
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
# PublishHelperBot
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue