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

文档太少了,不会用呀 #5

Open
Wangs121 opened this issue Dec 30, 2021 · 7 comments
Open

文档太少了,不会用呀 #5

Wangs121 opened this issue Dec 30, 2021 · 7 comments

Comments

@Wangs121
Copy link

怎么主动给qq群或好友发消息呀

@wyapx
Copy link
Owner

wyapx commented Dec 30, 2021

群发消息的话,用readme里面那个示例就行

文档迟些补上

@Wangs121
Copy link
Author

Wangs121 commented Dec 30, 2021

谢谢你这么快回复,readme那个只能对别人发得做出回应。其实我想弄早报机器人,定时执行一下脚本发信息到群里

@wyapx
Copy link
Owner

wyapx commented Dec 30, 2021

那你需要使用apscheduler之类的定时框架来调用函数

@Wangs121
Copy link
Author

Wangs121 commented Dec 31, 2021

就是我不知道怎么实现主动发消息,我的程序:

from ela.app import Mirai
from ela.message.models import Image
from ela.component.group import Group,Permission


# 指定群
# 这个可能也有问题
PixARK_g = Group(id= xxxxxxxxxx ,name='。。',permission=Permission.Owner)

print(str(PixARK_g))
# :id=xxxxxxxxxx name='。。' permission=<Permission.Owner: 'OWNER'>

#README中收到群消息输出是
# print(str(ev.group))
# :id=xxxxxxxxx name='。。' permission=<Permission.Owner: 'OWNER'>
# print(type(ev.group))
# :<class 'ela.component.group.Group'>

# 实例化类,以便接下来使用
mirai_app = Mirai("http://xxx.xxx.xxx.xxx:8080/",
                  qq=xxxxxx, verify_key="xxxxxx")

# 我不知道主动发信息这个函数绑定到哪里
@mirai_app.run()
async def morningNews(app: Mirai):
    await mirai_app.sendGroupMessage(PixARK_g, [Image(url="https://api.vvhan.com/api/60s")])


if __name__ == '__main__':
    mirai_app.run()

# 然后并没有发出任何消息

@wyapx
Copy link
Owner

wyapx commented Dec 31, 2021

就是我不知道怎么实现主动发消息,我的程序:

from ela.app import Mirai
from ela.message.models import Image
from ela.component.group import Group,Permission


# 指定群
# 这个可能也有问题
PixARK_g = Group(id= xxxxxxxxxx ,name='。。',permission=Permission.Owner)

print(str(PixARK_g))
# :id=xxxxxxxxxx name='。。' permission=<Permission.Owner: 'OWNER'>

#README中收到群消息输出是
# print(str(ev.group))
# :id=xxxxxxxxx name='。。' permission=<Permission.Owner: 'OWNER'>
# print(type(ev.group))
# :<class 'ela.component.group.Group'>

# 实例化类,以便接下来使用
mirai_app = Mirai("http://xxx.xxx.xxx.xxx:8080/",
                  qq=xxxxxx, verify_key="xxxxxx")

# 我不知道主动发信息这个函数绑定到哪里
@mirai_app.run()
async def morningNews(app: Mirai):
    await mirai_app.sendGroupMessage(PixARK_g, [Image(url="https://api.vvhan.com/api/60s")])


if __name__ == '__main__':
    mirai_app.run()

# 然后并没有发出任何消息

首先,group是内部类,不需要实例化
sendGroupMessage的第一个参数只需要填入群号就可以了

其次,run是启动主循环用的,它会阻塞程序来完成请求

最后,你需要参考
https://github.com/agronholm/apscheduler/blob/3.x/examples/schedulers/asyncio_.py
上的示例来做定时任务

@Wangs121
Copy link
Author

Wangs121 commented Dec 31, 2021

抱歉,我太笨了😥
文件只执行

# test.py
from ela.app import Mirai
from ela.message.models import Image

mirai_app = Mirai("http://xxx.xxx.xxx.xxx:8080/",
                  qq=xxxxxx, verify_key="xxxxxx")

mirai_app.sendGroupMessage(qq群号, [Image(url="https://api.vvhan.com/api/60s")])

输出为

 RuntimeWarning: coroutine 'API.sendGroupMessage' was never awaited
 mirai_app.sendGroupMessage(qq群号, [Image(url="https://api.vvhan.com/api/60s")])
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001E40E662310>

并且也发不出去消息。我还是不知道怎么主动发送消息,实在麻烦您了。我也不着急。我应该好好学学python了😥

@wyapx
Copy link
Owner

wyapx commented Jan 1, 2022

你知道异步吗?

我觉得你需要学习一下异步的相关知识

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants