Compare commits

...

5 Commits

Author SHA1 Message Date
Kwoth
d1db54498b Updatec changelog. Upped version to 4.3.21 2024-04-16 13:55:19 +00:00
Kwoth
eef5b3f948 Fixed .clubapply hopefully, and removed some redundant discriminators 2024-04-16 13:48:23 +00:00
Kwoth
d86b5b2b6c Fixed .stock 2024-04-05 03:07:40 +00:00
Kwoth
127a46a9b8 Possible fix for duplicate .bank take in .h .bank 2024-02-09 02:32:34 +00:00
Kwoth
a7e1e8a982 Fixed .config searches followedStreams.maxCount. Version upped to 4.3.20 2024-01-20 15:06:45 +00:00
15 changed files with 101 additions and 55 deletions

View File

@@ -2,6 +2,18 @@
Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.com/en/1.0.0/) except date format. a-c-f-r-o
## [4.3.21]
### Fixed
- Possible fix for a duplicate in `.h bank`
- Fixed `.stock` command
- Fixed `.clubapply` and `.clubaccept`
- Removed some redundant discriminators
## [4.3.20] - 20.01.2024
### Fixed
- Fixed `.config searches followedStreams.maxCount` not working
## [4.3.19] - 20.01.2024 ## [4.3.19] - 20.01.2024
@@ -36,7 +48,6 @@ Experimental changelog. Mostly based on [keepachangelog](https://keepachangelog.
### Removed ### Removed
- `.revimg` and `.revav` as google removed reverse image search - `.revimg` and `.revav` as google removed reverse image search
-
## [4.3.17] - 06.09.2023 ## [4.3.17] - 06.09.2023

View File

@@ -28,5 +28,10 @@ public class DiscordUser : DbEntity
=> UserId.GetHashCode(); => UserId.GetHashCode();
public override string ToString() public override string ToString()
=> Username + "#" + Discriminator; {
if (string.IsNullOrWhiteSpace(Discriminator) || Discriminator == "0000")
return Username;
return Username + "#" + Discriminator;
}
} }

View File

@@ -19,25 +19,25 @@ public class WaifuInfo : DbEntity
public override string ToString() public override string ToString()
{ {
var claimer = "no one";
var status = string.Empty; var status = string.Empty;
var waifuUsername = Waifu.Username.TrimTo(20); var waifuUsername = Waifu.ToString().TrimTo(20);
var claimerUsername = Claimer?.Username.TrimTo(20); var claimer = Claimer?.ToString().TrimTo(20)
?? "no one";
var affinity = Affinity?.ToString().TrimTo(20);
if (ClaimerId is not null)
claimer = $"{claimerUsername}#{Claimer.Discriminator}";
if (AffinityId is null) if (AffinityId is null)
status = $"... but {waifuUsername}'s heart is empty"; status = $"... but {waifuUsername}'s heart is empty";
else if (AffinityId == ClaimerId) else if (AffinityId == ClaimerId)
status = $"... and {waifuUsername} likes {claimerUsername} too <3"; status = $"... and {waifuUsername} likes {claimer} too <3";
else else
{ {
status = status =
$"... but {waifuUsername}'s heart belongs to {Affinity.Username.TrimTo(20)}#{Affinity.Discriminator}"; $"... but {waifuUsername}'s heart belongs to {affinity}";
} }
return $"**{waifuUsername}#{Waifu.Discriminator}** - claimed by **{claimer}**\n\t{status}"; return $"**{waifuUsername}** - claimed by **{claimer}**\n\t{status}";
} }
} }

View File

@@ -363,7 +363,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
if (before.Username != after.Username) if (before.Username != after.Username)
{ {
embed.WithTitle("👥 " + GetText(g, strs.username_changed)) embed.WithTitle("👥 " + GetText(g, strs.username_changed))
.WithDescription($"{before.Username}#{before.Discriminator} | {before.Id}") .WithDescription($"{before.Username} | {before.Id}")
.AddField("Old Name", $"{before.Username}", true) .AddField("Old Name", $"{before.Username}", true)
.AddField("New Name", $"{after.Username}", true) .AddField("New Name", $"{after.Username}", true)
.WithFooter(CurrentTime(g)) .WithFooter(CurrentTime(g))
@@ -905,7 +905,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
str = "🎙" str = "🎙"
+ Format.Code(PrettyCurrentTime(usr.Guild)) + Format.Code(PrettyCurrentTime(usr.Guild))
+ GetText(logChannel.Guild, + GetText(logChannel.Guild,
strs.user_vmoved("👤" + Format.Bold(usr.Username + "#" + usr.Discriminator), strs.user_vmoved("👤" + Format.Bold(usr.Username),
Format.Bold(beforeVch?.Name ?? ""), Format.Bold(beforeVch?.Name ?? ""),
Format.Bold(afterVch?.Name ?? ""))); Format.Bold(afterVch?.Name ?? "")));
} }
@@ -914,7 +914,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
str = "🎙" str = "🎙"
+ Format.Code(PrettyCurrentTime(usr.Guild)) + Format.Code(PrettyCurrentTime(usr.Guild))
+ GetText(logChannel.Guild, + GetText(logChannel.Guild,
strs.user_vjoined("👤" + Format.Bold(usr.Username + "#" + usr.Discriminator), strs.user_vjoined("👤" + Format.Bold(usr.Username),
Format.Bold(afterVch?.Name ?? ""))); Format.Bold(afterVch?.Name ?? "")));
} }
else if (afterVch is null) else if (afterVch is null)
@@ -922,7 +922,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor
str = "🎙" str = "🎙"
+ Format.Code(PrettyCurrentTime(usr.Guild)) + Format.Code(PrettyCurrentTime(usr.Guild))
+ GetText(logChannel.Guild, + GetText(logChannel.Guild,
strs.user_vleft("👤" + Format.Bold(usr.Username + "#" + usr.Discriminator), strs.user_vleft("👤" + Format.Bold(usr.Username),
Format.Bold(beforeVch.Name ?? ""))); Format.Bold(beforeVch.Name ?? "")));
} }

