首次提交
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__
|
||||||
36
__init__.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
from nonebot.plugin import PluginMetadata
|
||||||
|
from nonebot import get_driver
|
||||||
|
|
||||||
|
from zhenxun.configs.utils import PluginExtraData
|
||||||
|
from zhenxun.services.plugin_init import PluginInit
|
||||||
|
|
||||||
|
from .gClass import(
|
||||||
|
g_pSqlManager,
|
||||||
|
g_pJsonManager
|
||||||
|
)
|
||||||
|
from .command import (
|
||||||
|
diuse_register
|
||||||
|
)
|
||||||
|
|
||||||
|
__plugin_meta = PluginMetadata(
|
||||||
|
name = "真寻的农场",
|
||||||
|
description = "快乐的农场时光",
|
||||||
|
usage = """
|
||||||
|
农场快乐时光
|
||||||
|
""".strip(),
|
||||||
|
extra = PluginExtraData(
|
||||||
|
author="molanp",
|
||||||
|
version="1.0",
|
||||||
|
menu_type="群内小游戏",
|
||||||
|
).dict(),
|
||||||
|
)
|
||||||
|
|
||||||
|
#注册启动函数
|
||||||
|
driver = get_driver()
|
||||||
|
|
||||||
|
@driver.on_startup
|
||||||
|
async def start():
|
||||||
|
#初始化数据库
|
||||||
|
await g_pSqlManager.init()
|
||||||
|
|
||||||
|
await g_pJsonManager.init()
|
||||||
31
command.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from nonebot.rule import to_me
|
||||||
|
from nonebot_plugin_uninfo import Uninfo
|
||||||
|
from nonebot_plugin_alconna import Alconna, on_alconna, Text
|
||||||
|
|
||||||
|
from zhenxun.services.log import logger
|
||||||
|
|
||||||
|
|
||||||
|
from .gClass import(
|
||||||
|
g_pSqlManager
|
||||||
|
)
|
||||||
|
|
||||||
|
diuse_register = on_alconna(
|
||||||
|
Alconna("注册空间"),
|
||||||
|
priority = 5,
|
||||||
|
rule=to_me(),
|
||||||
|
block = True,
|
||||||
|
)
|
||||||
|
|
||||||
|
@diuse_register.handle()
|
||||||
|
async def _(session: Uninfo):
|
||||||
|
uid = str(session.user.id)
|
||||||
|
|
||||||
|
user = await g_pSqlManager.getUserByUid(uid)
|
||||||
|
|
||||||
|
if user:
|
||||||
|
await diuse_register.send(Text("你已经有啦"), reply_to=True)
|
||||||
|
else:
|
||||||
|
info = {'uid' : uid, 'name' : '测试', 'level' : 1, 'point' : 0}
|
||||||
|
|
||||||
|
aaa = await g_pSqlManager.appendUserByUserInfo(info)
|
||||||
|
await diuse_register.send(Text(str(aaa)), reply_to=True)
|
||||||
55
config.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from zhenxun.services.log import logger
|
||||||
|
from zhenxun.configs.path_config import DATA_PATH, IMAGE_PATH, TEMPLATE_PATH
|
||||||
|
|
||||||
|
g_sDBPath = DATA_PATH / "farm_db"
|
||||||
|
g_sDBFilePath = DATA_PATH / "farm_db/farm.db"
|
||||||
|
|
||||||
|
class CJsonManager:
|
||||||
|
def __init__(self):
|
||||||
|
self.m_pItem = None
|
||||||
|
self.m_pPlant = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def init(cls) -> bool:
|
||||||
|
if not await cls.initItem():
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not await cls.initPlant():
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def initItem(cls) -> bool:
|
||||||
|
current_file_path = Path(__file__)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(current_file_path.resolve().parent / "config/item.json", 'r', encoding='utf-8') as file:
|
||||||
|
cls.m_pItem = json.load(file)
|
||||||
|
|
||||||
|
return True
|
||||||
|
except FileNotFoundError:
|
||||||
|
logger.warning(f"item.json 打开失败: {e}")
|
||||||
|
return False
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
logger.warning(f"item.json JSON格式错误: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def initPlant(cls) -> bool:
|
||||||
|
current_file_path = Path(__file__)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(current_file_path.resolve().parent / "config/plant.json", 'r', encoding='utf-8') as file:
|
||||||
|
cls.m_pPlant = json.load(file)
|
||||||
|
|
||||||
|
return True
|
||||||
|
except FileNotFoundError:
|
||||||
|
logger.warning(f"plant.json 打开失败: {e}")
|
||||||
|
return False
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
logger.warning(f"plant.json JSON格式错误: {e}")
|
||||||
|
return False
|
||||||
21
config/item.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"item":
|
||||||
|
{
|
||||||
|
"zhuShi":
|
||||||
|
[
|
||||||
|
"name: 名称",
|
||||||
|
"level: 等级",
|
||||||
|
"price: 单价",
|
||||||
|
"icon: 显示图片",
|
||||||
|
"sell: 是否可以上架交易行"
|
||||||
|
],
|
||||||
|
"muBan":
|
||||||
|
{
|
||||||
|
"name": "木板",
|
||||||
|
"level": 0,
|
||||||
|
"price": 5000,
|
||||||
|
"icon": "Test",
|
||||||
|
"sell": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
65
config/plant.json
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"plant":
|
||||||
|
{
|
||||||
|
"zhuShi":
|
||||||
|
[
|
||||||
|
"name: 名称",
|
||||||
|
"level: 解锁等级",
|
||||||
|
"limit: 限制等级 0:普通土地 1:红土地 2:黄土地 3:黑土地",
|
||||||
|
"experience: 收获经验",
|
||||||
|
"harvest: 收获数量",
|
||||||
|
"price: 单价",
|
||||||
|
"time: 成熟时间 单位:分钟",
|
||||||
|
"crop: 作物可以收几次",
|
||||||
|
"again: 再次成熟时间 单位:分钟",
|
||||||
|
"phase: 阶段 目前为 成熟时间 / 阶段 来显示每阶段图片",
|
||||||
|
"general: 第一阶段是否为通用阶段素材",
|
||||||
|
"sell: 是否可以上架交易行"
|
||||||
|
],
|
||||||
|
"daBaiCai":
|
||||||
|
{
|
||||||
|
"name": "大白菜",
|
||||||
|
"level": 0,
|
||||||
|
"limit": 0,
|
||||||
|
"experience": 5,
|
||||||
|
"harvest": 30,
|
||||||
|
"price": 5,
|
||||||
|
"time": 780,
|
||||||
|
"crop": 1,
|
||||||
|
"again": 0,
|
||||||
|
"phase": 5,
|
||||||
|
"general": true,
|
||||||
|
"sell": false
|
||||||
|
},
|
||||||
|
"baiLuoBo":
|
||||||
|
{
|
||||||
|
"name": "白萝卜",
|
||||||
|
"level": 0,
|
||||||
|
"limit": 0,
|
||||||
|
"experience": 5,
|
||||||
|
"harvest": 30,
|
||||||
|
"price": 5,
|
||||||
|
"time": 600,
|
||||||
|
"crop": 1,
|
||||||
|
"again": 0,
|
||||||
|
"phase": 5,
|
||||||
|
"general": true,
|
||||||
|
"sell": false
|
||||||
|
},
|
||||||
|
"huLuoBo":
|
||||||
|
{
|
||||||
|
"name": "胡萝卜",
|
||||||
|
"level": 0,
|
||||||
|
"limit": 0,
|
||||||
|
"experience": 5,
|
||||||
|
"harvest": 30,
|
||||||
|
"price": 5,
|
||||||
|
"time": 5,
|
||||||
|
"crop": 1,
|
||||||
|
"again": 0,
|
||||||
|
"phase": 5,
|
||||||
|
"general": true,
|
||||||
|
"sell": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
108
database.py
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
import os
|
||||||
|
import aiosqlite
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from zhenxun.services.log import logger
|
||||||
|
from zhenxun.configs.path_config import DATA_PATH, IMAGE_PATH, TEMPLATE_PATH
|
||||||
|
|
||||||
|
from .config import (
|
||||||
|
g_sDBPath,
|
||||||
|
g_sDBFilePath
|
||||||
|
)
|
||||||
|
|
||||||
|
class CSqlManager:
|
||||||
|
def __init__(self):
|
||||||
|
g_sDBPath.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
if self.m_pDB:
|
||||||
|
self.m_pDB.close()
|
||||||
|
self.m_pDB = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def init(cls) -> bool:
|
||||||
|
bIsExist = os.path.exists(g_sDBFilePath)
|
||||||
|
|
||||||
|
cls.m_pDB = await aiosqlite.connect(g_sDBFilePath)
|
||||||
|
|
||||||
|
if bIsExist == False:
|
||||||
|
#TODO 缺少判断创建失败事件
|
||||||
|
await cls.createDB()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def createDB(cls) -> bool:
|
||||||
|
"""初始化数据库表
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: 是否创建成功
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
await cls.m_pDB.execute('''
|
||||||
|
CREATE TABLE user (
|
||||||
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
level INTEGER DEFAULT 1,
|
||||||
|
point INTEGER DEFAULT 0
|
||||||
|
);
|
||||||
|
''')
|
||||||
|
await cls.m_pDB.commit()
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def getUserByUid(cls, uid : str) -> list[dict]:
|
||||||
|
"""根据用户Uid获取用户信息
|
||||||
|
|
||||||
|
Args:
|
||||||
|
uid (str): 用户Uid
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list[dict]: 用户信息
|
||||||
|
"""
|
||||||
|
if len(uid) <= 0:
|
||||||
|
return []
|
||||||
|
|
||||||
|
try:
|
||||||
|
async with cls.m_pDB.execute("SELECT * FROM user WHERE uid = ?", (uid,)) as cursor:
|
||||||
|
results = []
|
||||||
|
|
||||||
|
async for row in cursor:
|
||||||
|
user_dict = {
|
||||||
|
'uid': row[0],
|
||||||
|
'name': row[1],
|
||||||
|
'level': row[2],
|
||||||
|
'point': row[3]
|
||||||
|
}
|
||||||
|
results.append(user_dict)
|
||||||
|
|
||||||
|
return results
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"查询失败: {e}")
|
||||||
|
return []
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def appendUserByUserInfo(cls, info : list[dict]) -> bool:
|
||||||
|
"""添加用户信息
|
||||||
|
|
||||||
|
Args:
|
||||||
|
info (list[dict]): 用户信息
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: 是否添加成功
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
await cls.m_pDB.execute('''
|
||||||
|
INSERT INTO user (uid, name, level, point) VALUES (?, ?, ?, ?)
|
||||||
|
''', (info['uid'], info['name'], info['level'], info['point']))
|
||||||
|
await cls.m_pDB.commit()
|
||||||
|
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"添加失败: {e}")
|
||||||
|
return False
|
||||||
6
gClass.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from .config import CJsonManager
|
||||||
|
from .database import CSqlManager
|
||||||
|
|
||||||
|
g_pJsonManager = CJsonManager()
|
||||||
|
|
||||||
|
g_pSqlManager = CSqlManager()
|
||||||
8
initFarm.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from nonebot_plugin_uninfo import Uninfo
|
||||||
|
from nonebot_plugin_alconna import Alconna, At, Image, Match, Text, UniMsg, on_alconna
|
||||||
|
|
||||||
|
import command
|
||||||
|
|
||||||
|
@diuse_register.handle()
|
||||||
|
async def _(session: Uninfo):
|
||||||
|
uid = str(session.user.id)
|
||||||
BIN
resource/basic/0.png
Normal file
|
After Width: | Height: | Size: 29 KiB |
BIN
resource/basic/9.png
Normal file
|
After Width: | Height: | Size: 41 KiB |
BIN
resource/大白菜/icon.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
resource/大蒜/icon.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
resource/小麦/icon.png
Normal file
|
After Width: | Height: | Size: 9.7 KiB |
BIN
resource/水稻/icon.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
resource/油菜/icon.png
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
BIN
resource/牧草/icon.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
resource/玉米/icon.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
resource/生菜/icon.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
resource/白萝卜/icon.png
Normal file
|
After Width: | Height: | Size: 9.1 KiB |
BIN
resource/胡萝卜/1.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
resource/胡萝卜/2.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
resource/胡萝卜/3.png
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
BIN
resource/胡萝卜/4.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
resource/胡萝卜/icon.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |