opq-osc / botoy Goto Github PK
View Code? Open in Web Editor NEWOPQ/IOTQQ/IOTBot的一个Python开发助手🐌
Home Page: https://botoy.opqbot.com
License: MIT License
OPQ/IOTQQ/IOTBot的一个Python开发助手🐌
Home Page: https://botoy.opqbot.com
License: MIT License
带atuser的消息全部返回500
不带atuser的能正常使用
await action.shutUserUp(ctx.g.from_group, ctx.g.from_user, 60)
用了这个方式禁言,但是并没有用啊,大佬求教一下
目前是把 bot.run() 放在一个单独的线程中跑
然后在 botoy 收到 websocket 消息的时候会报错
Exception in thread Thread-6:
Traceback (most recent call last):
File "/home/milkice/.pyenv/versions/3.9.0/lib/python3.9/threading.py", line 950, in _bootstrap_inner
self.run()
File "/home/milkice/.pyenv/versions/3.9.0/lib/python3.9/threading.py", line 888, in run
self._target(*self._args, **self._kwargs)
File "/home/milkice/.pyenv/versions/3.9.0/envs/venv/lib/python3.9/site-packages/socketio/client.py", line 616, in _handle_eio_message
self._handle_event(pkt.namespace, pkt.id, pkt.data)
File "/home/milkice/.pyenv/versions/3.9.0/envs/venv/lib/python3.9/site-packages/socketio/client.py", line 500, in _handle_event
r = self._trigger_event(data[0], namespace, *data[1:])
File "/home/milkice/.pyenv/versions/3.9.0/envs/venv/lib/python3.9/site-packages/socketio/client.py", line 550, in _trigger_event
return self.handlers[namespace][event](*args)
File "/home/milkice/.pyenv/versions/3.9.0/envs/venv/lib/python3.9/site-packages/botoy/client.py", line 304, in _friend_msg_handler
self.pool.submit(self._friend_context_distributor, context)
File "/home/milkice/.pyenv/versions/3.9.0/envs/venv/lib/python3.9/site-packages/botoy/pool.py", line 17, in submit
super().submit(*args, **kwargs).add_done_callback(self.callback)
File "/home/milkice/.pyenv/versions/3.9.0/lib/python3.9/concurrent/futures/thread.py", line 163, in submit
raise RuntimeError('cannot schedule new futures after '
RuntimeError: cannot schedule new futures after interpreter shutdown
不太清楚是不是自己的问题
想实现到了某个时间就发送一条消息。
然后感谢作者提供这么好用的库。😀
在 777df33 中移除了close()方法,因为这里我们需要调用这个方法来结束botoy线程,所以想问下有没有替代close()的方案呢?
https://github.com/xiyaowong/botoy/blob/4669856b273c730afb5d36e07ee04e3083a53667/botoy/client.py#L247
我的代码依赖于在run()结束阻塞后进行其他cleanup,以及停掉其他线程。这里的sys.exit显然打断了这一过程,并导致我的其他线程收不到通知,使得进程依旧未能退出。去掉后依然功能正常
line450
url=path是不是应当是url=self.config.address+path
另换群++++++++++头价格冰点,证书类型较多,绝对满足你的一切需求,不信你来试试
Traceback (most recent call last):
File "/www/server/python_manager/versions/3.8.12/lib/python3.8/site-packages/botoy-8.5-py3.8.egg/botoy/_internal/context.py", line 258, in friend_msg
msg = FriendMsg(self.__data)
File "/www/server/python_manager/versions/3.8.12/lib/python3.8/site-packages/botoy-8.5-py3.8.egg/botoy/_internal/context.py", line 169, in init
model = models.FriendMsg(**data)
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.init
pydantic.error_wrappers.ValidationError: 1 validation error for FriendMsg
CurrentPacket -> EventName
value is not a valid enumeration member; permitted: 'ON_EVENT_FRIEND_NEW_MSG' (type=type_error.enum; enum_values=[<EventName.ON_EVENT_FRIEND_NEW_MSG: 'ON_EVENT_FRIEND_NEW_MSG'>])
如题我看botoy和opq的文档里好像没写
不知道是不是端口的问题,我启动python文件的时候只会提示以下两句话:
ℹ️ 2020-10-27 23:36:29 INFO Connecting to the server...
bye~
是不是和ip地址有关系?
py文件中 bot = Botoy()
我用的是默认的127.0.0.1:8888(ssh隧道) 请问在云服务器上该如何配置?
我最近在写一个类似的东西,和botoy一样也是用的python-socketio库的client,但是每连接一分钟后就会断开重连(看log是opq那边主动断开的),目测是心跳的原因。
我看了botoy的代码发现并没有这方面的处理,python-socketio这个库好像本身也实现了心跳,实在是找不到原因,所以来问问您
这个是更新之前的,可以正常使用,因为图床国内直连速度很慢,所以只能通过代理,先获取图片编码成base64,再发送
from iotbot.sugar import Picture
from iotbot import GroupMsg
import linecache,random
import requests
import base64
proxies = {
"http": "http://127.0.0.1:1080",
"https": "http://127.0.0.1:1080",
}
def receive_group_msg(ctx: GroupMsg):
content = ctx.Content
if content == '/图片1':
num=random.randint(1,814)
url = linecache.getline('./plugins/pic/VOCALOID.txt',num)
url1 = url.strip()
r = requests.get(url1,proxies=proxies)
picbase64 = base64.b64encode(r.content)
Picture(pic_base64=picbase64)
这个是更新之后的
from botoy.sugar import Picture
from botoy import GroupMsg
import linecache,random
import requests
import base64
proxies = {
"http": "http://192.168.0.100:1080",
"https": "http://192.168.0.100:1080",
}
def receive_group_msg(ctx: GroupMsg):
content = ctx.Content
if content == '/图片1':
num=random.randint(1,814)
url = linecache.getline('./plugins/pic/VOCALOID.txt',num)
url1 = url.strip()
r = requests.get(url1,proxies=proxies)
picbase64 = base64.b64encode(r.content)
Picture(pic_base64=picbase64)
基本都是一样的,图片链接,这个图床的“https://user-gold-cdn.xitu.io/2020/5/30/17265fc33abb9785?w=2480&h=3508&f=jpeg&s=1017960”和“https://p.sda1.dev/0/ed707d00d9610cacb9cfae01168fa0d9/1.jpg”都不行
环境:win10 64位使用pycharm运行,Python 3.7.4
ubuntu 64位arm Python 3.8.5 都不行
使用的是最新的botoy模块
希望大佬可以帮一下我,另祝大佬新年快乐~
2021-01-01_10-56-31_100026.log
qwq
你好, 我这里报这个问题:
❌ 04-23 13:20:36 ERROR 连接失败,请检查ip端口是否配置正确,检查机器人是否启动,确保能够连接上! 2.3 后开始重试连接
ℹ 04-23 13:20:38 INFO Connecting to the server[http://127.0.0.1:8086]...
❌ 04-23 13:20:38 ERROR 连接失败,请检查ip端口是否配置正确,检查机器人是否启动,确保能够连接上! 4.7 后开始重试连接
ℹ 04-23 13:20:43 INFO Connecting to the server[http://127.0.0.1:8086]...
❌ 04-23 13:20:43 ERROR 连接失败,请检查ip端口是否配置正确,检查机器人是否启动,确保能够连接上! 7.6 后开始重试连接
ℹ 04-23 13:20:50 INFO Connecting to the server[http://127.0.0.1:8086]...
❌ 04-23 13:20:50 ERROR 连接失败,请检查ip端口是否配置正确,检查机器人是否启动,确保能够连接上! 13.9 后开始重试连接
我看框架是正常启动的,也能收到对应的消息
2023/04/23 13:22:07.853 [D] User 心跳成功 time:2023年04月23日 13时22分07秒
2023/04/23 13:22:37.850 [D] User 心跳成功 time:2023年04月23日 13时22分37秒
2023/04/23 13:23:07.861 [D] User 心跳成功 time:2023年04月23日 13时23分07秒
2023/04/23 13:23:08.040 [M] GET /socket.io/?transport=websocket&EIO=3&t=1682227388.0399275 35.154µs
2023/04/23 13:23:37.855 [D] User 心跳成功 time:2023年04月23日 13时23分37秒
我的端口也是正常的:
tcp6 0 0 :::3306 :::* LISTEN 2127/mysqld
tcp6 0 0 :::81 :::* LISTEN 30928/java
tcp6 0 0 :::8086 :::* LISTEN 4438/./OPQBot
tcp6 0 0 ::1:25 :::* LISTEN 931/master
tcp6 0 0 :::2234 :::* LISTEN 7103/sshd
这是我的框架启动参数:
[root@hecs-267874 OPQBot_6.9.6-0413_linux_amd64]# ./OPQBot -help
Usage of ./OPQBot:
-h this help
-port string
webapi/websocket 服务端口默认8086 (default "8086")
-token string
授权Token
-wsserver string
反向链接所搭建的websocket服务器 如:ws://127.0.0.1:8081/ws
-wthread int
工作线程 (default 100)
[root@hecs-267874 OPQBot_6.9.6-0413_linux_amd64]# ./OPQBot -token=bbb0e36
有什么需要注意的吗?
host用的是云服务器公网ip,
在本地能够成功运行,并且能够访问到网站上的那个面板,但是一放到云服务器运行的时候就遇到这种情况,之前还可以,现在就不行了,请问是发生了什么问题?谢谢!
websocket-client 这玩意没有在pip自动安装
1)这个是我的代码和配置:
[root@hecs-267874 jinghogn]# cat bot.py
from botoy import bot
bot.load_plugins() # 加载插件
bot.print_receivers() # 打印插件信息
bot.run() # 一键启动
[root@hecs-267874 jinghogn]# cat botoy.json
{
"qq": 3533411752,
"url": "localhost:8086",
"use_plugins": true
}
这个是相关插件的代码:
[root@hecs-267874 plugins]# cat hello.py mark_recv.py test.py
from botoy import S, ctx, mark_recv
async def hello():
if g := ctx.g: # ctx.g == ctx.group_msg
if g.text == "hello":
await S.text("ok")
async def hi():
if f := ctx.f: # ctx.f == ctx.friend_msg
if f.text == 'hello':
await S.text('hi')
_ = mark_recv + hello + hi
from botoy import mark_recv
class A:
@classmethod
def class_method(cls):
pass
def object_method(self):
pass
@classmethod
async def async_class_method(cls):
pass
async def async_object_method(self):
pass
lambda_function = lambda: None
def sync_function():
pass
async def async_function():
pass
a = A()
_ = (
mark_recv
+ (A.class_method, '类方法')
+ (a.object_method, "实例方法")
+ (lambda_function, '匿名函数')
+ (sync_function, '同步函数')
+ (async_function, '异步函数')
+ (a.async_class_method, '异步类方法')
+ (a.async_object_method, '异步实例方法')
)
from botoy import S, ctx, mark_recv
async def test():
print("xxxxxxxxxxxxxx")
if g := ctx.group_msg:
print(g.text)
if g.text == "test": # 接收信息内容为 test
await S.text("ok") # 根据场景发送文本
mark_recv(test, name="测试", author='tester', usage='群聊中发送 test') # 插件信息仅用于控制台显示, 可选
你好, 现在有个问题,就是后端 没有消息输出,感觉 test 这个回调没有执行到
[root@hecs-267874 jinghogn]# python3.8 bot.py
<function test at 0x7f8e884b65e0>
<function hello at 0x7f8e8844d940>
<function hi at 0x7f8e8844d9d0>
<function at 0x7f8e8846f670>
<function sync_function at 0x7f8e8846f940>
<function async_function at 0x7f8e8846f9d0>
<bound method A.class_method of <class 'plugins.mark_recv.A'>>
<bound method A.object_method of <plugins.mark_recv.A object at 0x7f8e884727f0>>
<bound method A.async_class_method of <class 'plugins.mark_recv.A'>>
<bound method A.async_object_method of <plugins.mark_recv.A object at 0x7f8e884727f0>>
+--------------+--------+-----------------+------------------------------+
| Name | Author | Usage | Meta |
+--------------+--------+-----------------+------------------------------+
| 测试 | tester | 群聊中发送 test | plugins/test.py line 5 |
| hello | | | plugins/hello.py line 4 |
| hi | | | plugins/hello.py line 10 |
| 匿名函数 | | | plugins/mark_recv.py line 20 |
| 同步函数 | | | plugins/mark_recv.py line 23 |
| 异步函数 | | | plugins/mark_recv.py line 27 |
| 类方法 | | | plugins/mark_recv.py line 5 |
| 实例方法 | | | plugins/mark_recv.py line 9 |
| 异步类方法 | | | plugins/mark_recv.py line 12 |
| 异步实例方法 | | | plugins/mark_recv.py line 16 |
+--------------+--------+-----------------+------------------------------+
ℹ️ 04-24 11:19:39 INFO 连接中[ws://localhost:8086/ws]...
✅ 04-24 11:19:39 SUCCESS 连接成功!
一直没有输出
但是我自己实现一个python脚本是能够有输出的
[root@hecs-267874 Plugins]# cat test.py
import asyncio
import json
import random
import requests
import websockets
#websocket client
SERCIVE_HOST = "127.0.0.1:8086"
async def Wsdemo():
uri = "ws://{}/ws".format(SERCIVE_HOST)
try:
async with websockets.connect(uri) as websocket:
while True:
greeting = await websocket.recv()
EventJson = json.loads(greeting)
EventName = EventJson["CurrentPacket"]["EventName"]
EventData = EventJson["CurrentPacket"]["EventData"]
print(f"<{EventName} {greeting}")
except Exception as e:
# 断线重连
t = random.randint(5, 8)
print(f"< 超时重连中... { t}", e)
await asyncio.sleep(t)
await Wsdemo()
asyncio.get_event_loop().run_until_complete(Wsdemo())
[root@hecs-267874 Plugins]# python3.8 test.py
<ON_EVENT_FRIEND_NEW_MSG {"CurrentPacket":{"EventData":{"MsgHead":{"FromUin":1111111111,"ToUin":1111111111,"FromType":1,"SenderUin":1111111111,"SenderNick":"","MsgType":528,"C2cCmd":349,"MsgSeq":26809,"MsgTime":1682306496,"MsgRandom":3074301992,"MsgUid":144115191150157864,"GroupInfo":null,"C2CTempMessageHead":null},"MsgBody":null,"Event":null},"EventName":"ON_EVENT_FRIEND_NEW_MSG"},"CurrentQQ":1111111111}
<ON_EVENT_FRIEND_NEW_MSG {"CurrentPacket":{"EventData":{"MsgHead":{"FromUin":1111111111,"ToUin":1111111111,"FromType":1,"SenderUin":1111111111,"SenderNick":"","MsgType":528,"C2cCmd":349,"MsgSeq":35640,"MsgTime":1682306496,"MsgRandom":3408870727,"MsgUid":144115191484726599,"GroupInfo":null,"C2CTempMessageHead":null},"MsgBody":null,"Event":null},"EventName":"ON_EVENT_FRIEND_NEW_MSG"},"CurrentQQ":1111111111}
<ON_EVENT_FRIEND_NEW_MSG {"CurrentPacket":{"EventData":{"MsgHead":{"FromUin":1111111111,"ToUin":1111111111,"FromType":1,"SenderUin":1111111111,"SenderNick":"","MsgType":528,"C2cCmd":349,"MsgSeq":55206,"MsgTime":1682306496,"MsgRandom":2319627722,"MsgUid":144115190395483594,"GroupInfo":null,"C2CTempMessageHead":null},"MsgBody":null,"Event":null},"EventName":"ON_EVENT_FRIEND_NEW_MSG"},"CurrentQQ":1111111111}
所以,想请教下具体是什么原因呢?
我的框架和插件都是最新的版本, 感谢 ~~
请问这是bug吗?还是我这里配置有问题
@bot.on_group_msg
def group(ctx: GroupMsg):
if ctx.FromUserId != ctx.CurrentQQ and ctx.Content == '1':
Action(ctx.CurrentQQ).sendGroupText(654745,"1")
这个是可以的
但是
@bot.on_group_msg
def group(ctx: GroupMsg):
if ctx.FromUserId != ctx.CurrentQQ and ctx.Content == '1':
Action(ctx.CurrentQQ).sendGroupText(654745,"111")
这个就不行了,因为有三个1了
如图,感谢作者回复(老是在这里提issue可能不太好,不知道作者有没有考虑过开一个答疑的电报群?感谢!)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.