mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 10:18:27 -04:00
Many IDisposable fixes. GlobalNadeko won't have file watchers for creds. Wallet simplified
This commit is contained in:
@@ -98,15 +98,16 @@ public partial class Searches
|
||||
return;
|
||||
|
||||
var fileName = $"{query}-sparkline.{imageData.Extension}";
|
||||
using var attachment = new FileAttachment(
|
||||
imageData.FileData,
|
||||
fileName
|
||||
);
|
||||
await message.ModifyAsync(mp =>
|
||||
{
|
||||
mp.Attachments =
|
||||
new(new[]
|
||||
{
|
||||
new FileAttachment(
|
||||
imageData.FileData,
|
||||
fileName
|
||||
)
|
||||
attachment
|
||||
});
|
||||
|
||||
mp.Embed = eb.WithImageUrl($"attachment://{fileName}").Build();
|
||||
|
@@ -1,55 +1,55 @@
|
||||
using System.Net.Http.Json;
|
||||
|
||||
namespace NadekoBot.Modules.Searches;
|
||||
|
||||
public sealed class PolygonApiClient : IDisposable
|
||||
{
|
||||
private const string BASE_URL = "https://api.polygon.io/v3";
|
||||
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly string _apiKey;
|
||||
|
||||
public PolygonApiClient(HttpClient httpClient, string apiKey)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_apiKey = apiKey;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<PolygonTickerData>> TickersAsync(string? ticker = null, string? query = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
query = null;
|
||||
|
||||
if(query is not null)
|
||||
query = Uri.EscapeDataString(query);
|
||||
|
||||
var requestString = $"{BASE_URL}/reference/tickers"
|
||||
+ "?type=CS"
|
||||
+ "&active=true"
|
||||
+ "&order=asc"
|
||||
+ "&limit=1000"
|
||||
+ $"&apiKey={_apiKey}";
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(ticker))
|
||||
requestString += $"&ticker={ticker}";
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(query))
|
||||
requestString += $"&search={query}";
|
||||
|
||||
|
||||
var response = await _httpClient.GetFromJsonAsync<PolygonTickerResponse>(requestString);
|
||||
|
||||
if (response is null)
|
||||
return Array.Empty<PolygonTickerData>();
|
||||
|
||||
return response.Results;
|
||||
}
|
||||
|
||||
// public async Task<PolygonTickerDetailsV3> TickerDetailsV3Async(string ticker)
|
||||
// {
|
||||
// return new();
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
=> _httpClient.Dispose();
|
||||
}
|
||||
// using System.Net.Http.Json;
|
||||
//
|
||||
// namespace NadekoBot.Modules.Searches;
|
||||
//
|
||||
// public sealed class PolygonApiClient : IDisposable
|
||||
// {
|
||||
// private const string BASE_URL = "https://api.polygon.io/v3";
|
||||
//
|
||||
// private readonly HttpClient _httpClient;
|
||||
// private readonly string _apiKey;
|
||||
//
|
||||
// public PolygonApiClient(HttpClient httpClient, string apiKey)
|
||||
// {
|
||||
// _httpClient = httpClient;
|
||||
// _apiKey = apiKey;
|
||||
// }
|
||||
//
|
||||
// public async Task<IReadOnlyCollection<PolygonTickerData>> TickersAsync(string? ticker = null, string? query = null)
|
||||
// {
|
||||
// if (string.IsNullOrWhiteSpace(query))
|
||||
// query = null;
|
||||
//
|
||||
// if(query is not null)
|
||||
// query = Uri.EscapeDataString(query);
|
||||
//
|
||||
// var requestString = $"{BASE_URL}/reference/tickers"
|
||||
// + "?type=CS"
|
||||
// + "&active=true"
|
||||
// + "&order=asc"
|
||||
// + "&limit=1000"
|
||||
// + $"&apiKey={_apiKey}";
|
||||
//
|
||||
// if (!string.IsNullOrWhiteSpace(ticker))
|
||||
// requestString += $"&ticker={ticker}";
|
||||
//
|
||||
// if (!string.IsNullOrWhiteSpace(query))
|
||||
// requestString += $"&search={query}";
|
||||
//
|
||||
//
|
||||
// var response = await _httpClient.GetFromJsonAsync<PolygonTickerResponse>(requestString);
|
||||
//
|
||||
// if (response is null)
|
||||
// return Array.Empty<PolygonTickerData>();
|
||||
//
|
||||
// return response.Results;
|
||||
// }
|
||||
//
|
||||
// // public async Task<PolygonTickerDetailsV3> TickerDetailsV3Async(string ticker)
|
||||
// // {
|
||||
// // return new();
|
||||
// // }
|
||||
//
|
||||
// public void Dispose()
|
||||
// => _httpClient.Dispose();
|
||||
// }
|
@@ -34,7 +34,7 @@ public partial class Searches
|
||||
return;
|
||||
|
||||
using var http = _httpFactory.CreateClient("memelist");
|
||||
var res = await http.GetAsync("https://api.memegen.link/templates/");
|
||||
using var res = await http.GetAsync("https://api.memegen.link/templates/");
|
||||
|
||||
var rawJson = await res.Content.ReadAsStringAsync();
|
||||
|
||||
|
@@ -109,7 +109,8 @@ public class SearchesService : INService
|
||||
using (var avatarImg = Image.Load<Rgba32>(data))
|
||||
{
|
||||
avatarImg.Mutate(x => x.Resize(85, 85).ApplyRoundedCorners(42));
|
||||
data = avatarImg.ToStream().ToArray();
|
||||
await using var avStream = avatarImg.ToStream();
|
||||
data = avStream.ToArray();
|
||||
DrawAvatar(bg, avatarImg);
|
||||
}
|
||||
|
||||
@@ -141,7 +142,8 @@ public class SearchesService : INService
|
||||
bg.Mutate(x => x.DrawImage(flowers, new(0, 0), new GraphicsOptions()));
|
||||
}
|
||||
|
||||
return bg.ToStream().ToArray();
|
||||
await using var stream = bg.ToStream();
|
||||
return stream.ToArray();
|
||||
}
|
||||
|
||||
public Task<WeatherData> GetWeatherDataAsync(string query)
|
||||
@@ -532,7 +534,7 @@ public class SearchesService : INService
|
||||
http.DefaultRequestHeaders.Clear();
|
||||
|
||||
using var response = await http.SendAsync(msg);
|
||||
var content = await response.Content.ReadAsStreamAsync();
|
||||
await using var content = await response.Content.ReadAsStreamAsync();
|
||||
|
||||
using var document = await _googleParser.ParseDocumentAsync(content);
|
||||
var elems = document.QuerySelectorAll("div.g > div > div");
|
||||
|
@@ -62,7 +62,7 @@ public class PicartoProvider : Provider
|
||||
{
|
||||
http.DefaultRequestHeaders.Accept.Add(new("application/json"));
|
||||
// get id based on the username
|
||||
var res = await http.GetAsync($"https://api.picarto.tv/v1/channel/name/{login}");
|
||||
using var res = await http.GetAsync($"https://api.picarto.tv/v1/channel/name/{login}");
|
||||
|
||||
if (!res.IsSuccessStatusCode)
|
||||
continue;
|
||||
|
@@ -59,7 +59,7 @@ If you are experiencing ratelimits, you should create your own application at: h
|
||||
// so there is no need for ratelimit checks atm
|
||||
try
|
||||
{
|
||||
var res = await http.PostAsJsonAsync(
|
||||
using var res = await http.PostAsJsonAsync(
|
||||
$"https://open-api.trovo.live/openplatform/channels/id",
|
||||
new TrovoRequestData()
|
||||
{
|
||||
|
Reference in New Issue
Block a user