docs.更新Python接口注释

This commit is contained in:
MistEO
2021-12-09 00:06:49 +08:00
parent 544cd85399
commit 45b27d569c
5 changed files with 356 additions and 53 deletions

View File

@@ -2,14 +2,28 @@ import ctypes
import os
import json
import pathlib
from msg import Msg
from message import Message
class Asst:
CallBackType = ctypes.CFUNCTYPE(
None, ctypes.c_int, ctypes.c_char_p, ctypes.c_void_p)
"""
回调函数使用实例可参照my_callback
:params:
``param1 message``: 消息类型
``param2 details``: gbk json string
``param3 arg``: 自定义参数
"""
def __init__(self, dirname: str, callback: CallBackType, arg=None):
"""
:params:
``dirname``: DLL及资源所在文件夹路径
``callback``: 回调函数
``arg``: 自定义参数
"""
os.chdir(dirname)
self.__dllpath = pathlib.Path(dirname) / 'MeoAssistance.dll'
self.__dll = ctypes.WinDLL(str(self.__dllpath))
@@ -23,36 +37,80 @@ class Asst:
self.__dll.AsstDestroy(self.__ptr)
def catch_default(self) -> bool:
"""
连接配置文件中的默认选项模拟器or安卓手机
:return: 是否连接成功
"""
self.__dll.AsstCatchDefault.argtypes = (ctypes.c_void_p,)
return self.__dll.AsstCatchDefault(self.__ptr)
def catch_emulator(self) -> bool:
"""
连接模拟器
:return: 是否连接成功
"""
self.__dll.AsstCatchEmulator.argtypes = (ctypes.c_void_p,)
return self.__dll.AsstCatchEmulator(self.__ptr)
def catch_custom(self, address: str) -> bool:
"""
连接自定义设备
:return: 是否连接成功
"""
self.__dll.AsstCatchCustom.argtypes = (
ctypes.c_void_p, ctypes.c_char_p,)
return self.__dll.AsstCatchCustom(self.__ptr, address)
def append_fight(self, max_medicine: int, max_stone: int, max_times: int) -> bool:
"""
添加刷理智任务
:params:
``max_medicine``: 最多吃多少理智药
``max_stone``: 最多吃多少源石
``max_times``: 最多刷多少
"""
self.__dll.AsstAppendFight.argtypes = (
ctypes.c_void_p, ctypes.c_int, ctypes.c_int, ctypes.c_int,)
return self.__dll.AsstAppendFight(self.__ptr, max_medicine, max_stone, max_times)
def append_award(self) -> bool:
"""
添加领取每日奖励任务
"""
self.__dll.AsstAppendAward.argtypes = (ctypes.c_void_p,)
return self.__dll.AsstAppendAward(self.__ptr)
def append_visit(self) -> bool:
"""
添加访问好友任务
"""
self.__dll.AsstAppendVisit.argtypes = (ctypes.c_void_p,)
return self.__dll.AsstAppendVisit(self.__ptr)
def append_mall(self, with_shopping: bool) -> bool:
"""
添加信用商店任务
:params:
``with_shopping``: 是否信用商店购物
"""
self.__dll.AsstAppendMall.argtypes = (ctypes.c_void_p, ctypes.c_bool)
return self.__dll.AsstAppendMall(self.__ptr, with_shopping)
def append_infrast(self, work_mode: int, order_list: list, uses_of_drones: str, dorm_threshold: float) -> bool:
"""
添加基建任务
:params:
``work_mode``: 工作模式,当前仅支持传 1
``order_list``: 换班顺序str list例如 [ "Mfg", "Trade", "Control", "Power", "Reception", "Office", "Dorm"]
``uses_of_drones``: 无人机用途,支持以下之一:"_NotUse""Money""SyntheticJade""CombatRecord""PureGold""OriginStone""Chip"
``dorm_threshold``: 宿舍心情阈值,取值 [0, 1.0]
"""
order_len = len(order_list)
order_arr = (ctypes.c_char_p * order_len)()
order_arr[:] = order_list
@@ -66,6 +124,15 @@ class Asst:
uses_of_drones, dorm_threshold)
def append_recruit(self, max_times: int, select_level: list, confirm_level: list, need_refresh: bool) -> bool:
"""
添加自动公招任务
:params:
``max_times``: 自动公招次数
``select_level``: 要点击的Tags等级例如3级Tags不选也可以直接确认int list
``confirm_level``: 要确认开始招募的Tags等级int list
``need_refresh``: 是否刷新3级Tags
"""
select_len = len(select_level)
select_arr = (ctypes.c_int * select_len)()
select_arr[:] = select_level
@@ -83,10 +150,20 @@ class Asst:
confirm_arr, confirm_len, need_refresh)
def start(self) -> bool:
"""
开始任务
"""
self.__dll.AsstStart.argtypes = (ctypes.c_void_p,)
return self.__dll.AsstStart(self.__ptr)
def start_recurit_clac(self, select_level: list, set_time: bool) -> bool:
def start_recurit_calc(self, select_level: list, set_time: bool) -> bool:
"""
进行公招计算
:params:
``select_level``: 要点击的Tags等级int list
``set_time``: 是否要点击9小时
"""
select_len = len(select_level)
select_arr = (ctypes.c_int * select_len)()
select_arr[:] = select_level
@@ -96,27 +173,40 @@ class Asst:
return self.__dll.AsstStartRecruitCalc(self.__ptr, select_arr, select_len, set_time)
def stop(self) -> bool:
"""
停止并清空所有任务
"""
self.__dll.AsstStop.argtypes = (ctypes.c_void_p,)
return self.__dll.AsstStop(self.__ptr)
def set_penguin_id(self, id: str) -> bool:
"""
设置企鹅物流ID
:params:
``id``: 企鹅物流ID仅数字部分
"""
self.__dll.AsstSetPenguinId.argtypes = (
ctypes.c_void_p, ctypes.c_char_p)
return self.__dll.AsstSetPenguinId(self.__ptr, id)
def get_version(self) -> str:
"""
获取DLL版本号
:return: 版本号
"""
self.__dll.AsstGetVersion.restype = ctypes.c_char_p
return self.__dll.AsstGetVersion()
@Asst.CallBackType
def my_callback(msg, details, arg):
d = json.loads(details.decode('gbk'))
print(Msg(msg), d, arg)
if __name__ == "__main__":
@Asst.CallBackType
def my_callback(msg, details, arg):
d = json.loads(details.decode('gbk'))
print(Message(msg), d, arg)
asst = Asst('D:\\Code\\MeoAssistance\\x64\\Release\\', my_callback)
if asst.catch_default():
print('连接成功')