Config提供type字段确定配置项类型

This commit is contained in:
HibiKier
2023-02-26 22:17:26 +08:00
parent a63fda8a0d
commit 8133b61ebd
53 changed files with 1589 additions and 1000 deletions
+46 -30
View File
@@ -1,24 +1,27 @@
from typing import Type, Tuple, Any
from nonebot import on_command
from nonebot.matcher import Matcher
from utils.utils import scheduler, is_number
from nonebot.adapters.onebot.v11.permission import GROUP
from nonebot.typing import T_State
from nonebot.adapters.onebot.v11 import GroupMessageEvent, MessageEvent, Message
from nonebot.permission import SUPERUSER
import random
from nonebot.plugin import MatcherGroup
from configs.path_config import IMAGE_PATH
from typing import Any, Tuple, Type
from nonebot import on_command
from nonebot.adapters.onebot.v11 import GroupMessageEvent, Message, MessageEvent
from nonebot.adapters.onebot.v11.permission import GROUP
from nonebot.matcher import Matcher
from nonebot.params import CommandArg, RegexGroup
from nonebot.permission import SUPERUSER
from nonebot.plugin import MatcherGroup
from nonebot.typing import T_State
from configs.config import Config
from configs.path_config import IMAGE_PATH
from utils.utils import is_number, scheduler
from .open_cases_c import (
open_case,
total_open_statistics,
group_statistics,
my_knifes_name,
open_shilian_case,
open_case,
open_multiple_case,
total_open_statistics,
)
from .utils import util_get_buff_price, util_get_buff_img, update_count_daily
from configs.config import Config
from .utils import reset_count_daily, util_get_buff_img, util_get_buff_price
__zx_plugin_name__ = "开箱"
__plugin_usage__ = """
@@ -73,11 +76,17 @@ __plugin_task__ = {"open_case_reset_remind": "每日开箱重置提醒"}
__plugin_cd_limit__ = {"rst": "着什么急啊,慢慢来!"}
__plugin_resources__ = {f"cases": IMAGE_PATH}
__plugin_configs__ = {
"INITIAL_OPEN_CASE_COUNT": {"value": 20, "help": "初始每日开箱次数", "default_value": 20},
"INITIAL_OPEN_CASE_COUNT": {
"value": 20,
"help": "初始每日开箱次数",
"default_value": 20,
"type": int,
},
"EACH_IMPRESSION_ADD_COUNT": {
"value": 3,
"help": "每 * 点好感度额外增加开箱次数",
"default_value": 3,
"type": int,
},
"COOKIE": {
"value": None,
@@ -92,6 +101,7 @@ Config.add_plugin_config(
True,
help_="被动 每日开箱重置提醒 进群默认开关状态",
default_value=True,
type=int,
)
cases_name = ["狂牙大行动", "突围大行动", "命悬一线", "裂空", "光谱"]
@@ -101,12 +111,12 @@ cases_matcher_group = MatcherGroup(priority=5, permission=GROUP, block=True)
k_open_case = cases_matcher_group.on_command("开箱")
reload_count = cases_matcher_group.on_command("重置开箱",permission=SUPERUSER)
reload_count = cases_matcher_group.on_command("重置开箱", permission=SUPERUSER)
@reload_count.handle()
async def _(event: GroupMessageEvent):
await update_count_daily()
await reset_count_daily()
@k_open_case.handle()
@@ -153,11 +163,13 @@ async def _(event: GroupMessageEvent):
)
open_shilian: Type[Matcher] = cases_matcher_group.on_regex("(.*)连开箱(.*)?")
open_multiple: Type[Matcher] = cases_matcher_group.on_regex("(.*)连开箱(.*)?")
@open_shilian.handle()
async def _(event: GroupMessageEvent, state: T_State, reg_group: Tuple[Any, ...] = RegexGroup()):
@open_multiple.handle()
async def _(
event: GroupMessageEvent, state: T_State, reg_group: Tuple[Any, ...] = RegexGroup()
):
num, case_name = reg_group
if is_number(num) or num_dict.get(num):
try:
@@ -165,18 +177,18 @@ async def _(event: GroupMessageEvent, state: T_State, reg_group: Tuple[Any, ...]
except KeyError:
num = int(num)
if num > 30:
await open_shilian.finish("开箱次数不要超过30啊笨蛋!", at_sender=True)
await open_multiple.finish("开箱次数不要超过30啊笨蛋!", at_sender=True)
if num < 0:
await open_shilian.finish("再负开箱就扣你明天开箱数了!", at_sender=True)
await open_multiple.finish("再负开箱就扣你明天开箱数了!", at_sender=True)
else:
await open_shilian.finish("必须要是数字切不要超过30啊笨蛋!中文也可!", at_sender=True)
await open_multiple.finish("必须要是数字切不要超过30啊笨蛋!中文也可!", at_sender=True)
case_name = case_name.replace("武器箱", "").strip()
if not case_name:
case_name = random.choice(cases_name)
elif case_name not in cases_name:
await open_shilian.finish("武器箱未收录!", at_sender=True)
await open_shilian.finish(
await open_shilian_case(event.user_id, event.group_id, case_name, num),
await open_multiple.finish("武器箱未收录!", at_sender=True)
await open_multiple.finish(
await open_multiple_case(event.user_id, event.group_id, case_name, num),
at_sender=True,
)
@@ -220,7 +232,9 @@ update_price = on_command("更新开箱价格", priority=1, permission=SUPERUSER
@update_price.handle()
async def _(event: MessageEvent, arg: Message = CommandArg()):
await update_price.send(await util_get_buff_price(arg.extract_plain_text().strip() or "狂牙大行动"))
await update_price.send(
await util_get_buff_price(arg.extract_plain_text().strip() or "狂牙大行动")
)
update_img = on_command("更新开箱图片", priority=1, permission=SUPERUSER, block=True)
@@ -228,7 +242,9 @@ update_img = on_command("更新开箱图片", priority=1, permission=SUPERUSER,
@update_img.handle()
async def _(event: MessageEvent, arg: Message = CommandArg()):
await update_img.send(await util_get_buff_img(arg.extract_plain_text().strip() or "狂牙大行动"))
await update_img.send(
await util_get_buff_img(arg.extract_plain_text().strip() or "狂牙大行动")
)
# 重置开箱
@@ -238,4 +254,4 @@ async def _(event: MessageEvent, arg: Message = CommandArg()):
minute=1,
)
async def _():
await update_count_daily()
await reset_count_daily()
+341 -129
View File
@@ -1,5 +1,9 @@
import random
import pypinyin
from typing import List, Tuple
from services.log import logger
from .models.buff_skin import BuffSkin
BLUE = 0.7981
BLUE_ST = 0.0699
@@ -29,152 +33,360 @@ BATTLE_SCARED_S = 0.45
BATTLE_SCARED_E = 0.99999
# 狂牙大行动
KUANGYADAXINGDONG_CASE_KNIFE = ['摩托手套 | 第三特种兵连', '狂牙手套 | 翡翠', '驾驶手套 | 美洲豹女王', '运动手套 | 弹弓', '专业手套 | 老虎精英'
, '专业手套 | 渐变大理石', '运动手套 | 夜行衣', '驾驶手套 | 西装革履', '摩托手套 | 终点线', '摩托手套 | 血压',
'运动手套 | 猩红头巾', '驾驶手套 | 雪豹', '裹手 | 长颈鹿', '驾驶手套 | 绯红列赞', '裹手 | 沙漠头巾',
'专业手套 | 一线特工', '狂牙手套 | 黄色斑纹', '摩托手套 | 小心烟幕弹', '裹手 | 蟒蛇', '裹手 | 警告!',
'狂牙手套 | 精神错乱', '运动手套 | 大型猎物', '狂牙手套 | 针尖', '专业手套 | 陆军少尉长官']
KUANGYADAXINGDONG_CASE_RED = ['M4A1 | 印花集', '格洛克 | 黑色魅影']
KUANGYADAXINGDONG_CASE_PINK = ['FN57 | 童话城堡', 'M4A4 | 赛博', 'USP | 小绿怪']
KUANGYADAXINGDONG_CASE_PURPLE = ['AWP | 亡灵之主', '双持贝瑞塔 | 灾难', '新星 | 一见青心', 'SSG 08 | 抖枪', 'UMP-45 | 金铋辉煌']
KUANGYADAXINGDONG_CASE_BLUE = ['CZ75 | 世仇', 'P90 | 大怪兽RUSH', 'G3SG1 | 血腥迷彩', '加利尔 AR | 破坏者', 'P250 | 污染物',
'M249 | 等高线', 'MP5-SD | 零点行动']
KUANGYADAXINGDONG_CASE_KNIFE = [
"摩托手套 | 第三特种兵连",
"狂牙手套 | 翡翠",
"驾驶手套 | 美洲豹女王",
"运动手套 | 弹弓",
"专业手套 | 老虎精英",
"专业手套 | 渐变大理石",
"运动手套 | 夜行衣",
"驾驶手套 | 西装革履",
"摩托手套 | 终点线",
"摩托手套 | 血压",
"运动手套 | 猩红头巾",
"驾驶手套 | 雪豹",
"裹手 | 长颈鹿",
"驾驶手套 | 绯红列赞",
"裹手 | 沙漠头巾",
"专业手套 | 一线特工",
"狂牙手套 | 黄色斑纹",
"摩托手套 | 小心烟幕弹",
"裹手 | 蟒蛇",
"裹手 | 警告!",
"狂牙手套 | 精神错乱",
"运动手套 | 大型猎物",
"狂牙手套 | 针尖",
"专业手套 | 陆军少尉长官",
]
KUANGYADAXINGDONG_CASE_RED = ["M4A1 | 印花集", "格洛克 | 黑色魅影"]
KUANGYADAXINGDONG_CASE_PINK = ["FN57 | 童话城堡", "M4A4 | 赛博", "USP | 小绿怪"]
KUANGYADAXINGDONG_CASE_PURPLE = [
"AWP | 亡灵之主",
"双持贝瑞塔 | 灾难",
"新星 | 一见青心",
"SSG 08 | 抖枪",
"UMP-45 | 金铋辉煌",
]
KUANGYADAXINGDONG_CASE_BLUE = [
"CZ75 | 世仇",
"P90 | 大怪兽RUSH",
"G3SG1 | 血腥迷彩",
"加利尔 AR | 破坏者",
"P250 | 污染物",
"M249 | 等高线",
"MP5-SD | 零点行动",
]
# 突围大行动
TUWEIDAXINGDONG_CASE_KNIFE = ['蝴蝶刀 | 无涂装', '蝴蝶刀 | 蓝钢', '蝴蝶刀 | 屠夫', '蝴蝶刀 | 森林 DDPAT', '蝴蝶刀 | 北方森林',
'蝴蝶刀 | 狩猎网格', '蝴蝶刀 | 枯焦之色', '蝴蝶刀 | 人工染色', '蝴蝶刀 | 都市伪装', '蝴蝶刀 | 表面淬火',
'蝴蝶刀 | 深红之网', '蝴蝶刀 | 渐变之色', '蝴蝶刀 | 噩梦之夜']
TUWEIDAXINGDONG_CASE_RED = ['P90 | 二西莫夫', 'M4A1 | 次时代']
TUWEIDAXINGDONG_CASE_PINK = ['沙漠之鹰 | 阴谋者', 'FN57 | 狩猎利器', '格洛克 | 水灵']
TUWEIDAXINGDONG_CASE_PURPLE = ['PP-野牛 | 死亡主宰者', 'CZ75 | 猛虎', '新星 | 锦鲤', 'P250 | 超新星']
TUWEIDAXINGDONG_CASE_BLUE = ['MP7 | 都市危机', '内格夫 | 沙漠精英', 'P2000 | 乳白象牙', 'SSG 08 | 无尽深海', 'UMP-45 | 迷之宫']
TUWEIDAXINGDONG_CASE_KNIFE = [
"蝴蝶刀 | 无涂装",
"蝴蝶刀 | 蓝钢",
"蝴蝶刀 | 屠夫",
"蝴蝶刀 | 森林 DDPAT",
"蝴蝶刀 | 北方森林",
"蝴蝶刀 | 狩猎网格",
"蝴蝶刀 | 枯焦之色",
"蝴蝶刀 | 人工染色",
"蝴蝶刀 | 都市伪装",
"蝴蝶刀 | 表面淬火",
"蝴蝶刀 | 深红之网",
"蝴蝶刀 | 渐变之色",
"蝴蝶刀 | 噩梦之夜",
]
TUWEIDAXINGDONG_CASE_RED = ["P90 | 二西莫夫", "M4A1 | 次时代"]
TUWEIDAXINGDONG_CASE_PINK = ["沙漠之鹰 | 阴谋者", "FN57 | 狩猎利器", "格洛克 | 水灵"]
TUWEIDAXINGDONG_CASE_PURPLE = ["PP-野牛 | 死亡主宰者", "CZ75 | 猛虎", "新星 | 锦鲤", "P250 | 超新星"]
TUWEIDAXINGDONG_CASE_BLUE = [
"MP7 | 都市危机",
"内格夫 | 沙漠精英",
"P2000 | 乳白象牙",
"SSG 08 | 无尽深海",
"UMP-45 | 迷之宫",
]
# 命悬一线
MINGXUANYIXIAN_CASE_KNIFE = ['专业手套 | 大腕', '专业手套 | 深红之网', '专业手套 | 渐变之色', '专业手套 | 狩鹿', '九头蛇手套 | 响尾蛇',
'九头蛇手套 | 红树林', '九头蛇手套 | 翡翠色调', '九头蛇手套 | 表面淬火', '摩托手套 | 交运', '摩托手套 | 嘭!',
'摩托手套 | 多边形', '摩托手套 | 玳瑁', '裹手 | 套印', '裹手 | 森林色调', '裹手 | 钴蓝骷髅', '裹手 | 防水布胶带',
'运动手套 | 双栖', '运动手套 | 欧米伽', '运动手套 | 迈阿密风云', '运动手套 | 青铜形态', '驾驶手套 | 墨绿色调',
'驾驶手套 | 王蛇', '驾驶手套 | 蓝紫格子', '驾驶手套 | 超越']
MINGXUANYIXIAN_CASE_RED = ['M4A4 | 黑色魅影', 'MP7 | 血腥运动']
MINGXUANYIXIAN_CASE_PINK = ['AUG | 湖怪鸟', 'AWP | 死神', 'USP | 脑洞大开']
MINGXUANYIXIAN_CASE_PURPLE = ['MAG-7 | SWAG-7', 'UMP-45 | 白狼', '内格夫 | 狮子鱼', '新星 | 狂野六号', '格洛克 | 城里的月光']
MINGXUANYIXIAN_CASE_BLUE = ['FN57 | 焰色反应', 'MP9 | 黑砂', 'P2000 | 都市危机', 'PP-野牛 | 黑夜暴乱', 'R8 左轮手枪 | 稳',
'SG 553 | 阿罗哈', 'XM1014 | 锈蚀烈焰']
MINGXUANYIXIAN_CASE_KNIFE = [
"专业手套 | 大腕",
"专业手套 | 深红之网",
"专业手套 | 渐变之色",
"专业手套 | 狩鹿",
"九头蛇手套 | 响尾蛇",
"九头蛇手套 | 红树林",
"九头蛇手套 | 翡翠色调",
"九头蛇手套 | 表面淬火",
"摩托手套 | 交运",
"摩托手套 | 嘭!",
"摩托手套 | 多边形",
"摩托手套 | 玳瑁",
"裹手 | 套印",
"裹手 | 森林色调",
"裹手 | 钴蓝骷髅",
"裹手 | 防水布胶带",
"运动手套 | 双栖",
"运动手套 | 欧米伽",
"运动手套 | 迈阿密风云",
"运动手套 | 青铜形态",
"驾驶手套 | 墨绿色调",
"驾驶手套 | 王蛇",
"驾驶手套 | 蓝紫格子",
"驾驶手套 | 超越",
]
MINGXUANYIXIAN_CASE_RED = ["M4A4 | 黑色魅影", "MP7 | 血腥运动"]
MINGXUANYIXIAN_CASE_PINK = ["AUG | 湖怪鸟", "AWP | 死神", "USP | 脑洞大开"]
MINGXUANYIXIAN_CASE_PURPLE = [
"MAG-7 | SWAG-7",
"UMP-45 | 白狼",
"内格夫 | 狮子鱼",
"新星 | 狂野六号",
"格洛克 | 城里的月光",
]
MINGXUANYIXIAN_CASE_BLUE = [
"FN57 | 焰色反应",
"MP9 | 黑砂",
"P2000 | 都市危机",
"PP-野牛 | 黑夜暴乱",
"R8 左轮手枪 | 稳",
"SG 553 | 阿罗哈",
"XM1014 | 锈蚀烈焰",
]
LIEKONG_CASE_KNIFE = ['求生匕首 | 无涂装', '求生匕首 | 人工染色', '求生匕首 | 北方森林', '求生匕首 | 夜色', '求生匕首 | 屠夫',
'求生匕首 | 枯焦之色', '求生匕首 | 森林 DDPAT', '求生匕首 | 深红之网', '求生匕首 | 渐变之色', '求生匕首 | 狩猎网格',
'求生匕首 | 蓝钢', '求生匕首 | 表面淬火', '求生匕首 | 都市伪装', '流浪者匕首 | 无涂装', '流浪者匕首 | 人工染色',
'流浪者匕首 | 北方森林', '流浪者匕首 | 夜色', '流浪者匕首 | 屠夫', '流浪者匕首 | 枯焦之色', '流浪者匕首 | 森林 DDPAT',
'流浪者匕首 | 深红之网', '流浪者匕首 | 渐变之色', '流浪者匕首 | 狩猎网格', '流浪者匕首 | 蓝钢', '流浪者匕首 | 表面淬火',
'流浪者匕首 | 都市伪装', '系绳匕首 | 无涂装', '系绳匕首 | 人工染色', '系绳匕首 | 北方森林', '系绳匕首 | 夜色',
'系绳匕首 | 屠夫', '系绳匕首 | 枯焦之色', '系绳匕首 | 森林 DDPAT', '系绳匕首 | 深红之网', '系绳匕首 | 渐变之色',
'系绳匕首 | 狩猎网格', '系绳匕首 | 蓝钢', '系绳匕首 | 表面淬火', '系绳匕首 | 都市伪装', '骷髅匕首 | 无涂装',
'骷髅匕首 | 人工染色', '骷髅匕首 | 北方森林', '骷髅匕首 | 夜色', '骷髅匕首 | 屠夫', '骷髅匕首 | 枯焦之色',
'骷髅匕首 | 森林 DDPAT', '骷髅匕首 | 深红之网', '骷髅匕首 | 渐变之色', '骷髅匕首 | 狩猎网格', '骷髅匕首 | 蓝钢',
'骷髅匕首 | 表面淬火', '骷髅匕首 | 都市伪装']
LIEKONG_CASE_RED = ['AK-47 | 阿努比斯军团', '沙漠之鹰 | 印花集']
LIEKONG_CASE_PINK = ['M4A4 | 齿仙', 'XM1014 | 埋葬之影', '格洛克 | 摩登时代']
LIEKONG_CASE_PURPLE = ['加利尔 AR | 凤凰商号', 'Tec-9 | 兄弟连', 'MP5-SD | 猛烈冲锋', 'MAG-7 | 北冥有鱼', 'MAC-10 | 魅惑']
LIEKONG_CASE_BLUE = ['内格夫 | 飞羽', 'SSG 08 | 主机001', 'SG 553 | 锈蚀之刃', 'PP-野牛 | 神秘碑文', 'P90 | 集装箱', 'P250 | 卡带',
'P2000 | 盘根错节']
LIEKONG_CASE_KNIFE = [
"求生匕首 | 无涂装",
"求生匕首 | 人工染色",
"求生匕首 | 北方森林",
"求生匕首 | 夜色",
"求生匕首 | 屠夫",
"求生匕首 | 枯焦之色",
"求生匕首 | 森林 DDPAT",
"求生匕首 | 深红之网",
"求生匕首 | 渐变之色",
"求生匕首 | 狩猎网格",
"求生匕首 | 蓝钢",
"求生匕首 | 表面淬火",
"求生匕首 | 都市伪装",
"流浪者匕首 | 无涂装",
"流浪者匕首 | 人工染色",
"流浪者匕首 | 北方森林",
"流浪者匕首 | 夜色",
"流浪者匕首 | 屠夫",
"流浪者匕首 | 枯焦之色",
"流浪者匕首 | 森林 DDPAT",
"流浪者匕首 | 深红之网",
"流浪者匕首 | 渐变之色",
"流浪者匕首 | 狩猎网格",
"流浪者匕首 | 蓝钢",
"流浪者匕首 | 表面淬火",
"流浪者匕首 | 都市伪装",
"系绳匕首 | 无涂装",
"系绳匕首 | 人工染色",
"系绳匕首 | 北方森林",
"系绳匕首 | 夜色",
"系绳匕首 | 屠夫",
"系绳匕首 | 枯焦之色",
"系绳匕首 | 森林 DDPAT",
"系绳匕首 | 深红之网",
"系绳匕首 | 渐变之色",
"系绳匕首 | 狩猎网格",
"系绳匕首 | 蓝钢",
"系绳匕首 | 表面淬火",
"系绳匕首 | 都市伪装",
"骷髅匕首 | 无涂装",
"骷髅匕首 | 人工染色",
"骷髅匕首 | 北方森林",
"骷髅匕首 | 夜色",
"骷髅匕首 | 屠夫",
"骷髅匕首 | 枯焦之色",
"骷髅匕首 | 森林 DDPAT",
"骷髅匕首 | 深红之网",
"骷髅匕首 | 渐变之色",
"骷髅匕首 | 狩猎网格",
"骷髅匕首 | 蓝钢",
"骷髅匕首 | 表面淬火",
"骷髅匕首 | 都市伪装",
]
LIEKONG_CASE_RED = ["AK-47 | 阿努比斯军团", "沙漠之鹰 | 印花集"]
LIEKONG_CASE_PINK = ["M4A4 | 齿仙", "XM1014 | 埋葬之影", "格洛克 | 摩登时代"]
LIEKONG_CASE_PURPLE = [
"加利尔 AR | 凤凰商号",
"Tec-9 | 兄弟连",
"MP5-SD | 猛烈冲锋",
"MAG-7 | 北冥有鱼",
"MAC-10 | 魅惑",
]
LIEKONG_CASE_BLUE = [
"内格夫 | 飞羽",
"SSG 08 | 主机001",
"SG 553 | 锈蚀之刃",
"PP-野牛 | 神秘碑文",
"P90 | 集装箱",
"P250 | 卡带",
"P2000 | 盘根错节",
]
GUANGPU_CASE_KNIFE = ['弯刀 | 外表生锈', '弯刀 | 多普勒', '弯刀 | 大马士革钢', '弯刀 | 渐变大理石', '弯刀 | 致命紫罗兰', '弯刀 | 虎牙',
'暗影双匕 | 外表生锈', '暗影双匕 | 多普勒', '暗影双匕 | 大马士革钢', '暗影双匕 | 渐变大理石', '暗影双匕 | 致命紫罗兰',
'暗影双匕 | 虎牙', '猎杀者匕首 | 外表生锈', '猎杀者匕首 | 多普勒', '猎杀者匕首 | 大马士革钢', '猎杀者匕首 | 渐变大理石',
'猎杀者匕首 | 致命紫罗兰', '猎杀者匕首 | 虎牙', '蝴蝶刀 | 外表生锈', '蝴蝶刀 | 多普勒', '蝴蝶刀 | 大马士革钢',
'蝴蝶刀 | 渐变大理石', '蝴蝶刀 | 致命紫罗兰', '蝴蝶刀 | 虎牙', '鲍伊猎刀 | 外表生锈', '鲍伊猎刀 | 多普勒',
'鲍伊猎刀 | 大马士革钢', '鲍伊猎刀 | 渐变大理石', '鲍伊猎刀 | 致命紫罗兰', '鲍伊猎刀 | 虎牙']
GUANGPU_CASE_RED = ['USP | 黑色魅影', 'AK-47 | 血腥运动']
GUANGPU_CASE_PINK = ['M4A1 | 毁灭者 2000', 'CZ75 | 相柳', 'AWP | 浮生如梦']
GUANGPU_CASE_PURPLE = ['加利尔 AR | 深红海啸', 'XM1014 | 四季', 'UMP-45 | 支架', 'MAC-10 | 绝界之行', 'M249 | 翠绿箭毒蛙']
GUANGPU_CASE_BLUE = ['沙漠之鹰 | 锈蚀烈焰', '截短霰弹枪 | 梭鲈', 'SCAR-20 | 蓝图', 'PP-野牛 | 丛林滑流', 'P250 | 涟漪', 'MP7 | 非洲部落',
'FN57 | 毛细血管']
GUANGPU_CASE_KNIFE = [
"弯刀 | 外表生锈",
"弯刀 | 多普勒",
"弯刀 | 大马士革钢",
"弯刀 | 渐变大理石",
"弯刀 | 致命紫罗兰",
"弯刀 | 虎牙",
"暗影双匕 | 外表生锈",
"暗影双匕 | 多普勒",
"暗影双匕 | 大马士革钢",
"暗影双匕 | 渐变大理石",
"暗影双匕 | 致命紫罗兰",
"暗影双匕 | 虎牙",
"猎杀者匕首 | 外表生锈",
"猎杀者匕首 | 多普勒",
"猎杀者匕首 | 大马士革钢",
"猎杀者匕首 | 渐变大理石",
"猎杀者匕首 | 致命紫罗兰",
"猎杀者匕首 | 虎牙",
"蝴蝶刀 | 外表生锈",
"蝴蝶刀 | 多普勒",
"蝴蝶刀 | 大马士革钢",
"蝴蝶刀 | 渐变大理石",
"蝴蝶刀 | 致命紫罗兰",
"蝴蝶刀 | 虎牙",
"鲍伊猎刀 | 外表生锈",
"鲍伊猎刀 | 多普勒",
"鲍伊猎刀 | 大马士革钢",
"鲍伊猎刀 | 渐变大理石",
"鲍伊猎刀 | 致命紫罗兰",
"鲍伊猎刀 | 虎牙",
]
GUANGPU_CASE_RED = ["USP | 黑色魅影", "AK-47 | 血腥运动"]
GUANGPU_CASE_PINK = ["M4A1 | 毁灭者 2000", "CZ75 | 相柳", "AWP | 浮生如梦"]
GUANGPU_CASE_PURPLE = [
"加利尔 AR | 深红海啸",
"XM1014 | 四季",
"UMP-45 | 支架",
"MAC-10 | 绝界之行",
"M249 | 翠绿箭毒蛙",
]
GUANGPU_CASE_BLUE = [
"沙漠之鹰 | 锈蚀烈焰",
"截短霰弹枪 | 梭鲈",
"SCAR-20 | 蓝图",
"PP-野牛 | 丛林滑流",
"P250 | 涟漪",
"MP7 | 非洲部落",
"FN57 | 毛细血管",
]
NO_STA_KNIFE = ['求生匕首 | 北方森林', '求生匕首 | 夜色', '求生匕首 | 枯焦之色', '流浪者匕首 | 夜色', '流浪者匕首 | 枯焦之色', '流浪者匕首 | 森林 DDPAT',
'系绳匕首 | 夜色', '系绳匕首 | 狩猎网格', '骷髅匕首 | 夜色', '骷髅匕首 | 森林 DDPAT', '骷髅匕首 | 狩猎网格']
NO_STA_KNIFE = [
"求生匕首 | 北方森林",
"求生匕首 | 夜色",
"求生匕首 | 枯焦之色",
"流浪者匕首 | 夜色",
"流浪者匕首 | 枯焦之色",
"流浪者匕首 | 森林 DDPAT",
"系绳匕首 | 夜色",
"系绳匕首 | 狩猎网格",
"骷髅匕首 | 夜色",
"骷髅匕首 | 森林 DDPAT",
"骷髅匕首 | 狩猎网格",
]
def get_wear(num: float) -> str:
if num <= FACTORY_NEW_E:
def get_wear(rand: float) -> str:
"""判断磨损度
Args:
rand (float): 随机rand
Returns:
str: 磨损名称
"""
if rand <= FACTORY_NEW_E:
return "崭新出厂"
if MINIMAL_WEAR_S <= num <= MINIMAL_WEAR_E:
if MINIMAL_WEAR_S <= rand <= MINIMAL_WEAR_E:
return "略有磨损"
if FIELD_TESTED_S <= num <= FIELD_TESTED_E:
if FIELD_TESTED_S <= rand <= FIELD_TESTED_E:
return "久经沙场"
if WELL_WORN_S <= num <= WELL_WORN_E:
if WELL_WORN_S <= rand <= WELL_WORN_E:
return "破损不堪"
return "战痕累累"
def get_color_quality(rand: float, case_name: str):
case = ""
mosun = random.random()/2 + random.random()/2
for i in pypinyin.pinyin(case_name, style=pypinyin.NORMAL):
case += ''.join(i)
case = case.upper()
CASE_KNIFE = eval(case + "_CASE_KNIFE")
CASE_RED = eval(case + "_CASE_RED")
CASE_PINK = eval(case + "_CASE_PINK")
CASE_PURPLE = eval(case + "_CASE_PURPLE")
CASE_BLUE = eval(case + "_CASE_BLUE")
if rand <= KNIFE:
skin = "罕见级(金色): " + random.choice(CASE_KNIFE)
if random.random() <= KNIFE_ST and (skin[2:4] != "手套" or skin[:2] != "裹手") and skin.split(':')[1] \
not in NO_STA_KNIFE:
skin_sp = skin.split("|")
skin = skin_sp[0] + "(StatTrak™) | " + skin_sp[1]
elif KNIFE < rand <= RED:
skin = "隐秘级(红色): " + random.choice(CASE_RED)
if random.random() <= RED_ST:
skin_sp = skin.split("|")
skin = skin_sp[0] + "(StatTrak™) | " + skin_sp[1]
elif RED < rand <= PINK:
skin = "保密级(粉色): " + random.choice(CASE_PINK)
if random.random() <= PINK_ST:
skin_sp = skin.split("|")
skin = skin_sp[0] + "(StatTrak™) | " + skin_sp[1]
elif PINK < rand <= PURPLE:
skin = "受限级(紫色): " + random.choice(CASE_PURPLE)
if random.random() <= PURPLE_ST:
skin_sp = skin.split("|")
skin = skin_sp[0] + "(StatTrak™) | " + skin_sp[1]
else:
skin = "军规级(蓝色): " + random.choice(CASE_BLUE)
if random.random() <= BLUE_ST:
skin_sp = skin.split("|")
skin = skin_sp[0] + "(StatTrak™) | " + skin_sp[1]
if skin.find("(") != -1:
cpskin = skin.split(":")[1]
ybskin = cpskin.split("|")
temp_skin = ybskin[0].strip()[:-11] + " | " + ybskin[1].strip()
else:
temp_skin = skin.split(":")[1].strip()
# 崭新 -> 略磨
if temp_skin in [] or temp_skin.find('渐变之色') != -1 or temp_skin.find('多普勒') != -1 or temp_skin.find('虎牙') != -1\
or temp_skin.find('渐变大理石') != -1:
mosun = random.uniform(FACTORY_NEW_S, MINIMAL_WEAR_E) / 2 + random.uniform(FACTORY_NEW_S, MINIMAL_WEAR_E) / 2
# 崭新 -> 久经
if temp_skin in ['沙漠之鹰 | 阴谋者', '新星 | 锦鲤'] or temp_skin.find('屠夫') != -1:
mosun = random.uniform(FACTORY_NEW_S, FIELD_TESTED_E) / 2 + random.uniform(FACTORY_NEW_S, FIELD_TESTED_E) / 2
# 崭新 -> 破损
if temp_skin in ['UMP-45 | 迷之宫', 'P250 | 超新星', '系绳匕首 | 深红之网', 'M249 | 翠绿箭毒蛙', 'AK-47 | 血腥运动']:
mosun = random.uniform(FACTORY_NEW_S, WELL_WORN_E) / 2 + random.uniform(FACTORY_NEW_S, WELL_WORN_E) / 2
# 破损 -> 战痕
if temp_skin in [] or temp_skin.find('外表生锈') != -1:
mosun = random.uniform(WELL_WORN_S, BATTLE_SCARED_E) / 2 + random.uniform(WELL_WORN_S, BATTLE_SCARED_E) / 2
if mosun > MINIMAL_WEAR_E:
for _ in range(2):
if random.random() < 5:
if random.random() < 0.2:
mosun /= 3
else:
mosun /= 2
break
skin += " (" + get_wear(mosun) + ")"
return skin, mosun
def random_color_and_st(rand: float) -> Tuple[str, bool]:
"""获取皮肤品质及是否暗金
# M249(StatTrak™) | 等高线
Args:
rand (float): 随机rand
Returns:
Tuple[str, bool]: 品质,是否暗金
"""
if rand <= KNIFE:
if random.random() <= KNIFE_ST:
return ("KNIFE", True)
return ("KNIFE", False)
elif KNIFE < rand <= RED:
if random.random() <= RED_ST:
return ("RED", True)
return ("RED", False)
elif RED < rand <= PINK:
if random.random() <= PINK_ST:
return ("PINK", True)
return ("PINK", False)
elif PINK < rand <= PURPLE:
if random.random() <= PURPLE_ST:
return ("PURPLE", True)
return ("PURPLE", False)
else:
if random.random() <= BLUE_ST:
return ("BLUE", True)
return ("BLUE", False)
async def random_skin(num: int, case_name: str) -> List[Tuple[BuffSkin, float]]:
"""
随机抽取皮肤
"""
color_map = {}
for _ in range(num):
rand = random.random()
# 尝试降低磨损
if rand > MINIMAL_WEAR_E:
for _ in range(2):
if random.random() < 0.5:
logger.debug(f"[START]开箱随机磨损触发降低磨损条件: {rand}")
if random.random() < 0.2:
rand /= 3
else:
rand /= 2
logger.debug(f"[END]开箱随机磨损触发降低磨损条件: {rand}")
break
abrasion = get_wear(rand)
logger.debug(f"开箱随机磨损: {rand} | {abrasion}")
color, is_stattrak = random_color_and_st(rand)
if not color_map.get(color):
color_map[color] = {}
if is_stattrak:
if not color_map[color].get(f"{abrasion}_st"):
color_map[color][f"{abrasion}_st"] = []
color_map[color][f"{abrasion}_st"].append(rand)
else:
if not color_map[color].get(abrasion):
color_map[color][f"{abrasion}"] = []
color_map[color][f"{abrasion}"].append(rand)
skin_list = []
for color in color_map:
for abrasion in color_map[color]:
rand_list = color_map[color][abrasion]
is_stattrak = "_st" in abrasion
abrasion = abrasion.replace("_st", "")
skin_list_ = await BuffSkin.random_skin(
len(rand_list), color, abrasion, is_stattrak, case_name
)
skin_list += [(skin, rand) for skin, rand in zip(skin_list_, rand_list)]
return skin_list
# M249(StatTrak™) | 等高线
-2
View File
@@ -1,2 +0,0 @@
from .open_cases_user import *
from .buff_prices import *
+50
View File
@@ -0,0 +1,50 @@
import random
from typing import List, Optional
from tortoise import fields
from tortoise.contrib.postgres.functions import Random
from services.db_context import Model
class BuffSkin(Model):
id = fields.IntField(pk=True, generated=True, auto_increment=True)
"""自增id"""
case_name = fields.CharField(255)
"""箱子名称"""
name = fields.CharField(255)
"""武器/手套/刀名称"""
skin_name = fields.CharField(255)
"""皮肤名称"""
is_stattrak = fields.BooleanField(default=False)
"""是否暗金(计数)"""
abrasion = fields.CharField(255)
"""磨损度"""
color = fields.CharField(255)
"""颜色(品质)"""
skin_price = fields.FloatField(default=0)
"""皮肤价格"""
create_time = fields.DatetimeField(auto_add_now=True)
"""创建日期"""
update_time = fields.DatetimeField(auto_add=True)
"""更新日期"""
class Meta:
table = "buff_skin"
table_description = "Buff皮肤数据表"
@classmethod
async def random_skin(
cls,
num: int,
color: str,
abrasion: str,
is_stattrak: bool = False,
case_name: Optional[str] = None,
) -> List["BuffSkin"]:
query = cls
if case_name:
query = query.filter(case_name=case_name)
query = query.filter(abrasion=abrasion, is_stattrak=is_stattrak, color=color)
return await query.annotate(rand=Random()).limit(num) # type:ignore
+22 -16
View File
@@ -4,7 +4,6 @@ from services.db_context import Model
class OpenCasesUser(Model):
__tablename__ = "open_cases_users"
id = fields.IntField(pk=True, generated=True, auto_increment=True)
"""自增id"""
@@ -12,40 +11,47 @@ class OpenCasesUser(Model):
"""用户id"""
group_id = fields.BigIntField()
"""群聊id"""
total_count = fields.IntField(default=0)
total_count: int = fields.IntField(default=0)
"""总开启次数"""
blue_count = fields.IntField(default=0)
blue_count: int = fields.IntField(default=0)
"""蓝色"""
blue_st_count = fields.IntField(default=0)
blue_st_count: int = fields.IntField(default=0)
"""蓝色暗金"""
purple_count = fields.IntField(default=0)
purple_count: int = fields.IntField(default=0)
"""紫色"""
purple_st_count = fields.IntField(default=0)
purple_st_count: int = fields.IntField(default=0)
"""紫色暗金"""
pink_count = fields.IntField(default=0)
pink_count: int = fields.IntField(default=0)
"""粉色"""
pink_st_count = fields.IntField(default=0)
pink_st_count: int = fields.IntField(default=0)
"""粉色暗金"""
red_count = fields.IntField(default=0)
red_count: int = fields.IntField(default=0)
"""紫色"""
red_st_count = fields.IntField(default=0)
red_st_count: int = fields.IntField(default=0)
"""紫色暗金"""
knife_count = fields.IntField(default=0)
knife_count: int = fields.IntField(default=0)
"""金色"""
knife_st_count = fields.IntField(default=0)
knife_st_count: int = fields.IntField(default=0)
"""金色暗金"""
spend_money = fields.IntField(default=0)
spend_money: int = fields.IntField(default=0)
"""花费金币"""
make_money = fields.IntField(default=0)
make_money: float = fields.FloatField(default=0)
"""赚取金币"""
today_open_total = fields.IntField(default=0)
today_open_total: int = fields.IntField(default=0)
"""今日开箱数量"""
open_cases_time_last = fields.DatetimeField()
"""最后开箱日期"""
knifes_name = fields.TextField(default="")
knifes_name: str = fields.TextField(default="")
"""已获取金色"""
class Meta:
table = "open_cases_users"
table_description = "开箱统计数据表"
unique_together = ("user_qq", "group_id")
@classmethod
async def _run_script(cls):
await cls.raw(
"alter table open_cases_users alter COLUMN make_money type float;"
)
"""将make_money字段改为float"""
+178 -269
View File
@@ -1,8 +1,10 @@
import asyncio
import random
from datetime import datetime, timedelta
from datetime import datetime
from typing import Union
import pypinyin
from nonebot.adapters.onebot.v11 import Message
from PIL import Image
from configs.config import Config
@@ -16,164 +18,147 @@ from utils.utils import cn2py
from .config import *
from .models.buff_prices import BuffPrice
from .models.open_cases_user import OpenCasesUser
from .utils import get_price
RESULT_MESSAGE = {
"BLUE": ["这样看着才舒服", "是自己人,大伙把刀收好", "非常舒适~"],
"PURPLE": ["还行吧,勉强接受一下下", "居然不是蓝色,太假了", "运气-1-1-1-1-1..."],
"PINK": ["开始不适....", "你妈妈买菜必涨价!涨三倍!", "你最近不适合出门,真的"],
"RED": ["已经非常不适", "好兄弟你开的什么箱子啊,一般箱子不是只有蓝色的吗", "开始拿阳寿开箱子了?"],
"KNIFE": ["你的好运我收到了,你可以去喂鲨鱼了", "最近该吃啥就迟点啥吧,哎,好好的一个人怎么就....哎", "众所周知,欧皇寿命极短."],
}
COLOR2NAME = {"BLUE": "军规", "PURPLE": "受限", "PINK": "保密", "RED": "隐秘", "KNIFE": "罕见"}
COLOR2CN = {"BLUE": "蓝", "PURPLE": "紫", "PINK": "粉", "RED": "红", "KNIFE": "金"}
async def open_case(user_qq: int, group: int, case_name: str = "狂牙大行动") -> str:
def add_count(user: OpenCasesUser, skin: BuffSkin):
if skin.color == "BLUE":
if skin.is_stattrak:
user.blue_st_count += 1
else:
user.blue_count += 1
elif skin.color == "PURPLE":
if skin.is_stattrak:
user.purple_st_count += 1
else:
user.purple_count += 1
elif skin.color == "PINK":
if skin.is_stattrak:
user.pink_st_count += 1
else:
user.pink_count += 1
elif skin.color == "RED":
if skin.is_stattrak:
user.red_st_count += 1
else:
user.red_count += 1
elif skin.color == "KNIFE":
if skin.is_stattrak:
user.knife_st_count += 1
else:
user.knife_count += 1
user.today_open_total += 1
user.total_count += 1
user.make_money += skin.skin_price
user.spend_money += 17
async def get_user_max_count(user_qq: int, group_id: int) -> int:
"""获取用户每日最大开箱次数
Args:
user_qq (int): 用户id
group_id (int): 群号
Returns:
int: 最大开箱次数
"""
user, _ = await SignGroupUser.get_or_create(user_qq=user_qq, group_id=group_id)
impression = int(user.impression)
initial_open_case_count = Config.get_config("open_cases", "INITIAL_OPEN_CASE_COUNT")
each_impression_add_count = Config.get_config(
"open_cases", "EACH_IMPRESSION_ADD_COUNT"
)
return int(initial_open_case_count + impression / each_impression_add_count) # type: ignore
async def open_case(
user_qq: int, group_id: int, case_name: str = "狂牙大行动"
) -> Union[str, Message]:
"""开箱
Args:
user_qq (int): 用户id
group_id (int): 群号
case_name (str, optional): 武器箱名称. Defaults to "狂牙大行动".
Returns:
Union[str, Message]: 回复消息
"""
if case_name not in ["狂牙大行动", "突围大行动", "命悬一线", "裂空", "光谱"]:
return "武器箱未收录"
knifes_flag = False
# lan zi fen hong jin price
uplist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0]
case = ""
for i in pypinyin.pinyin(case_name, style=pypinyin.NORMAL):
case += "".join(i)
user, _ = await SignGroupUser.get_or_create(user_qq=user_qq, group_id=group)
impression = user.impression
rand = random.random()
await OpenCasesUser.get_or_none(user_qq=user_qq, group_id=group)
# user, _ = await OpenCasesUser.get_or_create(user_qq=user_qq, group_id=group)
user = await OpenCasesUser.get_or_none(user_qq=user_qq, group_id=group)
logger.debug(f"尝试开启武器箱: {case_name}", "开箱", user_qq, group_id)
case = cn2py(case_name)
user = await OpenCasesUser.get_or_none(user_qq=user_qq, group_id=group_id)
if not user:
user = await OpenCasesUser.create(
user_qq=user_qq, group_id=group, open_cases_time_last=datetime.now()
user_qq=user_qq, group_id=group_id, open_cases_time_last=datetime.now()
)
max_count = await get_user_max_count(user_qq, group_id)
# 一天次数上限
if user.today_open_total >= int(
Config.get_config("open_cases", "INITIAL_OPEN_CASE_COUNT")
+ int(impression) / Config.get_config("open_cases", "EACH_IMPRESSION_ADD_COUNT")
):
if user.today_open_total >= max_count:
return _handle_is_MAX_COUNT()
skin, mosun = get_color_quality(rand, case_name)
# 调侃
if skin[:2] == "军规":
if skin.find("StatTrak") == -1:
uplist[0] = 1
else:
uplist[1] = 1
ridicule_result = random.choice(["这样看着才舒服", "是自己人,大伙把刀收好", "非常舒适~"])
if skin[:2] == "受限":
if skin.find("StatTrak") == -1:
uplist[2] = 1
else:
uplist[3] = 1
ridicule_result = random.choice(
["还行吧,勉强接受一下下", "居然不是蓝色,太假了", "运气-1-1-1-1-1..."]
skin_list = await random_skin(1, case_name)
if not skin_list:
return "未抽取到任何皮肤..."
skin, rand = skin_list[0]
rand = str(rand)[:11]
add_count(user, skin)
ridicule_result = random.choice(RESULT_MESSAGE[skin.color])
price_result = skin.skin_price
if skin.color == "KNIFE":
user.knifes_name = (
user.knifes_name
+ f"{case}||{skin.name}{'(StatTrak™)' if skin.is_stattrak else ''} | {skin.skin_name} ({skin.abrasion}) 磨损:{rand}, 价格:{skin.skin_price},"
)
if skin[:2] == "保密":
if skin.find("StatTrak") == -1:
uplist[4] = 1
else:
uplist[5] = 1
ridicule_result = random.choice(["开始不适....", "你妈妈买菜必涨价!涨三倍!", "你最近不适合出门,真的"])
if skin[:2] == "隐秘":
if skin.find("StatTrak") == -1:
uplist[6] = 1
else:
uplist[7] = 1
ridicule_result = random.choice(
["已经非常不适", "好兄弟你开的什么箱子啊,一般箱子不是只有蓝色的吗", "开始拿阳寿开箱子了?"]
)
if skin[:2] == "罕见":
knifes_flag = True
if skin.find("StatTrak") == -1:
uplist[8] = 1
else:
uplist[9] = 1
ridicule_result = random.choice(
["你的好运我收到了,你可以去喂鲨鱼了", "最近该吃啥就迟点啥吧,哎,好好的一个人怎么就....哎", "众所周知,欧皇寿命极短."]
)
if skin.find("(") != -1:
cskin = skin.split("(")
skin = cskin[0].strip() + "(" + cskin[1].strip()
skin = skin.split("|")[0].strip() + " | " + skin.split("|")[1].strip()
# 价格
if skin.find("无涂装") == -1:
search_name = skin[9:]
else:
search_name = skin[9 : skin.rfind("(")].strip()
price_result = 0
if data := await BuffPrice.get_or_none(skin_name=search_name):
if data.skin_price != 0:
price_result = data.skin_price
logger.info("数据库查询到价格: ", data.skin_price)
uplist[10] = data.skin_price
else:
price = -1
price_result = "未查询到"
price_list, status = await get_price(skin[9:])
if price_list not in ["访问超时! 请重试或稍后再试!", "访问失败!"]:
for price_l in price_list[1:]:
pcp = price_l.split(":")
if pcp[0] == skin[9:]:
price = float(pcp[1].strip())
break
if price != -1:
logger.info("存储入数据库---->{price}")
uplist[10] = price
price_result = str(price)
data.skin_price = price
data.update_date = datetime.now()
await data.save(update_fields=["skin_price", "update_date"])
# sp = skin.split("|")
# cskin_word = sp[1][:sp[1].find("(") - 1].strip()
if knifes_flag:
await user.update(
knifes_name=user.knifes_name
+ f"{case}||{skin.split(':')[1].strip()} 磨损:{str(mosun)[:11]}, 价格:{uplist[10]},"
).apply()
cskin_word = skin.split(":")[1].replace("|", "-").replace("(StatTrak™)", "")
cskin_word = cskin_word[: cskin_word.rfind("(")].strip()
skin_name = cn2py(cskin_word.replace("|", "-").replace("(StatTrak™)", "").strip())
img = image(IMAGE_PATH / "cases" / case / f"{skin_name}.png")
# if knifes_flag:
# await user.update(
# knifes_name=user.knifes_name + f"{skin} 磨损:{mosun}, 价格:{uplist[10]}"
# ).apply()
if await update_user_total(user, uplist):
logger.info(
f"qq:{user_qq} 群:{group} 开启{case_name}武器箱 获得 {skin} 磨损:{mosun}, 价格:{uplist[10]}, 数据更新成功"
)
else:
logger.warning(
f"qq:{user_qq} 群:{group} 开启{case_name}武器箱 获得 {skin} 磨损:{mosun}, 价格:{uplist[10]}, 数据更新失败"
)
user, _ = await OpenCasesUser.get_or_create(user_qq=user_qq, group_id=group)
over_count = (
int(
Config.get_config("open_cases", "INITIAL_OPEN_CASE_COUNT")
+ int(impression)
/ Config.get_config("open_cases", "EACH_IMPRESSION_ADD_COUNT")
)
- user.today_open_total
img_path = (
IMAGE_PATH
/ "cases"
/ case
/ f"{cn2py(skin.name)} - {cn2py(skin.skin_name)}.png"
)
logger.info(
f"开启{case_name}武器箱获得 {skin.name}{'(StatTrak™)' if skin.is_stattrak else ''} | {skin.skin_name} ({skin.abrasion}) 磨损: [{rand}] 价格: {skin.skin_price}",
"开箱",
user_qq,
group_id,
)
await user.save()
over_count = max_count - user.today_open_total
return (
f"开启{case_name}武器箱.\n剩余开箱次数:{over_count}.\n" + img + "\n" + f"皮肤:{skin}\n"
f"磨损:{mosun:.9f}\n"
f"开启{case_name}武器箱.\n剩余开箱次数:{over_count}.\n"
+ image(img_path)
+ "\n"
+ f"皮肤:[{COLOR2NAME[skin.color]}]{skin.name}{'(StatTrak™)' if skin.is_stattrak else ''} | {skin.skin_name} ({skin.abrasion})\n"
f"磨损:{rand}\n"
f"价格:{price_result}\n"
f"{ridicule_result}"
f":{ridicule_result}"
)
async def open_shilian_case(user_qq: int, group: int, case_name: str, num: int = 10):
user, _ = await OpenCasesUser.get_or_create(user_qq=user_qq, group_id=group)
sign_user, _ = await SignGroupUser.get_or_create(user_qq=user_qq, group_id=group)
impression = sign_user.impression
max_count = int(
Config.get_config("open_cases", "INITIAL_OPEN_CASE_COUNT")
+ int(impression) / Config.get_config("open_cases", "EACH_IMPRESSION_ADD_COUNT")
)
async def open_multiple_case(
user_qq: int, group_id: int, case_name: str, num: int = 10
):
user, _ = await OpenCasesUser.get_or_create(user_qq=user_qq, group_id=group_id)
max_count = await get_user_max_count(user_qq, group_id)
if user.today_open_total >= max_count:
return _handle_is_MAX_COUNT()
if max_count - user.today_open_total < num:
return (
f"今天开箱次数不足{num}次噢,请单抽试试看(也许单抽运气更好?)"
f"\n剩余开箱次数:{max_count - user.today_open_total}"
f"\n剩余开箱次数:{max_count - user.today_open_total}"
)
user.total_count = user.total_count + num
user.spend_money = user.spend_money + 17 * num
user.today_open_total = user.today_open_total + num
await user.save(update_fields=["total_count", "spend_money", "today_open_total"])
if num < 5:
h = 270
elif num % 5 == 0:
@@ -181,149 +166,73 @@ async def open_shilian_case(user_qq: int, group: int, case_name: str, num: int =
else:
h = 270 * int(num / 5) + 270
case = cn2py(case_name)
# lan zi fen hong jin
# skin_list = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
# lan zi fen hong jin price
uplist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0]
skin_count = {}
img_list = []
name_list = ["蓝", "蓝(暗金)", "紫", "紫(暗金)", "粉", "粉(暗金)", "红", "红(暗金)", "金", "金(暗金)"]
for _ in range(num):
knifes_flag = False
rand = random.random()
skin, mosun = get_color_quality(rand, case_name)
if skin[:2] == "军规":
if skin.find("StatTrak") == -1:
uplist[0] += 1
else:
uplist[1] += 1
if skin[:2] == "受限":
if skin.find("StatTrak") == -1:
uplist[2] += 1
else:
uplist[3] += 1
if skin[:2] == "保密":
if skin.find("StatTrak") == -1:
uplist[4] += 1
else:
uplist[5] += 1
if skin[:2] == "隐秘":
if skin.find("StatTrak") == -1:
uplist[6] += 1
else:
uplist[7] += 1
if skin[:2] == "罕见":
knifes_flag = True
if skin.find("StatTrak") == -1:
uplist[8] += 1
else:
uplist[9] += 1
if skin.find("(") != -1:
cskin = skin.split("(")
skin = cskin[0].strip() + "(" + cskin[1].strip()
skin = skin.split("|")[0].strip() + " | " + skin.split("|")[1].strip()
# 价格
if skin.find("无涂装") == -1:
search_name = skin[9:]
else:
search_name = skin[9 : skin.rfind("(")].strip()
if dbprice := await BuffPrice.get_or_none(skin_name=search_name):
if dbprice.skin_price != 0:
price_result = dbprice.skin_price
uplist[10] += price_result
else:
price_result = "未查询到"
if knifes_flag:
await user.update(
knifes_name=user.knifes_name
+ f"{case}||{skin.split(':')[1].strip()} 磨损:{str(mosun)[:11]}, 价格:{dbprice.skin_price},"
).apply()
cskin_word = skin.split(":")[1].replace("|", "-").replace("(StatTrak™)", "")
cskin_word = cskin_word[: cskin_word.rfind("(")].strip()
skin_name = ""
for i in pypinyin.pinyin(
cskin_word.replace("|", "-").replace("(StatTrak™)", "").strip(),
style=pypinyin.NORMAL,
):
skin_name += "".join(i)
wImg = BuildImage(200, 270, 200, 200)
wImg.paste(
alpha2white_pil(
Image.open(IMAGE_PATH / "cases" / case / f"{skin_name}.png").resize(
(200, 200), Image.ANTIALIAS
)
),
(0, 0),
skin_list = await random_skin(num, case_name)
if not skin_list:
return "未抽取到任何皮肤..."
total_price = 0
for skin, rand in skin_list:
total_price += skin.skin_price
rand = str(rand)[:11]
add_count(user, skin)
color_name = COLOR2CN[skin.color]
if skin.is_stattrak:
color_name += "(暗金)"
if not skin_count.get(color_name):
skin_count[color_name] = 0
skin_count[color_name] += 1
if skin.color == "KNIFE":
user.knifes_name = (
user.knifes_name
+ f"{case}||{skin.name}{'(StatTrak™)' if skin.is_stattrak else ''} | {skin.skin_name} ({skin.abrasion}) 磨损:{rand}, 价格:{skin.skin_price},"
)
wImg.text((5, 200), skin)
wImg.text((5, 220), f"磨损:{str(mosun)[:9]}")
wImg.text((5, 240), f"价格:{price_result}")
img_list.append(wImg)
logger.info(
f"USER {user_qq} GROUP {group} 开启{case_name}武器箱 获得 {skin} 磨损:{mosun}, 价格:{uplist[10]}"
)
if await update_user_total(user, uplist, 0):
logger.info(
f"USER {user_qq} GROUP {group} 开启{case_name}武器箱 {num} 次, 数据更新成功"
)
else:
logger.warning(
f"USER {user_qq} GROUP {group} 开启{case_name}武器箱 {num} 次, 价格:{uplist[10]}, 数据更新失败"
)
# markImg = BuildImage(1000, h, 200, 270)
# for img in img_list:
# markImg.paste(img)
markImg = await asyncio.get_event_loop().run_in_executor(
None, paste_markImg, h, img_list
)
over_count = max_count - user.today_open_total
result = ""
for i in range(len(name_list)):
if uplist[i]:
result += f"[{name_list[i]}:{uplist[i]}] "
return (
f"开启{case_name}武器箱\n剩余开箱次数:{over_count}\n"
+ image(b64=markImg.pic2bs4())
+ "\n"
+ result[:-1]
+ f"\n总获取金额:{uplist[-1]:.2f}\n总花费:{17 * num}"
)
def paste_markImg(h: int, img_list: list):
wImg = BuildImage(200, 270, 200, 200)
await wImg.apaste(
alpha2white_pil(
Image.open(
IMAGE_PATH
/ "cases"
/ case
/ f"{cn2py(skin.name)} - {cn2py(skin.skin_name)}.png"
).resize((200, 200), Image.ANTIALIAS)
),
(0, 0),
)
await wImg.atext(
(5, 200),
f"{skin.name}{'(StatTrak™)' if skin.is_stattrak else ''} | {skin.skin_name} ({skin.abrasion})",
)
await wImg.atext((5, 220), f"磨损:{rand}")
await wImg.atext((5, 240), f"价格:{skin.skin_price}")
img_list.append(wImg)
logger.info(
f"开启{case_name}武器箱获得 {skin.name}{'(StatTrak™)' if skin.is_stattrak else ''} | {skin.skin_name} ({skin.abrasion}) 磨损: [{rand}] 价格: {skin.skin_price}",
"开箱",
user_qq,
group_id,
)
await user.save()
markImg = BuildImage(1000, h, 200, 270)
for img in img_list:
markImg.paste(img)
return markImg
over_count = max_count - user.today_open_total
result = ""
for color_name in skin_count:
result += f"[{color_name}:{skin_count[color_name]}] "
return (
f"开启{case_name}武器箱\n剩余开箱次数:{over_count}\n"
+ image(markImg.pic2bs4())
+ "\n"
+ result[:-1]
+ f"\n总获取金额:{total_price:.2f}\n总花费:{17 * num}"
)
def _handle_is_MAX_COUNT() -> str:
return f"今天已达开箱上限了喔,明天再来吧\n(提升好感度可以增加每日开箱数 #疯狂暗示)"
async def update_user_total(user: OpenCasesUser, up_list: list, num: int = 1) -> bool:
try:
await user.update_or_create(
total_count=user.total_count + num,
blue_count=user.blue_count + up_list[0],
blue_st_count=user.blue_st_count + up_list[1],
purple_count=user.purple_count + up_list[2],
purple_st_count=user.purple_st_count + up_list[3],
pink_count=user.pink_count + up_list[4],
pink_st_count=user.pink_st_count + up_list[5],
red_count=user.red_count + up_list[6],
red_st_count=user.red_st_count + up_list[7],
knife_count=user.knife_count + up_list[8],
knife_st_count=user.knife_st_count + up_list[9],
spend_money=user.spend_money + 17 * num,
make_money=user.make_money + up_list[10],
today_open_total=user.today_open_total + num,
open_cases_time_last=datetime.now(),
)
return True
except:
return False
async def total_open_statistics(user_qq: int, group: int) -> str:
user, _ = await OpenCasesUser.get_or_create(user_qq=user_qq, group_id=group)
return (
+84 -18
View File
@@ -1,23 +1,25 @@
import os
from asyncio.exceptions import TimeoutError
from datetime import datetime, timedelta
from datetime import datetime
from typing import Optional
from nonebot.adapters.onebot.v11 import ActionFailed
import nonebot
from configs.config import Config
from configs.path_config import IMAGE_PATH
from services.log import logger
from utils.http_utils import AsyncHttpx
from utils.manager import group_manager
from utils.utils import cn2py, get_bot
from utils.utils import broadcast_group, cn2py
from .config import *
from .models.buff_prices import BuffPrice
from .models.buff_skin import BuffSkin
from .models.open_cases_user import OpenCasesUser
url = "https://buff.163.com/api/market/goods"
# proxies = 'http://49.75.59.242:3128'
driver = nonebot.get_driver()
async def util_get_buff_price(case_name: str = "狂牙大行动") -> str:
cookie = {"session": Config.get_config("open_cases", "COOKIE")}
@@ -255,22 +257,86 @@ async def get_price(d_name):
return result[:-1], 999
async def update_count_daily():
async def reset_count_daily():
"""
重置每日开箱
"""
try:
await OpenCasesUser.all().update(today_open_total=0)
bot = get_bot()
gl = await bot.get_group_list()
gl = [g["group_id"] for g in gl]
for g in gl:
try:
await bot.send_group_msg(
group_id=g, message="[[_task|open_case_reset_remind]]今日开箱次数重置成功"
)
except ActionFailed:
logger.warning(f"{g} 群被禁言,无法发送 开箱重置提醒")
logger.info("今日开箱次数重置成功")
await broadcast_group(
"[[_task|open_case_reset_remind]]今日开箱次数重置成功", log_cmd="开箱重置提醒"
)
except Exception as e:
logger.error(f"开箱重置错误 e:{e}")
logger.error(f"开箱重置错误", e=e)
def get_color(case_name: str, name: str, skin_name: str) -> Optional[str]:
case_py = cn2py(case_name).upper()
color_map = {}
color_map["KNIFE"] = eval(case_py + "_CASE_KNIFE")
color_map["RED"] = eval(case_py + "_CASE_RED")
color_map["PINK"] = eval(case_py + "_CASE_PINK")
color_map["PURPLE"] = eval(case_py + "_CASE_PURPLE")
color_map["BLUE"] = eval(case_py + "_CASE_BLUE")
for key in color_map:
for skin in color_map[key]:
if name in skin and skin_name in skin:
return key
return None
@driver.on_startup
async def _():
"""
将旧表数据移动到新表
"""
if not await BuffSkin.first() and await BuffPrice.first():
logger.debug("开始移动旧表数据 BuffPrice -> BuffSkin")
id2name = {1: "狂牙大行动", 2: "突围大行动", 3: "命悬一线", 4: "裂空", 5: "光谱"}
data_list: List[BuffSkin] = []
for data in await BuffPrice.all():
logger.debug(f"移动旧表数据: {data.skin_name}")
case_name = id2name[data.case_id]
name = data.skin_name
is_stattrak = "StatTrak" in name
name = name.replace("(★ StatTrak™)", "").replace("(StatTrak™)", "").strip()
name, skin_name = name.split("|")
abrasion = "无涂装"
if "(" in skin_name:
skin_name, abrasion = skin_name.split("(")
if abrasion.endswith(")"):
abrasion = abrasion[:-1]
color = get_color(case_name, name.strip(), skin_name.strip())
if not color:
search_list = [
x
for x in data_list
if x.skin_name == skin_name.strip() and x.name == name.strip()
]
if search_list:
color = get_color(
case_name, search_list[0].name, search_list[0].skin_name
)
if not color:
logger.debug(
f"箱子: [{case_name}] 皮肤: [{name}|{skin_name}] 未获取到皮肤品质,跳过..."
)
continue
data_list.append(
BuffSkin(
case_name=case_name,
name=name.strip(),
skin_name=skin_name.strip(),
is_stattrak=is_stattrak,
abrasion=abrasion.strip(),
skin_price=data.skin_price,
color=color,
create_time=datetime.now(),
update_time=datetime.now(),
)
)
await BuffSkin.bulk_create(data_list, batch_size=10)
logger.debug("完成移动旧表数据 BuffPrice -> BuffSkin")
# 蝴蝶刀(★) | 噩梦之夜 (久经沙场)