Delete plugins directory

This commit is contained in:
HibiKier
2021-05-20 19:18:32 +08:00
committed by GitHub
parent b4aef2bba6
commit a9f2035041
477 changed files with 0 additions and 12952 deletions
-181
View File
@@ -1,181 +0,0 @@
from nonebot import on_command
from util.utils import FreqLimiter, scheduler, get_message_text, is_number
from nonebot.adapters.cqhttp.permission import GROUP
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, GroupMessageEvent, MessageEvent
from nonebot.permission import SUPERUSER
import random
from nonebot.plugin import MatcherGroup
import re
from .open_cases_c import open_case, total_open_statistics, group_statistics, my_knifes_name, open_shilian_case
from .utils import util_get_buff_price, util_get_buff_img, update_count_daily
__plugin_name__ = '开箱'
__plugin_usage__ = (
'用法:\n'
'看看你的人品罢了\n'
'目前只支持\n\t'
'1.狂牙大行动武器箱\n\t'
'2.突围大行动武器箱\n\t'
'3.命悬一线武器箱\n\t'
'4.裂空武器箱\n\t'
'5.光谱武器箱\n\t'
'示例:小真寻开箱 突围大行动(不输入指定武器箱则随机)\n'
'示例:我的开箱(开箱统计)\n'
'示例:群开箱统计\n'
'示例:我的金色'
)
_flmt = FreqLimiter(3)
cases_name = ['狂牙大行动', '突围大行动', '命悬一线', '裂空']
cases_matcher_group = MatcherGroup(priority=5, permission=GROUP, block=True)
k_open_case = cases_matcher_group.on_command("开箱")
@k_open_case.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
if str(event.get_message()).strip() in ['帮助']:
await k_open_case.finish(__plugin_usage__)
if not _flmt.check(event.user_id):
await k_open_case.finish('着什么急啊,慢慢来!', at_sender=True)
_flmt.start_cd(event.user_id)
case_name = get_message_text(event.json())
if case_name:
result = await open_case(event.user_id, event.group_id, case_name)
else:
result = await open_case(event.user_id, event.group_id, random.choice(cases_name))
await k_open_case.finish(result, at_sender=True)
total_case_data = cases_matcher_group.on_command("我的开箱", aliases={'开箱统计', '开箱查询', '查询开箱'})
@total_case_data.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
await total_case_data.finish(
await total_open_statistics(event.user_id, event.group_id),
at_sender=True,
)
group_open_case_statistics = cases_matcher_group.on_command("群开箱统计")
@group_open_case_statistics.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
await group_open_case_statistics.finish(await group_statistics(event.group_id))
my_kinfes = on_command("我的金色", priority=1, permission=GROUP, block=True)
@my_kinfes.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
await my_kinfes.finish(await my_knifes_name(event.user_id, event.group_id), at_sender=True)
open_shilian = cases_matcher_group.on_regex(".*连开箱")
@open_shilian.handle()
async def _(bot: Bot, event: GroupMessageEvent, state: T_State):
# if not _flmt.check(event.user_id):
# await k_open_case.finish('着什么急啊,慢慢来!', at_sender=True)
_flmt.start_cd(event.user_id)
msg = get_message_text(event.json())
rs = re.search(r'(.*)连开箱(.*)', msg)
if rs:
num = rs.group(1).strip()
if is_number(num) or num_dict.get(num):
try:
num = num_dict[num]
except KeyError:
num = int(num)
if num > 30:
await open_shilian.finish('开箱次数不要超过30啊笨蛋!', at_sender=True)
else:
await open_shilian.finish('必须要是数字切不要超过30啊笨蛋!中文也可!', at_sender=True)
case_name = rs.group(2).strip()
if case_name.find('武器箱') != -1:
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), at_sender=True)
# await open_shilian.send("嘟嘟嘟...开箱中...")
# num = 10
# if str(state["_prefix"]["raw_command"]).find('十') != -1:
# num = 10
# elif str(state["_prefix"]["raw_command"]).find('五') != -1:
# num = 5
# if case_name:
# await open_shilian.finish(await open_shilian_case(event.user_id, event.group_id, case_name, num), at_sender=True)
# else:
# await open_shilian.finish(await open_shilian_case(event.user_id, event.group_id, random.choice(cases_name), num),
# at_sender=True)
num_dict = {
'一': 1,
'二': 2,
'三': 3,
'四': 4,
'五': 5,
'六': 6,
'七': 7,
'八': 8,
'九': 9,
'十': 10,
'十一': 11,
'十二': 12,
'十三': 13,
'十四': 14,
'十五': 15,
'十六': 16,
'十七': 17,
'十八': 18,
'十九': 19,
'二十': 20,
'二十一': 21,
'二十二': 22,
'二十三': 23,
'二十四': 24,
'二十五': 25,
'二十六': 26,
'二十七': 27,
'二十八': 28,
'二十九': 29,
'三十': 30
}
update_price = on_command("更新价格", priority=1, permission=SUPERUSER, block=True)
@update_price.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
await update_price.send(await util_get_buff_price(str(event.get_message())))
update_img = on_command("更新图片", priority=1, permission=SUPERUSER, block=True)
@update_img.handle()
async def _(bot: Bot, event: MessageEvent, state: T_State):
await update_img.send(await util_get_buff_img(str(event.get_message())))
# 重置开箱
@scheduler.scheduled_job(
'cron',
hour=0,
minute=1,
)
async def _():
await update_count_daily()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-180
View File
@@ -1,180 +0,0 @@
import random
import pypinyin
BLUE = 0.7981
BLUE_ST = 0.0699
PURPLE = 0.1626
PURPLE_ST = 0.0164
PINK = 0.0315
PINK_ST = 0.0048
RED = 0.0057
RED_ST = 0.00021
KNIFE = 0.0021
KNIFE_ST = 0.000041
# 崭新
FACTORY_NEW_S = 0
FACTORY_NEW_E = 0.0699999
# 略磨
MINIMAL_WEAR_S = 0.07
MINIMAL_WEAR_E = 0.14999
# 久经
FIELD_TESTED_S = 0.15
FIELD_TESTED_E = 0.37999
# 破损
WELL_WORN_S = 0.38
WELL_WORN_E = 0.44999
# 战痕
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 | 零点行动']
# 突围大行动
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 | 锈蚀烈焰']
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 | 毛细血管']
NO_STA_KNIFE = ['求生匕首 | 北方森林', '求生匕首 | 夜色', '求生匕首 | 枯焦之色', '流浪者匕首 | 夜色', '流浪者匕首 | 枯焦之色', '流浪者匕首 | 森林 DDPAT',
'系绳匕首 | 夜色', '系绳匕首 | 狩猎网格', '骷髅匕首 | 夜色', '骷髅匕首 | 森林 DDPAT', '骷髅匕首 | 狩猎网格']
def get_wear(num: float) -> str:
if num <= FACTORY_NEW_E:
return "崭新出厂"
if MINIMAL_WEAR_S <= num <= MINIMAL_WEAR_E:
return "略有磨损"
if FIELD_TESTED_S <= num <= FIELD_TESTED_E:
return "久经沙场"
if WELL_WORN_S <= num <= 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
# M249(StatTrak™) | 等高线
-381
View File
@@ -1,381 +0,0 @@
from datetime import datetime, timedelta
from .config import *
from services.log import logger
from services.db_context import db
from models.open_cases_user import OpenCasesUser
from models.sigin_group_user import SignGroupUser
from util.init_result import image
import pypinyin
import random
from .utils import get_price
from models.buff_price import BuffPrice
from PIL import Image
from util.img_utils import alphabg2white_PIL, CreateImg
from configs.path_config import IMAGE_PATH
import asyncio
from util.utils import cn2py
from configs.config import INITIAL_OPEN_CASE_COUNT
MAX_COUNT = INITIAL_OPEN_CASE_COUNT
async def open_case(user_qq: int, group: int, case_name: str = "狂牙大行动") -> str:
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)
impression = (await SignGroupUser.ensure(user_qq, group)).impression
rand = random.random()
async with db.transaction():
user = await OpenCasesUser.ensure(user_qq, group, for_update=True)
# 一天次数上限
if user.today_open_total == int(MAX_COUNT + int(impression) / 3):
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...'])
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:
dbprice = await BuffPrice.ensure(skin[9:])
else:
dbprice = await BuffPrice.ensure(skin[9: skin.rfind('(')].strip())
if dbprice.skin_price != 0:
price_result = dbprice.skin_price
print("数据库查询到价格: ", dbprice.skin_price)
uplist[10] = dbprice.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:
print("存储入数据库---->", price)
uplist[10] = price
price_result = str(price)
await dbprice.update(
skin_price=price,
update_date=datetime.now(),
).apply()
# sp = skin.split("|")
# cskin_word = sp[1][:sp[1].find("(") - 1].strip()
if knifes_flag:
await user.update(
knifes_name=user.knifes_name + f"{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(f'{skin_name}.png', "cases/" + case)
# 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.ensure(user_qq, group, for_update=True)
over_count = int(MAX_COUNT + int(impression) / 3) - user.today_open_total
return f"开启{case_name}武器箱.\n剩余开箱次数:{over_count}.\n" \
+ img + "\n" + \
f"皮肤:{skin}\n" \
f"磨损:{mosun:.9f}\n" \
f"价格:{price_result}\n" \
f"{ridicule_result}"
async def open_shilian_case(user_qq: int, group: int, case_name: str, num: int = 10):
user = await OpenCasesUser.ensure(user_qq, group, for_update=True)
impression = (await SignGroupUser.ensure(user_qq, group)).impression
if user.today_open_total == int(MAX_COUNT + int(impression) / 3):
return _handle_is_MAX_COUNT()
if int(MAX_COUNT + int(impression) / 3) - user.today_open_total < num:
return f"今天开箱次数不足{num}次噢,请单抽试试看(也许单抽运气更好?)" \
f"\n剩余开箱次数:{int(MAX_COUNT + int(impression) / 3) - user.today_open_total}"
if num < 5:
h = 270
elif num % 5 == 0:
h = 270 * int(num / 5)
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]
img_list = []
name_list = ['蓝', '蓝(暗金)', '紫', '紫(暗金)', '粉', '粉(暗金)', '红', '红(暗金)', '金', '金(暗金)']
async with db.transaction():
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:
dbprice = await BuffPrice.ensure(skin[9:])
else:
dbprice = await BuffPrice.ensure(skin[9: skin.rfind('(')].strip())
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)
# img = image(skin_name, "cases/" + case, "png")
wImg = CreateImg(200, 270, 200, 200)
wImg.paste(alphabg2white_PIL(Image.open(IMAGE_PATH + f'cases/{case}/{skin_name}.png').resize((200, 200), Image.ANTIALIAS)), (0, 0))
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, num):
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 = CreateImg(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 = int(MAX_COUNT + int(impression) / 3) - 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):
markImg = CreateImg(1000, h, 200, 270)
for img in img_list:
markImg.paste(img)
return markImg
def _handle_is_MAX_COUNT() -> str:
return f"今天已达开箱上限了喔,明天再来吧\n(提升好感度可以增加每日开箱数 #疯狂暗示)"
async def update_user_total(user: OpenCasesUser, uplist: list, num: int = 1) -> bool:
try:
await user.update(
total_count=user.total_count + num,
blue_count=user.blue_count + uplist[0],
blue_st_count=user.blue_st_count + uplist[1],
purple_count=user.purple_count + uplist[2],
purple_st_count=user.purple_st_count + uplist[3],
pink_count=user.pink_count + uplist[4],
pink_st_count=user.pink_st_count + uplist[5],
red_count=user.red_count + uplist[6],
red_st_count=user.red_st_count + uplist[7],
knife_count=user.knife_count + uplist[8],
knife_st_count=user.knife_st_count + uplist[9],
spend_money=user.spend_money + 17 * num,
make_money=user.make_money + uplist[10],
today_open_total=user.today_open_total + num,
open_cases_time_last=datetime.now()
).apply()
return True
except:
return False
async def total_open_statistics(user_qq: int, group: int) -> str:
async with db.transaction():
user = await OpenCasesUser.ensure(user_qq, group, for_update=True)
return f"开箱总数:{user.total_count}\n" \
f"今日开箱:{user.today_open_total}\n" \
f"蓝色军规:{user.blue_count}\n" \
f"蓝色暗金:{user.blue_st_count}\n" \
f"紫色受限:{user.purple_count}\n" \
f"紫色暗金:{user.purple_st_count}\n" \
f"粉色保密:{user.pink_count}\n" \
f"粉色暗金:{user.pink_st_count}\n" \
f"红色隐秘:{user.red_count}\n" \
f"红色暗金:{user.red_st_count}\n" \
f"金色罕见:{user.knife_count}\n" \
f"金色暗金:{user.knife_st_count}\n" \
f"花费金额:{user.spend_money}\n" \
f"获取金额:{user.make_money:.2f}\n" \
f"最后开箱日期:{(user.open_cases_time_last + timedelta(hours=8)).date()}"
async def group_statistics(group: int):
user_list = await OpenCasesUser.get_user_all(group)
# lan zi fen hong jin pricei
uplist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0, 0]
for user in user_list:
uplist[0] += user.blue_count
uplist[1] += user.blue_st_count
uplist[2] += user.purple_count
uplist[3] += user.purple_st_count
uplist[4] += user.pink_count
uplist[5] += user.pink_st_count
uplist[6] += user.red_count
uplist[7] += user.red_st_count
uplist[8] += user.knife_count
uplist[9] += user.knife_st_count
uplist[10] += user.make_money
uplist[11] += user.total_count
uplist[12] += user.today_open_total
return f"群开箱总数:{uplist[11]}\n" \
f"群今日开箱:{uplist[12]}\n" \
f"蓝色军规:{uplist[0]}\n" \
f"蓝色暗金:{uplist[1]}\n" \
f"紫色受限:{uplist[2]}\n" \
f"紫色暗金:{uplist[3]}\n" \
f"粉色保密:{uplist[4]}\n" \
f"粉色暗金:{uplist[5]}\n" \
f"红色隐秘:{uplist[6]}\n" \
f"红色暗金:{uplist[7]}\n" \
f"金色罕见:{uplist[8]}\n" \
f"金色暗金:{uplist[9]}\n" \
f"花费金额:{uplist[11] * 17}\n" \
f"获取金额:{uplist[10]:.2f}"
async def my_knifes_name(user_id: int, group: int):
knifes_name = (await OpenCasesUser.ensure(user_id, group)).knifes_name
if knifes_name:
knifes_list = knifes_name[:-1].split(",")
length = len(knifes_list)
if length < 5:
h = 600
w = length * 540
elif length % 5 == 0:
h = 600 * int(length / 5)
w = 540 * 5
else:
h = 600 * int(length / 5) + 600
w = 540 * 5
A = await asyncio.get_event_loop().run_in_executor(None, _pst_my_knife, w, h, knifes_list)
return image(b64=A.pic2bs4())
else:
return "您木有开出金色级别的皮肤喔"
def _pst_my_knife(w, h, knifes_list):
A = CreateImg(w, h, 540, 600)
for knife in knifes_list:
case = knife.split('||')[0]
knife = knife.split('||')[1]
name = knife[:knife.find('(')].strip()
itype = knife[knife.find('(')+1: knife.find(')')].strip()
mosun = knife[knife.find('磨损:')+3: knife.rfind('价格:')].strip()
if mosun[-1] == ',' or mosun[-1] == ',':
mosun = mosun[:-1]
price = knife[knife.find('价格:')+3:]
skin_name = ""
for i in pypinyin.pinyin(name.replace('|', '-').replace('(StatTrak™)', '').strip(),
style=pypinyin.NORMAL):
skin_name += ''.join(i)
knife_img = CreateImg(470, 600, 470, 470, font_size=20)
knife_img.paste(alphabg2white_PIL(
Image.open(IMAGE_PATH + f'cases/{case}/{skin_name}.png').resize((470, 470), Image.ANTIALIAS)), (0, 0))
knife_img.text((5, 500), f'\t{name}({itype})')
knife_img.text((5, 530), f'\t磨损:{mosun}')
knife_img.text((5, 560), f'\t价格:{price}')
A.paste(knife_img)
return A
# G3SG1(StatTrak™) | 血腥迷彩 (战痕累累)
# G3SG1(StatTrak™) | 血腥迷彩 (战痕累累)
# G3SG1(StatTrak™) | 血腥迷彩 (战痕累累)
-294
View File
@@ -1,294 +0,0 @@
from models.buff_price import BuffPrice
from services.db_context import db
from datetime import datetime, timedelta
from util.user_agent import get_user_agent
from configs.path_config import IMAGE_PATH
import aiohttp
import aiofiles
from models.open_cases_user import OpenCasesUser
import os
from services.log import logger
from util.utils import get_bot
from models.group_remind import GroupRemind
from util.utils import get_cookie_text
from asyncio.exceptions import TimeoutError
import pypinyin
from nonebot.adapters.cqhttp.exception import ActionFailed
<<<<<<< HEAD
from configs.config import buff_proxy
=======
>>>>>>> master
url = "https://buff.163.com/api/market/goods"
# proxies = 'http://49.75.59.242:3128'
async def util_get_buff_price(case_name: str = "狂牙大行动") -> str:
cookie = {'session': get_cookie_text('buff')}
failed_list = []
case = ""
for i in pypinyin.pinyin(case_name, style=pypinyin.NORMAL):
case += ''.join(i)
if case_name == "狂牙大行动":
case_id = 1
elif case_name == "突围大行动":
case_id = 2
elif case_name == "命悬一线":
case_id = 3
elif case_name == '裂空':
case_id = 4
elif case_name == '光谱':
case_id = 5
else:
return "未查询到武器箱"
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")
async with aiohttp.ClientSession(cookies=cookie, headers=get_user_agent()) as session:
for total_list in [CASE_KNIFE, CASE_RED, CASE_PINK, CASE_PURPLE, CASE_BLUE]:
print("----------------------------------")
for skin in total_list:
print(skin)
if skin in ["蝴蝶刀 | 无涂装", '求生匕首 | 无涂装', '流浪者匕首 | 无涂装', '系绳匕首 | 无涂装', '骷髅匕首 | 无涂装']:
skin = skin.split('|')[0].strip()
async with db.transaction():
name_list = []
price_list = []
parameter = {
"game": "csgo",
"page_num": "1",
"search": skin
}
try:
<<<<<<< HEAD
async with session.get(url, proxy=buff_proxy, params=parameter, timeout=20) as response:
=======
async with session.get(url, params=parameter, timeout=20) as response:
>>>>>>> master
if response.status == 200:
data = (await response.json())["data"]
total_page = data["total_page"]
data = data["items"]
flag = False
if skin.find('|') == -1: # in ['蝴蝶刀', '求生匕首', '流浪者匕首', '系绳匕首', '骷髅匕首']:
for i in range(1, total_page + 1):
name_list = []
price_list = []
parameter = {
"game": "csgo",
"page_num": f"{i}",
"search": skin
}
async with session.get(url, params=parameter, timeout=20) as res:
data = (await response.json())["data"]["items"]
for j in range(len(data)):
if data[j]['name'] in [f'{skin}(★)']:
name = data[j]["name"]
price = data[j]["sell_reference_price"]
name_list.append(name.split('(')[0].strip() + ' | 无涂装')
price_list.append(price)
print(name_list[-1])
print(price_list[-1])
flag = True
break
if flag:
break
else:
try:
for _ in range(total_page):
for i in range(len(data)):
name = data[i]["name"]
price = data[i]["sell_reference_price"]
name_list.append(name)
price_list.append(price)
except Exception as e:
failed_list.append(skin)
print(f"{skin}更新失败")
else:
failed_list.append(skin)
print(f"{skin}更新失败")
except Exception:
failed_list.append(skin)
print(f"{skin}更新失败")
continue
for i in range(len(name_list)):
name = name_list[i].strip()
price = float(price_list[i])
if name.find("(★)") != -1:
name = name[: name.find("(")] + name[name.find(")") + 1:]
if name.find("消音") != -1 and name.find("(S") != -1:
name = name.split("(")[0][:-4] + "(" + name.split("(")[1]
name = name.split("|")[0].strip() + " | " + name.split("|")[1].strip()
elif name.find("消音") != -1:
name = name.split("|")[0][:-5].strip() + " | " + name.split("|")[1].strip()
if name.find(" 18 ") != -1 and name.find("(S") != -1:
name = name.split("(")[0][:-5] + "(" + name.split("(")[1]
name = name.split("|")[0].strip() + " | " + name.split("|")[1].strip()
elif name.find(" 18 ") != -1:
name = name.split("|")[0][:-6].strip() + " | " + name.split("|")[1].strip()
dbskin = await BuffPrice.ensure(name, True)
if (dbskin.update_date + timedelta(8)).date() == datetime.now().date():
continue
await dbskin.update(
case_id=case_id,
skin_price=price,
update_date=datetime.now(),
).apply()
print(f"{name_list[i]}---------->成功更新")
result = None
if failed_list:
result = ""
for fail_skin in failed_list:
result += fail_skin + "\n"
return result[:-1] if result else "更新价格成功"
async def util_get_buff_img(case_name: str = "狂牙大行动") -> str:
cookie = {'session': get_cookie_text('buff')}
error_list = []
case = ""
for i in pypinyin.pinyin(case_name, style=pypinyin.NORMAL):
case += ''.join(i)
path = "cases/" + case + "/"
if not os.path.exists(IMAGE_PATH + path):
os.mkdir(IMAGE_PATH + path)
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")
async with aiohttp.ClientSession(cookies=cookie, headers=get_user_agent()) as session:
for total_list in [CASE_KNIFE, CASE_RED, CASE_PINK, CASE_PURPLE, CASE_BLUE]:
for skin in total_list:
parameter = {
"game": "csgo",
"page_num": "1",
"search": skin
}
if skin in ["蝴蝶刀 | 无涂装", '求生匕首 | 无涂装', '流浪者匕首 | 无涂装', '系绳匕首 | 无涂装', '骷髅匕首 | 无涂装']:
skin = skin.split('|')[0].strip()
print("开始更新----->", skin)
print(skin)
skin_name = ''
# try:
<<<<<<< HEAD
async with session.get(url, proxy=buff_proxy, params=parameter, timeout=20) as response:
=======
async with session.get(url, params=parameter, timeout=20) as response:
>>>>>>> master
if response.status == 200:
data = (await response.json())["data"]
total_page = data["total_page"]
flag = False
if skin.find('|') == -1: # in ['蝴蝶刀', '求生匕首', '流浪者匕首', '系绳匕首', '骷髅匕首']:
for i in range(1, total_page + 1):
async with session.get(url, params=parameter, timeout=20) as res:
data = (await response.json())["data"]["items"]
for j in range(len(data)):
if data[j]['name'] in [f'{skin}(★)']:
img_url = data[j]['goods_info']['icon_url']
for k in pypinyin.pinyin(skin + '无涂装', style=pypinyin.NORMAL):
skin_name += ''.join(k)
async with aiofiles.open(IMAGE_PATH + path + skin_name + ".png", 'wb') as f:
print("------->开始写入 ", skin)
async with session.get(img_url, timeout=7) as res:
await f.write(await res.read())
flag = True
break
if flag:
break
else:
img_url = (await response.json())["data"]['items'][0]['goods_info']['icon_url']
for i in pypinyin.pinyin(skin.replace('|', '-').strip(), style=pypinyin.NORMAL):
skin_name += ''.join(i)
async with aiofiles.open(IMAGE_PATH + path + skin_name + ".png", 'wb') as f:
print("------->开始写入 ", skin)
async with session.get(img_url, timeout=7) as res:
await f.write(await res.read())
# async with session.get(url, params=parameter, timeout=7) as response:
# if response.status == 200:
# img_url = (await response.json())["data"]['items'][0]['goods_info']['icon_url']
# skin_name = ''
# for i in pypinyin.pinyin(skin.split("|")[1].strip(), style=pypinyin.NORMAL):
# skin_name += ''.join(i)
# async with aiofiles.open(IMAGE_PATH + path + skin_name + ".png", 'wb') as f:
# print("------->开始写入 ", skin)
# async with session.get(img_url, timeout=7) as res:
# await f.write(await res.read())
# except Exception:
# print("图片更新失败 ---->", skin)
# error_list.append(skin)
result = None
if error_list:
result = ""
for errskin in error_list:
result += errskin + "\n"
return result[:-1] if result else "更新图片成功"
async def get_price(dname):
cookie = {'session': get_cookie_text('buff')}
name_list = []
price_list = []
parameter = {
"game": "csgo",
"page_num": "1",
"search": dname
}
try:
async with aiohttp.ClientSession(cookies=cookie, headers=get_user_agent()) as session:
async with session.get(url, params=parameter, timeout=7) as response:
if response.status == 200:
try:
data = (await response.json())["data"]
total_page = data["total_page"]
data = data["items"]
for _ in range(total_page):
for i in range(len(data)):
name = data[i]["name"]
price = data[i]["sell_reference_price"]
name_list.append(name)
price_list.append(price)
except Exception as e:
return "没有查询到...", 998
else:
return "访问失败!", response.status
except TimeoutError as e:
return "访问超时! 请重试或稍后再试!", 997
result = f"皮肤: {dname}({len(name_list)})\n"
# result = "皮肤: " + dname + "\n"
for i in range(len(name_list)):
result += name_list[i] + ": " + price_list[i] + "\n"
return result[:-1], 999
async def update_count_daily():
try:
users = await OpenCasesUser.get_user_all()
if users:
for user in users:
await user.update(
today_open_total=0,
).apply()
bot = get_bot()
gl = await bot.get_group_list(self_id=bot.self_id)
gl = [g['group_id'] for g in gl]
for g in gl:
if await GroupRemind.get_status(g, 'kxcz'):
try:
await bot.send_group_msg(group_id=g, message="今日开箱次数重置成功")
except ActionFailed:
logger.warning(f'{g} 群被禁言,无法发送 开箱重置提醒')
logger.info("今日开箱次数重置成功")
except Exception as e:
logger.error(f'开箱重置错误 e:{e}')
# 蝴蝶刀(★) | 噩梦之夜 (久经沙场)
if __name__ == '__main__':
print(util_get_buff_img("xxxx/"))