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 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); }
public async Task StartAsync(CancellationToken cancellationToken) { ILoggerFactory loggerFactory = new LoggerFactory(); var logger = new Logger <WechatyPuppet>(loggerFactory); var PuppetOptions = new Schemas.PuppetOptions() { // eg http://192.168.2.200:8788 Endpoint = Configuration["Wechaty_EndPoint"], Token = Configuration["Wechaty_Token"] }; var grpcPuppet = new GrpcPuppet(PuppetOptions, logger, loggerFactory); var wechatyOptions = new WechatyOptions() { Name = Configuration["Wechaty_Name"], Puppet = grpcPuppet, }; bot = new Wechaty(wechatyOptions, loggerFactory); await bot.OnScan(WechatyScanEventListener) .OnLogin(WechatyLoginEventListener) .OnMessage(WechatyMessageEventListenerAsync) .OnHeartbeat(WechatyHeartbeatEventListener) .Start(); }
/// <summary> /// init <see cref="Message"/> /// </summary> /// <param name="id"></param> /// <param name="wechaty"></param> /// <param name="logger"></param> /// <param name="name"></param> public Message([DisallowNull] string id, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <Message> logger, [AllowNull] string?name = null) : base(wechaty, logger, name) { Id = id; if (Logger.IsEnabled(LogLevel.Trace)) { Logger.LogTrace($"constructor({id}) for class {GetType().Name ?? nameof(Message)}"); } _loadAll = new AsyncLazy <object>(async() => { Payload = await Puppet.MessagePayload(Id); if (Payload == null) { throw new InvalidOperationException("no payload"); } var roomId = Payload.RoomId; var fromId = Payload.FromId; var toId = Payload.ToId; if (!string.IsNullOrWhiteSpace(roomId)) { await WechatyInstance.Room.Load(id).Ready(); } if (!string.IsNullOrWhiteSpace(fromId)) { await WechatyInstance.Contact.Load(fromId).Ready(); } if (!string.IsNullOrWhiteSpace(toId)) { await WechatyInstance.Contact.Load(toId).Ready(); } return(typeof(object)); }, AsyncLazyFlags.ExecuteOnCallingThread | AsyncLazyFlags.RetryOnFailure); }
/// <summary> /// init <see cref="ContactRepository{TContactRepository, TContact}"/> /// </summary> /// <param name="loggerForContact"></param> /// <param name="wechaty"></param> /// <param name="logger"></param> /// <param name="name"></param> protected ContactRepository([DisallowNull] ILogger <TContact> loggerForContact, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <TContactRepository> logger, [AllowNull] string?name = null) : base(wechaty, logger, name) { _loggerForContact = loggerForContact; _name = name; }
public RoomRepository([DisallowNull] ILogger <Room> loggerForRoom, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <RoomRepository> logger, [AllowNull] string?name = null) : base(wechaty, logger, name) { _loggerForRoom = loggerForRoom; _name = name; }
public RoomInvitationRepository([DisallowNull] ILogger <RoomInvitation> loggerForRoomInvitation, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <RoomInvitationRepository> logger, [AllowNull] string?name = null) : base(wechaty, logger, name) { _loggerForRoomInvitation = loggerForRoomInvitation; _name = name; }
/// <summary> /// init <see cref="FriendshipRepository"/> /// </summary> /// <param name="loggerForFriendship"></param> /// <param name="wechaty"></param> /// <param name="logger"></param> /// <param name="name"></param> public FriendshipRepository([DisallowNull] ILogger <Friendship> loggerForFriendship, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <FriendshipRepository> logger, [AllowNull] string?name = null) : base(wechaty, logger, name) { _loggerForFriendship = loggerForFriendship; _name = name; }
/// <summary> /// init <see cref="ImageRepository"/> /// </summary> /// <param name="loggerForImage"></param> /// <param name="wechaty"></param> /// <param name="logger"></param> /// <param name="name"></param> public ImageRepository([DisallowNull] ILogger <Image> loggerForImage, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <ImageRepository> logger, [AllowNull] string?name = null) : base(wechaty, logger, name) { _loggerForImage = loggerForImage; _name = name; }
public TagRepository([DisallowNull] ILogger <Tag> loggerForTag, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <TagRepository> logger, [AllowNull] string?name = null) : base(wechaty, logger, name) { _loggerForTag = loggerForTag; _name = name; }
/// <summary> /// init <see cref="Friendship"/> /// </summary> /// <param name="id"></param> /// <param name="wechaty"></param> /// <param name="logger"></param> /// <param name="name"></param> public Friendship([DisallowNull] string id, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <Friendship> logger, [AllowNull] string?name = default) : base(wechaty, logger, name) { Id = id; if (Logger.IsEnabled(LogLevel.Trace)) { Logger.LogTrace($"constructor{id}"); } }
public Contact([DisallowNull] string id, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <Contact> logger, [AllowNull] string?name = default) : base(wechaty, logger, name) { Id = id; if (Logger.IsEnabled(LogLevel.Trace)) { Logger.LogTrace($"constructor(${id})"); } }
public RoomInvitation([DisallowNull] string id, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <RoomInvitation> logger, [AllowNull] string?name = null) : base(wechaty, logger, name) { Id = id; if (Logger.IsEnabled(LogLevel.Trace)) { Logger.LogTrace($"constructor({id})"); } }
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 Task Install(Wechaty bot) { _ = bot.OnMessage((message) => { if (message.Text == "ding") { message.Say("dong"); } if (message.Text == "dong") { message.Say("ding"); } }); return(Task.CompletedTask); }
public async Task StartAsync(CancellationToken cancellationToken) { var PuppetOptions = new Module.Puppet.Schemas.PuppetOptions() { Token = _configuration["WECHATY_PUPPET_SERVICE_TOKEN"], }; bot = new Wechaty(PuppetOptions); // Automatic plug-in registration //var serviceCollection = new ServiceCollection() // .AddSingleton<IWechatPlugin, ScanPlugin>() // .AddSingleton<IWechatPlugin, DingDongPlugin>(); //var plugins = serviceCollection.BuildServiceProvider().GetServices<IWechatPlugin>().ToArray(); // Manual plug-in registration var qrCodeTerminalPlugin = new QRCodeTerminalPlugin(); var dingDongPlugin = new DingDongPlugin(); bot.Use(qrCodeTerminalPlugin) .Use(dingDongPlugin); await bot //.OnScan(WechatyScanEventListener) //.OnLogin(async (ContactSelf user) => //{ // //Console.WriteLine($"{user.Name}在{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}上线了!"); //}) .OnMessage(WechatyMessageEventListenerAsync) .OnHeartbeat(WechatyHeartbeatEventListener) .OnRoomInvite(WechatyRoomInviteEventListener) .OnRoomJoin(WechatyRoomJoinEventListener) .OnRoomLeave(WechatyRoomLeaveEventListener) .OnRoomTopic(WechatyRoomTopicEventListener) .Start(); }
public Task Install(Wechaty bot) { bot.OnScan((string qrcode, ScanStatus status, string?data) => { const string QrcodeServerUrl = "https://wechaty.github.io/qrcode/"; if (status == ScanStatus.Waiting || status == ScanStatus.Timeout) { var qrcodeImageUrl = QrcodeServerUrl + qrcode; Console.WriteLine(qrcodeImageUrl); } else if (status == ScanStatus.Scanned) { Console.WriteLine(data); } }) .OnLogin((ContactSelf user) => { Console.WriteLine($"{user.Name}在{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}上线了!"); }); return(Task.CompletedTask); }
public async Task StartAsync(CancellationToken cancellationToken) { var PuppetOptions = new Module.Puppet.Schemas.PuppetOptions() { Token = _configuration["WECHATY_PUPPET_HOSTIE_TOKEN"], PuppetService = _configuration["WECHATY_PUPPET"] }; bot = new Wechaty(PuppetOptions); await bot.OnScan(WechatyScanEventListener) .OnLogin(async(ContactSelf user) => { Console.WriteLine($"{user.Name}在{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}上线了!"); }) .OnMessage(WechatyMessageEventListenerAsync) .OnHeartbeat(WechatyHeartbeatEventListener) .OnRoomInvite(WechatyRoomInviteEventListener) .OnRoomJoin(WechatyRoomJoinEventListener) .OnRoomLeave(WechatyRoomLeaveEventListener) .OnRoomTopic(WechatyRoomTopicEventListener) .Start(); }
public UrlLinkRepository([DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <UrlLinkRepository> logger, [AllowNull] string?name = null) : base(wechaty, logger, name) { }
public ContactSelfRepository([DisallowNull] ILogger <ContactSelf> loggerForContactSelf, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <ContactSelfRepository> logger, [AllowNull] string?name = null) : base(loggerForContactSelf, wechaty, logger, name) { }
///<inheritdoc/> protected override ContactSelf New( [DisallowNull] string id, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <ContactSelf> logger, [AllowNull] string?name = null) => new ContactSelf(id, WechatyInstance, logger, name);
public ContactSelf([DisallowNull] string id, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <ContactSelf> logger, [AllowNull] string?name = null) : base(id, wechaty, logger, name) { }
/// <summary> /// init <see cref="Favorite"/> /// </summary> /// <param name="wechaty"></param> /// <param name="logger"></param> /// <param name="name"></param> public Favorite([DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <Favorite> logger, [AllowNull] string?name = null) : base(wechaty, logger, name) { }
/// <summary> /// new <typeparamref name="TContact"/> /// </summary> /// <param name="id"></param> /// <param name="wechaty"></param> /// <param name="puppet"></param> /// <param name="logger"></param> /// <param name="name"></param> /// <returns></returns> protected abstract TContact New([DisallowNull] string id, [DisallowNull] Wechaty wechaty, [DisallowNull] ILogger <TContact> logger, [AllowNull] string?name = default);