Compare commits

...

13 Commits
4.1.3 ... 4.1.6

34 changed files with 330 additions and 171 deletions

View File

@@ -18,41 +18,41 @@ variables:
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/NadekoBot-build/${CI_COMMIT_TAG}"
INSTALLER_OUTPUT_DIR: "nadeko-installers/${CI_COMMIT_TAG}"
INSTALLER_FILE_NAME: "nadeko-setup-${CI_COMMIT_TAG}.exe"
build:
stage: build
script:
- "dotnet publish -c Release -r linux-x64 -o $LINUX_X64_OUTPUT_DIR src/NadekoBot/NadekoBot.csproj"
- "dotnet publish -c Release -r win7-x64 -o $WIN_X64_OUTPUT_DIR src/NadekoBot/NadekoBot.csproj"
- "dotnet publish -c Release -r linux-x64 --self-contained -o $LINUX_X64_OUTPUT_DIR src/NadekoBot/NadekoBot.csproj"
- "dotnet publish -c Release -r win7-x64 --self-contained -o $WIN_X64_OUTPUT_DIR src/NadekoBot/NadekoBot.csproj"
artifacts:
paths:
- "$LINUX_X64_OUTPUT_DIR/"
- "$WIN_X64_OUTPUT_DIR/"
upload-builds:
stage: upload-builds
image: alpine:latest
rules:
- if: $CI_COMMIT_TAG
script:
- apk add --no-cache curl tar zip
- "tar cvf $LINUX_X64_RELEASE $LINUX_X64_OUTPUT_DIR/*"
- "zip -r $WIN_X64_RELEASE $WIN_X64_OUTPUT_DIR/*"
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $LINUX_X64_RELEASE $PACKAGE_REGISTRY_URL/$LINUX_X64_RELEASE
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $WIN_X64_RELEASE $PACKAGE_REGISTRY_URL/$WIN_X64_RELEASE
stage: upload-builds
image: alpine:latest
rules:
- if: $CI_COMMIT_TAG
script:
- apk add --no-cache curl tar zip
- "tar cvf $LINUX_X64_RELEASE $LINUX_X64_OUTPUT_DIR/*"
- "zip -r $WIN_X64_RELEASE $WIN_X64_OUTPUT_DIR/*"
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $LINUX_X64_RELEASE $PACKAGE_REGISTRY_URL/$LINUX_X64_RELEASE
- |
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $WIN_X64_RELEASE $PACKAGE_REGISTRY_URL/$WIN_X64_RELEASE
release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: $CI_COMMIT_TAG
script:
- |
release-cli create --name "NadekoBot v$CI_COMMIT_TAG" --description "## [Changelog](https://gitlab.com/Kwoth/nadekobot/-/blob/v4/CHANGELOG.md#$(echo "$CI_COMMIT_TAG" | sed "s/\.//g")-$(date +%d%m%Y))" --tag-name $CI_COMMIT_TAG \
--assets-link "{\"name\":\"${LINUX_X64_RELEASE}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${LINUX_X64_RELEASE}\"}" \
--assets-link "{\"name\":\"${WIN_X64_RELEASE}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${WIN_X64_RELEASE}\"}"
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: $CI_COMMIT_TAG
script:
- |
release-cli create --name "NadekoBot v$CI_COMMIT_TAG" --description "## [Changelog](https://gitlab.com/Kwoth/nadekobot/-/blob/v4/CHANGELOG.md#$(echo "$CI_COMMIT_TAG" | sed "s/\.//g")-$(date +%d%m%Y))" --tag-name $CI_COMMIT_TAG \
--assets-link "{\"name\":\"${LINUX_X64_RELEASE}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${LINUX_X64_RELEASE}\"}" \
--assets-link "{\"name\":\"${WIN_X64_RELEASE}\",\"url\":\"${PACKAGE_REGISTRY_URL}/${WIN_X64_RELEASE}\"}"
test:
stage: test
@@ -63,63 +63,63 @@ test:
- "dotnet test"
publish-windows:
stage: publish-windows
rules:
- if: '$CI_COMMIT_TAG'
image: scottyhardy/docker-wine
before_script:
- choco install dotnet-6.0-runtime -y
- choco install dotnet-6.0-sdk -y
- choco install innosetup -y
artifacts:
paths:
- "$INSTALLER_OUTPUT_DIR/$INSTALLER_FILE_NAME"
script:
- dotnet clean
- dotnet restore
- dotnet publish -c Release --runtime win7-x64 /p:Version=$CI_COMMIT_TAG src/NadekoBot
- $env:NADEKOBOT_INSTALL_VERSION = $CI_COMMIT_TAG
- iscc.exe "/O+" ".\exe_builder.iss"
tags:
- windows
stage: publish-windows
rules:
- if: "$CI_COMMIT_TAG"
image: scottyhardy/docker-wine
before_script:
- choco install dotnet-6.0-runtime --version=6.0.4 -y
- choco install dotnet-6.0-sdk --version=6.0.202 -y
- choco install innosetup -y
artifacts:
paths:
- "$INSTALLER_OUTPUT_DIR/$INSTALLER_FILE_NAME"
script:
- dotnet clean
- dotnet restore -f --no-cache -v n
- dotnet publish -c Release --runtime win7-x64 /p:Version=$CI_COMMIT_TAG src/NadekoBot
- $env:NADEKOBOT_INSTALL_VERSION = $CI_COMMIT_TAG
- iscc.exe "/O+" ".\exe_builder.iss"
tags:
- windows
upload-windows-updater-release:
stage: upload-windows-updater-release
rules:
- if: '$CI_COMMIT_TAG'
image:
name: amazon/aws-cli
entrypoint: [""]
script:
- sed -i "s/_INSTALLER_FILE_NAME_/$INSTALLER_FILE_NAME/g" releases-v3.json
- sed -i "s/_VERSION_/$CI_COMMIT_TAG/g" releases-v3.json
- aws --version
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/$INSTALLER_FILE_NAME" --acl public-read --body "$INSTALLER_OUTPUT_DIR/$INSTALLER_FILE_NAME"
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/releases-v3.json" --acl public-read --body "releases-v3.json"
stage: upload-windows-updater-release
rules:
- if: "$CI_COMMIT_TAG"
image:
name: amazon/aws-cli
entrypoint: [""]
script:
- sed -i "s/_INSTALLER_FILE_NAME_/$INSTALLER_FILE_NAME/g" releases-v3.json
- sed -i "s/_VERSION_/$CI_COMMIT_TAG/g" releases-v3.json
- aws --version
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/$INSTALLER_FILE_NAME" --acl public-read --body "$INSTALLER_OUTPUT_DIR/$INSTALLER_FILE_NAME"
- aws --endpoint-url $AWS_SERVICE_URL s3api put-object --bucket "$AWS_BUCKET_NAME" --key "dl/bot/releases-v3.json" --acl public-read --body "releases-v3.json"
docker-build:
# Use the official docker image.
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
- docker push "$CI_REGISTRY_IMAGE${tag}"
# Run this job in a branch where a Dockerfile exists
rules:
- if: $CI_COMMIT_BRANCH
exists:
- Dockerfile
# Use the official docker image.
image: docker:latest
stage: build
services:
- docker:dind
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
- docker push "$CI_REGISTRY_IMAGE${tag}"
# Run this job in a branch where a Dockerfile exists
rules:
- if: $CI_COMMIT_BRANCH
exists:
- Dockerfile

View File

@@ -3,6 +3,32 @@
Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o
## Unreleased
## [4.1.6] - 14.05.2022
### Fixed
- Fixed windows release and updated packages
## [4.1.5] - 11.05.2022
### Changed
- `.clubdesc <msg>` will now have a nicer response
### Fixed
- `.give` DM will once again show an amount
- Fixed an issue with filters not working and with custom reactions no longer being able to override commands.
- Fixed `.stock` command
## [4.1.4] - 06.05.2022
### Fixed
- Fixed `.yun`
## [4.1.3] - 06.05.2022
### Added
@@ -44,7 +70,7 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
- Fixed `.deletexp` command
- `.give` command should send DMs again
- `.modules` commanad now has a medusa module description
- `.modules` command now has a medusa module description
## [4.1.2] - 16.04.2022

View File

@@ -13,8 +13,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Discord.Net.Core" Version="3.5.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Discord.Net.Core" Version="3.6.1" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="YamlDotNet" Version="11.2.1" />
</ItemGroup>

View File

@@ -9,10 +9,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.44.0" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Grpc.AspNetCore" Version="2.45.0" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="YamlDotNet" Version="11.2.1" />
</ItemGroup>

View File

@@ -8,9 +8,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
</ItemGroup>
<ItemGroup>

View File

