mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
Delete models directory
This commit is contained in:
parent
b930de0368
commit
f9cef92384
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,190 +0,0 @@
|
||||
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class UserBag(db.Model):
|
||||
__tablename__ = 'bag_users'
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
user_qq = db.Column(db.BigInteger(), nullable=False)
|
||||
belonging_group = db.Column(db.BigInteger(), nullable=False)
|
||||
gold = db.Column(db.Integer(), default=100)
|
||||
props = db.Column(db.TEXT(), nullable=False, default="")
|
||||
spend_total_gold = db.Column(db.Integer(), default=0)
|
||||
get_total_gold = db.Column(db.Integer(), default=0)
|
||||
get_today_gold = db.Column(db.Integer(), default=0)
|
||||
spend_today_gold = db.Column(db.Integer(), default=0)
|
||||
|
||||
_idx1 = db.Index('bag_group_users_idx1', 'user_qq', 'belonging_group', unique=True)
|
||||
|
||||
@classmethod
|
||||
async def get_my_total_gold(cls, user_qq: int, belonging_group: int) -> str:
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
user = await query.gino.first()
|
||||
if not user:
|
||||
user = await cls.create(
|
||||
user_qq=user_qq,
|
||||
belonging_group=belonging_group,
|
||||
)
|
||||
return f'当前金币:{user.gold}\n今日获取金币:{user.get_today_gold}\n今日花费金币:{user.spend_today_gold}' \
|
||||
f'\n今日收益:{user.get_today_gold - user.spend_today_gold}' \
|
||||
f'\n总赚取金币:{user.get_total_gold}\n总花费金币:{user.spend_total_gold}'
|
||||
|
||||
@classmethod
|
||||
async def get_gold(cls, user_qq: int, belonging_group: int) -> int:
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
user = await query.gino.first()
|
||||
if user:
|
||||
return user.gold
|
||||
else:
|
||||
await cls.create(
|
||||
user_qq=user_qq,
|
||||
belonging_group=belonging_group,
|
||||
)
|
||||
return 100
|
||||
|
||||
@classmethod
|
||||
async def get_props(cls, user_qq: int, belonging_group: int) -> str:
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
user = await query.gino.first()
|
||||
if user:
|
||||
return user.props
|
||||
else:
|
||||
await cls.create(
|
||||
user_qq=user_qq,
|
||||
belonging_group=belonging_group,
|
||||
)
|
||||
return ''
|
||||
|
||||
@classmethod
|
||||
async def add_glod(cls, user_qq: int, belonging_group: int, num: int) -> bool:
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
try:
|
||||
if user:
|
||||
await user.update(
|
||||
gold=user.gold + num,
|
||||
get_total_gold=user.get_total_gold + num,
|
||||
get_today_gold=user.get_today_gold + num
|
||||
).apply()
|
||||
else:
|
||||
await cls.create(
|
||||
user_qq=user_qq,
|
||||
belonging_group=belonging_group,
|
||||
gold=100 + num,
|
||||
get_total_gold=num,
|
||||
get_today_gold=num,
|
||||
)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def spend_glod(cls, user_qq: int, belonging_group: int, num: int) -> bool:
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
try:
|
||||
if user:
|
||||
await user.update(
|
||||
gold=user.gold - num,
|
||||
spend_total_gold=user.spend_total_gold + num,
|
||||
spend_today_gold=user.spend_today_gold + num
|
||||
).apply()
|
||||
else:
|
||||
await cls.create(
|
||||
user_qq=user_qq,
|
||||
belonging_group=belonging_group,
|
||||
gold=100 - num,
|
||||
spend_total_gold=num,
|
||||
spend_today_gold=num
|
||||
)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def add_props(cls, user_qq: int, belonging_group: int, name: str) -> bool:
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
try:
|
||||
if user:
|
||||
await user.update(
|
||||
props=user.props + f'{name},'
|
||||
).apply()
|
||||
else:
|
||||
await cls.create(
|
||||
user_qq=user_qq,
|
||||
belonging_group=belonging_group,
|
||||
props=f'{name},'
|
||||
)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def del_props(cls, user_qq: int, belonging_group: int, name: str) -> bool:
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
try:
|
||||
if user:
|
||||
rst = ''
|
||||
props = user.props
|
||||
if props.find(name) != -1:
|
||||
props = props.split(',')
|
||||
try:
|
||||
index = props.index(name)
|
||||
except ValueError:
|
||||
return False
|
||||
props = props[:index] + props[index + 1:]
|
||||
for p in props:
|
||||
if p != '':
|
||||
rst += p + ','
|
||||
await user.update(
|
||||
props=rst
|
||||
).apply()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def get_user_all(cls, group_id: int = None) -> list:
|
||||
user_list = []
|
||||
if not group_id:
|
||||
query = await cls.query.gino.all()
|
||||
else:
|
||||
query = await cls.query.where(
|
||||
(cls.belonging_group == group_id)
|
||||
).gino.all()
|
||||
for user in query:
|
||||
user_list.append(user)
|
||||
return user_list
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,84 +0,0 @@
|
||||
from services.db_context import db
|
||||
import time
|
||||
|
||||
|
||||
class BanUser(db.Model):
|
||||
__tablename__ = 'ban_users'
|
||||
|
||||
user_qq = db.Column(db.BigInteger(), nullable=False, primary_key=True)
|
||||
ban_level = db.Column(db.Integer(), nullable=False)
|
||||
ban_time = db.Column(db.BigInteger())
|
||||
duration = db.Column(db.BigInteger())
|
||||
|
||||
_idx1 = db.Index('ban_group_users_idx1', 'user_qq', unique=True)
|
||||
|
||||
@classmethod
|
||||
async def check_ban_level(cls, user_qq: int, level: int) -> 'bool':
|
||||
user = await cls.query.where(
|
||||
(cls.user_qq == user_qq)
|
||||
).gino.first()
|
||||
if not user:
|
||||
return False
|
||||
if user.ban_level > level:
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def check_ban_time(cls, user_qq: int) -> 'str':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq)
|
||||
)
|
||||
user = await query.gino.first()
|
||||
if not user:
|
||||
return ''
|
||||
if time.time() - (user.ban_time + user.duration) > 0 and user.duration != -1:
|
||||
return ''
|
||||
if user.duration == -1:
|
||||
return '∞'
|
||||
return time.time() - user.ban_time - user.duration
|
||||
|
||||
@classmethod
|
||||
async def isban(cls, user_qq: int) -> 'bool':
|
||||
if await cls.check_ban_time(user_qq):
|
||||
return True
|
||||
else:
|
||||
await cls.unban(user_qq, True)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def ban(cls, user_qq: int, ban_level: int, duration: int, for_update: bool = False) -> 'bool':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq)
|
||||
)
|
||||
if for_update:
|
||||
query = await query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
if not await cls.check_ban_time(user_qq):
|
||||
await cls.unban(user_qq)
|
||||
user = None
|
||||
if user is None:
|
||||
await cls.create(
|
||||
user_qq=user_qq,
|
||||
ban_level=ban_level,
|
||||
ban_time=time.time(),
|
||||
duration=duration,
|
||||
)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def unban(cls, user_qq: int, for_update: bool = False) -> 'bool':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq)
|
||||
)
|
||||
if for_update:
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
if user is None:
|
||||
return False
|
||||
else:
|
||||
await cls.delete.where(
|
||||
(cls.user_qq == user_qq)
|
||||
).gino.status()
|
||||
return True
|
||||
@ -1,33 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
from services.db_context import db
|
||||
|
||||
# 1.狂牙武器箱
|
||||
|
||||
|
||||
class BuffPrice(db.Model):
|
||||
__tablename__ = 'buff_prices'
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
case_id = db.Column(db.Integer(), nullable=False)
|
||||
skin_name = db.Column(db.Unicode(), nullable=False)
|
||||
skin_price = db.Column(db.Float(), nullable=False)
|
||||
update_date = db.Column(db.DateTime(), nullable=False)
|
||||
|
||||
_idx1 = db.Index('buff_price_idx1', 'skin_name', unique=True)
|
||||
|
||||
@classmethod
|
||||
async def ensure(cls, skin_name: str, for_update: bool = False) -> 'BuffPrice':
|
||||
query = cls.query.where(
|
||||
(cls.skin_name == skin_name)
|
||||
)
|
||||
if for_update:
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
return user or await cls.create(
|
||||
case_id=1,
|
||||
skin_name=skin_name,
|
||||
skin_price=0,
|
||||
update_date=datetime.min,
|
||||
)
|
||||
|
||||
@ -1,78 +0,0 @@
|
||||
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class UserCount(db.Model):
|
||||
__tablename__ = 'count_users'
|
||||
|
||||
user_qq = db.Column(db.BigInteger(), nullable=False, primary_key=True)
|
||||
reimu_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
setu_r18_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
|
||||
_idx1 = db.Index('sign_reimu_users_idx1', 'user_qq', unique=True)
|
||||
|
||||
@classmethod
|
||||
async def add_user(cls, user_qq: int):
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq)
|
||||
)
|
||||
query = query.with_for_update()
|
||||
if not await query.gino.first():
|
||||
await cls.create(
|
||||
user_qq=user_qq,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def add_count(cls, user_qq: int, name: str, count: int = 1):
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq)
|
||||
)
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
if user:
|
||||
if name == 'reimu':
|
||||
await user.update(
|
||||
reimu_count=cls.reimu_count + count
|
||||
).apply()
|
||||
if name == 'setu_r18':
|
||||
await user.update(
|
||||
setu_r18_count=cls.setu_r18_count + count
|
||||
).apply()
|
||||
else:
|
||||
await cls.create(
|
||||
user_qq=user_qq
|
||||
)
|
||||
|
||||
|
||||
@classmethod
|
||||
async def check_count(cls, user_qq: int, name: str, max_count: int) -> bool:
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq)
|
||||
)
|
||||
user = await query.gino.first()
|
||||
if user:
|
||||
if name == 'reimu':
|
||||
if user.reimu_count == max_count:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
if name == 'setu_r18':
|
||||
if user.setu_r18_count == max_count:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
await cls.add_user(user_qq)
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def reset_count(cls):
|
||||
for user in await cls.query.gino.all():
|
||||
await user.update(
|
||||
reimu_count=0,
|
||||
setu_r18_count=0
|
||||
).apply()
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,87 +0,0 @@
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class FriendUser(db.Model):
|
||||
__tablename__ = 'friend_users'
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
user_id = db.Column(db.BigInteger(), nullable=False)
|
||||
user_name = db.Column(db.Unicode(), nullable=False, default="")
|
||||
nickname = db.Column(db.Unicode())
|
||||
|
||||
_idx1 = db.Index('friend_users_idx1', 'user_id', unique=True)
|
||||
|
||||
@classmethod
|
||||
async def get_user_name(cls, user_id: int) -> str:
|
||||
query = cls.query.where(
|
||||
cls.user_id == user_id
|
||||
)
|
||||
user = await query.gino.first()
|
||||
if user:
|
||||
return user.user_name
|
||||
else:
|
||||
return ''
|
||||
|
||||
@classmethod
|
||||
async def add_friend_info(cls, user_id: int, user_name: str) -> 'bool':
|
||||
try:
|
||||
query = cls.query.where(
|
||||
cls.user_id == user_id
|
||||
)
|
||||
user = await query.with_for_update().gino.first()
|
||||
if not user:
|
||||
await cls.create(
|
||||
user_id=user_id,
|
||||
user_name=user_name,
|
||||
)
|
||||
else:
|
||||
await user.update(
|
||||
user_name=user_name,
|
||||
).apply()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def delete_friend_info(cls, user_id: int) -> 'bool':
|
||||
try:
|
||||
query = cls.query.where(
|
||||
cls.user_id == user_id
|
||||
)
|
||||
user = await query.with_for_update().gino.first()
|
||||
if user:
|
||||
await user.delete()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def get_friend_nickname(cls, user_id: int) -> 'str':
|
||||
query = cls.query.where(
|
||||
cls.user_id == user_id
|
||||
)
|
||||
user = await query.with_for_update().gino.first()
|
||||
if user:
|
||||
if user.nickname:
|
||||
return user.nickname
|
||||
return ''
|
||||
|
||||
@classmethod
|
||||
async def set_friend_nickname(cls, user_id: int, nickname: str) -> 'bool':
|
||||
try:
|
||||
query = cls.query.where(
|
||||
cls.user_id == user_id
|
||||
)
|
||||
user = await query.with_for_update().gino.first()
|
||||
if not user:
|
||||
await cls.create(
|
||||
user_id=user_id,
|
||||
nickname=nickname,
|
||||
)
|
||||
else:
|
||||
await user.update(
|
||||
nickname=nickname,
|
||||
).apply()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
@ -1,56 +0,0 @@
|
||||
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class GroupInfo(db.Model):
|
||||
__tablename__ = 'group_info'
|
||||
|
||||
group_id = db.Column(db.BigInteger(), nullable=False, primary_key=True)
|
||||
group_name = db.Column(db.Unicode(), nullable=False, default="")
|
||||
max_member_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
member_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
|
||||
_idx1 = db.Index('group_info_idx1', 'group_id', unique=True)
|
||||
|
||||
@classmethod
|
||||
async def get_group_info(cls, group_id: int) -> 'GroupInfo':
|
||||
query = cls.query.where(
|
||||
cls.group_id == group_id
|
||||
)
|
||||
return await query.gino.first()
|
||||
|
||||
@classmethod
|
||||
async def add_group_info(cls, group_id: int, group_name: str, max_member_count: int, member_count: int) -> bool:
|
||||
try:
|
||||
group = await cls.query.where(
|
||||
cls.group_id == group_id
|
||||
).with_for_update().gino.first()
|
||||
if group:
|
||||
await cls.update(
|
||||
group_id=group_id,
|
||||
group_name=group_name,
|
||||
max_member_count=max_member_count,
|
||||
member_count=member_count,
|
||||
).apply()
|
||||
else:
|
||||
await cls.create(
|
||||
group_id=group_id,
|
||||
group_name=group_name,
|
||||
max_member_count=max_member_count,
|
||||
member_count=member_count,
|
||||
)
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def delete_group_info(cls, group_id: int) -> bool:
|
||||
try:
|
||||
await cls.delete.where(
|
||||
cls.group_id == group_id
|
||||
).gino.status()
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
@ -1,99 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class GroupInfoUser(db.Model):
|
||||
__tablename__ = 'group_info_users'
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
user_qq = db.Column(db.BigInteger(), nullable=False)
|
||||
user_name = db.Column(db.Unicode(), nullable=False)
|
||||
belonging_group = db.Column(db.BigInteger(), nullable=False)
|
||||
user_join_time = db.Column(db.DateTime(), nullable=False)
|
||||
nickname = db.Column(db.Unicode())
|
||||
|
||||
_idx1 = db.Index('info_group_users_idx1', 'user_qq', 'belonging_group', unique=True)
|
||||
|
||||
@classmethod
|
||||
async def insert(cls, user_qq: int, belonging_group: int, user_name: str, user_join_time: datetime) -> 'bool':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
query = query.with_for_update()
|
||||
try:
|
||||
if await query.gino.first() is None:
|
||||
await cls.create(
|
||||
user_qq=user_qq,
|
||||
user_name=user_name,
|
||||
belonging_group=belonging_group,
|
||||
user_join_time=user_join_time,
|
||||
)
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def select_member_info(cls, user_qq: int, belonging_group: int) -> 'GroupInfoUser':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
return await query.gino.first()
|
||||
|
||||
@classmethod
|
||||
async def delete_member_info(cls, user_qq: int, belonging_group: int) -> 'bool':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
try:
|
||||
if user is None:
|
||||
return True
|
||||
else:
|
||||
await cls.delete.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
).gino.status()
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def query_group_member_list(cls, belonging_group: int) -> 'list':
|
||||
member_list = []
|
||||
query = cls.query.where(
|
||||
(cls.belonging_group == belonging_group)
|
||||
)
|
||||
for user in await query.gino.all():
|
||||
member_list.append(user.user_qq)
|
||||
return member_list
|
||||
|
||||
@classmethod
|
||||
async def set_group_member_nickname(cls, user_qq: int, belonging_group: int, nickname: str) -> 'bool':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
user = await query.gino.first()
|
||||
if user:
|
||||
await user.update(
|
||||
nickname=nickname
|
||||
).apply()
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def get_group_member_nickname(cls, user_qq: int, belonging_group: int) -> 'str':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
user = await query.gino.first()
|
||||
if user:
|
||||
if user.nickname:
|
||||
return user.nickname
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,100 +0,0 @@
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class GroupRemind(db.Model):
|
||||
__tablename__ = 'group_reminds'
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
group_id = db.Column(db.BigInteger(), nullable=False)
|
||||
hy = db.Column(db.Boolean(), default=True) # 进群欢迎
|
||||
kxcz = db.Column(db.Boolean(), default=True) # 开箱重置
|
||||
zwa = db.Column(db.Boolean(), default=True) # 早晚安
|
||||
gb = db.Column(db.Boolean(), default=True) # 广播
|
||||
blpar = db.Column(db.Boolean(), default=True) # bilibili转发解析
|
||||
pa = db.Column(db.Boolean(), default=True) # 爬
|
||||
epic = db.Column(db.Boolean(), default=False) # epic
|
||||
almanac = db.Column(db.Boolean(), default=False) # 原神黄历
|
||||
|
||||
_idx1 = db.Index('info_group_reminds_idx1', 'group_id', unique=True)
|
||||
|
||||
@classmethod
|
||||
async def get_status(cls, group_id: int, name: str) -> bool:
|
||||
group = await cls.query.where(
|
||||
(cls.group_id == group_id)
|
||||
).gino.first()
|
||||
if not group:
|
||||
group = await cls.create(
|
||||
group_id=group_id,
|
||||
)
|
||||
if name == 'hy':
|
||||
return group.hy
|
||||
if name == 'kxcz':
|
||||
return group.kxcz
|
||||
if name == 'zwa':
|
||||
return group.zwa
|
||||
if name == 'gb':
|
||||
return group.gb
|
||||
if name == 'blpar':
|
||||
return group.blpar
|
||||
if name == 'epic':
|
||||
return group.epic
|
||||
if name == 'pa':
|
||||
return group.pa
|
||||
if name == 'almanac':
|
||||
return group.almanac
|
||||
|
||||
@classmethod
|
||||
async def set_status(cls, group_id: int, name: str, status: bool) -> bool:
|
||||
try:
|
||||
group = await cls.query.where(
|
||||
(cls.group_id == group_id)
|
||||
).gino.first()
|
||||
if not group:
|
||||
group = await cls.create(
|
||||
group_id=group_id,
|
||||
)
|
||||
if name == 'hy':
|
||||
await group.update(
|
||||
hy=status,
|
||||
).apply()
|
||||
if name == 'kxcz':
|
||||
await group.update(
|
||||
kxcz=status,
|
||||
).apply()
|
||||
if name == 'zwa':
|
||||
await group.update(
|
||||
zwa=status,
|
||||
).apply()
|
||||
if name == 'gb':
|
||||
await group.update(
|
||||
gb=status,
|
||||
).apply()
|
||||
if name == 'blpar':
|
||||
await group.update(
|
||||
blpar=status,
|
||||
).apply()
|
||||
if name == 'epic':
|
||||
await group.update(
|
||||
epic=status,
|
||||
).apply()
|
||||
if name == 'pa':
|
||||
await group.update(
|
||||
pa=status,
|
||||
).apply()
|
||||
if name == 'almanac':
|
||||
await group.update(
|
||||
almanac=status,
|
||||
).apply()
|
||||
return True
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,94 +0,0 @@
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class LevelUser(db.Model):
|
||||
__tablename__ = 'level_users'
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
user_qq = db.Column(db.BigInteger(), nullable=False)
|
||||
group_id = db.Column(db.BigInteger(), nullable=False)
|
||||
user_level = db.Column(db.BigInteger(), nullable=False)
|
||||
group_flag = db.Column(db.Integer(), nullable=False, default=0)
|
||||
|
||||
_idx1 = db.Index('level_group_users_idx1', 'user_qq', 'group_id', unique=True)
|
||||
|
||||
@classmethod
|
||||
async def get_user_level(cls, user_qq: int, group_id: int) -> int:
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.group_id == group_id)
|
||||
)
|
||||
user = await query.gino.first()
|
||||
if user:
|
||||
return user.user_level
|
||||
else:
|
||||
return -1
|
||||
|
||||
@classmethod
|
||||
async def set_level(cls, user_qq: int, group_id: int, level: int, group_flag: int = 0) -> 'bool':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.group_id == group_id)
|
||||
)
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
if user is None:
|
||||
await cls.create(
|
||||
user_qq=user_qq,
|
||||
group_id=group_id,
|
||||
user_level=level,
|
||||
group_flag=group_flag,
|
||||
)
|
||||
return True
|
||||
else:
|
||||
await user.update(user_level=level, group_flag=group_flag).apply()
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def delete_level(cls, user_qq: int, group_id: int, for_update: bool = False) -> 'bool':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.group_id == group_id)
|
||||
)
|
||||
if for_update:
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
if user is None:
|
||||
return False
|
||||
else:
|
||||
await user.delete()
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
async def check_level(cls, user_qq: int, group_id: int, level: int) -> 'bool':
|
||||
if group_id != 0:
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.group_id == group_id)
|
||||
)
|
||||
user = await query.gino.first()
|
||||
if user is None:
|
||||
return False
|
||||
user_level = user.user_level
|
||||
else:
|
||||
query = cls.query.where(
|
||||
cls.user_qq == user_qq
|
||||
)
|
||||
highest_level = 0
|
||||
for user in await query.gino.all():
|
||||
if user.user_level > highest_level:
|
||||
highest_level = user.user_level
|
||||
user_level = highest_level
|
||||
if user_level >= level:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
async def is_group_flag(cls, user_qq: int, group_id: int) -> 'bool':
|
||||
user = await cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.group_id == group_id)
|
||||
).gino.first()
|
||||
if not user:
|
||||
return False
|
||||
if user.group_flag == 1:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@ -1,59 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class OpenCasesUser(db.Model):
|
||||
__tablename__ = 'open_cases_users'
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
user_qq = db.Column(db.BigInteger(), nullable=False)
|
||||
belonging_group = db.Column(db.BigInteger(), nullable=False)
|
||||
total_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
blue_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
blue_st_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
purple_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
purple_st_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
pink_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
pink_st_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
red_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
red_st_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
knife_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
knife_st_count = db.Column(db.Integer(), nullable=False, default=0)
|
||||
spend_money = db.Column(db.Integer(), nullable=False, default=0)
|
||||
make_money = db.Column(db.Float(), nullable=False, default=0)
|
||||
today_open_total = db.Column(db.Integer(), nullable=False, default=0)
|
||||
open_cases_time_last = db.Column(db.DateTime(timezone=True), nullable=False, default=datetime.now())
|
||||
knifes_name = db.Column(db.Unicode(), nullable=False, default="")
|
||||
|
||||
_idx1 = db.Index('open_cases_group_users_idx1', 'user_qq', 'belonging_group', unique=True)
|
||||
|
||||
@classmethod
|
||||
async def ensure(cls, user_qq: int, belonging_group: int, for_update: bool = False) -> 'OpenCasesUser':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
if for_update:
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
return user or await cls.create(
|
||||
user_qq=user_qq,
|
||||
belonging_group=belonging_group,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def get_user_all(cls, group_id: int = None) -> 'list':
|
||||
user_list = []
|
||||
if not group_id:
|
||||
query = await cls.query.gino.all()
|
||||
else:
|
||||
query = await cls.query.where(
|
||||
(cls.belonging_group == group_id)
|
||||
).gino.all()
|
||||
for user in query:
|
||||
user_list.append(user)
|
||||
return user_list
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,59 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
from services.db_context import db
|
||||
|
||||
|
||||
class SignGroupUser(db.Model):
|
||||
__tablename__ = 'sign_group_users'
|
||||
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
user_qq = db.Column(db.BigInteger(), nullable=False)
|
||||
belonging_group = db.Column(db.BigInteger(), nullable=False)
|
||||
|
||||
checkin_count = db.Column(db.Integer(), nullable=False)
|
||||
checkin_time_last = db.Column(db.DateTime(timezone=True), nullable=False)
|
||||
impression = db.Column(db.Numeric(scale=3, asdecimal=False), nullable=False)
|
||||
add_probability = db.Column(db.Numeric(scale=3, asdecimal=False), nullable=False, default=0)
|
||||
specify_probability = db.Column(db.Numeric(scale=3, asdecimal=False), nullable=False, default=0)
|
||||
|
||||
_idx1 = db.Index('sign_group_users_idx1', 'user_qq', 'belonging_group', unique=True)
|
||||
|
||||
@classmethod
|
||||
async def ensure(cls, user_qq: int, belonging_group: int, for_update: bool = False) -> 'SignGroupUser':
|
||||
query = cls.query.where(
|
||||
(cls.user_qq == user_qq) & (cls.belonging_group == belonging_group)
|
||||
)
|
||||
if for_update:
|
||||
query = query.with_for_update()
|
||||
user = await query.gino.first()
|
||||
return user or await cls.create(
|
||||
user_qq=user_qq,
|
||||
belonging_group=belonging_group,
|
||||
checkin_count=0,
|
||||
checkin_time_last=datetime.min, # 从未签到过
|
||||
impression=0,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
async def query_impression_all(cls, belonging_group: int) -> 'list,list':
|
||||
impression_list = []
|
||||
user_qq_list = []
|
||||
query = cls.query.where(
|
||||
(cls.belonging_group == belonging_group)
|
||||
)
|
||||
for user in await query.gino.all():
|
||||
impression_list.append(user.impression)
|
||||
user_qq_list.append(user.user_qq)
|
||||
return user_qq_list, impression_list
|
||||
|
||||
@classmethod
|
||||
async def query_glod_all(cls, belonging_group: int) -> 'list,list':
|
||||
glod_list = []
|
||||
user_qq_list = []
|
||||
query = cls.query.where(
|
||||
(cls.belonging_group == belonging_group)
|
||||
)
|
||||
for user in await query.gino.all():
|
||||
glod_list.append(user.glod)
|
||||
user_qq_list.append(user.user_qq)
|
||||
return user_qq_list, glod_list
|
||||
Loading…
Reference in New Issue
Block a user