Skip to content

Commit

Permalink
feat 新增 MYBAN 命令
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Nov 25, 2024
1 parent cd3092b commit f43ace4
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 86 deletions.
8 changes: 7 additions & 1 deletion ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ public Task OnLoaded()

"REGISTEDATE" when access >= EAccess.Operator =>
Account.Command.ResponseGetRegisteDate(bot),


"MYBAN" when access >= EAccess.Operator =>
Account.Command.ResponseGetMyBans(bot),

//Cart
"CART" or
"C" when access >= EAccess.Operator =>
Expand Down Expand Up @@ -624,6 +627,9 @@ public Task OnLoaded()
"RL" when access >= EAccess.Master =>
Account.Command.ResponseRemoveFreeLicenses(bot, args[1]),

"MYBAN" when access >= EAccess.Operator =>
Account.Command.ResponseGetMyBans(Utilities.GetArgsAsText(args, 1, ",")),

//Cart
"CART" or
"C" when access >= EAccess.Operator =>
Expand Down
50 changes: 50 additions & 0 deletions ASFEnhance/Account/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,56 @@ async Task workThread(uint subId)

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

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

/// <summary>
/// 移除免费许可证
/// </summary>
/// <param name="bot"></param>
/// <param name="query"></param>
/// <returns></returns>
internal static async Task<string?> ResponseGetMyBans(Bot bot)
{
if (!bot.IsConnectedAndLoggedOn)
{
return bot.FormatBotResponse(Strings.BotNotConnected);
}

var sb = new StringBuilder();
sb.AppendLine(bot.FormatBotResponse(Langs.MultipleLineResult));

var response = await WebRequest.GetMyBans(bot).ConfigureAwait(false);
sb.AppendLine(response);

return sb.ToString();
}

/// <summary>
/// 移除免费许可证 (多个Bot)
/// </summary>
/// <param name="botNames"></param>
/// <param name="query"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
internal static async Task<string?> ResponseGetMyBans(string botNames)
{
if (string.IsNullOrEmpty(botNames))
{
throw new ArgumentNullException(nameof(botNames));
}

var bots = Bot.GetBots(botNames);

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

var results = await Utilities.InParallel(bots.Select(ResponseGetMyBans)).ConfigureAwait(false);

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

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

0 comments on commit f43ace4

Please sign in to comment.