Giter VIP home page Giter VIP logo

botoy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

botoy's Issues

自动断开链接

image
`from botoy import Botoy

bot = Botoy(qq=1223, use_plugins=True, log_file=False)

if name == 'main':
bot.run()`

Websocket 收到消息时报错 RuntimeError: cannot schedule new futures after interpreter shutdown

目前是把 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

不太清楚是不是自己的问题

action.py

line450
url=path是不是应当是url=self.config.address+path

value is not a valid enumeration member; permitted: 'ON_EVENT_FRIEND_NEW_MSG'

另换群++++++++++头价格冰点,证书类型较多,绝对满足你的一切需求,不信你来试试
⚠️ 04-27 11:27:12 WARNING 收到该错误,请进行反馈!
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'>])

将bot.py启动并挂载在云服务器上的方法

不知道是不是端口的问题,我启动python文件的时候只会提示以下两句话:

ℹ️ 2020-10-27 23:36:29 INFO Connecting to the server...
bye~

是不是和ip地址有关系?

py文件中 bot = Botoy()

我用的是默认的127.0.0.1:8888(ssh隧道) 请问在云服务器上该如何配置?

请问botoy的socketio有做什么特殊处理吗

我最近在写一个类似的东西,和botoy一样也是用的python-socketio库的client,但是每连接一分钟后就会断开重连(看log是opq那边主动断开的),目测是心跳的原因。
我看了botoy的代码发现并没有这方面的处理,python-socketio这个库好像本身也实现了心跳,实在是找不到原因,所以来问问您

TypeError: 'NoneType' object is not iterable

在没有更改任何代码的情况下,过一段时间使用action或者S发送消息时会报这个错误,而且之后每次用action和S发消息都会报这个错误,重启bot也不行,但是重新安装框架就好了。
MRV)ILD$P6YL7JSRVQP@9M

更新之后原来通过base64发图片的代码就失效了

这个是更新之前的,可以正常使用,因为图床国内直连速度很慢,所以只能通过代理,先获取图片编码成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

(re.Pattern) TypeError: 'type' object is not subscriptable

你好, 我这里报这个问题:
❌ 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
有什么需要注意的吗?

ℹ️ 2020-11-10 12:10:58 INFO Connecting to the server... bye~

host用的是云服务器公网ip,
在本地能够成功运行,并且能够访问到网站上的那个面板,但是一放到云服务器运行的时候就遇到这种情况,之前还可以,现在就不行了,请问是发生了什么问题?谢谢!

receiver can not receive any messages

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

也可以调用mark_recv多次

mark_recv(hello)

mark_recv(hi)

运算符调用使用数组形式传递位置参数 name, author, usage

_ = mark_recv + hello + (hi, 'hi friend')

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了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.