-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QRCodeTerminalPlugin\FriendshipAccepterPlugin\
DingDongPlugin
- Loading branch information
Showing
7 changed files
with
196 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
66
src/Plugins/Wechaty.Plugin.Contrib/FriendshipAccepterPlugin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
src/Plugins/Wechaty.Plugin.Contrib/QRCodeTerminalPlugin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
src/Plugins/Wechaty.Plugin.Contrib/Wechaty.Plugin.Contrib.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters