Skip to content

Commit

Permalink
feat(plugins/telegramplugin/): 自动重新登录
Browse files Browse the repository at this point in the history
0.1.3
  • Loading branch information
yiyungent committed Aug 4, 2023
1 parent d57b9fc commit e041d5d
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 56 deletions.
113 changes: 62 additions & 51 deletions .github/workflows/TelegramPlugin-release.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,72 @@
name: TelegramPlugin Release

on:
on:
push:
tags:
- 'TelegramPlugin-v*'
- "TelegramPlugin-v*"

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v2
with:
# 为了让 git 有日志 (git log) 可寻,还得在检出的时候顺带把所有提交历史一并拉下来,指定 fetch-depth 就能做到
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.100

- name: Build
run: |
cd ./plugins/TelegramPlugin
dotnet build --configuration Release
ls
ls ./bin/Release/
ls ./bin/Release/net6.0/
- name: Zip the Build
run: |
cd ./plugins/TelegramPlugin/bin/Release/net6.0
zip -r TelegramPlugin-net6.0.zip *
cd ../../../../../
mv ./plugins/TelegramPlugin/bin/Release/net6.0/*.zip ./
- name: Create temp-release-note.md
run: |
cp utils/generate-release-note.ps1 generate-release-note.ps1
$env:GitProjectTagName="TelegramPlugin"
$env:GitProjectPath="plugins/TelegramPlugin/*"
./generate-release-note.ps1
shell: pwsh

- name: Create Release and Upload Release Asset
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
#tag_name: ${{ github.ref }}
#name: ${{ github.ref }}
# body: TODO New Release.
body_path: temp-release-note.md
draft: false
prerelease: false
files: |
TelegramPlugin-net6.0.zip
LICENSE
README.md
- name: Checkout source
uses: actions/checkout@v2
with:
# 为了让 git 有日志 (git log) 可寻,还得在检出的时候顺带把所有提交历史一并拉下来,指定 fetch-depth 就能做到
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod

- name: Set outputs
id: vars
run: |
tagPrefix=refs/tags/TelegramPlugin-
# 获取字符串长度
tagPrefixLen=${#tagPrefix}
# 去掉前面的 refs/tags/TelegramPlugin-
RELEASE_VERSION=${GITHUB_REF:$tagPrefixLen}
# 提取出 v1.0.0
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_OUTPUT
shell: bash

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.100

- name: Build
run: |
cd ./plugins/TelegramPlugin
dotnet build --configuration Release
ls
ls ./bin/Release/
ls ./bin/Release/net6.0/
shell: bash

- name: Zip the Build
run: |
cd ./plugins/TelegramPlugin/bin/Release/net6.0
zip -r TelegramPlugin-${{ steps.vars.outputs.RELEASE_VERSION }}-net6.0.zip *
shell: bash

- name: Create temp-release-note.md
run: |
cp utils/generate-release-note.ps1 generate-release-note.ps1
$env:GitProjectTagName="TelegramPlugin"
$env:GitProjectPath="plugins/TelegramPlugin/*"
./generate-release-note.ps1
shell: pwsh

- name: Create Release and Upload Release Asset
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
#tag_name: ${{ github.ref }}
#name: ${{ github.ref }}
# body: TODO New Release.
body_path: temp-release-note.md
draft: false
prerelease: false
files: |
./plugins/TelegramPlugin/bin/Release/net6.0/TelegramPlugin-${{ steps.vars.outputs.RELEASE_VERSION }}-net6.0.zip
./plugins/TelegramPlugin/README.md
./plugins/TelegramPlugin/LICENSE
2 changes: 1 addition & 1 deletion plugins/TelegramPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@
> 本项目基于 [TelegramBots/Telegram.Bot: .NET Client for Telegram Bot API](https://github.com/TelegramBots/Telegram.Bot)
<!-- 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.TelegramPlugin-v0.1.2.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.TelegramPlugin-v0.1.3.README" style="border:0" alt="" />
<!-- End Matomo -->
59 changes: 58 additions & 1 deletion plugins/TelegramPlugin/TelegramPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,33 @@
using System.Text;
using System.Collections.Generic;
using System.Linq;
using PluginCore.Interfaces;

namespace TelegramPlugin
{
public class TelegramPlugin : BasePlugin
public class TelegramPlugin : BasePlugin, ITimeJobPlugin
{

#region Fields

/// <summary>
/// 1min
/// </summary>
public long SecondsPeriod => 60;

private readonly IPluginFinder _pluginFinder;

private readonly bool _debug;

#endregion

#region Ctor
public TelegramPlugin(IPluginFinder pluginFinder)
{
_pluginFinder = pluginFinder;
}
#endregion

public override (bool IsSuccess, string Message) AfterEnable()
{
Console.WriteLine($"{nameof(TelegramPlugin)}: {nameof(AfterEnable)}");
Expand All @@ -24,5 +46,40 @@ public override (bool IsSuccess, string Message) BeforeDisable()
return base.BeforeDisable();
}

public override void AppStart()
{

}

#region 定时任务
public async Task ExecuteAsync()
{
try
{
#region 由于内部自动断线重连, 因此断线只有可能是由于程序重启导致需要重新登录上线
if (TelegramBotStore.Bots == null || TelegramBotStore.Bots.Count <= 0)
{
try
{
var homeController = new Controllers.HomeController(_pluginFinder);
await homeController.Start();
}
catch (Exception ex)
{
Console.WriteLine("尝试 自动重新登录 TelegramPlugin 失败:");
Console.WriteLine(ex.ToString());
}
}
#endregion
}
catch (Exception ex)
{
Console.WriteLine($"执行定时任务失败: {ex.ToString()}");
}

await Task.CompletedTask;
}
#endregion

}
}
21 changes: 19 additions & 2 deletions plugins/TelegramPlugin/TelegramPlugin.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<PackageId>PluginCore.TelegramPlugin</PackageId>
<Version>0.1.3</Version>
<FileVersion>0.1.3.0</FileVersion>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Company>yiyun</Company>
<Authors>yiyun</Authors>
<Description>PluginCore 插件: TelegramPlugin</Description>
<Copyright>Copyright (c) 2023-present yiyun</Copyright>
<RepositoryUrl>https://github.com/yiyungent/KnifeHub</RepositoryUrl>
<PackageLicenseUrl>https://github.com/yiyungent/KnifeHub/blob/main/LICENSE</PackageLicenseUrl>
<PackageTags>PluginCore PluginCore.IPlugins</PackageTags>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0">
<ExcludeAssets>runtime</ExcludeAssets>
Expand All @@ -14,7 +31,7 @@
</PackageReference>-->
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
<PackageReference Include="PluginCore.IPlugins.AspNetCore" Version="0.0.1">
<PackageReference Include="PluginCore.IPlugins.AspNetCore" Version="0.1.0">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" />
Expand Down
2 changes: 1 addition & 1 deletion plugins/TelegramPlugin/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"DisplayName": "Telegram插件",
"Description": "Telegram基础插件",
"Author": "yiyun",
"Version": "0.1.2",
"Version": "0.1.3",
"SupportedVersions": [ "0.0.1" ]
}

0 comments on commit e041d5d

Please sign in to comment.