Skip to content

Commit

Permalink
移除节日相关代码
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Jun 20, 2022
1 parent c243a15 commit 397df3a
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 463 deletions.
29 changes: 5 additions & 24 deletions ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,6 @@ public Task OnLoaded()
switch (args[0].ToUpperInvariant())
{
//Event
case "EVENT" when access >= EAccess.Operator:
case "E" when access >= EAccess.Operator:
return await Event.Command.ResponseEvent(bot).ConfigureAwait(false);
case "EVENTENDLESS" when access >= EAccess.Operator:
case "EE" when access >= EAccess.Operator:
return await Event.Command.ResponseEventEndless(bot).ConfigureAwait(false);
case "EVENTSTATUS" when access >= EAccess.Operator:
case "ES" when access >= EAccess.Operator:
return await Event.Command.ResponseEventStatus(bot).ConfigureAwait(false);
case "FAILEDDEMOS":
case "FAILEDDEMO":
return await Event.Command.ResponseFailedDemos(bot).ConfigureAwait(false);

//Shortcut
case "P":
Expand Down Expand Up @@ -182,6 +170,11 @@ public Task OnLoaded()
case "PC" when access >= EAccess.Master:
return await Cart.Command.ResponsePurchaseSelf(bot).ConfigureAwait(false);

//Explorer
case "EXPLORER" when access >= EAccess.Master:
case "EX" when access >= EAccess.Master:
return await Explorer.Command.ResponseExploreDiscoveryQueue(bot).ConfigureAwait(false);

//Group
case "GROUPLIST" when access >= EAccess.FamilySharing:
case "GL" when access >= EAccess.FamilySharing:
Expand Down Expand Up @@ -237,18 +230,6 @@ public Task OnLoaded()
switch (args[0].ToUpperInvariant())
{
//Event
case "EVENT" when access >= EAccess.Operator:
case "E" when access >= EAccess.Operator:
return await Event.Command.ResponseEvent(Utilities.GetArgsAsText(message, 1)).ConfigureAwait(false);
case "EVENTENDLESS" when access >= EAccess.Operator:
case "EE" when access >= EAccess.Operator:
return await Event.Command.ResponseEventEndless(Utilities.GetArgsAsText(message, 1)).ConfigureAwait(false);
case "EVENTSTATUS" when access >= EAccess.Operator:
case "ES" when access >= EAccess.Operator:
return await Event.Command.ResponseEventStatus(Utilities.GetArgsAsText(message, 1)).ConfigureAwait(false);
case "FAILEDDEMOS":
case "FAILEDDEMO":
return await Event.Command.ResponseFailedDemos(Utilities.GetArgsAsText(message, 1)).ConfigureAwait(false);

//Shortcut
case "AL":
Expand Down
4 changes: 2 additions & 2 deletions ASFEnhance/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reflection;

[assembly: System.CLSCompliant(false)]
[assembly: AssemblyVersion("1.6.5.546")]
[assembly: AssemblyFileVersion("1.6.5.546")]
[assembly: AssemblyVersion("1.6.5.577")]
[assembly: AssemblyFileVersion("1.6.5.577")]

[assembly: AssemblyCopyright("Copyright © 2022 Chr_")]
[assembly: AssemblyProduct("ASFEnhance")]
Expand Down
307 changes: 0 additions & 307 deletions ASFEnhance/Event/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,313 +12,6 @@ namespace ASFEnhance.Event
{
internal static class Command
{
internal static async Task<string?> ResponseEvent(Bot bot)
{
if (!bot.IsConnectedAndLoggedOn)
{
return bot.FormatBotResponse(Strings.BotNotConnected);
}

bool Paused = bot.CardsFarmer.Paused;

if (!Paused)
{
await bot.Commands.Response(EAccess.Master, $"PAUSE {bot.BotName}").ConfigureAwait(false);
}

List<uint> demos = new() { 1431000, 1805630, 1937760, 1923740, 1993130, 1490520, 2015730, 1991740, 2012980, 1402220 };
string demoStr = string.Join(',', demos.Select(x => $"app/{x}"));
string demoStr2 = string.Join(',', demos);

await bot.Commands.Response(EAccess.Master, $"ADDLICENSE {bot.BotName} {demoStr}").ConfigureAwait(false);
await bot.Commands.Response(EAccess.Master, $"PLAY {bot.BotName} {demoStr2}").ConfigureAwait(false);

if (!Paused)
{
await bot.Commands.Response(EAccess.Master, $"RESUME {bot.BotName}").ConfigureAwait(false);
}

return bot.FormatBotResponse("Done!");
}

internal static async Task<string?> ResponseEvent(string botNames)
{
if (string.IsNullOrEmpty(botNames))
{
throw new ArgumentNullException(nameof(botNames));
}

HashSet<Bot>? bots = Bot.GetBots(botNames);

if ((bots == null) || (bots.Count == 0))
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
}

IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseEvent(bot))).ConfigureAwait(false);

List<string> responses = new(results.Where(result => !string.IsNullOrEmpty(result))!);

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}

private static ConcurrentDictionary<string, HashSet<uint>> FailedDemos = new();
private static ConcurrentDictionary<string, HashSet<uint>> AddedDemos = new();
private static ConcurrentDictionary<string, string> Status = new();
private static ConcurrentDictionary<string, DateTime> NextTime = new();

internal static Task<string?> ResponseEventEndless(Bot bot)
{
if (!bot.IsConnectedAndLoggedOn)
{
return Task.FromResult(bot.FormatBotResponse(Strings.BotNotConnected));
}

_ = Task.Run(async () => {
string ownStr = bot.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.BotOwnedAlready, "")[..^1]);

bool Paused = bot.CardsFarmer.Paused;

string botName = bot.BotName;

try
{
List<uint> demos = new();

HashSet<uint> failedDemos = new();
HashSet<uint> addedDemos = new();

FailedDemos[botName] = failedDemos;
AddedDemos[botName] = addedDemos;
NextTime[botName] = DateTime.Now;

int index = 0;
while (index < DemosDB.Demos.Count)
{
Status[botName] = "Running";

demos.Clear();

int error = 5;
while (!bot.IsConnectedAndLoggedOn)
{
await Task.Delay(10000).ConfigureAwait(false);
if (error-- == 0)
{
return;
}
}

int count = 0;
while (count < 45 && index < DemosDB.Demos.Count)
{
if (!Paused)
{
await bot.Commands.Response(EAccess.Master, $"PAUSE {botName}").ConfigureAwait(false);
}

uint appid = DemosDB.Demos[index++];

//获取Appdetail
int tries = 5;
Data.AppDetailData? data = null;

while (tries-- > 0)
{
var detail = await Store.WebRequest.GetAppDetails(bot, appid).ConfigureAwait(false);
if (detail.Success)
{
data = detail.Data;
break;
}
}

if (data == null || data.Demos == null || data.Demos?.Count == 0)
{
failedDemos.Add(appid);
continue;
}

appid = data.Demos.First().AppID;

//检查是否已拥有
string result = await bot.Commands.Response(EAccess.Owner, $"OWNS {botName} {appid}").ConfigureAwait(false) ?? "";
bool owned = result.Contains(ownStr);
ASFLogger.LogGenericInfo(result);


if (!owned)
{
count++;
string r1 = await bot.Commands.Response(EAccess.Owner, $"ADDLICENSE {botName} app/{appid}").ConfigureAwait(false);
ASFLogger.LogGenericInfo(r1);
await Task.Delay(1000).ConfigureAwait(false);
result = await bot.Commands.Response(EAccess.Owner, $"OWNS {botName} {appid}").ConfigureAwait(false) ?? "";
ASFLogger.LogGenericInfo(result);
owned = result.Contains(ownStr);
}

if (!owned)
{
failedDemos.Add(appid);
}

demos.Add(appid);

//游玩Demo
if (demos.Count >= 20)
{
string arg = string.Join(',', demos);
await bot.Commands.Response(EAccess.Owner, $"PLAY {botName} {arg}").ConfigureAwait(false);
await Task.Delay(5000).ConfigureAwait(false);

foreach (var i in demos)
{
addedDemos.Add(i);
}

if (!Paused)
{
await bot.Commands.Response(EAccess.Master, $"RESUME {botName}").ConfigureAwait(false);
}

demos.Clear();
}
}

Status[botName] = "Running[Waiting]";
NextTime[botName] = DateTime.Now + TimeSpan.FromMinutes(65);
await Task.Delay(TimeSpan.FromMinutes(65)).ConfigureAwait(false);
}

if (demos.Count > 0)
{
string arg = string.Join(',', demos);
await bot.Commands.Response(EAccess.Owner, $"PLAY {botName} {arg}").ConfigureAwait(false);
await Task.Delay(5000).ConfigureAwait(false);

foreach (var i in demos)
{
addedDemos.Add(i);
}

if (!Paused)
{
await bot.Commands.Response(EAccess.Master, $"RESUME {botName}").ConfigureAwait(false);
}
}
}
finally
{
Status[botName] = "Stopped";
}
});

