mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
6c7ac44ed0 | ||
|
542cdc2d0d | ||
|
02fa501530 | ||
|
556142c5ce | ||
|
3db5a71d01 | ||
|
06f692283b | ||
|
49ff0dd27a | ||
|
2053296154 | ||
|
42fc0c263d | ||
|
cf1d950308 | ||
|
0fdccea31c | ||
|
2f8f62afcb | ||
|
570f39d4f8 |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -369,4 +369,9 @@ __pycache__/
|
||||
|
||||
### VisualStudio Patch ###
|
||||
build/
|
||||
site/
|
||||
site/
|
||||
|
||||
## AI
|
||||
|
||||
.aider.*
|
||||
PROMPT.md
|
@@ -29,6 +29,10 @@ variables:
|
||||
|
||||
build:
|
||||
stage: build
|
||||
rules:
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||
when: never
|
||||
- if: $CI_COMMIT_TAG
|
||||
script:
|
||||
- |
|
||||
VERSION_STRING=""
|
||||
@@ -54,6 +58,8 @@ upload-builds:
|
||||
stage: upload-builds
|
||||
image: alpine:latest
|
||||
rules:
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||
when: never
|
||||
- if: $CI_COMMIT_TAG
|
||||
script:
|
||||
- apk add --no-cache curl tar zip
|
||||
@@ -83,6 +89,8 @@ release:
|
||||
stage: release
|
||||
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
||||
rules:
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||
when: never
|
||||
- if: $CI_COMMIT_TAG
|
||||
script:
|
||||
- |
|
||||
@@ -130,7 +138,6 @@ publish-medusa-package:
|
||||
rules:
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||
when: never
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_TAG
|
||||
script:
|
||||
- LAST_TAG=$(git describe --tags --abbrev=0)
|
||||
- if [ $CI_COMMIT_TAG ];then MEDUSA_VERSION="$CI_COMMIT_TAG"; else MEDUSA_VERSION="$LAST_TAG-alpha$CI_COMMIT_SHORT_SHA"; fi
|
||||
@@ -162,6 +169,8 @@ docker-build:
|
||||
- docker push "$CI_REGISTRY_IMAGE${tag}"
|
||||
# Run this job in a branch where a Dockerfile exists
|
||||
rules:
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||
when: never
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_TAG
|
||||
exists:
|
||||
- Dockerfile
|
||||
|
19
CHANGELOG.md
19
CHANGELOG.md
@@ -2,6 +2,25 @@
|
||||
|
||||
Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o
|
||||
|
||||
## [5.3.9] - 30.01.2025
|
||||
|
||||
## Added
|
||||
|
||||
- Added `.todo archive done <name>`
|
||||
- Creates an archive of only currently completed todos
|
||||
- An alternative to ".todo archive add <name>" which moves all todos to an archive
|
||||
|
||||
## Changed
|
||||
|
||||
- Increased todo and archive limits slightly
|
||||
- Global nadeko captcha patron ad will show 12.5% of the time now, down from 20%, and be smaller
|
||||
- `.remind` now has a 1 year max timeout, up from 2 months
|
||||
|
||||
## Fixed
|
||||
|
||||
- Captcha is now slightly bigger, with larger margin, to mitigate phone edge issues
|
||||
- Fixed `.stock` command, unless there is some ip blocking going on
|
||||
|
||||
## [5.3.8] - 27.01.2025
|
||||
|
||||
## Fixed
|
||||
|
@@ -1,4 +1,4 @@
|
||||
Copyright 2023 Kwoth
|
||||
Copyright 2025 Breaker
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
@@ -12,8 +12,6 @@ ProjectSection(SolutionItems) = preProject
|
||||
README.md = README.md
|
||||
.gitlab-ci.yml = .gitlab-ci.yml
|
||||
Dockerfile = Dockerfile
|
||||
migrate.ps1 = migrate.ps1
|
||||
remove-migration.ps1 = remove-migration.ps1
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NadekoBot", "src\NadekoBot\NadekoBot.csproj", "{45EC1473-C678-4857-A544-07DFE0D0B478}"
|
||||
|
11
README.md
11
README.md
@@ -1,9 +1,4 @@
|
||||
[](https://nadeko.bot/)
|
||||
|
||||
[](https://invite.nadeko.bot/)
|
||||
|
||||
[](https://nadeko.bot/commands)
|
||||
|
||||
### Useful links
|
||||
- [Self hosting Guides and Docs](https://nadekobot.readthedocs.io/en/latest)
|
||||
- [Discord support server](https://discord.nadeko.bot)
|
||||
- Nadeko has been moved to https://github.com/nadeko-bot/nadekobot
|
||||
|
||||
- This repo will stay here as a v3, v4 and v5 archive
|
@@ -54,7 +54,7 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
else
|
||||
await Response().Pending(strs.imageonly_disable).SendAsync();
|
||||
}
|
||||
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPerm.Administrator)]
|
||||
@@ -97,9 +97,9 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
var (enabled, channels) = _service.GetDelMsgOnCmdData(ctx.Guild.Id);
|
||||
|
||||
var embed = CreateEmbed()
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.server_delmsgoncmd))
|
||||
.WithDescription(enabled ? "✅" : "❌");
|
||||
.WithOkColor()
|
||||
.WithTitle(GetText(strs.server_delmsgoncmd))
|
||||
.WithDescription(enabled ? "✅" : "❌");
|
||||
|
||||
var str = string.Join("\n",
|
||||
channels.Select(x =>
|
||||
@@ -221,7 +221,7 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
[BotPerm(GuildPerm.ManageChannels)]
|
||||
public async Task CreaTxtChanl([Leftover] string channelName)
|
||||
{
|
||||
var txtCh = await ctx.Guild.CreateTextChannelAsync(channelName);
|
||||
var txtCh = await ctx.Guild.CreateTextChannelAsync(channelName);
|
||||
await Response().Confirm(strs.createtextchan(Format.Bold(txtCh.Name))).SendAsync();
|
||||
}
|
||||
|
||||
@@ -301,6 +301,16 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
public Task Delete(ulong messageId, ParsedTimespan timespan = null)
|
||||
=> Delete((ITextChannel)ctx.Channel, messageId, timespan);
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Delete(MessageLink messageLink, ParsedTimespan timespan = null)
|
||||
{
|
||||
if (messageLink.Channel is not ITextChannel tc)
|
||||
return;
|
||||
|
||||
await Delete(tc, messageLink.Message.Id, timespan);
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Delete(ITextChannel channel, ulong messageId, ParsedTimespan timespan = null)
|
||||
@@ -360,11 +370,11 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
{
|
||||
if (ctx.Channel is not SocketTextChannel stc)
|
||||
return;
|
||||
|
||||
|
||||
await stc.CreateThreadAsync(name, message: ctx.Message.ReferencedMessage);
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
|
||||
|
||||
[Cmd]
|
||||
[BotPerm(ChannelPermission.ManageThreads)]
|
||||
[UserPerm(ChannelPermission.ManageThreads)]
|
||||
@@ -373,14 +383,15 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
if (ctx.Channel is not SocketTextChannel stc)
|
||||
return;
|
||||
|
||||
var t = stc.Threads.FirstOrDefault(x => string.Equals(x.Name, name, StringComparison.InvariantCultureIgnoreCase));
|
||||
var t = stc.Threads.FirstOrDefault(
|
||||
x => string.Equals(x.Name, name, StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (t is null)
|
||||
{
|
||||
await Response().Error(strs.not_found).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
await t.DeleteAsync();
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
@@ -406,7 +417,7 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
await Response().Confirm(strs.autopublish_disable).SendAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Cmd]
|
||||
[UserPerm(GuildPerm.ManageNicknames)]
|
||||
[BotPerm(GuildPerm.ChangeNickname)]
|
||||
@@ -450,8 +461,9 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
public async Task SetServerBanner([Leftover] string img = null)
|
||||
{
|
||||
// Tier2 or higher is required to set a banner.
|
||||
if (ctx.Guild.PremiumTier is PremiumTier.Tier1 or PremiumTier.None) return;
|
||||
|
||||
if (ctx.Guild.PremiumTier is PremiumTier.Tier1 or PremiumTier.None)
|
||||
return;
|
||||
|
||||
var result = await _service.SetServerBannerAsync(ctx.Guild, img);
|
||||
|
||||
switch (result)
|
||||
@@ -472,7 +484,7 @@ public partial class Administration : NadekoModule<AdministrationService>
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[UserPerm(GuildPermission.ManageGuild)]
|
||||
|
@@ -162,15 +162,15 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
|
||||
if (password is not null)
|
||||
{
|
||||
var img = GetPasswordImage(password);
|
||||
var img = _captchaService.GetPasswordImage(password);
|
||||
await using var stream = await img.ToStreamAsync();
|
||||
var toSend = Response()
|
||||
.File(stream, "timely.png");
|
||||
|
||||
#if GLOBAL_NADEKO
|
||||
if (_rng.Next(0, 5) == 0)
|
||||
if (_rng.Next(0, 8) == 0)
|
||||
toSend = toSend
|
||||
.Confirm("[Sub on Patreon](https://patreon.com/nadekobot) to remove captcha.");
|
||||
.Text("*[Sub on Patreon](https://patreon.com/nadekobot) to remove captcha.*");
|
||||
#endif
|
||||
|
||||
var captchaMessage = await toSend.SendAsync();
|
||||
@@ -194,39 +194,6 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||
await ClaimTimely();
|
||||
}
|
||||
|
||||
private Image<Rgba32> GetPasswordImage(string password)
|
||||
{
|
||||
var img = new Image<Rgba32>(50, 24);
|
||||
|
||||
var font = _fonts.NotoSans.CreateFont(22);
|
||||
var outlinePen = new SolidPen(Color.Black, 0.5f);
|
||||
var strikeoutRun = new RichTextRun
|
||||
{
|
||||
Start = 0,
|
||||
End = password.GetGraphemeCount(),
|
||||
Font = font,
|
||||
StrikeoutPen = new SolidPen(Color.White, 4),
|
||||
TextDecorations = TextDecorations.Strikeout
|
||||
};
|
||||
// draw password on the image
|
||||
img.Mutate(x =>
|
||||
{
|
||||
x.DrawText(new RichTextOptions(font)
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
FallbackFontFamilies = _fonts.FallBackFonts,
|
||||
Origin = new(25, 12),
|
||||
TextRuns = [strikeoutRun]
|
||||
},
|
||||
password,
|
||||
Brushes.Solid(Color.White),
|
||||
outlinePen);
|
||||
});
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
private async Task ClaimTimely()
|
||||
{
|
||||
var period = Config.Timely.Cooldown;
|
||||
|
@@ -111,8 +111,20 @@ public partial class OpenAiApiSession : IChatterBotSession
|
||||
});
|
||||
|
||||
var dataString = await data.Content.ReadAsStringAsync();
|
||||
|
||||
try
|
||||
{
|
||||
data.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, "Failed to get response from OpenAI: {Message}", ex.Message);
|
||||
return new Error<string>("Failed to get response from OpenAI");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var response = JsonConvert.DeserializeObject<OpenAiCompletionResponse>(dataString);
|
||||
|
||||
// Log.Information("Received response: {Response} ", dataString);
|
||||
|
@@ -17,7 +17,7 @@ public sealed class CaptchaService(FontProvider fonts, IBotCache cache, IPatrona
|
||||
|
||||
public Image<Rgba32> GetPasswordImage(string password)
|
||||
{
|
||||
var img = new Image<Rgba32>(50, 24);
|
||||
var img = new Image<Rgba32>(60, 34);
|
||||
|
||||
var font = fonts.NotoSans.CreateFont(22);
|
||||
var outlinePen = new SolidPen(Color.Black, 0.5f);
|
||||
@@ -39,7 +39,7 @@ public sealed class CaptchaService(FontProvider fonts, IBotCache cache, IPatrona
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
FallbackFontFamilies = fonts.FallBackFonts,
|
||||
Origin = new(25, 12),
|
||||
Origin = new(30, 15),
|
||||
TextRuns = [strikeoutRun]
|
||||
},
|
||||
password,
|
||||
@@ -52,7 +52,7 @@ public sealed class CaptchaService(FontProvider fonts, IBotCache cache, IPatrona
|
||||
|
||||
public string GeneratePassword()
|
||||
{
|
||||
var num = _rng.Next((int)Math.Pow(31, 2), (int)Math.Pow(32, 3));
|
||||
var num = _rng.Next((int)Math.Pow(32, 2) + 1, (int)Math.Pow(32, 3));
|
||||
return new kwum(num).ToString();
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
namespace NadekoBot.Modules.Games;
|
||||
|
||||
public sealed class FishCatch
|
||||
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
@@ -33,9 +33,9 @@ public partial class Games
|
||||
.File(stream, "timely.png");
|
||||
|
||||
#if GLOBAL_NADEKO
|
||||
if (_rng.Next(0, 5) == 0)
|
||||
if (_rng.Next(0, 8) == 0)
|
||||
toSend = toSend
|
||||
.Confirm("[Sub on Patreon](https://patreon.com/nadekobot) to remove captcha.");
|
||||
.Text("*[Sub on Patreon](https://patreon.com/nadekobot) to remove captcha.*");
|
||||
#endif
|
||||
var captcha = await toSend.SendAsync();
|
||||
|
||||
|
@@ -2,6 +2,8 @@
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace NadekoBot.Modules.Searches;
|
||||
@@ -9,54 +11,57 @@ namespace NadekoBot.Modules.Searches;
|
||||
public sealed class DefaultStockDataService : IStockDataService, INService
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IBotCache _cache;
|
||||
|
||||
public DefaultStockDataService(IHttpClientFactory httpClientFactory)
|
||||
=> _httpClientFactory = httpClientFactory;
|
||||
public DefaultStockDataService(IHttpClientFactory httpClientFactory, IBotCache cache)
|
||||
=> (_httpClientFactory, _cache) = (httpClientFactory, cache);
|
||||
|
||||
private static TypedKey<StockData> GetStockDataKey(string query)
|
||||
=> new($"stockdata:{query}");
|
||||
|
||||
public async Task<StockData?> GetStockDataAsync(string query)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(query);
|
||||
|
||||
return await _cache.GetOrAddAsync(GetStockDataKey(query.Trim().ToLowerInvariant()),
|
||||
() => GetStockDataInternalAsync(query),
|
||||
expiry: TimeSpan.FromHours(1));
|
||||
}
|
||||
|
||||
public async Task<StockData?> GetStockDataInternalAsync(string query)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!query.IsAlphaNumeric())
|
||||
return default;
|
||||
|
||||
using var http = _httpClientFactory.CreateClient();
|
||||
var sum = await GetNasdaqDataResponse<NasdaqSummaryResponse>(
|
||||
$"https://api.nasdaq.com/api/quote/{query}/summary?assetclass=stocks");
|
||||
|
||||
var quoteHtmlPage = $"https://finance.yahoo.com/quote/{query.ToUpperInvariant()}";
|
||||
if (sum?.Data is not { } d || d.SummaryData is not { } sd)
|
||||
return default;
|
||||
|
||||
var config = Configuration.Default.WithDefaultLoader();
|
||||
using var document = await BrowsingContext.New(config).OpenAsync(quoteHtmlPage);
|
||||
var closePrice = double.Parse(sd.PreviousClose.Value?.Substring(1) ?? "0",
|
||||
NumberStyles.Any,
|
||||
CultureInfo.InvariantCulture);
|
||||
|
||||
var tickerName = document.QuerySelector("div.top > .left > .container > h1")
|
||||
?.TextContent;
|
||||
|
||||
if (tickerName is null)
|
||||
var info = await GetNasdaqDataResponse<NasdaqInfoResponse>(
|
||||
$"https://api.nasdaq.com/api/quote/{query}/info?assetclass=stocks");
|
||||
|
||||
if (info?.Data?.PrimaryData is not { } pd)
|
||||
return default;
|
||||
|
||||
var marketcap = document
|
||||
.QuerySelector("li > span > fin-streamer[data-field='marketCap']")
|
||||
?.TextContent;
|
||||
|
||||
|
||||
var volume = document.QuerySelector("li > span > fin-streamer[data-field='regularMarketVolume']")
|
||||
?.TextContent;
|
||||
|
||||
var close = document.QuerySelector("li > span > fin-streamer[data-field='regularMarketPreviousClose']")
|
||||
?.TextContent
|
||||
?? "0";
|
||||
|
||||
var price = document.QuerySelector("fin-streamer.livePrice > span")
|
||||
?.TextContent
|
||||
?? "0";
|
||||
var priceStr = pd.LastSalePrice;
|
||||
|
||||
return new()
|
||||
{
|
||||
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),
|
||||
Name = info.Data.CompanyName,
|
||||
Symbol = sum.Data.Symbol,
|
||||
Price = double.Parse(priceStr?.Substring(1) ?? "0", NumberStyles.Any, CultureInfo.InvariantCulture),
|
||||
Close = closePrice,
|
||||
MarketCap = sd.MarketCap.Value,
|
||||
DailyVolume =
|
||||
(long)double.Parse(sd.AverageVolume.Value ?? "0", NumberStyles.Any, CultureInfo.InvariantCulture),
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -66,6 +71,36 @@ public sealed class DefaultStockDataService : IStockDataService, INService
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<NasdaqDataResponse<T>?> GetNasdaqDataResponse<T>(string url)
|
||||
{
|
||||
using var httpClient = _httpClientFactory.CreateClient("google:search");
|
||||
|
||||
var req = new HttpRequestMessage(HttpMethod.Get,
|
||||
url)
|
||||
{
|
||||
Headers =
|
||||
{
|
||||
{ "Host", "api.nasdaq.com" },
|
||||
{ "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:132.0) Gecko/20100101 Firefox/132.0" },
|
||||
{ "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" },
|
||||
{ "Accept-Language", "en-US,en;q=0.5" },
|
||||
{ "Accept-Encoding", "gzip, deflate, br, zstd" },
|
||||
{ "Connection", "keep-alive" },
|
||||
{ "Upgrade-Insecure-Requests", "1" },
|
||||
{ "Sec-Fetch-Dest", "document" },
|
||||
{ "Sec-Fetch-Mode", "navigate" },
|
||||
{ "Sec-Fetch-Site", "none" },
|
||||
{ "Sec-Fetch-User", "?1" },
|
||||
{ "Priority", "u=0, i" },
|
||||
{ "TE", "trailers" }
|
||||
}
|
||||
};
|
||||
var res = await httpClient.SendAsync(req);
|
||||
|
||||
var info = await res.Content.ReadFromJsonAsync<NasdaqDataResponse<T>>();
|
||||
return info;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<SymbolData>> SearchSymbolAsync(string query)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(query))
|
||||
@@ -91,22 +126,37 @@ public sealed class DefaultStockDataService : IStockDataService, INService
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static CsvConfiguration _csvConfig = new(CultureInfo.InvariantCulture);
|
||||
private static TypedKey<IReadOnlyCollection<CandleData>> GetCandleDataKey(string query)
|
||||
=> new($"candledata:{query}");
|
||||
|
||||
public async Task<IReadOnlyCollection<CandleData>> GetCandleDataAsync(string query)
|
||||
=> await _cache.GetOrAddAsync(GetCandleDataKey(query),
|
||||
async () => await GetCandleDataInternalAsync(query),
|
||||
expiry: TimeSpan.FromHours(4))
|
||||
?? [];
|
||||
|
||||
public async Task<IReadOnlyCollection<CandleData>> GetCandleDataInternalAsync(string query)
|
||||
{
|
||||
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()}"
|
||||
+ $"&period2={DateTime.UtcNow.ToTimestamp()}"
|
||||
+ "&interval=1d");
|
||||
|
||||
using var textReader = new StreamReader(resStream);
|
||||
using var csv = new CsvReader(textReader, _csvConfig);
|
||||
var records = csv.GetRecords<YahooFinanceCandleData>().ToArray();
|
||||
var now = DateTime.UtcNow;
|
||||
var fromdate = now.Subtract(30.Days()).ToString("yyyy-MM-dd");
|
||||
var todate = now.ToString("yyyy-MM-dd");
|
||||
|
||||
return records
|
||||
.Map(static x => new CandleData(x.Open, x.Close, x.High, x.Low, x.Volume));
|
||||
var res = await GetNasdaqDataResponse<NasdaqChartResponse>(
|
||||
$"https://api.nasdaq.com/api/quote/{query}/chart?assetclass=stocks"
|
||||
+ $"&fromdate={fromdate}"
|
||||
+ $"&todate={todate}");
|
||||
|
||||
if (res?.Data?.Chart is not { } chart)
|
||||
return Array.Empty<CandleData>();
|
||||
|
||||
|
||||
return chart.Select(d => new CandleData(d.Z.Open,
|
||||
d.Z.Close,
|
||||
d.Z.High,
|
||||
d.Z.Low,
|
||||
(long)double.Parse(d.Z.Volume, NumberStyles.Any, CultureInfo.InvariantCulture)))
|
||||
.ToList();
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
namespace NadekoBot.Modules.Searches;
|
||||
|
||||
public sealed class NasdaqChartResponse
|
||||
{
|
||||
public required NasdaqChartResponseData[] Chart { get; init; }
|
||||
|
||||
public sealed class NasdaqChartResponseData
|
||||
{
|
||||
public required CandleData Z { get; init; }
|
||||
|
||||
public sealed class CandleData
|
||||
{
|
||||
public required decimal High { get; init; }
|
||||
public required decimal Low { get; init; }
|
||||
public required decimal Open { get; init; }
|
||||
public required decimal Close { get; init; }
|
||||
public required string Volume { get; init; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
namespace NadekoBot.Modules.Searches;
|
||||
|
||||
public sealed class NasdaqDataResponse<T>
|
||||
{
|
||||
public required T? Data { get; init; }
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
namespace NadekoBot.Modules.Searches;
|
||||
|
||||
public sealed class NasdaqInfoResponse
|
||||
{
|
||||
public required string Symbol { get; init; }
|
||||
public required string CompanyName {get; init; }
|
||||
public required NasdaqInfoPrimaryData PrimaryData { get; init; }
|
||||
|
||||
public sealed class NasdaqInfoPrimaryData
|
||||
{
|
||||
public required string LastSalePrice{ get; init; }
|
||||
public required string PercentageChange { get; init; }
|
||||
public required string DeltaIndicator { get; init; }
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace NadekoBot.Modules.Searches;
|
||||
|
||||
public sealed class NasdaqSummaryResponse
|
||||
{
|
||||
public required string Symbol { get; init; }
|
||||
|
||||
public required NasdaqSummaryResponseData SummaryData { get; init; }
|
||||
|
||||
public sealed class NasdaqSummaryResponseData
|
||||
{
|
||||
public required PreviousCloseData PreviousClose { get; init; }
|
||||
public required MarketCapData MarketCap { get; init; }
|
||||
public required AverageVolumeData AverageVolume { get; init; }
|
||||
|
||||
public sealed class PreviousCloseData
|
||||
{
|
||||
public required string Value { get; init; }
|
||||
}
|
||||
|
||||
public sealed class MarketCapData
|
||||
{
|
||||
public required string Value { get; init; }
|
||||
}
|
||||
|
||||
public sealed class AverageVolumeData
|
||||
{
|
||||
public required string Value { get; init; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -183,7 +183,7 @@ public partial class Utility
|
||||
{
|
||||
var time = DateTime.UtcNow + ts;
|
||||
|
||||
if (ts > TimeSpan.FromDays(60))
|
||||
if (ts > TimeSpan.FromDays(366))
|
||||
return false;
|
||||
|
||||
if (ctx.Guild is not null)
|
||||
|
@@ -150,7 +150,26 @@ public partial class Utility
|
||||
[Cmd]
|
||||
public async Task TodoArchiveAdd([Leftover] string name)
|
||||
{
|
||||
var result = await _service.ArchiveTodosAsync(ctx.User.Id, name);
|
||||
var result = await _service.ArchiveTodosAsync(ctx.User.Id, name, false);
|
||||
if (result == ArchiveTodoResult.NoTodos)
|
||||
{
|
||||
await Response().Error(strs.todo_no_todos).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == ArchiveTodoResult.MaxLimitReached)
|
||||
{
|
||||
await Response().Error(strs.todo_archive_max_limit).SendAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task TodoArchiveDone([Leftover] string name)
|
||||
{
|
||||
var result = await _service.ArchiveTodosAsync(ctx.User.Id, name, true);
|
||||
if (result == ArchiveTodoResult.NoTodos)
|
||||
{
|
||||
await Response().Error(strs.todo_no_todos).SendAsync();
|
||||
@@ -193,7 +212,7 @@ public partial class Utility
|
||||
|
||||
foreach (var archivedList in items)
|
||||
{
|
||||
eb.AddField($"id: {archivedList.Id.ToString()}", archivedList.Name, true);
|
||||
eb.AddField($"id: {new kwum(archivedList.Id)}", archivedList.Name, true);
|
||||
}
|
||||
|
||||
return eb;
|
||||
@@ -202,7 +221,7 @@ public partial class Utility
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task TodoArchiveShow(int id)
|
||||
public async Task TodoArchiveShow(kwum id)
|
||||
{
|
||||
var list = await _service.GetArchivedTodoListAsync(ctx.User.Id, id);
|
||||
if (list == null || list.Items.Count == 0)
|
||||
@@ -234,7 +253,7 @@ public partial class Utility
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
public async Task TodoArchiveDelete(int id)
|
||||
public async Task TodoArchiveDelete(kwum id)
|
||||
{
|
||||
if (!await _service.ArchiveDeleteAsync(ctx.User.Id, id))
|
||||
{
|
||||
|
@@ -6,8 +6,8 @@ namespace NadekoBot.Modules.Utility;
|
||||
|
||||
public sealed class TodoService : INService
|
||||
{
|
||||
private const int ARCHIVE_MAX_COUNT = 9;
|
||||
private const int TODO_MAX_COUNT = 27;
|
||||
private const int ARCHIVE_MAX_COUNT = 18;
|
||||
private const int TODO_MAX_COUNT = 36;
|
||||
|
||||
private readonly DbService _db;
|
||||
|
||||
@@ -111,7 +111,7 @@ public sealed class TodoService : INService
|
||||
.DeleteAsync();
|
||||
}
|
||||
|
||||
public async Task<ArchiveTodoResult> ArchiveTodosAsync(ulong userId, string name)
|
||||
public async Task<ArchiveTodoResult> ArchiveTodosAsync(ulong userId, string name, bool onlyDone)
|
||||
{
|
||||
// create a new archive
|
||||
|
||||
@@ -140,7 +140,7 @@ public sealed class TodoService : INService
|
||||
|
||||
var updated = await ctx
|
||||
.GetTable<TodoModel>()
|
||||
.Where(x => x.UserId == userId && x.ArchiveId == null)
|
||||
.Where(x => x.UserId == userId && (!onlyDone || x.IsDone) && x.ArchiveId == null)
|
||||
.Set(x => x.ArchiveId, inserted.Id)
|
||||
.UpdateAsync();
|
||||
|
||||
@@ -204,4 +204,5 @@ public sealed class TodoService : INService
|
||||
.Where(x => x.UserId == userId && x.Id == todoId)
|
||||
.FirstOrDefaultAsyncLinqToDB();
|
||||
}
|
||||
|
||||
}
|
@@ -4,7 +4,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>true</ImplicitUsings>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
<Version>5.3.8</Version>
|
||||
<Version>5.3.9</Version>
|
||||
|
||||
<!-- Output/build -->
|
||||
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
|
||||
|
@@ -30,4 +30,5 @@ public static class SocketMessageComponentExtensions
|
||||
string text,
|
||||
bool ephemeral = false)
|
||||
=> smc.RespondAsync(sender, text, MsgType.Ok, ephemeral);
|
||||
|
||||
}
|
@@ -1441,6 +1441,11 @@ todoarchivedelete:
|
||||
- del
|
||||
- remove
|
||||
- rm
|
||||
todoarchivedone:
|
||||
- done
|
||||
- compelete
|
||||
- finish
|
||||
- completed
|
||||
todoedit:
|
||||
- edit
|
||||
- change
|
||||
|
@@ -4134,7 +4134,11 @@ edit:
|
||||
text:
|
||||
desc: "The new text content of the edited message."
|
||||
delete:
|
||||
desc: Deletes a single message given the channel and message ID. If channel is ommited, message will be searched for in the current channel. You can also specify time parameter after which the message will be deleted (up to 7 days). This timer won't persist through bot restarts.
|
||||
desc: |-
|
||||
Deletes a single message given the channel and message ID, or a message link.
|
||||
If channel is omitted, message will be searched for in the current channel.
|
||||
You can also specify time parameter after which the message will be deleted (up to 7 days).
|
||||
This timer won't persist through bot restarts.
|
||||
ex:
|
||||
- '#chat 771562360594628608'
|
||||
- 771562360594628608
|
||||
@@ -4144,6 +4148,10 @@ delete:
|
||||
desc: "The id of a specific message within a channel, used to target the deletion operation."
|
||||
time:
|
||||
desc: "The duration after which the message should be automatically deleted."
|
||||
- messageLink:
|
||||
desc: "The link of the message to delete. It must be on the same server."
|
||||
time:
|
||||
desc: "The duration after which the message should be automatically deleted."
|
||||
- channel:
|
||||
desc: "The channel where the message is located or should be searched for."
|
||||
messageId:
|
||||
@@ -4524,6 +4532,13 @@ todoarchiveadd:
|
||||
params:
|
||||
- name:
|
||||
desc: "The name of the archive to be created."
|
||||
todoarchivedone:
|
||||
desc: Creates a new archive with the specified name using only completed current todos.
|
||||
ex:
|
||||
- Success!
|
||||
params:
|
||||
- name:
|
||||
desc: "The name of the archive to be created."
|
||||
todoarchivelist:
|
||||
desc: Lists all archived todo lists.
|
||||
ex:
|
||||
|
Reference in New Issue
Block a user