View File

@@ -239,7 +239,7 @@ public partial class Gambling : GamblingModule<GamblingService>
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)]; var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)];
await SendConfirmAsync("🎟 " + GetText(strs.raffled_user), await SendConfirmAsync("🎟 " + GetText(strs.raffled_user),
$"**{usr.Username}#{usr.Discriminator}**", $"**{usr.Username}**",
footer: $"ID: {usr.Id}"); footer: $"ID: {usr.Id}");
} }
@@ -258,7 +258,7 @@ public partial class Gambling : GamblingModule<GamblingService>
var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)]; var usr = membersArray[new NadekoRandom().Next(0, membersArray.Length)];
await SendConfirmAsync("🎟 " + GetText(strs.raffled_user), await SendConfirmAsync("🎟 " + GetText(strs.raffled_user),
$"**{usr.Username}#{usr.Discriminator}**", $"**{usr.Username}**",
footer: $"ID: {usr.Id}"); footer: $"ID: {usr.Id}");
} }

View File

@@ -292,7 +292,7 @@ public partial class Help : NadekoModule<HelpService>
.WithTitle(GetText(strs.cmd_group_commands(group.Name))) .WithTitle(GetText(strs.cmd_group_commands(group.Name)))
.WithOkColor(); .WithOkColor();
foreach (var cmd in group.Commands) foreach (var cmd in group.Commands.DistinctBy(x => x.Aliases[0]))
{ {
eb.AddField(prefix + cmd.Aliases.First(), cmd.RealSummary(_strings, _medusae, Culture, prefix)); eb.AddField(prefix + cmd.Aliases.First(), cmd.RealSummary(_strings, _medusae, Culture, prefix));
} }

View File

@@ -85,11 +85,11 @@ public partial class Searches
.WithUrl($"https://www.tradingview.com/chart/?symbol={stock.Symbol}") .WithUrl($"https://www.tradingview.com/chart/?symbol={stock.Symbol}")
.WithTitle(stock.Name) .WithTitle(stock.Name)
.AddField(GetText(strs.price), $"{sign} **{price}**", true) .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(GetText(strs.volume_24h), stock.DailyVolume.ToString("C0", localCulture), true)
.AddField("Change", $"{change} ({changePercent})", true) .AddField("Change", $"{change} ({changePercent})", true)
.AddField("Change 50d", $"{sign50}{change50}", true) // .AddField("Change 50d", $"{sign50}{change50}", true)
.AddField("Change 200d", $"{sign200}{change200}", true) // .AddField("Change 200d", $"{sign200}{change200}", true)
.WithFooter(stock.Exchange); .WithFooter(stock.Exchange);
var message = await ctx.Channel.EmbedAsync(eb); var message = await ctx.Channel.EmbedAsync(eb);

View File

