Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement basic ding-dong bot #39

Merged
merged 7 commits into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions examples/ding-dong-bot.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
#!/usr/bin/env python3.8
"""doc"""
import asyncio

from wechaty import Wechaty
from wechaty.user import Message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we export Message in our module root? Because it will be convenience for the developers using, and that's also what we did in TS:

from wechaty import (
  Wechaty,
  Message,
)



async def message(msg: Message):
"""back on message"""
from_contact = msg.talker()
text = msg.text()
if from_contact is not None and text == 'ding':
await from_contact.say('dong')
print(msg)


async def do_some_thing():
"""do some thing"""
friends = await bot.Contact.find_all()
print(friends)
print('dong some thing')

bot = Wechaty(token='your-token-here').on('message', message)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we follow the same WechatyOptions in the TS in our Python Wechaty?

That will be a convenience for the developers who are using multiple languages to develop the wechaty program.

See: https://github.com/wechaty/wechaty/blob/769921d996cd5303a5aee6614d084186aef87921/src/wechaty.ts#L105-L115

export interface WechatyOptions {
  memory?        : MemoryCard,
  name?          : string,                    // Wechaty Name

  // @deprecated: use `name` instead of `profile`
  profile?       : null | string,             // DEPRECATED: use name instead

  puppet?        : PuppetModuleName | Puppet, // Puppet name or instance
  puppetOptions? : PuppetOptions,             // Puppet TOKEN
  ioToken?       : string,                    // Io TOKEN
}



async def main():
"""doc"""
print('hello')
await asyncio.sleep(1)
print('world')
bot = Wechaty()
print(await bot.name())

await bot.start()
await do_some_thing()

asyncio.run(main())
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ pylint-quotes
pytest
pytype
semver
grpclib
pyee
requests
qrcode
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
grpclib
huan marked this conversation as resolved.
Show resolved Hide resolved
pyee
requests
qrcode
Empty file added src/chatie_grpc/__init__.py
Empty file.
Loading