Compare commits

..

No commits in common. "f318ec274181b43fecda120c7825914ccf623ef9" and "ca64765c34c367785de8ef0b45b6b7460516660e" have entirely different histories.

11 changed files with 95 additions and 299 deletions

View file

@ -1,46 +0,0 @@
echo ""
echo "███████╗██╗ ██╗ ██╗███████╗██████╗ ██████╗ ████████╗"
echo "██╔════╝██║ ██║ ██║██╔════╝██╔══██╗██╔═══██╗╚══██╔══╝"
echo "█████╗ ██║ ██║ ██║█████╗ ██████╔╝██║ ██║ ██║ "
echo "██╔══╝ ██║ ██║ ██║██╔══╝ ██╔══██╗██║ ██║ ██║ "
echo "███████╗███████╗███████╗██║███████╗██████╔╝╚██████╔╝ ██║ "
echo "╚══════╝╚══════╝╚══════╝╚═╝╚══════╝╚═════╝ ╚═════╝ ╚═╝ "
echo ""
echo "Copyright © 2024 Toastie_t0ast & EllieBotDevs"
echo ""
echo ""
echo "Publishing EllieBot"
echo ""
echo ""
dotnet publish -c Release -r linux-x64 --self-contained -o elliebot-linux-x64 src/EllieBot/EllieBot.csproj
echo ""
dotnet publish -c Release -r linux-arm64 --self-contained -o elliebot-linux-arm64 src/EllieBot/EllieBot.csproj
echo ""
dotnet publish -c Release -r win-x64 --self-contained -o elliebot-windows-x64 src/EllieBot/EllieBot.csproj
echo ""
dotnet publish -c Release -r win-arm64 --self-contained -o elliebot-windows-arm64 src/EllieBot/EllieBot.csproj
echo ""
dotnet publish -c Release -r osx-x64 --self-contained -o elliebot-osx-x64 src/EllieBot/EllieBot.csproj
echo ""
dotnet publish -c Release -r osx-arm64 --self-contained -o elliebot-osx-arm64 src/EllieBot/EllieBot.csproj
echo ""
echo "Preparing the Windows installer build."
echo ""
dotnet clean
dotnet restore -f --no-cache -v n
dotnet publish -c Release --self-contained --runtime win-x64 /p:Version=5.1.3 src/EllieBot
echo ""
echo ""
echo "Finished the initial build script"
echo ""
echo "To build the Windows installer please install Inno Setup from"
echo "https://jrsoftware.org/isdl.php"
echo "And compile the exe_builder.iss"
echo ""
echo "If you are running on Windows please run the wsl command"
echo "then run build.sh"

View file

