Skip to content

Commit

Permalink
feat 添加手动更新Cookies命令
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed May 22, 2023
1 parent 43bc098 commit 8f13482
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
8 changes: 6 additions & 2 deletions ASFBuffBot/ASFBuffBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public Task OnLoaded()
/// <param name="args"></param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
private static async Task<string?> ResponseCommand(Bot bot, EAccess access, string[] args)
private static async Task<string?> ResponseCommand(Bot bot, EAccess access, string message, string[] args)
{
string cmd = args[0].ToUpperInvariant();

Expand Down Expand Up @@ -270,6 +270,10 @@ public Task OnLoaded()
case "BS" when access >= EAccess.Master:
return await Core.Command.ResponseBotStatus(Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);

case "UPDATECOOKIESBOT" when argLength >= 3 && access >= EAccess.Master:
case "UCB" when argLength >= 3 && access >= EAccess.Master:
return await Core.Command.ResponseUpdateCoolies(args[1], Utilities.GetArgsAsText(message, 2)).ConfigureAwait(false);

default:
return null;
}
Expand All @@ -296,7 +300,7 @@ public Task OnLoaded()

try
{
return await ResponseCommand(bot, access, args).ConfigureAwait(false);
return await ResponseCommand(bot, access, message,args).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down
26 changes: 26 additions & 0 deletions ASFBuffBot/Core/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,30 @@ internal static async Task<string> ResponseBotStatus(Bot bot)

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

/// <summary>
/// 命令更新Cookies
/// </summary>
/// <param name="cookies"></param>
/// <returns></returns>
internal static async Task<string?> ResponseUpdateCoolies(string botName, string cookies)
{
var bot = Bot.GetBot(botName);
if (bot == null)
{
return Utils.FormatStaticResponse(string.Format(Strings.BotNotFound, botName));
}

bot.ArchiWebHandler.WebBrowser.CookieContainer.SetCookies(new Uri("https://buff.163.com"), cookies);

var valid = await WebRequest.CheckCookiesValid(bot).ConfigureAwait(false);
if (valid)
{
return bot.FormatBotResponse(Langs.BuffCookiesValid);
}
else
{
return bot.FormatBotResponse(Langs.BuffCookiesInvalid);
}
}
}
2 changes: 1 addition & 1 deletion ASFBuffBot/Localization/Langs.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ASFBuffBot/Localization/Langs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
<value>未找到匹配的交易报价, 可能交易报价已取消, Id: {0}</value>
</data>
<data name="BuffCookiesValid" xml:space="preserve">
<value>Cookies有效, Cookies信息保存{0}</value>
<value>Cookies有效</value>
</data>
<data name="BuffCookiesInvalid" xml:space="preserve">
<value>Cookies无效, 请检查Buff是否登录以及Cookies是否完整</value>
Expand Down
2 changes: 1 addition & 1 deletion ASFBuffBot/Localization/Langs.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
<value>Cookies无效, 请检查Buff是否登录以及Cookies是否完整</value>
</data>
<data name="BuffCookiesValid" xml:space="preserve">
<value>Cookies有效, Cookies信息保存{0}</value>
<value>Cookies有效</value>
</data>
<data name="BuffDeliverCount" xml:space="preserve">
<value>检测到共有 {0} 个Csgo订单, {1} 个Dota2订单等待发货</value>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>1.0.6.0</Version>
<Version>1.0.7.0</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 8f13482

Please sign in to comment.