Init
This commit is contained in:
+299
@@ -0,0 +1,299 @@
|
||||
# Huge kudos to all contributors to https://github.com/github/gitignore which is where
|
||||
# this file came from.
|
||||
|
||||
syntax: glob
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# DNX
|
||||
project.lock.json
|
||||
artifacts/
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignoreable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
#*.pfx
|
||||
*.publishsettings
|
||||
node_modules/
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# Visual Studio design time assembly cache
|
||||
*.cache
|
||||
|
||||
#Aeroclub lib catalog
|
||||
[Ll]ib/
|
||||
src/Aeroclub.WCF.CommonGateway/!Web.config
|
||||
src/Aeroclub.WCF.CommonGateway/Web.config
|
||||
src/Aeroclub.WCF.CommonGateway/!NLog.config
|
||||
|
||||
*.ncrunchproject
|
||||
|
||||
# WSCommon logs
|
||||
src/Aeroclub.WCF.CommonGateway/logs/
|
||||
build/nuget/*.exe
|
||||
*.orig
|
||||
|
||||
tools/Confluence.dll*
|
||||
.sonarqube/*
|
||||
paket.lock
|
||||
test/*
|
||||
.paket/Paket/tools/paket.exe
|
||||
coverage/*
|
||||
src/WscommonDoc/Help/*.json
|
||||
src/WscommonDoc/Help/*.json
|
||||
src/WscommonDoc/Help/*
|
||||
src/WscommonDoc/icons/Help.png
|
||||
src/WscommonDoc/Doc/Working/*
|
||||
src/WscommonDoc/Doc/*
|
||||
.paket/*
|
||||
*.env
|
||||
.teamcity/target/*
|
||||
docfx_project/_site/*
|
||||
docfx_project/api/*.yml
|
||||
fake/*
|
||||
tools/paket/.store/*
|
||||
*.lock
|
||||
tools/paket/*
|
||||
src/Aeroclub.WCF.CommonGateway/web.config
|
||||
tools/sonarscanner/*
|
||||
.ionide/symbolCache.db
|
||||
Tests/*
|
||||
src/tests/*
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS publish
|
||||
|
||||
ADD ./src /src
|
||||
WORKDIR /src
|
||||
|
||||
# Restore
|
||||
RUN dotnet restore RgDevBot.sln
|
||||
RUN dotnet build RgDevBot.sln -c Release -o /app
|
||||
RUN dotnet test RgDevBot.sln -c Release
|
||||
RUN dotnet publish RgDevBot.sln -c Release -o /app
|
||||
|
||||
# Final image
|
||||
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app .
|
||||
ENTRYPOINT ["dotnet", "RgDevBot.dll"]
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30320.27
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RgDevBot", "RgDevBot\RgDevBot.csproj", "{2BAF765F-8E7E-4544-87D5-483EA9FECCA7}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2BAF765F-8E7E-4544-87D5-483EA9FECCA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2BAF765F-8E7E-4544-87D5-483EA9FECCA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2BAF765F-8E7E-4544-87D5-483EA9FECCA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2BAF765F-8E7E-4544-87D5-483EA9FECCA7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {9ACBCBC1-5D08-41F1-868C-F21CBF396874}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using RgDevBot.ObjectModel;
|
||||
|
||||
namespace RgDevBot
|
||||
{
|
||||
public class NewsParser
|
||||
{
|
||||
private readonly TelegramBot _bot;
|
||||
private int _lastSentId = -1;
|
||||
|
||||
public NewsParser(TelegramBot bot)
|
||||
{
|
||||
_bot = bot;
|
||||
}
|
||||
|
||||
public void Parse()
|
||||
{
|
||||
var url = "https://rg-dev.ru/api/news/?type=news";
|
||||
var content = Get(url);
|
||||
|
||||
var news = JsonConvert.DeserializeObject<NewsListResponse>(content);
|
||||
var latestNews = news.results.OrderByDescending(f => f.id).FirstOrDefault();
|
||||
|
||||
if (latestNews != null && latestNews.id != _lastSentId)
|
||||
{
|
||||
var text = $"{latestNews.title}:\r\nhttps://rg-dev.ru/press/news/all/{latestNews.id}/";
|
||||
Console.WriteLine(text);
|
||||
_bot.SendMessage(text);
|
||||
|
||||
_lastSentId = latestNews.id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public string Get(string url, string contentType = "application/json")
|
||||
{
|
||||
var httpRequest = (HttpWebRequest)WebRequest.Create(url);
|
||||
httpRequest.ContentType = contentType;
|
||||
httpRequest.Method = "GET";
|
||||
|
||||
var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
|
||||
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
|
||||
{
|
||||
var result = streamReader.ReadToEnd();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace RgDevBot.ObjectModel
|
||||
{
|
||||
public class News
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string title { get; set; }
|
||||
public string slug { get; set; }
|
||||
public string type { get; set; }
|
||||
public string intro { get; set; }
|
||||
public object image_display { get; set; }
|
||||
public object mobile_image_display { get; set; }
|
||||
public object image_preview { get; set; }
|
||||
public object mobile_image_preview { get; set; }
|
||||
public DateTime date { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace RgDevBot.ObjectModel
|
||||
{
|
||||
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
|
||||
|
||||
public class NewsListResponse
|
||||
{
|
||||
public int count { get; set; }
|
||||
public string next { get; set; }
|
||||
public object previous { get; set; }
|
||||
public List<News> results { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace RgDevBot
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var bot = new TelegramBot();
|
||||
var parser = new NewsParser(bot);
|
||||
while (true)
|
||||
{
|
||||
parser.Parse();
|
||||
Thread.Sleep(TimeSpan.FromSeconds(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Telegram.Bot" Version="10.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Telegram.Bot;
|
||||
|
||||
namespace RgDevBot
|
||||
{
|
||||
public class TelegramBot
|
||||
{
|
||||
private readonly TelegramBotClient _telegram;
|
||||
public string Token => "1479535614:AAFqHdsUFikzOti0zknK_pN2sEONNAXecPY";
|
||||
public long MainChatId;
|
||||
|
||||
public TelegramBot(long chatId = -415825856)
|
||||
{
|
||||
MainChatId = chatId;
|
||||
_telegram = new TelegramBotClient(Token);
|
||||
_telegram.OnMessage += Bot_OnMessage;
|
||||
_telegram.StartReceiving();
|
||||
}
|
||||
|
||||
public void Bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
|
||||
{
|
||||
Console.WriteLine($"[{e.Message.Chat.Id}, user: {e.Message.From.Id}] @{e.Message.From?.Username}: {e.Message.Text}");
|
||||
}
|
||||
|
||||
public void SendMessage(string message, long? chatId = null)
|
||||
{
|
||||
_telegram.SendTextMessageAsync(chatId ?? MainChatId, message).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user