Skip to content

Commit

Permalink
QRCodeTerminalPlugin\FriendshipAccepterPlugin\
Browse files Browse the repository at this point in the history
DingDongPlugin
  • Loading branch information
Jesn authored and echofool committed Dec 31, 2020
1 parent f021719 commit 8cc2889
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 20 deletions.
51 changes: 51 additions & 0 deletions src/Plugins/Wechaty.Plugin.Contrib/DingDongPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Threading.Tasks;
using Wechaty.Module.Puppet.Schemas;
using Wechaty.User;

namespace Wechaty.Plugin
{
public class DingDongPlugin : IWechatPlugin
{
public string Name => "DingDong Plugin";

public string Description => "Reply dong if bot receives a ding message.";

public string Version => "V1.0.0";

private DingDongConfig _config=new DingDongConfig();

public DingDongPlugin()
{

}

public DingDongPlugin(DingDongConfig config)
{
_config = config;
}

public Task Install(Wechaty bot)
{
bot.OnMessage(async (Message message) =>
{
if (message.Type == MessageType.Text)
{
if (_config.Ding == message.Text)
{
await message.Say(_config.Dong);
}
}
});
return Task.CompletedTask;
}

}



public class DingDongConfig
{
public string Ding { get; set; } = "ding";
public string Dong { get; set; } = "dong";
}
}
66 changes: 66 additions & 0 deletions src/Plugins/Wechaty.Plugin.Contrib/FriendshipAccepterPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Wechaty.User;

namespace Wechaty.Plugin
{
public class FriendshipAccepterPlugin : IWechatPlugin
{
public string Name => "FriendshipAccepter Plugin";

public string Description => "Accept friendship automatically, and say/do something for greeting.";

public string Version => "V1.0.0";


private FriendshipAccepterConfig config;

public FriendshipAccepterPlugin()
{

}

public FriendshipAccepterPlugin(FriendshipAccepterConfig _config)
{
config = _config;
}

public Task Install(Wechaty bot)
{
bot.OnFriendship(async (Friendship friendship) =>
{
var friendshipType = friendship.Type;
switch (friendshipType)
{
case Module.Puppet.Schemas.FriendshipType.Confirm:
var contact = friendship.Contact;
await contact.Say(config.Greeting);
break;
case Module.Puppet.Schemas.FriendshipType.Receive:
var hello = friendship.Hello;
if (hello.Contains(config.Greeting))
{
await friendship.Accept();
}
break;
case Module.Puppet.Schemas.FriendshipType.Unknown:
break;
case Module.Puppet.Schemas.FriendshipType.Verify:
break;
default:
break;
}
});

return Task.CompletedTask;
}
}

public class FriendshipAccepterConfig
{
public string Greeting { get; set; }
public string KeyWord { get; set; }
}
}
45 changes: 45 additions & 0 deletions src/Plugins/Wechaty.Plugin.Contrib/QRCodeTerminalPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Threading.Tasks;
using QRCoder;
using Wechaty.Module.Puppet.Schemas;
using static QRCoder.PayloadGenerator;

namespace Wechaty.Plugin
{
public class QRCodeTerminalPlugin : IWechatPlugin
{
public string Name => "QRCodeTerminal Plugin";

public string Description => "Show QR Code for Scan in Terminal";

public string Version => "V1.0.0";


public Task Install(Wechaty bot)
{
bot.OnScan((string qrcode, ScanStatus status, string? data) =>
{
if (status == ScanStatus.Waiting || status == ScanStatus.Timeout)
{
const string QrcodeServerUrl = "https://wechaty.github.io/qrcode/";
var qrcodeImageUrl = QrcodeServerUrl + qrcode;
Console.WriteLine(qrcodeImageUrl);

var generator = new Url(qrcode);
var payload = generator.ToString();

var qrGenerator = new QRCodeGenerator();
var qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.M);

var qrCodeAsi = new AsciiQRCode(qrCodeData);
var qrCodeAsAsciiArt = qrCodeAsi.GetGraphic(1);
Console.WriteLine(qrCodeAsAsciiArt);
}
});



return Task.CompletedTask;
}
}
}
15 changes: 15 additions & 0 deletions src/Plugins/Wechaty.Plugin.Contrib/Wechaty.Plugin.Contrib.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<PackageId>Wechaty.Plugin.Contrib</PackageId>
<AssemblyName>Wechaty.Plugin.Contrib</AssemblyName>
<RootNamespace>Wechaty.Plugin.Contrib</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\modules\Wechaty.Module.EventEmitter\Wechaty.Module.EventEmitter.csproj" />
<ProjectReference Include="..\..\Wechaty\Wechaty.csproj" />
</ItemGroup>

