commit e562a90c35012e0ed134d8455b181cdbc379ae3f Author: exsersewo Date: Tue Nov 30 19:43:02 2021 +0000 init commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..976e2f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,270 @@ +.cr/ + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +Commands/Skuld.Owner/ +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 cache/plugin data directory +.cr/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +#*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc +launchSettings.json + +.env \ No newline at end of file diff --git a/Interfaces/ISkuldAPIClient.cs b/Interfaces/ISkuldAPIClient.cs new file mode 100644 index 0000000..8629903 --- /dev/null +++ b/Interfaces/ISkuldAPIClient.cs @@ -0,0 +1,121 @@ +using RestEase; +using Skuld.Core.Models; +using Skuld.Models; +using System; +using System.IO; +using System.Threading.Tasks; + +namespace Skuld.API +{ + public interface ISkuldAPIClient : IDisposable + { + #region Guild + /// + /// Get a guild + /// + /// Guild Id + /// wrapped + [Get("/guild/{id}")] + public Task GetGuildAsync([Path] ulong id); + #endregion Guild + + #region User + /// + /// Get a user + /// + /// User Id + /// wrapped + [Get("/user/{id}")] + public Task GetUserAsync([Path] ulong id); + #endregion User + + #region Experience + /// + /// Gets the experience leaderboard + /// + /// Guild Id, Accepts 0 for all + /// %10 offset page + /// wrapped + [Get("/experience/{guildId}/{page}")] + public Task GetExperienceLeaderboardAsync([Path] ulong guildId, [Path] int page = 0); + #endregion Experience + + #region Money + /// + /// Gets the money leaderboard + /// + /// Guild Id, Accepts 0 for all + /// %10 offset page + /// wrapped + [Get("/money/{guildId}/{page}")] + public Task GetMoneyLeaderboardAsync([Path] ulong guildId, [Path] int page = 0); + #endregion Money + + #region Profile + /// + /// Get a user's profile card + /// + /// User Id + /// of profile card data + [Get("/image/profile/{id}")] + public Task GetProfileCardAsync([Path] ulong id); + + /// + /// Get a user's profile card with guild attributes + /// + /// User Id + /// Guild Id + /// of profile card data + [Get("/image/profile/{id}/{guildId}")] + public Task GetProfileCardAsync([Path] ulong id, [Path] ulong guildId); + + /// + /// Preview's a custom background image + /// + /// User Id + /// Background to preview + /// of profile card data + [Get("/image/profile/{id}/example")] + public Task GetExampleProfileCardAsync([Path] ulong id, [Query("previewBackground")] string previewBackground); + + #endregion Profile + + #region Rank + + /// + /// Get a user's rank card + /// + /// User Id + /// Guild Id + /// of profile card data + [Get("/image/rank/{id}/{guildId}")] + public Task GetRankCardAsync([Path] ulong id, [Path] ulong guildId); + + #endregion Rank + + #region Leave/Join Card + + /// + /// Get's the join card for a guild + /// + /// User Id + /// Guild Id + /// of join card + [Get("/image/join/{id}/{guildId}")] + public Task GetJoinCardAsync([Path] ulong id, [Path] ulong guildId); + + /// + /// Get's the leave card for a guild + /// + /// User Id + /// Guild Id + /// of leave card + [Get("/image/leave/{id}/{guildId}")] + public Task GetLeaveCardAsync([Path] ulong id, [Path] ulong guildId); + + #endregion Leave/Join Card + + [Get("/image/magik")] + public Task GetLiquidRescaledAsync([Query] string image); + } +} diff --git a/Skuld.API.csproj b/Skuld.API.csproj new file mode 100644 index 0000000..f3b2598 --- /dev/null +++ b/Skuld.API.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + + + + + + + + + + + diff --git a/SkuldAPI.cs b/SkuldAPI.cs new file mode 100644 index 0000000..ffd1ddd --- /dev/null +++ b/SkuldAPI.cs @@ -0,0 +1,176 @@ +using Newtonsoft.Json; +using RestEase; +using Skuld.Core.Models; +using System; +using System.IO; +using System.Net.Http; +using System.Reflection; +using System.Threading.Tasks; + +namespace Skuld.API +{ + public class SkuldAPI : ISkuldAPIClient, IDisposable + { + public static string WrapperVersion { get; } = + typeof(SkuldAPI).GetTypeInfo().Assembly.GetCustomAttribute()?.InformationalVersion ?? + typeof(SkuldAPI).GetTypeInfo().Assembly.GetName().Version.ToString(3) ?? + "Unknown"; + + private readonly ISkuldAPIClient _api; + + static string ApiBase; + static string Token; + private bool disposedValue; + + public SkuldAPI() + { + + } + + public SkuldAPI(string apiBase, string token) + { + ApiBase = apiBase; + Token = token; + + var httpClient = new HttpClient + { + BaseAddress = new Uri(ApiBase) + }; + httpClient.DefaultRequestHeaders.Add("User-Agent", $"Skuld.API.Client/v{WrapperVersion} (https://github.com/skuldbot/Skuld)"); + + if (!string.IsNullOrWhiteSpace(Token)) + { + httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {Token}"); + } + + JsonSerializerSettings settings = new() + { + Formatting = Formatting.Indented, + NullValueHandling = NullValueHandling.Ignore + }; + + _api = new RestClient(httpClient) + { + JsonSerializerSettings = settings + }.For(); + } + + /// + /// Get a guild + /// + /// Guild Id + /// wrapped + public Task GetGuildAsync(ulong id) + => !string.IsNullOrWhiteSpace(Token) ? _api.GetGuildAsync(id) : null; + + /// + /// Get a user + /// + /// User Id + /// wrapped + public Task GetUserAsync(ulong id) + => !string.IsNullOrWhiteSpace(Token) ? _api.GetUserAsync(id) : null; + + /// + /// Get a user's profile card + /// + /// User Id + /// of profile card data + public Task GetProfileCardAsync(ulong id) + => !string.IsNullOrWhiteSpace(Token) ? _api.GetProfileCardAsync(id) : null; + + /// + /// Get a user's profile card with guild attributes + /// + /// User Id + /// Guild Id + /// of profile card data + public Task GetProfileCardAsync(ulong id, ulong guildId) + => !string.IsNullOrWhiteSpace(Token) ? _api.GetProfileCardAsync(id, guildId) : null; + + /// + /// Get a user's rank card + /// + /// User Id + /// Guild Id + /// of profile card data + public Task GetRankCardAsync(ulong id, ulong guildId) + => !string.IsNullOrWhiteSpace(Token) ? _api.GetRankCardAsync(id, guildId) : null; + + /// + /// Preview's a custom background image + /// + /// User Id + /// Background to preview + /// of profile card data + public Task GetExampleProfileCardAsync(ulong id, string previewBackground) + => !string.IsNullOrWhiteSpace(Token) ? _api.GetExampleProfileCardAsync(id, previewBackground) : null; + + /// + /// Gets the experience leaderboard + /// + /// Guild Id, Accepts 0 for all + /// %10 offset page + /// wrapped + public Task GetExperienceLeaderboardAsync(ulong guildId, int page = 0) + => !string.IsNullOrWhiteSpace(Token) ? _api.GetExperienceLeaderboardAsync(guildId, page) : null; + + /// + /// Gets the money leaderboard + /// + /// Guild Id, Accepts 0 for all + /// %10 offset page + /// wrapped + public Task GetMoneyLeaderboardAsync(ulong guildId, int page = 0) + => !string.IsNullOrWhiteSpace(Token) ? _api.GetMoneyLeaderboardAsync(guildId, page) : null; + + public Task GetLiquidRescaledAsync(string image) + => !string.IsNullOrWhiteSpace(Token) ? _api.GetLiquidRescaledAsync(image) : null; + + /// + /// Get's the join card for a guild + /// + /// User Id + /// Guild Id + /// of join card + public Task GetJoinCardAsync(ulong id, ulong guildId) + => !string.IsNullOrWhiteSpace(Token) ? _api.GetJoinCardAsync(id, guildId) : null; + + /// + /// Get's the leave card for a guild + /// + /// User Id + /// Guild Id + /// of leave card + public Task GetLeaveCardAsync(ulong id, ulong guildId) + => !string.IsNullOrWhiteSpace(Token) ? _api.GetLeaveCardAsync(id, guildId) : null; + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects) + } + + // TODO: free unmanaged resources (unmanaged objects) and override finalizer + // TODO: set large fields to null + disposedValue = true; + } + } + + // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources + // ~SkuldAPI() + // { + // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + // Dispose(disposing: false); + // } + public void Dispose() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + } +}