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 5 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
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ clean:
.PHONY: lint
lint: pylint pycodestyle flake8 mypy pytype


# disable: TODO list temporay
.PHONY: pylint
pylint:
pylint \
--load-plugins pylint_quotes \
--disable=W0511 \
$(SOURCE_GLOB)

.PHONY: pycodestyle
Expand All @@ -52,8 +55,8 @@ mypy:

.PHONE: pytype
pytype:
pytype src/
pytype examples/
pytype src/ --disable=import-error
pytype examples/ --disable=import-error

.PHONY: install
install:
Expand Down
34 changes: 26 additions & 8 deletions examples/ding-dong-bot.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
#!/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,
)

from wechaty_puppet import PuppetOptions
from wechaty_puppet_hostie import HostiePuppet


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')


# puppet_options = PuppetOptions(token='your-token-here')
hostie_puppet = HostiePuppet(PuppetOptions('your-token-here'), 'hostie-puppet')
bot = Wechaty(hostie_puppet).on('message', message)
Copy link
Member

@huan huan May 9, 2020

Choose a reason for hiding this comment

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

Can we use the same argument as the TypeScript Wechaty?

bot = Wechaty({
  puppet: 'wechaty-puppet-hostie', 
  puppetOptions: { 
    token: 'the_token',
  },
})

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I will refactor it later.



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
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
grpclib
huan marked this conversation as resolved.
Show resolved Hide resolved
pyee
requests
qrcode
chatie-grpc==0.15.dev4
requests
Loading