@@ -1,5 +1,8 @@
using CsvHelper; using AngleSharp;
using AngleSharp.Html.Dom;
using CsvHelper;
using CsvHelper.Configuration; using CsvHelper.Configuration;
using CsvHelper.Configuration.Attributes;
using Google.Protobuf.WellKnownTypes; using Google.Protobuf.WellKnownTypes;
using System.Globalization; using System.Globalization;
using System.Net.Http.Json; using System.Net.Http.Json;
@@ -23,33 +26,61 @@ public sealed class DefaultStockDataService : IStockDataService, INService
return default; return default;
using var http = _httpClientFactory.CreateClient(); 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() return new()
{ {
Name = symbol.LongName, Name = tickerName,
Symbol = symbol.Symbol, Symbol = query,
Price = symbol.RegularMarketPrice, Price = double.Parse(price, NumberStyles.Any, CultureInfo.InvariantCulture),
Close = symbol.RegularMarketPreviousClose, Close = double.Parse(close, NumberStyles.Any, CultureInfo.InvariantCulture),
MarketCap = symbol.MarketCap, MarketCap = marketcap,
Change50d = symbol.FiftyDayAverageChangePercent, DailyVolume = (long)double.Parse(volume ?? "0", NumberStyles.Any, CultureInfo.InvariantCulture),
Change200d = symbol.TwoHundredDayAverageChangePercent,
DailyVolume = symbol.AverageDailyVolume10Day,
Exchange = symbol.FullExchangeName
}; };
} }
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; return default;
} }
} }
@@ -60,9 +91,9 @@ public sealed class DefaultStockDataService : IStockDataService, INService
throw new ArgumentNullException(nameof(query)); throw new ArgumentNullException(nameof(query));
query = Uri.EscapeDataString(query); query = Uri.EscapeDataString(query);
using var http = _httpClientFactory.CreateClient(); using var http = _httpClientFactory.CreateClient();
var res = await http.GetStringAsync( var res = await http.GetStringAsync(
"https://finance.yahoo.com/_finance_doubledown/api/resource/searchassist" "https://finance.yahoo.com/_finance_doubledown/api/resource/searchassist"
+ $";searchTerm={query}" + $";searchTerm={query}"
@@ -72,11 +103,11 @@ public sealed class DefaultStockDataService : IStockDataService, INService
if (data is null or { Items: null }) if (data is null or { Items: null })
return Array.Empty<SymbolData>(); return Array.Empty<SymbolData>();
return data.Items return data.Items
.Where(x => x.Type == "S") .Where(x => x.Type == "S")
.Select(x => new SymbolData(x.Symbol, x.Name)) .Select(x => new SymbolData(x.Symbol, x.Name))
.ToList(); .ToList();
} }
private static CsvConfiguration _csvConfig = new(CultureInfo.InvariantCulture) private static CsvConfiguration _csvConfig = new(CultureInfo.InvariantCulture)

View File

@@ -6,7 +6,7 @@ public class StockData
public string Name { get; set; } public string Name { get; set; }
public string Symbol { get; set; } public string Symbol { get; set; }
public double Price { get; set; } public double Price { get; set; }
public long MarketCap { get; set; } public string MarketCap { get; set; }
public double Close { get; set; } public double Close { get; set; }
public double Change50d { get; set; } public double Change50d { get; set; }
public double Change200d { get; set; } public double Change200d { get; set; }

View File

@@ -30,7 +30,7 @@ public class SearchesConfigService : ConfigServiceBase<SearchesConfig>
AddParsedProp("followedStreams.maxCount", AddParsedProp("followedStreams.maxCount",
sc => sc.FollowedStreams.MaxCount, sc => sc.FollowedStreams.MaxCount,
ConfigParsers.InsensitiveEnum, int.TryParse,
ConfigPrinters.ToString); ConfigPrinters.ToString);
Migrate(); Migrate();

View File

@@ -259,8 +259,8 @@ public partial class Xp
await ReplyConfirmLocalizedAsync(strs.club_applied(Format.Bold(club.ToString()))); await ReplyConfirmLocalizedAsync(strs.club_applied(Format.Bold(club.ToString())));
else if (result == ClubApplyResult.Banned) else if (result == ClubApplyResult.Banned)
await ReplyErrorLocalizedAsync(strs.club_join_banned); await ReplyErrorLocalizedAsync(strs.club_join_banned);
else if (result == ClubApplyResult.InsufficientLevel) else if (result == ClubApplyResult.AlreadyApplied)
await ReplyErrorLocalizedAsync(strs.club_insuff_lvl); await ReplyErrorLocalizedAsync(strs.club_already_applied);
else if (result == ClubApplyResult.AlreadyInAClub) else if (result == ClubApplyResult.AlreadyInAClub)
await ReplyErrorLocalizedAsync(strs.club_already_in); await ReplyErrorLocalizedAsync(strs.club_already_in);
} }

View File

@@ -146,7 +146,7 @@ public class ClubService : INService, IClubService
return ClubApplyResult.Banned; return ClubApplyResult.Banned;
if (club.Applicants.Any(x => x.UserId == du.Id)) if (club.Applicants.Any(x => x.UserId == du.Id))
return ClubApplyResult.InsufficientLevel; return ClubApplyResult.AlreadyApplied;
var app = new ClubApplicants var app = new ClubApplicants
{ {

View File

@@ -27,8 +27,7 @@ public interface IClubService
public enum ClubApplyResult public enum ClubApplyResult
{ {
Success, Success,
AlreadyInAClub, AlreadyInAClub,
Banned, Banned,
InsufficientLevel AlreadyApplied
} }

View File

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

View File

@@ -838,7 +838,7 @@
"server_leaderboard": "Server XP Leaderboard", "server_leaderboard": "Server XP Leaderboard",
"global_leaderboard": "Global XP Leaderboard", "global_leaderboard": "Global XP Leaderboard",
"modified": "Modified server XP of the user {0} by {1}", "modified": "Modified server XP of the user {0} by {1}",
"club_insuff_lvl": "You're insufficient level to join that club.", "club_already_applied": "You've already applied to that club.",
"club_join_banned": "You're banned from that club.", "club_join_banned": "You're banned from that club.",
"club_already_in": "You are already a member of a club.", "club_already_in": "You are already a member of a club.",
"club_create_error_name": "Failed creating the club. A club with that name already exists.", "club_create_error_name": "Failed creating the club. A club with that name already exists.",