Skip to content

Commit

Permalink
Updated to Bot API 6.7
Browse files Browse the repository at this point in the history
Allowed Long Polling in Web App
Ranamed projects
  • Loading branch information
Eptagone committed Jun 2, 2023
1 parent 9b23f31 commit 2b77f67
Show file tree
Hide file tree
Showing 107 changed files with 991 additions and 713 deletions.
41 changes: 0 additions & 41 deletions README.es.md

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This bot was created by a third party to use SauceNAO on Telegram. The project h

- Personal search history using inline. Forward the multimedia you've searched along with the sauce to your groups or channels.

- Anti-Cheats. If your group has "guess the character" bots or similar bots, you can use SauceNAO's AntiCheats feature. This will prevent [@SauceNAObot](https://t.me/SauceNAObot) from performing reverse media searches sent by specific bots you specified.
- Anti-Cheats. If your group has "guess the character" bots or similar bots, you can use SauceNAO's AntiCheats feature. This will prevent [@SauceNAObot](https://t.me/SauceNAObot) from performing reverse media searches sent by those bots.

## Command List

Expand All @@ -35,7 +35,6 @@ Your contributions are used to pay for the bot's hosting and the shared account
You can support this project through the following options:

- [Buy me a cookie](https://www.buymeacoffee.com/eptagone)
- **Bitcoin:** [bc1q0w43tprjn80zn248k7xlztu7lvhkzgy6dak8mt](bitcoin:BC1Q0W43TPRJN80ZN248K7XLZTU7LVHKZGY6DAK8MT?label=MyCoffe&message=Invite%20me%20for%20a%20coffee)
- **Toncoin:** [EQC3SWZxs_4ive2aD-njns1KnB4S2RUgaxDKJ7X44VA52SsY](ton://transfer/EQC3SWZxs_4ive2aD-njns1KnB4S2RUgaxDKJ7X44VA52SsY)

Note: Please be sure to confirm the amount you will donate. We don't make refunds.
2 changes: 1 addition & 1 deletion docs/SauceNao.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,6 @@ dotnet_style_qualification_for_field = true:silent
dotnet_style_qualification_for_property = true:silent
dotnet_style_qualification_for_method = true:silent
dotnet_style_qualification_for_event = true:silent

# Extra rules
file_header_template = Copyright (c) 2023 Quetzal Rivera.\nLicensed under the GNU General Public License v3.0, See LICENCE in the project root for license information.
28 changes: 0 additions & 28 deletions src/README.es.md

This file was deleted.

45 changes: 26 additions & 19 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,32 @@ This bot works using a webhook. You can run the webhook locally using [NGROK](ht

This solution is composed by **6** projects:

| Name | Description |
| :---------------------- | :---------------------------------------------------------------------- |
| SauceNAO.Core | Contains the main functionality of the bot |
| SauceNAO.Infrastructure | Implements clases for data access |
| SauceNAO.Webhook | The webhook application. Run the bot using a webhook. |
| SauceNAO.Service | Runs the bot using Long Polling. Some features will be disabled. |
| SauceNAO.LocalWebhook | The webhook application (like `SauceNAO.Webhook` but for local running) |
| SauceNAO.Tests | Unit Tests |
| Name | Description |
| :---------------------- | :--------------------------------------------------------------- |
| SauceNAO.Core | Contains the main functionality of the bot |
| SauceNAO.Infrastructure | Implements clases for data access |
| SauceNAO.WebApp | The web application. Allows you to configure a webhook. |
| SauceNAO.AppService | Runs the bot using Long Polling. Some features will be disabled. |
| SauceNAO.Tests | Unit Tests |

In order to run anyone of webhook projects, you need to set the following application settings via **json file** (`secrets.json`, `application.json`) or using **enviroment variables**. See the table below that shows the available settings.

| JSON property name | Enviroment variable | Apply to | Description |
| :------------------------ | :--------------------------- | :--------------- | :---------------------------------------------------------- |
| AccessToken | AccessToken | Both webhooks | Your webhook secret token specified by you. |
| FFmpegExec | FFmpegExec | Both webhooks | The ffmpeg path executable. |
| SauceNAO:ApiKey | SauceNAO\_\_ApiKey | All | You apikey for SauceNAO API. |
| Telegram:BotToken | Telegram\_\_BotToken | All | You bot token. |
| Telegram:SupportChatLink | Telegram\_\_SupportChatLink | All | Support chat link. (<https://t.me/+8NJMCbRmiTk2Yjkx>) |
| ConnectionStrings:Default | ConnectionStrings\_\_Default | All | The connection string to database. |
| DbProvider | DbProvider | All | Database provider. Can be 'sqlite' (default) or 'sqlserver' |
| ApplicationUrl | ApplicationUrl | SauceNAO.Webhook | Your webhook base url. (<https://example.com>) |
| Certificate | Certificate | SauceNAO.Webhook | Optional. Certificate path |
| JSON property name | Enviroment variable | Apply to | Description |
| :------------------------ | :--------------------------- | :------- | :----------------------------------------------------------- |
| ConnectionStrings:Default | ConnectionStrings\_\_Default | All | The connection string to database. |
| DbProvider | DbProvider | All | Database provider. Can be 'sqlite' (default) or 'sqlserver' |
| SNAO:ApiKey | SNAO\_\_ApiKey | All | You apikey for SauceNAO API. |
| SNAO:BotToken | SNAO\_\_BotToken | All | You bot token. |
| SNAO:SupportChatLink | SNAO\_\_SupportChatLink | All | Support chat link. (<https://t.me/+8NJMCbRmiTk2Yjkx>) |
| SNAO:ApplicationUrl | SNAO\_\_ApplicationUrl | WebApp | Optional. Your application base url. (<https://example.com>) |
| SNAO:FFmpegExec | SNAO\_\_FFmpegExec | WebApp | Optional. The ffmpeg path executable. |
| SNAO:SecretToken | SNAO\_\_SecretToken | WebApp | Optional. Your secret token to enable webhook. |
| SNAO:CertificatePath | SNAO\_\_CertificatePath | WebApp | Optional. Certificate path |
| SNAO:DropPendingUpdates | SNAO\_\_DropPendingUpdates | WebApp | Optional. Drop pending updates. |

## Local Mode

Local mode is a special mode that allows you to run the bot without a web server. This mode is useful for testing purposes.

> The AppService project will always run in local mode.
> The WebApp will run in local mode if the `ApplicationUrl`, `SecretToken` or `FFmpegExec` settings are not set.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["SauceNAO.Service/SauceNAO.Service.csproj", "SauceNAO.Service/"]
COPY ["SauceNAO.AppService/SauceNAO.AppService.csproj", "SauceNAO.AppService/"]
COPY ["SauceNAO.Infrastructure/SauceNAO.Infrastructure.csproj", "SauceNAO.Infrastructure/"]
COPY ["SauceNAO.Core/SauceNAO.Core.csproj", "SauceNAO.Core/"]
RUN dotnet restore "SauceNAO.Service/SauceNAO.Service.csproj"
RUN dotnet restore "SauceNAO.AppService/SauceNAO.AppService.csproj"
COPY . .
WORKDIR "/src/SauceNAO.Service"
RUN dotnet build "SauceNAO.Service.csproj" -c Release -o /app/build
WORKDIR "/src/SauceNAO.AppService"
RUN dotnet build "SauceNAO.AppService.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "SauceNAO.Service.csproj" -c Release -o /app/publish
RUN dotnet publish "SauceNAO.AppService.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SauceNAO.Service.dll"]
ENTRYPOINT ["dotnet", "SauceNAO.AppService.dll"]
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
// Copyright (c) 2022 Quetzal Rivera.
// Copyright (c) 2023 Quetzal Rivera.
// Licensed under the GNU General Public License v3.0, See LICENCE in the project root for license information.

using Microsoft.EntityFrameworkCore;
using SauceNAO.Core;
using SauceNAO.Core.Extensions;
using SauceNAO.Core.Services;
using SauceNAO.Infrastructure;
using SauceNAO.Infrastructure.Data;
using SauceNAO.Service;

IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
var configuration = context.Configuration;

// Configure database context
var connectionString = configuration.GetConnectionString("Default");

if (connectionString == null)
{
throw new NullReferenceException("The connection string cannot be null");
}
var connectionString = configuration.GetConnectionString("Default")
?? throw new ArgumentNullException("Default", "The connection string cannot be null");

switch (configuration["DbProvider"])
{
Expand Down Expand Up @@ -48,11 +43,8 @@
// Add bot service.
services.AddSauceBot<BotDb>();

// Add Data Cleaner service
//services.AddHostedService<CleanerService>();

// Add long polling service
services.AddHostedService<Worker>();
services.AddHostedService<PollingService>();
})
.Build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"profiles": {
"SauceNAO.Service": {
"SauceNAO.AppService": {
"commandName": "Project",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-SauceNAO.Service-05FE5EF8-712F-4623-8ACC-7BB63CD73D87</UserSecretsId>
<UserSecretsId>dotnet-SauceNAO.AppService-05FE5EF8-712F-4623-8ACC-7BB63CD73D87</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

Expand Down
10 changes: 10 additions & 0 deletions src/SauceNAO.AppService/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning",
"Microsoft.EntityFrameworkCore.Infrastructure": "Warning"
}
}
}
18 changes: 18 additions & 0 deletions src/SauceNAO.CleanerService/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2023 Quetzal Rivera.
// Licensed under the GNU General Public License v3.0, See LICENCE in the project root for license information.

using Microsoft.EntityFrameworkCore;
using SauceNAO.CleanerService;
using SauceNAO.Infrastructure;

IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices((context, services) =>
{
var connectionString = context.Configuration.GetConnectionString("Default");

services.AddDbContext<SauceNaoContext>(options => options.UseSqlServer(connectionString), ServiceLifetime.Transient);
services.AddHostedService<Worker>();
})
.Build();

await host.RunAsync();
11 changes: 11 additions & 0 deletions src/SauceNAO.CleanerService/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"profiles": {
"SauceNAO.CleanerService": {
"commandName": "Project",
"dotnetRunMessages": true,
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": {
"secrets1": {
"type": "secrets"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": {
"secrets1": {
"type": "secrets.user"
}
}
}
19 changes: 19 additions & 0 deletions src/SauceNAO.CleanerService/SauceNAO.CleanerService.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-SauceNAO.CleanerService-6c5b5a34-568a-47e4-8e05-4bc9fadaddc7</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SauceNAO.Core\SauceNAO.Core.csproj" />
<ProjectReference Include="..\SauceNAO.Infrastructure\SauceNAO.Infrastructure.csproj" />
</ItemGroup>
</Project>
Loading

0 comments on commit 2b77f67

Please sign in to comment.