mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Merged v4 and working on adding grpc api. INcomplete
This commit is contained in:
@@ -48,4 +48,23 @@ public interface IStatsService
|
||||
/// Gets total amount of private memory currently in use by the bot, in Megabytes.
|
||||
/// </summary>
|
||||
double GetPrivateMemoryMegabytes();
|
||||
|
||||
GuildInfo GetGuildInfo(string name);
|
||||
GuildInfo GetGuildInfo(ulong id);
|
||||
}
|
||||
|
||||
public record struct GuildInfo
|
||||
{
|
||||
public required string Name { get; init; }
|
||||
public required string IconUrl { get; init; }
|
||||
public required string Owner { get; init; }
|
||||
public required ulong OwnerId { get; init; }
|
||||
public required ulong Id { get; init; }
|
||||
public required int TextChannels { get; init; }
|
||||
public required int VoiceChannels { get; init; }
|
||||
public required DateTime CreatedAt { get; init; }
|
||||
public required IReadOnlyList<string> Features { get; init; }
|
||||
public required IReadOnlyList<Emote> Emojis { get; init; }
|
||||
public required IReadOnlyList<IRole> Roles { get; init; }
|
||||
public int MemberCount { get; init; }
|
||||
}
|
@@ -185,4 +185,28 @@ public sealed class StatsService : IStatsService, IReadyExecutor, INService
|
||||
_currentProcess.Refresh();
|
||||
return _currentProcess.PrivateMemorySize64 / 1.Megabytes().Bytes;
|
||||
}
|
||||
|
||||
public GuildInfo GetGuildInfo(string name)
|
||||
=> throw new NotImplementedException();
|
||||
|
||||
public GuildInfo GetGuildInfo(ulong id)
|
||||
{
|
||||
var g = _client.GetGuild(id);
|
||||
|
||||
return new GuildInfo()
|
||||
{
|
||||
Id = g.Id,
|
||||
IconUrl = g.IconUrl,
|
||||
Name = g.Name,
|
||||
Owner = g.Owner.Username,
|
||||
OwnerId = g.OwnerId,
|
||||
CreatedAt = g.CreatedAt.UtcDateTime,
|
||||
VoiceChannels = g.VoiceChannels.Count,
|
||||
TextChannels = g.TextChannels.Count,
|
||||
Features = g.Features.Value.ToString().Split(","),
|
||||
Emojis = g.Emotes.ToArray(),
|
||||
Roles = g.Roles.OrderByDescending(x => x.Position).ToArray(),
|
||||
MemberCount = g.MemberCount,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -85,11 +85,11 @@ public partial class Searches
|
||||
.WithUrl($"https://www.tradingview.com/chart/?symbol={stock.Symbol}")
|
||||
.WithTitle(stock.Name)
|
||||
.AddField(GetText(strs.price), $"{sign} **{price}**", true)
|
||||
.AddField(GetText(strs.market_cap), stock.MarketCap.ToString("C0", localCulture), true)
|
||||
.AddField(GetText(strs.market_cap), stock.MarketCap, true)
|
||||
.AddField(GetText(strs.volume_24h), stock.DailyVolume.ToString("C0", localCulture), true)
|
||||
.AddField("Change", $"{change} ({changePercent})", true)
|
||||
.AddField("Change 50d", $"{sign50}{change50}", true)
|
||||
.AddField("Change 200d", $"{sign200}{change200}", true)
|
||||
// .AddField("Change 50d", $"{sign50}{change50}", true)
|
||||
// .AddField("Change 200d", $"{sign200}{change200}", true)
|
||||
.WithFooter(stock.Exchange);
|
||||
|
||||
var message = await ctx.Channel.EmbedAsync(eb);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using CsvHelper;
|
||||
using AngleSharp;
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
using System.Globalization;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace NadekoBot.Modules.Searches;
|
||||
@@ -22,33 +22,61 @@ public sealed class DefaultStockDataService : IStockDataService, INService
|
||||
return default;
|
||||
|
||||
using var http = _httpClientFactory.CreateClient();
|
||||
var data = await http.GetFromJsonAsync<YahooQueryModel>(
|
||||
$"https://query1.finance.yahoo.com/v7/finance/quote?symbols={query}");
|
||||
|
||||
if (data is null)
|
||||
return default;
|
||||
|
||||
var symbol = data.QuoteResponse.Result.FirstOrDefault();
|
||||
|
||||
if (symbol is null)
|
||||
return default;
|
||||
var quoteHtmlPage = $"https://finance.yahoo.com/quote/{query.ToUpperInvariant()}";
|
||||
|
||||
var config = Configuration.Default.WithDefaultLoader();
|
||||
using var document = await BrowsingContext.New(config).OpenAsync(quoteHtmlPage);
|
||||
var divElem =
|
||||
document.QuerySelector(
|
||||
"#quote-header-info > div:nth-child(2) > div > div > h1");
|
||||
var tickerName = (divElem)?.TextContent;
|
||||
|
||||
var marketcap = document
|
||||
.QuerySelectorAll("table")
|
||||
.Skip(1)
|
||||
.First()
|
||||
.QuerySelector("tbody > tr > td:nth-child(2)")
|
||||
?.TextContent;
|
||||
|
||||
|
||||
var volume = document.QuerySelector("td[data-test='AVERAGE_VOLUME_3MONTH-value']")
|
||||
?.TextContent;
|
||||
|
||||
var close= document.QuerySelector("td[data-test='PREV_CLOSE-value']")
|
||||
?.TextContent ?? "0";
|
||||
|
||||
var price = document
|
||||
.QuerySelector("#quote-header-info")
|
||||
?.QuerySelector("fin-streamer[data-field='regularMarketPrice']")
|
||||
?.TextContent ?? close;
|
||||
|
||||
// var data = await http.GetFromJsonAsync<YahooQueryModel>(
|
||||
// $"https://query1.finance.yahoo.com/v7/finance/quote?symbols={query}");
|
||||
//
|
||||
// if (data is null)
|
||||
// return default;
|
||||
|
||||
// var symbol = data.QuoteResponse.Result.FirstOrDefault();
|
||||
|
||||
// if (symbol is null)
|
||||
// return default;
|
||||
|
||||
return new()
|
||||
{
|
||||
Name = symbol.LongName,
|
||||
Symbol = symbol.Symbol,
|
||||
Price = symbol.RegularMarketPrice,
|
||||
Close = symbol.RegularMarketPreviousClose,
|
||||
MarketCap = symbol.MarketCap,
|
||||
Change50d = symbol.FiftyDayAverageChangePercent,
|
||||
Change200d = symbol.TwoHundredDayAverageChangePercent,
|
||||
DailyVolume = symbol.AverageDailyVolume10Day,
|
||||
Exchange = symbol.FullExchangeName
|
||||
Name = tickerName,
|
||||
Symbol = query,
|
||||
Price = double.Parse(price, NumberStyles.Any, CultureInfo.InvariantCulture),
|
||||
Close = double.Parse(close, NumberStyles.Any, CultureInfo.InvariantCulture),
|
||||
MarketCap = marketcap,
|
||||
DailyVolume = (long)double.Parse(volume ?? "0", NumberStyles.Any, CultureInfo.InvariantCulture),
|
||||
};
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log.Warning(ex, "Error getting stock data: {ErrorMessage}", ex.Message);
|
||||
Log.Warning(ex, "Error getting stock data: {ErrorMessage}", ex.ToString());
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -73,9 +101,9 @@ public sealed class DefaultStockDataService : IStockDataService, INService
|
||||
return Array.Empty<SymbolData>();
|
||||
|
||||
return data.Items
|
||||
.Where(x => x.Type == "S")
|
||||
.Select(x => new SymbolData(x.Symbol, x.Name))
|
||||
.ToList();
|
||||
.Where(x => x.Type == "S")
|
||||
.Select(x => new SymbolData(x.Symbol, x.Name))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static CsvConfiguration _csvConfig = new(CultureInfo.InvariantCulture)
|
||||
|
@@ -6,7 +6,7 @@ public class StockData
|
||||
public string Name { get; set; }
|
||||
public string Symbol { get; set; }
|
||||
public double Price { get; set; }
|
||||
public long MarketCap { get; set; }
|
||||
public string MarketCap { get; set; }
|
||||
public double Close { get; set; }
|
||||
public double Change50d { get; set; }
|
||||
public double Change200d { get; set; }
|
||||
|
@@ -208,7 +208,6 @@ public sealed class Bot : IBot
|
||||
if (baseType is null)
|
||||
continue;
|
||||
|
||||
Log.Information(ft.Name);
|
||||
var typeReader = (TypeReader)ActivatorUtilities.CreateInstance(Services, ft);
|
||||
var typeArgs = baseType.GetGenericArguments();
|
||||
_commandService.AddTypeReader(typeArgs[0], typeReader);
|
||||
|
@@ -17,6 +17,7 @@
|
||||
|
||||
<!-- Profile-guided optimization -->
|
||||
<TieredPGO>true</TieredPGO>
|
||||
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -32,9 +33,10 @@
|
||||
<PackageReference Include="Google.Apis.Urlshortener.v1" Version="1.41.1.138" />
|
||||
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.62.1.3205" />
|
||||
<PackageReference Include="Google.Apis.Customsearch.v1" Version="1.49.0.2084" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.22.1" />
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.52.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.53.0">
|
||||
<PackageReference Include="Grpc.AspNetCore" Version="2.62.0" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.26.1" />
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.62.0" />
|
||||
<PackageReference Include="Grpc.Tools" Version="2.62.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
Reference in New Issue
Block a user