return Task.FromResult(bot.FormatBotResponse("Task will running in background"));
}

internal static async Task<string?> ResponseEventEndless(string botNames)
{
if (string.IsNullOrEmpty(botNames))
{
throw new ArgumentNullException(nameof(botNames));
}

HashSet<Bot>? bots = Bot.GetBots(botNames);

if ((bots == null) || (bots.Count == 0))
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
}

IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseEventEndless(bot))).ConfigureAwait(false);

List<string> responses = new(results.Where(result => !string.IsNullOrEmpty(result))!);

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}

internal static Task<string?> ResponseEventStatus(Bot bot)
{
string botName = bot.BotName;

if (!FailedDemos.ContainsKey(botName))
{
return Task.FromResult(bot.FormatBotResponse("No record"));
}

var failedDemos = FailedDemos[botName];
var addedDemos = AddedDemos[botName];
var status = Status[botName];
var runTime = NextTime[botName];

StringBuilder sb = new();
sb.AppendLine(bot.FormatBotResponse(Langs.MultipleLineResult));
sb.AppendLine(string.Format("Task Status: {0}", status));
sb.AppendLine(string.Format("Task Will Run At: {0}", runTime));
sb.AppendLine(string.Format("Added Demos Count: {0}", addedDemos.Count));
sb.AppendLine(string.Format("Failed Demos Count: {0}", failedDemos.Count));
sb.AppendLine(string.Format("Total Demos Count: {0}", DemosDB.Demos.Count));

return Task.FromResult(sb.ToString());
}