@ -1,18 +0,0 @@
echo ""
echo "Compressing build files"
echo ""
tar cvf 5.1.3-linux-x64-build.tar elliebot-linux-x64/*
tar cvf 5.1.3-linux-arm64-build.tar elliebot-linux-arm64/*
tar cvf 5.1.3-osx-x64-build.tar elliebot-osx-x64/*
tar cvf 5.1.3-osx-arm64-build.tar elliebot-osx-arm64/*
zip -r 5.1.3-windows-x64-build.zip elliebot-windows-x64/*
zip -r 5.1.3-windows-arm64-build.zip elliebot-windows-arm64/*
echo ""
echo "Moving the installer file you would have generated"
echo "if you followed the instructions in the bottom of the build.ps1 file"
echo "to the directory this script in run in."
echo ""
#mv ellie-installers/5.1.3/ellie-setup-5.1.3.exe ellie-setup-5.1.3.exe

View file

@ -181,9 +181,9 @@ dotnet_naming_rule.private_readonly_field.symbols = private_readonly_field
dotnet_naming_rule.private_readonly_field.style = begins_with_underscore dotnet_naming_rule.private_readonly_field.style = begins_with_underscore
dotnet_naming_rule.private_readonly_field.severity = warning dotnet_naming_rule.private_readonly_field.severity = warning
# dotnet_naming_rule.private_field.symbols = private_field dotnet_naming_rule.private_field.symbols = private_field
# dotnet_naming_rule.private_field.style = camel_case dotnet_naming_rule.private_field.style = camel_case
# dotnet_naming_rule.private_field.severity = warning dotnet_naming_rule.private_field.severity = warning
dotnet_naming_rule.const_fields.symbols = const_fields dotnet_naming_rule.const_fields.symbols = const_fields
dotnet_naming_rule.const_fields.style = all_upper dotnet_naming_rule.const_fields.style = all_upper

View file

@ -18,7 +18,7 @@ public partial class Searches
} }
[Cmd] [Cmd]
public async Task Stock([Leftover] string query) public async Task Stock([Leftover]string query)
{ {
using var typing = ctx.Channel.EnterTypingState(); using var typing = ctx.Channel.EnterTypingState();
@ -105,7 +105,10 @@ public partial class Searches
await message.ModifyAsync(mp => await message.ModifyAsync(mp =>
{ {
mp.Attachments = mp.Attachments =
new(new[] { attachment }); new(new[]
{
attachment
});
mp.Embed = eb.WithImageUrl($"attachment://{fileName}").Build(); mp.Embed = eb.WithImageUrl($"attachment://{fileName}").Build();
}); });
@ -162,8 +165,7 @@ public partial class Searches
.WithAuthor($"#{crypto.CmcRank}") .WithAuthor($"#{crypto.CmcRank}")
.WithTitle($"{crypto.Name} ({crypto.Symbol})") .WithTitle($"{crypto.Name} ({crypto.Symbol})")
.WithUrl($"https://coinmarketcap.com/currencies/{crypto.Slug}/") .WithUrl($"https://coinmarketcap.com/currencies/{crypto.Slug}/")
.WithThumbnailUrl( .WithThumbnailUrl($"https://s3.coinmarketcap.com/static/img/coins/128x128/{crypto.Id}.png")
$"https://s3.coinmarketcap.com/static/img/coins/128x128/{crypto.Id}.png")
.AddField(GetText(strs.market_cap), marketCap, true) .AddField(GetText(strs.market_cap), marketCap, true)
.AddField(GetText(strs.price), price, true) .AddField(GetText(strs.price), price, true)
.AddField(GetText(strs.volume_24h), volume, true) .AddField(GetText(strs.volume_24h), volume, true)
@ -190,54 +192,5 @@ public partial class Searches
await ctx.Channel.SendFileAsync(sparkline, fileName, embed: toSend.Build()); await ctx.Channel.SendFileAsync(sparkline, fileName, embed: toSend.Build());
} }
[Cmd]
public async Task Coins(int page = 1)
{
if (--page < 0)
return;
if (page > 25)
page = 25;
await Response()
.Paginated()
.PageItems(async (page) =>
{
var coins = await _service.GetTopCoins(page);
return coins;
})
.PageSize(10)
.Page((items, _) =>
{
var embed = _sender.CreateEmbed()
.WithOkColor();
if (items.Count > 0)
{
foreach (var coin in items)
{
embed.AddField($"#{coin.MarketCapRank} {coin.Symbol} - {coin.Name}",
$"""
`Price:` {GetArrowEmoji(coin.PercentChange24h)} {coin.CurrentPrice.ToShortString()}$ ({GetSign(coin.PercentChange24h)}{Math.Round(coin.PercentChange24h, 2)}%)
`MarketCap:` {coin.MarketCap.ToShortString()}$
`Supply:` {(coin.CirculatingSupply?.ToShortString() ?? "?")} / {(coin.TotalSupply?.ToShortString() ?? "?")}
""",
inline: false);
}
}
return embed;
})
.CurrentPage(page)
.AddFooter(false)
.SendAsync();
}
private static string GetArrowEmoji(decimal value)
=> value > 0 ? "▲" : "▼";
private static string GetSign(decimal value)
=> value >= 0 ? "+" : "-";
} }
} }

View file

@ -4,10 +4,8 @@ using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing; using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using System.Collections.ObjectModel;
using System.Globalization; using System.Globalization;
using System.Net.Http.Json; using System.Net.Http.Json;
using System.Text.Json.Serialization;
using System.Xml; using System.Xml;
using Color = SixLabors.ImageSharp.Color; using Color = SixLabors.ImageSharp.Color;
using StringExtensions = EllieBot.Extensions.StringExtensions; using StringExtensions = EllieBot.Extensions.StringExtensions;
@ -214,55 +212,4 @@ public class CryptoService : IEService
var points = GetSparklinePointsFromSvgText(str); var points = GetSparklinePointsFromSvgText(str);
return points; return points;
} }
private static TypedKey<IReadOnlyCollection<GeckoCoinsResult>> GetTopCoinsKey()
=> new($"crypto:top_coins");
public async Task<IReadOnlyCollection<GeckoCoinsResult>?> GetTopCoins(int page)
{
if (page >= 25)
page = 24;
using var http = _httpFactory.CreateClient();
http.AddFakeHeaders();
var result = await _cache.GetOrAddAsync<IReadOnlyCollection<GeckoCoinsResult>>(GetTopCoinsKey(),
async () => await http.GetFromJsonAsync<List<GeckoCoinsResult>>(
"https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=250")
?? [],
expiry: TimeSpan.FromHours(1));
return result!.Skip(page * 10).Take(10).ToList();
}
}
public sealed class GeckoCoinsResult
{
[JsonPropertyName("id")]
public required string Id { get; init; }
[JsonPropertyName("name")]
public required string Name { get; init; }
[JsonPropertyName("symbol")]
public required string Symbol { get; init; }
[JsonPropertyName("current_price")]
public required decimal CurrentPrice { get; init; }
[JsonPropertyName("price_change_percentage_24h")]
public required decimal PercentChange24h { get; init; }
[JsonPropertyName("market_cap")]
public required decimal MarketCap { get; init; }
[JsonPropertyName("circulating_supply")]
public required decimal? CirculatingSupply { get; init; }
[JsonPropertyName("total_supply")]
public required decimal? TotalSupply { get; init; }
[JsonPropertyName("market_cap_rank")]
public required int MarketCapRank { get; init; }
} }

View file

@ -123,8 +123,6 @@ public partial class Xp
}) })
.ToList(); .ToList();
var rank = await _service.GetClubRankAsync(club.Id);
await Response() await Response()
.Paginated() .Paginated()
.Items(allUsers) .Items(allUsers)
@ -137,7 +135,6 @@ public partial class Xp
.WithDescription(GetText(strs.level_x(lvl.Level + $" ({club.Xp} xp)"))) .WithDescription(GetText(strs.level_x(lvl.Level + $" ({club.Xp} xp)")))
.AddField(GetText(strs.desc), .AddField(GetText(strs.desc),
string.IsNullOrWhiteSpace(club.Description) ? "-" : club.Description) string.IsNullOrWhiteSpace(club.Description) ? "-" : club.Description)
.AddField(GetText(strs.rank), $"#{rank}", true)
.AddField(GetText(strs.owner), club.Owner.ToString(), true) .AddField(GetText(strs.owner), club.Owner.ToString(), true)
// .AddField(GetText(strs.level_req), club.MinimumLevelReq.ToString(), true) // .AddField(GetText(strs.level_req), club.MinimumLevelReq.ToString(), true)
.AddField(GetText(strs.members), .AddField(GetText(strs.members),

View file

@ -85,7 +85,7 @@ public class ClubService : IEService, IClubService
if (club is null) if (club is null)
return ToggleAdminResult.NotOwner; return ToggleAdminResult.NotOwner;
if (!club.Members.Contains(adminUser)) if(!club.Members.Contains(adminUser))
return ToggleAdminResult.TargetNotMember; return ToggleAdminResult.TargetNotMember;
var newState = adminUser.IsClubAdmin = !adminUser.IsClubAdmin; var newState = adminUser.IsClubAdmin = !adminUser.IsClubAdmin;
@ -134,18 +134,6 @@ public class ClubService : IEService, IClubService
return club is not null; return club is not null;
} }
public async Task<int> GetClubRankAsync(int clubId)
{
await using var uow = _db.GetDbContext();
var rank = await uow.Clubs
.ToLinqToDBTable()
.Where(x => x.Xp > (uow.Clubs.First(c => c.Id == clubId).Xp))
.CountAsyncLinqToDB();
return rank + 1;
}
public ClubApplyResult ApplyToClub(IUser user, ClubInfo club) public ClubApplyResult ApplyToClub(IUser user, ClubInfo club)
{ {
using var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();

View file

@ -6,7 +6,7 @@ namespace EllieBot.Modules.Xp.Services;
public interface IClubService public interface IClubService
{ {
Task<ClubCreateResult> CreateClubAsync(IUser user, string clubName); Task<ClubCreateResult> CreateClubAsync(IUser user, string clubName);
OneOf<ClubInfo, ClubTransferError> TransferClub(IUser from, IUser newOwner); OneOf<ClubInfo,ClubTransferError> TransferClub(IUser from, IUser newOwner);
Task<ToggleAdminResult> ToggleAdminAsync(IUser owner, IUser toAdmin); Task<ToggleAdminResult> ToggleAdminAsync(IUser owner, IUser toAdmin);
ClubInfo? GetClubByMember(IUser user); ClubInfo? GetClubByMember(IUser user);
Task<SetClubIconResult> SetClubIconAsync(ulong ownerUserId, string? url); Task<SetClubIconResult> SetClubIconAsync(ulong ownerUserId, string? url);
@ -23,7 +23,6 @@ public interface IClubService
ClubKickResult Kick(ulong kickerId, string userName, out ClubInfo club); ClubKickResult Kick(ulong kickerId, string userName, out ClubInfo club);
List<ClubInfo> GetClubLeaderboardPage(int page); List<ClubInfo> GetClubLeaderboardPage(int page);
Task<ClubRenameResult> RenameClubAsync(ulong userId, string clubName); Task<ClubRenameResult> RenameClubAsync(ulong userId, string clubName);
Task<int> GetClubRankAsync(int clubId);
} }
public enum ClubApplyResult public enum ClubApplyResult

View file

@ -147,5 +147,4 @@ public static class StringExtensions
var newString = str.UnescapeUnicodeCodePoint(); var newString = str.UnescapeUnicodeCodePoint();
return newString; return newString;
}); });
} }

View file

@ -1,30 +1,7 @@
using System.Globalization;
namespace EllieBot.Extensions; namespace EllieBot.Extensions;
public static class NumberExtensions public static class NumberExtensions
{ {
public static DateTimeOffset ToUnixTimestamp(this double number) public static DateTimeOffset ToUnixTimestamp(this double number)
=> new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).AddSeconds(number); => new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).AddSeconds(number);
public static string ToShortString(this decimal value)
{
if (value <= 1_000)
return Math.Round(value, 2).ToString(CultureInfo.InvariantCulture);
if (value <= 1_000_000)
return Math.Round(value, 1).ToString(CultureInfo.InvariantCulture);
var tokens = " MBtq";
var i = 2;
while (true)
{
var num = (decimal)Math.Pow(1000, i);
if (num > value)
{
var num2 = (decimal)Math.Pow(1000, i - 1);
return $"{Math.Round((value / num2), 1)}{tokens[i - 1]}".Trim();
}
i++;
}
}
} }