Skip to content

Commit

Permalink
Packages have been updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Eptagone committed Apr 18, 2022
1 parent d37027f commit ee933f4
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 89 deletions.
1 change: 1 addition & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ In order to run anyone of webhook projects, you need to set the following applic
| Certificate | Certificate | SauceNAO.Webhook | Optional. Certificate path |
| Ngrok:Port | Ngrok\_\_Port | SauceNAO.LocalWebhook | Port where your app is running. (7161) |
| Ngrok:TunnelName | Ngrok\_\_TunnelName | SauceNAO.LocalWebhook | Optional. The tunnel name. (SnaoTunnel) |
| Ngrok:ApiUrl | Ngrok\_\_ApiUrl | SauceNAO.LocalWebhook | Optional. Api url. (localhost:4040/api) |

> Before running the **SauceNAO.LocalWebhook** project, you have to start **ngrok** in the background. Otherwise, your application will not be able to start. You can use the following command: `ngrok start --none`.
Expand Down
12 changes: 12 additions & 0 deletions src/SauceNAO.LocalWebhook/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "6.0.3",
"commands": [
"dotnet-ef"
]
}
}
}
6 changes: 4 additions & 2 deletions src/SauceNAO.LocalWebhook/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
// Ensure start ngrok tunnel
string appUrl;
{
var agent = new NgrokAgentClient();
var ngrok = builder.Configuration.GetSection("Ngrok");
var agentapiurl = ngrok["ApiUrl"];

var agent = string.IsNullOrEmpty(agentapiurl) ? new NgrokAgentClient() : new NgrokAgentClient(agentapiurl);
var tunnelName = ngrok["TunnelName"] ?? "SnaoTunnel";
var tunnel = agent.ListTunnels().Tunnels.FirstOrDefault(t => t.Name == tunnelName);

Expand Down Expand Up @@ -104,7 +106,7 @@

// Configure the HTTP request pipeline.

app.UseHttpsRedirection();
// app.UseHttpsRedirection();

app.UseAuthorization();

Expand Down
2 changes: 1 addition & 1 deletion src/SauceNAO.LocalWebhook/SauceNAO.LocalWebhook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.4" />
<PackageReference Include="Ngrok.AgentAPI" Version="0.1.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/SauceNAO.Service/SauceNAO.Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.0" />
Expand Down
17 changes: 4 additions & 13 deletions src/SauceNao.Core/Bot/SauceNaoBot.InlineHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ void AddUserSauces(IEnumerable<SuccessfulSauce> sauces)
{
Id = offset.ToString(),
StickerFileId = sauce.FileId,
InputMessageContent = new InputTextMessageContent
{
MessageText = sauceText,
ParseMode = ParseMode.HTML,
},
InputMessageContent = new InputTextMessageContent(sauceText, ParseMode.HTML),
ReplyMarkup = keyboard
});
break;
Expand Down Expand Up @@ -136,20 +132,15 @@ void AddUserSauces(IEnumerable<SuccessfulSauce> sauces)
{
Id = "None",
Title = text,
InputMessageContent = new InputTextMessageContent
{
MessageText = text
}
InputMessageContent = new InputTextMessageContent(text)
});
}