internal static async Task<string?> ResponseEventStatus(string botNames)
{
if (string.IsNullOrEmpty(botNames))
{
throw new ArgumentNullException(nameof(botNames));
}

HashSet<Bot>? bots = Bot.GetBots(botNames);

if ((bots == null) || (bots.Count == 0))
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
}

IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseEventStatus(bot))).ConfigureAwait(false);

List<string> responses = new(results.Where(result => !string.IsNullOrEmpty(result))!);

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}

internal static Task<string?> ResponseFailedDemos(Bot bot)
{
string botName = bot.BotName;

if (!FailedDemos.ContainsKey(botName))
{
return Task.FromResult(bot.FormatBotResponse("No record"));
}

var failedDemos = FailedDemos[botName];

string data = string.Join(',', failedDemos);

return Task.FromResult(data);
}

internal static async Task<string?> ResponseFailedDemos(string botNames)
{
if (string.IsNullOrEmpty(botNames))
{
throw new ArgumentNullException(nameof(botNames));
}

HashSet<Bot>? bots = Bot.GetBots(botNames);

if ((bots == null) || (bots.Count == 0))
{
return FormatStaticResponse(string.Format(Strings.BotNotFound, botNames));
}

IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseFailedDemos(bot))).ConfigureAwait(false);

List<string> responses = new(results.Where(result => !string.IsNullOrEmpty(result))!);

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}
}
}
13 changes: 0 additions & 13 deletions ASFEnhance/Event/DemoAppResponse.cs

This file was deleted.

Loading

0 comments on commit 397df3a

Please sign in to comment.