</Project>
9 changes: 4 additions & 5 deletions src/Wechaty.Getting.Start/ConsoleClientHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Wechaty.Module.Puppet.Schemas;
using Wechaty.Plugin;
using Wechaty.User;
using Wechaty.Plugin.ScanEvent;
using Microsoft.Extensions.DependencyInjection;

namespace Wechaty.Getting.Start
{
Expand Down Expand Up @@ -49,9 +48,9 @@ public async Task StartAsync(CancellationToken cancellationToken)


// Manual plug-in registration
var scanPlugin = new ScanPlugin();
var qrCodeTerminalPlugin = new QRCodeTerminalPlugin();
var dingDongPlugin = new DingDongPlugin();
bot.Use(scanPlugin)
bot.Use(qrCodeTerminalPlugin)
.Use(dingDongPlugin);


Expand Down
2 changes: 1 addition & 1 deletion src/Wechaty.Getting.Start/Wechaty.Getting.Start.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Plugins\Wechaty.Plugin.ScanEvent\Wechaty.Plugin.ScanEvent.csproj" />
<ProjectReference Include="..\Plugins\Wechaty.Plugin.Contrib\Wechaty.Plugin.Contrib.csproj" />
<ProjectReference Include="..\Wechaty\Wechaty.csproj" />
</ItemGroup>

Expand Down
28 changes: 14 additions & 14 deletions src/Wechaty.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wechaty.Module.PuppetHostie
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{E44372E1-6A41-4B07-A1D2-E9C0CDA1433E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wechaty.Plugin.ScanEvent", "Plugins\Wechaty.Plugin.ScanEvent\Wechaty.Plugin.ScanEvent.csproj", "{FA08EA23-6358-45FA-96EB-A4D67546E673}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wechaty.Plugin.Contrib", "Plugins\Wechaty.Plugin.Contrib\Wechaty.Plugin.Contrib.csproj", "{3BE2B718-46F6-42ED-95AE-E54048F826F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -166,18 +166,18 @@ Global
{E893752C-FBEF-4326-8ADD-1827849D45B1}.Release|x64.Build.0 = Release|Any CPU
{E893752C-FBEF-4326-8ADD-1827849D45B1}.Release|x86.ActiveCfg = Release|Any CPU
{E893752C-FBEF-4326-8ADD-1827849D45B1}.Release|x86.Build.0 = Release|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Debug|x64.ActiveCfg = Debug|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Debug|x64.Build.0 = Debug|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Debug|x86.ActiveCfg = Debug|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Debug|x86.Build.0 = Debug|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Release|Any CPU.Build.0 = Release|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Release|x64.ActiveCfg = Release|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Release|x64.Build.0 = Release|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Release|x86.ActiveCfg = Release|Any CPU
{FA08EA23-6358-45FA-96EB-A4D67546E673}.Release|x86.Build.0 = Release|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Debug|x64.ActiveCfg = Debug|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Debug|x64.Build.0 = Debug|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Debug|x86.ActiveCfg = Debug|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Debug|x86.Build.0 = Debug|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Release|Any CPU.Build.0 = Release|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Release|x64.ActiveCfg = Release|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Release|x64.Build.0 = Release|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Release|x86.ActiveCfg = Release|Any CPU
{3BE2B718-46F6-42ED-95AE-E54048F826F1}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -191,7 +191,7 @@ Global
{1A0A1D81-928C-4737-8C21-0BC27CF5952D} = {AB934DD9-0575-48CB-9CA0-2F616179C4AD}
{E8D6F103-FCBF-4E4B-AA46-74B2929B09D5} = {AB934DD9-0575-48CB-9CA0-2F616179C4AD}
{E893752C-FBEF-4326-8ADD-1827849D45B1} = {AB934DD9-0575-48CB-9CA0-2F616179C4AD}
{FA08EA23-6358-45FA-96EB-A4D67546E673} = {E44372E1-6A41-4B07-A1D2-E9C0CDA1433E}
{3BE2B718-46F6-42ED-95AE-E54048F826F1} = {E44372E1-6A41-4B07-A1D2-E9C0CDA1433E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E484A767-EB25-4862-9955-84FD387F11A0}
Expand Down

0 comments on commit 8cc2889

Please sign in to comment.