Skip to content

Commit

Permalink
feat(plugins/tgclientplugin/): 增加自动登录
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyungent committed Mar 19, 2023
1 parent d024fa9 commit 292fc77
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plugins/TgClientPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
> 本项目基于 [wiz0u/WTelegramClient: Telegram Client API (MTProto) library written 100% in C# and .NET Standard](https://github.com/wiz0u/WTelegramClient)
<!-- Matomo Image Tracker-->
<img referrerpolicy="no-referrer-when-downgrade" src="https://matomo.moeci.com/matomo.php?idsite=2&amp;rec=1&amp;action_name=Plugins.TgClientPlugin-v0.0.1.README" style="border:0" alt="" />
<img referrerpolicy="no-referrer-when-downgrade" src="https://matomo.moeci.com/matomo.php?idsite=2&amp;rec=1&amp;action_name=Plugins.TgClientPlugin-v0.0.2.README" style="border:0" alt="" />
<!-- End Matomo -->
8 changes: 8 additions & 0 deletions plugins/TgClientPlugin/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@ public class SettingsModel : PluginSettingsModel

public ProxyModel Proxy { get; set; }

public AutoLoginModel AutoLogin { get; set; }

public class ProxyModel
{
public bool ProxyEnabled { get; set; }
public string ProxyHost { get; set; }
public int ProxyPort { get; set; }
}

public class AutoLoginModel
{
public bool Enabled { get; set; }
public string Phone { get; set; }
}
}
}
31 changes: 30 additions & 1 deletion plugins/TgClientPlugin/TgClientPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace TgClientPlugin
{
public class TgClientPlugin : BasePlugin
public class TgClientPlugin : BasePlugin, ITimeJobPlugin
{
public override (bool IsSuccess, string Message) AfterEnable()
{
Expand All @@ -24,5 +24,34 @@ public override (bool IsSuccess, string Message) BeforeDisable()
return base.BeforeDisable();
}

public long SecondsPeriod => 60;
public async Task ExecuteAsync()
{
var settings = Utils.SettingsUtil.Get(nameof(TgClientPlugin));
if (settings.AutoLogin == null || !settings.AutoLogin.Enabled)
{
await Task.CompletedTask;
return;
}
// TODO: 暂时没用到 IPluginFinder, 直接传递 null
Controllers.HomeController homeController = new Controllers.HomeController(null);
try
{
if (Controllers.HomeController.Client == null || Controllers.HomeController.Client.User == null)
{
await homeController.Login(new RequestModels.LoginRequestModel
{
LoginInfo = settings.AutoLogin.Phone
});
}
}
catch (System.Exception ex)
{
System.Console.WriteLine($"{nameof(TgClientPlugin)}.{nameof(ExecuteAsync)}");
System.Console.WriteLine(ex.ToString());
}

await Task.CompletedTask;
}
}
}
4 changes: 2 additions & 2 deletions plugins/TgClientPlugin/TgClientPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>PluginCore.TgClientPlugin</PackageId>
<Version>0.0.1</Version>
<FileVersion>0.0.1.0</FileVersion>
<Version>0.0.2</Version>
<FileVersion>0.0.2.0</FileVersion>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Company>yiyun</Company>
<Authors>yiyun</Authors>
Expand Down
2 changes: 1 addition & 1 deletion plugins/TgClientPlugin/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"DisplayName": "TgClient插件",
"Description": "TgClient插件",
"Author": "yiyun",
"Version": "0.0.1",
"Version": "0.0.2",
"SupportedVersions": [ "0.0.1" ]
}
4 changes: 4 additions & 0 deletions plugins/TgClientPlugin/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"ApiId": 0,
"ApiHash": "",
"AutoLogin": {
"Enabled": false,
"Phone": ""
},
"Proxy": {
"ProxyEnabled": false,
"ProxyHost": "127.0.0.1",
Expand Down

0 comments on commit 292fc77

Please sign in to comment.