@@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="MorseCode.ITask" Version="2.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.1" />
</ItemGroup>
</Project>

View File

@@ -363,7 +363,7 @@ public partial class Gambling : GamblingModule<GamblingService>
return;
}
if (!await _cs.TransferAsync(_eb, ctx.User, receiver, amount, msg))
if (!await _cs.TransferAsync(_eb, ctx.User, receiver, amount, msg, N(amount)))
{
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
return;

View File

@@ -264,18 +264,18 @@ public class SearchImageCacher : INService
return new();
}
private IImageDownloader GetImageDownloader(Booru booru, HttpClient http)
private IImageDownloader GetImageDownloader(Booru booru)
=> booru switch
{
Booru.Danbooru => new DanbooruImageDownloader(http),
Booru.Yandere => new YandereImageDownloader(http),
Booru.Konachan => new KonachanImageDownloader(http),
Booru.Safebooru => new SafebooruImageDownloader(http),
Booru.E621 => new E621ImageDownloader(http),
Booru.Derpibooru => new DerpibooruImageDownloader(http),
Booru.Gelbooru => new GelbooruImageDownloader(http),
Booru.Rule34 => new Rule34ImageDownloader(http),
Booru.Sankaku => new SankakuImageDownloader(http),
Booru.Danbooru => new DanbooruImageDownloader(_httpFactory),
Booru.Yandere => new YandereImageDownloader(_httpFactory),
Booru.Konachan => new KonachanImageDownloader(_httpFactory),
Booru.Safebooru => new SafebooruImageDownloader(_httpFactory),
Booru.E621 => new E621ImageDownloader(_httpFactory),
Booru.Derpibooru => new DerpibooruImageDownloader(_httpFactory),
Booru.Gelbooru => new GelbooruImageDownloader(_httpFactory),
Booru.Rule34 => new Rule34ImageDownloader(_httpFactory),
Booru.Sankaku => new SankakuImageDownloader(_httpFactory),
_ => throw new NotImplementedException($"{booru} downloader not implemented.")
};
@@ -290,8 +290,7 @@ public class SearchImageCacher : INService
{
Log.Information("Downloading from {Type} (page {Page})...", type, page);
using var http = _httpFactory.CreateClient();
var downloader = GetImageDownloader(type, http);
var downloader = GetImageDownloader(type);
var images = await downloader.DownloadImageDataAsync(tags, page, isExplicit, cancel);
if (images.Count == 0)

View File

@@ -9,7 +9,7 @@ public sealed class DanbooruImageDownloader : DapiImageDownloader
private static readonly ConcurrentDictionary<string, bool> _existentTags = new();
private static readonly ConcurrentDictionary<string, bool> _nonexistentTags = new();
public DanbooruImageDownloader(HttpClient http)
public DanbooruImageDownloader(IHttpClientFactory http)
: base(Booru.Danbooru, http, "http://danbooru.donmai.us")
{
}
@@ -22,7 +22,8 @@ public sealed class DanbooruImageDownloader : DapiImageDownloader
if (_nonexistentTags.ContainsKey(tag))
return false;
var tags = await _http.GetFromJsonAsync<DapiTag[]>(
using var http = _http.CreateClient();
var tags = await http.GetFromJsonAsync<DapiTag[]>(
_baseUrl + "/tags.json" + $"?search[name_or_alias_matches]={tag}",
_serializerOptions,
cancel);

View File

@@ -7,7 +7,7 @@ public abstract class DapiImageDownloader : ImageDownloader<DapiImageObject>
{
protected readonly string _baseUrl;
public DapiImageDownloader(Booru booru, HttpClient http, string baseUrl)
public DapiImageDownloader(Booru booru, IHttpClientFactory http, string baseUrl)
: base(booru, http)
=> _baseUrl = baseUrl;
@@ -43,7 +43,8 @@ public abstract class DapiImageDownloader : ImageDownloader<DapiImageObject>
var tagString = ImageDownloaderHelper.GetTagString(tags, isExplicit);
var uri = $"{_baseUrl}/posts.json?limit=200&tags={tagString}&page={page}";
var imageObjects = await _http.GetFromJsonAsync<DapiImageObject[]>(uri, _serializerOptions, cancel);
using var http = _http.CreateClient();
var imageObjects = await http.GetFromJsonAsync<DapiImageObject[]>(uri, _serializerOptions, cancel);
if (imageObjects is null)
return new();
return imageObjects.Where(x => x.FileUrl is not null).ToList();

View File

@@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Nsfw.Common;
public class DerpibooruImageDownloader : ImageDownloader<DerpiImageObject>
{
public DerpibooruImageDownloader(HttpClient http)
public DerpibooruImageDownloader(IHttpClientFactory http)
: base(Booru.Derpibooru, http)
{
}
@@ -21,7 +21,8 @@ public class DerpibooruImageDownloader : ImageDownloader<DerpiImageObject>
$"https://www.derpibooru.org/api/v1/json/search/images?q={tagString.Replace('+', ',')}&per_page=49&page={page}";
using var req = new HttpRequestMessage(HttpMethod.Get, uri);
req.Headers.AddFakeHeaders();
using var res = await _http.SendAsync(req, cancel);
using var http = _http.CreateClient();
using var res = await http.SendAsync(req, cancel);
res.EnsureSuccessStatusCode();
var container = await res.Content.ReadFromJsonAsync<DerpiContainer>(_serializerOptions, cancel);

View File

@@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Nsfw.Common;
public class E621ImageDownloader : ImageDownloader<E621Object>
{
public E621ImageDownloader(HttpClient http)
public E621ImageDownloader(IHttpClientFactory http)
: base(Booru.E621, http)
{
}
@@ -20,7 +20,8 @@ public class E621ImageDownloader : ImageDownloader<E621Object>
var uri = $"https://e621.net/posts.json?limit=32&tags={tagString}&page={page}";
using var req = new HttpRequestMessage(HttpMethod.Get, uri);
req.Headers.AddFakeHeaders();
using var res = await _http.SendAsync(req, cancel);
using var http = _http.CreateClient();
using var res = await http.SendAsync(req, cancel);
res.EnsureSuccessStatusCode();
var data = await res.Content.ReadFromJsonAsync<E621Response>(_serializerOptions, cancel);

View File

@@ -6,7 +6,7 @@ namespace NadekoBot.Modules.Nsfw.Common;
public class GelbooruImageDownloader : ImageDownloader<DapiImageObject>
{
public GelbooruImageDownloader(HttpClient http)
public GelbooruImageDownloader(IHttpClientFactory http)
: base(Booru.Gelbooru, http)
{
}
@@ -26,7 +26,8 @@ public class GelbooruImageDownloader : ImageDownloader<DapiImageObject>
+ $"&tags={tagString}"
+ $"&pid={page}";
using var req = new HttpRequestMessage(HttpMethod.Get, uri);
using var res = await _http.SendAsync(req, cancel);
using var http = _http.CreateClient();
using var res = await http.SendAsync(req, cancel);
res.EnsureSuccessStatusCode();
var resString = await res.Content.ReadAsStringAsync(cancel);
if (string.IsNullOrWhiteSpace(resString))

View File

@@ -8,7 +8,7 @@ public abstract class ImageDownloader<T> : IImageDownloader
where T : IImageData
{
public Booru Booru { get; }
protected readonly HttpClient _http;
protected readonly IHttpClientFactory _http;
protected readonly JsonSerializerOptions _serializerOptions = new()
{
@@ -16,7 +16,7 @@ public abstract class ImageDownloader<T> : IImageDownloader
NumberHandling = JsonNumberHandling.WriteAsString | JsonNumberHandling.AllowReadingFromString
};
public ImageDownloader(Booru booru, HttpClient http)
public ImageDownloader(Booru booru, IHttpClientFactory http)
{
_http = http;
Booru = booru;

View File

@@ -7,7 +7,7 @@ public sealed class KonachanImageDownloader : ImageDownloader<DapiImageObject>
{
private readonly string _baseUrl;
public KonachanImageDownloader(HttpClient http)
public KonachanImageDownloader(IHttpClientFactory http)
: base(Booru.Konachan, http)
=> _baseUrl = "https://konachan.com";
@@ -19,7 +19,8 @@ public sealed class KonachanImageDownloader : ImageDownloader<DapiImageObject>
{
var tagString = ImageDownloaderHelper.GetTagString(tags, isExplicit);
var uri = $"{_baseUrl}/post.json?s=post&q=index&limit=200&tags={tagString}&page={page}";
var imageObjects = await _http.GetFromJsonAsync<DapiImageObject[]>(uri, _serializerOptions, cancel);
using var http = _http.CreateClient();
var imageObjects = await http.GetFromJsonAsync<DapiImageObject[]>(uri, _serializerOptions, cancel);
if (imageObjects is null)
return new();
return imageObjects.Where(x => x.FileUrl is not null).ToList();

View File

@@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Nsfw.Common;
public class Rule34ImageDownloader : ImageDownloader<Rule34Object>
{
public Rule34ImageDownloader(HttpClient http)
public Rule34ImageDownloader(IHttpClientFactory http)
: base(Booru.Rule34, http)
{
}
@@ -17,9 +17,21 @@ public class Rule34ImageDownloader : ImageDownloader<Rule34Object>
CancellationToken cancel = default)
{
var tagString = ImageDownloaderHelper.GetTagString(tags);
var uri = "https://rule34.xxx/index.php?page=dapi&s=post&q=index&json=1&limit=100"
+ $"&tags={tagString}&pid={page}";
var images = await _http.GetFromJsonAsync<List<Rule34Object>>(uri, _serializerOptions, cancel);
var uri = $"https://api.rule34.xxx//index.php?page=dapi&s=post"
+ $"&q=index"
+ $"&json=1"
+ $"&limit=100"
+ $"&tags={tagString}"
+ $"&pid={page}";
using var http = _http.CreateClient();
http.DefaultRequestHeaders
.TryAddWithoutValidation("cookie", "cf_clearance=Gg3bVffg9fOL_.9fIdKmu5PJS86eTI.yTrhbR8z2tPc-1652310659-0-250");
http.DefaultRequestHeaders
.TryAddWithoutValidation("user-agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36");
var images = await http.GetFromJsonAsync<List<Rule34Object>>(uri, _serializerOptions, cancel);
if (images is null)
return new();

View File

@@ -5,7 +5,7 @@ namespace NadekoBot.Modules.Nsfw.Common;
public class SafebooruImageDownloader : ImageDownloader<SafebooruElement>
{
public SafebooruImageDownloader(HttpClient http)
public SafebooruImageDownloader(IHttpClientFactory http)
: base(Booru.Safebooru, http)
{
}
@@ -19,7 +19,9 @@ public class SafebooruImageDownloader : ImageDownloader<SafebooruElement>
var tagString = ImageDownloaderHelper.GetTagString(tags);
var uri =
$"https://safebooru.org/index.php?page=dapi&s=post&q=index&limit=200&tags={tagString}&json=1&pid={page}";
var images = await _http.GetFromJsonAsync<List<SafebooruElement>>(uri, _serializerOptions, cancel);
using var http = _http.CreateClient();
var images = await http.GetFromJsonAsync<List<SafebooruElement>>(uri, _serializerOptions, cancel);
if (images is null)
return new();

View File

@@ -7,11 +7,10 @@ public sealed class SankakuImageDownloader : ImageDownloader<SankakuImageObject>
{
private readonly string _baseUrl;
public SankakuImageDownloader(HttpClient http)
public SankakuImageDownloader(IHttpClientFactory http)
: base(Booru.Sankaku, http)
{
_baseUrl = "https://capi-v2.sankakucomplex.com";
_http.AddFakeHeaders();
}
public override async Task<List<SankakuImageObject>> DownloadImagesAsync(
@@ -24,9 +23,12 @@ public sealed class SankakuImageDownloader : ImageDownloader<SankakuImageObject>
var tagString = ImageDownloaderHelper.GetTagString(tags);
var uri = $"{_baseUrl}/posts?tags={tagString}&limit=50";
var data = await _http.GetStringAsync(uri);
using var http = _http.CreateClient();
http.AddFakeHeaders();
var data = await http.GetStringAsync(uri, cancel);
return JsonSerializer.Deserialize<SankakuImageObject[]>(data, _serializerOptions)
.Where(x => !string.IsNullOrWhiteSpace(x.FileUrl) && x.FileType.StartsWith("image"))
?.Where(x => !string.IsNullOrWhiteSpace(x.FileUrl) && x.FileType.StartsWith("image"))
.ToList();
}
}

View File

@@ -7,7 +7,7 @@ public sealed class YandereImageDownloader : ImageDownloader<DapiImageObject>
{
private readonly string _baseUrl;
public YandereImageDownloader(HttpClient http)
public YandereImageDownloader(IHttpClientFactory http)
: base(Booru.Yandere, http)
=> _baseUrl = "https://yande.re";
@@ -20,7 +20,9 @@ public sealed class YandereImageDownloader : ImageDownloader<DapiImageObject>
var tagString = ImageDownloaderHelper.GetTagString(tags, isExplicit);
var uri = $"{_baseUrl}/post.json?limit=200&tags={tagString}&page={page}";
var imageObjects = await _http.GetFromJsonAsync<DapiImageObject[]>(uri, _serializerOptions, cancel);
using var http = _http.CreateClient();
var imageObjects = await http.GetFromJsonAsync<DapiImageObject[]>(uri, _serializerOptions, cancel);
if (imageObjects is null)
return new();
return imageObjects.Where(x => x.FileUrl is not null).ToList();

View File

@@ -1,4 +1,6 @@
#nullable disable
using System.Text.Json.Serialization;
namespace NadekoBot.Modules.Nsfw.Common;
public class Rule34Object : IImageData
@@ -7,7 +9,9 @@ public class Rule34Object : IImageData
public int Directory { get; init; }
public string Tags { get; init; }
public int Score { get; init; }
[JsonPropertyName("file_url")]
public string FileUrl { get; init; }
public ImageData ToCachedImageData(Booru type)
=> new($"https://img.rule34.xxx//images/{Directory}/{Image}", Booru.Rule34, Tags.Split(' '), Score.ToString());
=> new(FileUrl, Booru.Rule34, Tags.Split(' '), Score.ToString());
}

View File

@@ -1,5 +1,9 @@
using System.Text.Json;
using YahooFinanceApi;
using CsvHelper;
using CsvHelper.Configuration;
using Google.Protobuf.WellKnownTypes;
using System.Globalization;
using System.Net.Http.Json;
using System.Text.Json;
namespace NadekoBot.Modules.Searches;
@@ -17,19 +21,14 @@ public sealed class DefaultStockDataService : IStockDataService, INService
if (!query.IsAlphaNumeric())
return default;
var symbols = await Yahoo.Symbols(query)
.Fields(Field.LongName,
Field.Symbol,
Field.RegularMarketPrice,
Field.RegularMarketPreviousClose,
Field.MarketCap,
Field.FiftyDayAverageChangePercent,
Field.TwoHundredDayAverageChangePercent,
Field.AverageDailyVolume10Day,
Field.FullExchangeName)
.QueryAsync();
using var http = _httpClientFactory.CreateClient();
var data = await http.GetFromJsonAsync<YahooQueryModel>(
$"https://query1.finance.yahoo.com/v7/finance/quote?symbols={query}");
var symbol = symbols.Values.FirstOrDefault();
if (data is null)
return default;
var symbol = data.QuoteResponse.Result.FirstOrDefault();
if (symbol is null)
return default;
@@ -79,11 +78,25 @@ public sealed class DefaultStockDataService : IStockDataService, INService
.ToList();
}
private static CsvConfiguration _csvConfig = new(CultureInfo.InvariantCulture)
{
PrepareHeaderForMatch = args => args.Header.Humanize(LetterCasing.Title)
};
public async Task<IReadOnlyCollection<CandleData>> GetCandleDataAsync(string query)
{
var candles = await Yahoo.GetHistoricalAsync(query, DateTime.Now.Subtract(30.Days()));
using var http = _httpClientFactory.CreateClient();
await using var resStream = await http.GetStreamAsync(
$"https://query1.finance.yahoo.com/v7/finance/download/{query}"
+ $"?period1={DateTime.UtcNow.Subtract(30.Days()).ToTimestamp().Seconds}"
+ $"&period2={DateTime.UtcNow.ToTimestamp().Seconds}"
+ "&interval=1d");
return candles
using var textReader = new StreamReader(resStream);
using var csv = new CsvReader(textReader, _csvConfig);
var records = csv.GetRecords<YahooFinanceCandleData>().ToArray();
return records
.Map(static x => new CandleData(x.Open, x.Close, x.High, x.Low, x.Volume));
}
}

View File

@@ -0,0 +1,43 @@
#nullable disable
using System.Text.Json.Serialization;
namespace NadekoBot.Modules.Searches;
public class QuoteResponse
{
public class ResultModel
{
[JsonPropertyName("longName")]
public string LongName { get; set; }
[JsonPropertyName("regularMarketPrice")]
public double RegularMarketPrice { get; set; }
[JsonPropertyName("regularMarketPreviousClose")]
public double RegularMarketPreviousClose { get; set; }
[JsonPropertyName("fullExchangeName")]
public string FullExchangeName { get; set; }
[JsonPropertyName("averageDailyVolume10Day")]
public int AverageDailyVolume10Day { get; set; }
[JsonPropertyName("fiftyDayAverageChangePercent")]
public double FiftyDayAverageChangePercent { get; set; }
[JsonPropertyName("twoHundredDayAverageChangePercent")]
public double TwoHundredDayAverageChangePercent { get; set; }
[JsonPropertyName("marketCap")]
public long MarketCap { get; set; }
[JsonPropertyName("symbol")]
public string Symbol { get; set; }
}
[JsonPropertyName("result")]
public List<ResultModel> Result { get; set; }
[JsonPropertyName("error")]
public object Error { get; set; }
}

View File

@@ -0,0 +1,12 @@
namespace NadekoBot.Modules.Searches;
public class YahooFinanceCandleData
{
public DateTime Date { get; set; }
public decimal Open { get; set; }
public decimal High { get; set; }
public decimal Low { get; set; }
public decimal Close { get; set; }
public decimal AdjClose { get; set; }
public long Volume { get; set; }
}

View File

@@ -0,0 +1,9 @@
using System.Text.Json.Serialization;
namespace NadekoBot.Modules.Searches;
public class YahooQueryModel
{
[JsonPropertyName("quoteResponse")]
public QuoteResponse QuoteResponse { get; set; } = null!;
}

View File

@@ -53,7 +53,7 @@ public class FeedsService : INService
if (kvp.Value.Count == 0)
continue;
var rssUrl = kvp.Key;
var rssUrl = kvp.Value.First().Url;
try
{
var feed = await FeedReader.ReadAsync(rssUrl);
@@ -143,12 +143,16 @@ public class FeedsService : INService
allSendTasks.Add(feedSendTasks.WhenAll());
}
}
catch
catch (Exception ex)
{
Log.Warning("An error occured while getting rss stream {RssFeed}"
+ "\n {Message}",
rssUrl,
$"[{ex.GetType().Name}]: {ex.Message}");
}
}
await Task.WhenAll(Task.WhenAll(allSendTasks), Task.Delay(10000));
await Task.WhenAll(Task.WhenAll(allSendTasks), Task.Delay(30000));
}
}

View File

@@ -319,9 +319,23 @@ public partial class Xp
public async partial Task ClubDescription([Leftover] string desc = null)
{
if (_service.SetDescription(ctx.User.Id, desc))
await ReplyConfirmLocalizedAsync(strs.club_desc_updated(Format.Bold(desc ?? "-")));
{
desc = string.IsNullOrWhiteSpace(desc)
? "-"
: desc;
var eb = _eb.Create(ctx)
.WithAuthor(ctx.User)
.WithTitle(GetText(strs.club_desc_update))
.WithOkColor()
.WithDescription(desc);
await ctx.Channel.EmbedAsync(eb);
}
else
{
await ReplyErrorLocalizedAsync(strs.club_desc_update_failed);
}
}
[Cmd]

View File

@@ -502,7 +502,10 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
var value = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
_cache.Redis.GetDatabase()
.StringSet(key, value, TimeSpan.FromMinutes(_xpConfig.Data.VoiceMaxMinutes), When.NotExists);
.StringSet(key,
value,
TimeSpan.FromMinutes(_xpConfig.Data.VoiceMaxMinutes),
when: When.NotExists);
}
private void UserLeftVoiceChannel(SocketGuildUser user, SocketVoiceChannel channel)
@@ -632,7 +635,10 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
var r = _cache.Redis.GetDatabase();
var key = $"{_creds.RedisKey()}_user_xp_gain_{userId}";
return r.StringSet(key, true, TimeSpan.FromMinutes(_xpConfig.Data.MessageXpCooldown), When.NotExists);
return r.StringSet(key,
true,
TimeSpan.FromMinutes(_xpConfig.Data.MessageXpCooldown),
when: When.NotExists);
}
public async Task<FullUserStats> GetUserStatsAsync(IGuildUser user)

View File

@@ -23,17 +23,18 @@
<PrivateAssets>all</PrivateAssets>
<Publish>True</Publish>
</PackageReference>
<PackageReference Include="AWSSDK.S3" Version="3.7.8.4" />
<PackageReference Include="AWSSDK.S3" Version="3.7.9.2" />
<PackageReference Include="CodeHollow.FeedReader" Version="1.2.4" />
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Discord.Net" Version="3.5.0" />
<PackageReference Include="CoreCLR-NCalc" Version="2.2.92" />
<PackageReference Include="CsvHelper" Version="27.2.1" />
<PackageReference Include="Discord.Net" Version="3.6.1" />
<PackageReference Include="CoreCLR-NCalc" Version="2.2.101" />
<PackageReference Include="Google.Apis.Urlshortener.v1" Version="1.41.1.138" />
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.56.0.2617" />
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.57.0.2665" />
<PackageReference Include="Google.Apis.Customsearch.v1" Version="1.49.0.2084" />
<PackageReference Include="Google.Protobuf" Version="3.19.4" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.44.0" />
<PackageReference Include="Grpc.Tools" Version="2.44.0">
<PackageReference Include="Google.Protobuf" Version="3.20.1" />
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.45.0" />
<PackageReference Include="Grpc.Tools" Version="2.46.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
@@ -55,7 +56,7 @@
<PackageReference Include="Serilog.Sinks.Seq" Version="5.1.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.4" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta0010" />
<PackageReference Include="StackExchange.Redis" Version="2.5.43" />
<PackageReference Include="StackExchange.Redis" Version="2.5.61" />
<PackageReference Include="YamlDotNet" Version="11.2.1" />
<PackageReference Include="Humanizer" Version="2.14.1">
@@ -63,25 +64,24 @@
<Publish>True</Publish>
</PackageReference>
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" />
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" />
<!-- Db-related packages -->
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.4">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="linq2db.EntityFrameworkCore" Version="6.7.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.5" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.4" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.1" />
<!-- <PackageReference Include="System.Runtime.Experimental" Version="6.0.2" />-->
<!-- Used by .crypto command -->
<PackageReference Include="YahooFinanceApi" Version="2.1.2" />
<!-- Used by stream notifications -->
<PackageReference Include="TwitchLib.Api" Version="3.4.1" />

View File

@@ -17,7 +17,8 @@ public static class CurrencyServiceExtensions
IUser from,
IUser to,
long amount,
string? note)
string? note,
string formattedAmount)
{
var fromWallet = await cs.GetWalletAsync(from.Id);
var toWallet = await cs.GetWalletAsync(to.Id);
@@ -28,8 +29,8 @@ public static class CurrencyServiceExtensions
{
await to.SendConfirmAsync(ebs,
string.IsNullOrWhiteSpace(note)
? $"Gift from {from}"
: $"Gift from {from}: {note}");
? $"Received {formattedAmount} from {from} "
: $"Received {formattedAmount} from {from}: {note}");
return true;
}

View File

@@ -116,6 +116,8 @@ public sealed class BehaviorHandler : IBehaviorHandler, INService
usrMsg.Author.Id,
usrMsg.Channel.Id,
usrMsg.Content?.TrimTo(10));
return true;
}
}
catch (Exception ex)

