|
1 | 1 | using System.Diagnostics.CodeAnalysis; |
2 | 2 | using CommandLine; |
3 | 3 | using Refresh.Database; |
| 4 | +using Refresh.Database.Models.Assets; |
4 | 5 | using Refresh.Database.Models.Users; |
5 | 6 | using Refresh.Interfaces.APIv3.Documentation; |
6 | 7 |
|
@@ -71,6 +72,22 @@ private class Options |
71 | 72 |
|
72 | 73 | [Option("reallow-email-domain", HelpText = "Re-allow the email domain to be used by anyone. Email option is required if this is set. If a whole Email address is given, only the substring after the last @ will be used.")] |
73 | 74 | public bool ReallowEmailDomain { get; set; } |
| 75 | + |
| 76 | + [Option("disallow-asset", HelpText = "Disallow an asset by hash. While this won't delete the asset, it will prevent it from being uploaded in the future, and do other actions, such as instructing the game to censor this asset. " |
| 77 | + + "Asset option is required if this is set, and both the Type and Reason options are optional.")] |
| 78 | + public bool DisallowAsset { get; set; } |
| 79 | + |
| 80 | + [Option("reallow-asset", HelpText = "Re-allow an asset by hash. It may be uploaded and used in various UGC again. Asset option is required if this is set.")] |
| 81 | + public bool ReallowAsset { get; set; } |
| 82 | + |
| 83 | + [Option("asset", HelpText = "The hash of the asset to operate on.")] |
| 84 | + public string? AssetHash { get; set; } |
| 85 | + |
| 86 | + [Option("type", HelpText = "The type of the asset to use. If this isn't set, we will use the corrensponding GameAsset's type from DB instead, if it exists.")] |
| 87 | + public string? AssetType { get; set; } |
| 88 | + |
| 89 | + [Option("reason", HelpText = "The (usually optional) reason for a moderation action, such as asset disallowance.")] |
| 90 | + public string? Reason { get; set; } |
74 | 91 |
|
75 | 92 | [Option("rename-user", HelpText = "Changes a user's username. (old) username or Email option is required if this is set.")] |
76 | 93 | public string? RenameUser { get; set; } |
@@ -236,6 +253,39 @@ private void StartWithOptions(Options options) |
236 | 253 | } |
237 | 254 | else Fail("No email domain was provided"); |
238 | 255 | } |
| 256 | + else if (options.DisallowAsset) |
| 257 | + { |
| 258 | + if (options.AssetHash != null) |
| 259 | + { |
| 260 | + GameAssetType? type = null; |
| 261 | + if (options.AssetType != null) |
| 262 | + { |
| 263 | + bool parsed = Enum.TryParse(options.AssetType, true, out GameAssetType assetType); |
| 264 | + if (!parsed) |
| 265 | + { |
| 266 | + Fail($"The asset type '{options.AssetType}' couldn't be parsed. Possible values: " |
| 267 | + + string.Join(", ", Enum.GetNames(typeof(GameAssetType)))); |
| 268 | + |
| 269 | + return; |
| 270 | + } |
| 271 | + |
| 272 | + type = assetType; |
| 273 | + } |
| 274 | + |
| 275 | + if (!this._server.DisallowAsset(options.AssetHash, type, options.Reason)) |
| 276 | + Fail("Asset is already disallowed"); |
| 277 | + } |
| 278 | + else Fail("No asset hash was provided"); |
| 279 | + } |
| 280 | + else if (options.ReallowAsset) |
| 281 | + { |
| 282 | + if (options.AssetHash != null) |
| 283 | + { |
| 284 | + if (!this._server.ReallowAsset(options.AssetHash)) |
| 285 | + Fail("Asset is already allowed"); |
| 286 | + } |
| 287 | + else Fail("No asset hash was provided"); |
| 288 | + } |
239 | 289 | else if (options.RenameUser != null) |
240 | 290 | { |
241 | 291 | if(string.IsNullOrWhiteSpace(options.RenameUser)) |
|
0 commit comments