var answeriquery = new AnswerInlineQueryArgs
var answeriquery = new AnswerInlineQueryArgs(inlineQuery.Id, results.ToArray())
{
InlineQueryId = inlineQuery.Id,
NextOffset = results.Count < 10 ? string.Empty : offset.ToString(),
IsPersonal = true,
CacheTime = 480,
Results = results.ToArray()
CacheTime = 480
};
await Api.AnswerInlineQueryAsync(answeriquery, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
135 changes: 68 additions & 67 deletions src/SauceNao.Core/Bot/SauceNaoBot.MessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,88 +13,89 @@ public partial class SauceNaoBot : AsyncTelegramBotBase<SnaoBotProperties>
{
protected override async Task OnMessageAsync(Message message, CancellationToken cancellationToken)
{
// If the message was sent by Telegram (linked channels), ignore it.
if (message.From.Id == 777000)
if (message.From != null)
{
return;
}

// If the message was sent by Telegram (linked channels), ignore it.
if (message.From.Id == 777000)
{
return;
}
#if DEBUG
_logger.LogInformation("A new message was received from user: {user_fullname} [{user_id}]. Chat: {chat_title} [{chat_id}]", message.From.GetFullname(), message.From.Id, message.Chat.Title ?? "Private chat", message.Chat.Id);
_logger.LogInformation("A new message was received from user: {user_fullname} [{user_id}]. Chat: {chat_title} [{chat_id}]", message.From.GetFullname(), message.From.Id, message.Chat.Title ?? "Private chat", message.Chat.Id);
#endif
// Save message instance
base.Message = message ?? throw new ArgumentNullException(nameof(message));
// Message has text
var hasText = !string.IsNullOrEmpty(message.Text);
// Message has caption
var hasCaption = !hasText && !string.IsNullOrEmpty(message.Caption);
// Is a private chat
isPrivate = message.Chat.Type == ChatType.Private;

// Save message instance
base.Message = message ?? throw new ArgumentNullException(nameof(message));
// Message has text
var hasText = !string.IsNullOrEmpty(message.Text);
// Message has caption
var hasCaption = !hasText && !string.IsNullOrEmpty(message.Caption);
// Is a private chat
isPrivate = message.Chat.Type == ChatType.Private;

// Local function: LoadData
async Task LoadDataAsync()
{
// Load user data
User = await _db.Users.GetUserAsync(message.From, cancellationToken).ConfigureAwait(false);
Date = DateTimeOffset.FromUnixTimeSeconds(message.Date).DateTime;
if (isPrivate)
{
// Set lang
Language = new CultureInfo(User.LanguageCode ?? "en");
}
else
// Local function: LoadData
async Task LoadDataAsync()
{
// Load group data
Group = await _db.Groups.GetGroupAsync(message.Chat, cancellationToken).ConfigureAwait(false);
// Set lang
Language = new CultureInfo(User.LangForce ? User.LanguageCode ?? "en" : Group.LanguageCode ?? "en");
// Load user data
User = await _db.Users.GetUserAsync(message.From, cancellationToken).ConfigureAwait(false);
Date = DateTimeOffset.FromUnixTimeSeconds(message.Date).DateTime;
if (isPrivate)
{
// Set lang
Language = new CultureInfo(User.LanguageCode ?? "en");
}
else
{
// Load group data
Group = await _db.Groups.GetGroupAsync(message.Chat, cancellationToken).ConfigureAwait(false);
// Set lang
Language = new CultureInfo(User.LangForce ? User.LanguageCode ?? "en" : Group.LanguageCode ?? "en");
}
}
}

// If chat is private and message is not text
if (isPrivate && !hasText)
{
if (message.ViaBot?.Id != Me.Id)
// If chat is private and message is not text
if (isPrivate && !hasText)
{
await LoadDataAsync().ConfigureAwait(false);
// New search
await SauceAsync(message, cancellationToken).ConfigureAwait(false);
}
return;
}
// Check if message constains text.
if (hasText)
{
// If text == "sauce" or text is a metion for me (bot): Search
if ((message.Text.ToLowerInvariant() == "sauce" || message.Text.Contains($"@{Me.Username}")) && message.ReplyToMessage != default && !message.Text.StartsWith('/'))
{
await LoadDataAsync().ConfigureAwait(false); ;
await SauceAsync(message.ReplyToMessage, cancellationToken).ConfigureAwait(false);
if (message.ViaBot?.Id != Me.Id)
{
await LoadDataAsync().ConfigureAwait(false);
// New search
await SauceAsync(message, cancellationToken).ConfigureAwait(false);
}
return;
}
// If message is a command: process command
else
// Check if message constains text.
if (hasText)
{
var cmdMatch = Properties.CommandHelper.Match(message.Text);
if (cmdMatch.Success)
// If text == "sauce" or text is a metion for me (bot): Search
if ((message.Text!.ToLowerInvariant() == "sauce" || message.Text.Contains($"@{Me.Username}")) && message.ReplyToMessage != default && !message.Text.StartsWith('/'))
{
await LoadDataAsync().ConfigureAwait(false); ;
var parameters = string.IsNullOrEmpty(cmdMatch.Params) ? Array.Empty<string>() : cmdMatch.Params.Split(' ', StringSplitOptions.RemoveEmptyEntries);
await OnCommandAsync(cmdMatch.Name, parameters, cancellationToken).ConfigureAwait(false);
await SauceAsync(message.ReplyToMessage, cancellationToken).ConfigureAwait(false);
}
// If message is a command: process command
else
{
var cmdMatch = Properties.CommandHelper.Match(message.Text);
if (cmdMatch.Success)
{
await LoadDataAsync().ConfigureAwait(false); ;
var parameters = string.IsNullOrEmpty(cmdMatch.Params) ? Array.Empty<string>() : cmdMatch.Params.Split(' ', StringSplitOptions.RemoveEmptyEntries);
await OnCommandAsync(cmdMatch.Name, parameters, cancellationToken).ConfigureAwait(false);
}
}
}
}
// Check if message constains caption.
else if (hasCaption)
{
var caption = message.Caption;
var lowerCaption = caption.ToLowerInvariant();
// If caption == "sauce" or caption is a metion for me (bot): Search
if (lowerCaption == "sauce" || caption.Contains($"@{Me.Username}") || lowerCaption == "/sauce")
// Check if message constains caption.
else if (hasCaption)
{
await LoadDataAsync().ConfigureAwait(false); ;
// New Search
await SauceAsync(message, cancellationToken).ConfigureAwait(false);
var caption = message.Caption;
var lowerCaption = caption!.ToLowerInvariant();
// If caption == "sauce" or caption is a metion for me (bot): Search
if (lowerCaption == "sauce" || caption.Contains($"@{Me.Username}") || lowerCaption == "/sauce")
{
await LoadDataAsync().ConfigureAwait(false); ;
// New Search
await SauceAsync(message, cancellationToken).ConfigureAwait(false);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/SauceNao.Core/SauceNAO.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Telegram.BotAPI" Version="5.2.1" />
<PackageReference Include="Telegram.BotAPI" Version="5.9.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/SauceNao.Infrastructure/SauceNAO.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/SauceNao.Webhook/SauceNAO.Webhook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.15.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.4" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit ee933f4

Please sign in to comment.