View File

@@ -147,8 +147,10 @@ public class RedisCache : IDataCache
if (db.StringSet($"{_redisKey}_ratelimit_{id}_{name}",
0, // i don't use the value
TimeSpan.FromSeconds(expireIn),
When.NotExists))
when: When.NotExists))
{
return null;
}
return db.KeyTimeToLive($"{_redisKey}_ratelimit_{id}_{name}");
}

View File

@@ -7,7 +7,7 @@ namespace NadekoBot.Services;
public sealed class StatsService : IStatsService, IReadyExecutor, INService
{
public const string BOT_VERSION = "4.1.3";
public const string BOT_VERSION = "4.1.6";
public string Author
=> "Kwoth#2452";

View File

@@ -838,7 +838,7 @@
"club_user_ban_fail": "Failed to ban. You're either not the club owner, or that user is not in your club or applied to it.",
"club_user_unbanned": "Unbanned user {0} in {1} club.",
"club_user_unban_fail": "Failed to unban. You're either not the club owner, or that user is not in your club or applied to it.",
"club_desc_updated": "Updated club description to {0}",
"club_desc_update": "Club Description Updated",
"club_desc_update_failed": "Failed changing club description.",
"club_disbanded": "Club {0} has been disbanded",
"club_disband_error": "Error. You are either not in a club, or you are not the owner of your club.",

View File

@@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="System.Threading.Channels" Version="6.0.0" />
</ItemGroup>
</Project>