Skip to content

Commit

Permalink
switch to organization
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudokhvist committed Sep 16, 2024
1 parent 6d4cb60 commit 1ecb859
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 60 deletions.
2 changes: 1 addition & 1 deletion ArchiSteamFarm
Submodule ArchiSteamFarm updated 446 files
18 changes: 0 additions & 18 deletions CommandlessRedeem/CommandAliasPlugin.csproj

This file was deleted.

90 changes: 72 additions & 18 deletions CommandlessRedeem/CommandlessRedeem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,87 @@
using System.Threading.Tasks;
using ArchiSteamFarm.Core;
using ArchiSteamFarm.Steam;
using ArchiSteamFarm.Localization;
using ArchiSteamFarm.Plugins.Interfaces;
using ArchiSteamFarm.Web.GitHub.Data;
using ArchiSteamFarm.Web.GitHub;
using System.Globalization;

namespace CommandlessRedeem {
[Export(typeof(IPlugin))]
public sealed class CommandlessRedeem : IBotMessage, IBotCommand2 {
public string Name => nameof(CommandlessRedeem);
public Version Version => typeof(CommandlessRedeem).Assembly.GetName().Version ?? new Version("0");
namespace CommandlessRedeem;
[Export(typeof(IPlugin))]
internal sealed class CommandlessRedeem : IBotMessage, IBotCommand2, IGitHubPluginUpdates {
public string Name => nameof(CommandlessRedeem);
public Version Version => typeof(CommandlessRedeem).Assembly.GetName().Version ?? new Version("0");

public Task OnLoaded() {
ASF.ArchiLogger.LogGenericInfo("Commandless Redeem Plugin by Rudokhvist, powered by ginger cats");
return Task.CompletedTask;
public string RepositoryName => "CatPoweredPlugins/CommandlessRedeem";

public async Task<Uri?> GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, bool stable, bool forced) {
ArgumentNullException.ThrowIfNull(asfVersion);
ArgumentException.ThrowIfNullOrEmpty(asfVariant);

if (string.IsNullOrEmpty(RepositoryName)) {
ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(RepositoryName)));

return null;
}

ReleaseResponse? releaseResponse = await GitHubService.GetLatestRelease(RepositoryName, stable).ConfigureAwait(false);

if (releaseResponse == null) {
return null;
}

Version newVersion = new(releaseResponse.Tag);

if (!(Version.Major == newVersion.Major && Version.Minor == newVersion.Minor && Version.Build == newVersion.Build) && !(asfUpdate || forced)) {
ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, "New {0} plugin version {1} is only compatible with latest ASF version", Name, newVersion));
return null;
}


if (Version >= newVersion & !forced) {
ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateNotFound, Name, Version, newVersion));

return null;
}

public Task<string?> OnBotMessage(Bot bot, ulong steamID, string message) => HandleMessageInternal(bot, bot.GetAccess(steamID), message);
if (releaseResponse.Assets.Count == 0) {
ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateNoAssetFound, Name, Version, newVersion));

public static async Task<string?> HandleMessageInternal(Bot bot, EAccess access, string message) {
if (access < EAccess.Operator) {
return null;
}
return null;
}

ReleaseAsset? asset = await ((IGitHubPluginUpdates) this).GetTargetReleaseAsset(asfVersion, asfVariant, newVersion, releaseResponse.Assets).ConfigureAwait(false);

if (!Utilities.IsValidCdKey(message.Split((char[]?) null, StringSplitOptions.RemoveEmptyEntries)[0])) {
return null;
}
if ((asset == null) || !releaseResponse.Assets.Contains(asset)) {
ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateNoAssetFound, Name, Version, newVersion));

return await bot.Commands.Response(access, "r " + bot.BotName + " " + message).ConfigureAwait(false);
return null;
}

public Task<string?> OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) => HandleMessageInternal(bot, access, string.Join(" ", args));
ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateFound, Name, Version, newVersion));

return asset.DownloadURL;
}

public Task OnLoaded() {
ASF.ArchiLogger.LogGenericInfo("Commandless Redeem Plugin by Rudokhvist, powered by ginger cats");
return Task.CompletedTask;
}

public Task<string?> OnBotMessage(Bot bot, ulong steamID, string message) => HandleMessageInternal(bot, bot.GetAccess(steamID), message);

public static async Task<string?> HandleMessageInternal(Bot bot, EAccess access, string message) {
if (access < EAccess.Operator) {
return null;
}

if (!Utilities.IsValidCdKey(message.Split((char[]?) null, StringSplitOptions.RemoveEmptyEntries)[0])) {
return null;
}

return await bot.Commands.Response(access, "r " + bot.BotName + " " + message).ConfigureAwait(false);
}

public Task<string?> OnBotCommand(Bot bot, EAccess access, string message, string[] args, ulong steamID = 0) => HandleMessageInternal(bot, access, string.Join(" ", args));
}
27 changes: 13 additions & 14 deletions CommandlessRedeem/CommandlessRedeem.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>

<PropertyGroup>
<Authors>Rudokhvist</Authors>
<AssemblyVersion>0.5.2.0</AssemblyVersion>
<TargetFrameworks>net7.0;net481</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" PrivateAssets="all" />
<PackageReference Include="System.Composition.AttributedModel" IncludeAssets="compile" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Composition.AttributedModel" Version="*" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ArchiSteamFarm\ArchiSteamFarm\ArchiSteamFarm.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ArchiSteamFarm\ArchiSteamFarm\ArchiSteamFarm.csproj" ExcludeAssets="all" Private="false" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="..\ArchiSteamFarm\ArchiSteamFarm\bin\$(Configuration)\$(TargetFramework)\plugins\" SkipUnchangedFiles="true" />
</Target>
</Project>
20 changes: 11 additions & 9 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ if exist out rmdir /Q /S out

rem release generic version

dotnet publish -c "Release" -f "net7.0" -o "out/generic" "/p:LinkDuringPublish=false"
dotnet publish -c "Release" -f "net8.0" -o "out/generic" "/p:LinkDuringPublish=false"
mkdir .\out\%CurrDirName%
copy .\out\generic\%CurrDirName%.dll .\out\%CurrDirName%
rem comment section below (downto :zip label) if you don't want to include documentation
if not exist README.md (goto zip)
where /q pandoc.exe
if ERRORLEVEL 1 (
copy README.md .\out\%CurrDirName%
goto zip
) else (
pandoc --metadata title="%CurrDirName%" --standalone --columns 2000 -f markdown -t html --self-contained -c .\github-pandoc.css -o .\out\%CurrDirName%\README.html README.md
)
:zip
7z a -tzip -mx7 .\out\%CurrDirName%.zip .\out\%CurrDirName%
rmdir /Q /S out\%CurrDirName%

rem release generic-netf version
rem comment section below if you don't target netf ASF version

dotnet publish -c "Release" -f "net481" -o "out/generic-netf"
mkdir .\out\%CurrDirName%
copy .\out\generic-netf\%CurrDirName%.dll .\out\%CurrDirName%
7z a -tzip -mx7 .\out\%CurrDirName%-netf.zip .\out\%CurrDirName%
rmdir /Q /S out\%CurrDirName%

0 comments on commit 1ecb859

Please sign in to comment.