class Guild(Document): class Meta: strict = False id = fields.IntegerField(attribute="_id") channel = fields.IntegerField(default=None) channels = fields.ListField(fields.IntegerField, default=list) prefix = fields.StringField(default=None) silence = fields.BooleanField(default=False) display_images = fields.BooleanField(default=True) auction_channel = fields.IntegerField(default=None) lat = fields.FloatField(default=37.7790262) lng = fields.FloatField(default=-122.4199061) loc = fields.StringField( default= "San Francisco, San Francisco City and County, California, United States of America" ) @property def is_day(self): sun = Sun(self.lat, self.lng) sunrise, sunset = sun.get_sunrise_time(), sun.get_sunset_time() if sunset < sunrise: sunset += timedelta(days=1) now = datetime.now(timezone.utc) return (sunrise < now < sunset or sunrise < now + timedelta(days=1) < sunset or sunrise < now + timedelta(days=-1) < sunset)
class Member(Document): class Meta: collection_name = "member" # vouch = fields.ListField(fields.IntegerField, default=list) id = fields.IntegerField(attribute="_id") balance = fields.IntegerField(default=0) banker_balance = fields.IntegerField(default=0) joined_at = fields.DateTimeField(default=None) suspended = fields.BooleanField(default=False) invites = fields.IntegerField(default=0) gatcha_counter = fields.DictField(fields.StringField(), fields.IntegerField(), default=dict) # shitty event collected code has_collected = fields.BooleanField(default=False) # even more shitty reputation system vouched_for = fields.ListField(fields.IntegerField()) vouched_by = fields.ListField(fields.IntegerField()) reported_for = fields.ListField(fields.IntegerField()) reported_by = fields.ListField(fields.IntegerField()) pray_count = fields.IntegerField(default=0) pray_winnings = fields.IntegerField(default=0) #event system event_activated = fields.BooleanField(default=False) event_multiplier = fields.FloatField(default=1.0) work_activated = fields.BooleanField(default=False) bonus_bought = fields.BooleanField(default=False) points = fields.FloatField(default=0.0)
class Member(Document): class Meta: strict = False id = fields.IntegerField(attribute="_id") pokemon = fields.ListField(fields.EmbeddedField(Pokemon), required=True) selected = fields.IntegerField(required=True) order_by = fields.StringField(default="number") pokedex = fields.DictField(fields.StringField(), fields.IntegerField(), default=dict) shinies_caught = fields.IntegerField(default=0) balance = fields.IntegerField(default=0) redeems = fields.IntegerField(default=0) shiny_hunt = fields.IntegerField(default=None) shiny_streak = fields.IntegerField(default=0) boost_expires = fields.DateTimeField(default=datetime.min) last_voted = fields.DateTimeField(default=datetime.min) vote_total = fields.IntegerField(default=0) vote_streak = fields.IntegerField(default=0) gifts_normal = fields.IntegerField(default=0) gifts_great = fields.IntegerField(default=0) gifts_ultra = fields.IntegerField(default=0) gifts_master = fields.IntegerField(default=0) silence = fields.BooleanField(default=False) joined_at = fields.DateTimeField(default=None) invites = fields.IntegerField(default=0) suspended = fields.BooleanField(default=False) @property def selected_pokemon(self): try: return next( filter(lambda x: x.number == int(self.selected), self.pokemon)) except StopIteration: return None @property def boost_active(self): return datetime.utcnow() < self.boost_expires @property def shiny_hunt_chance(self): return (1 + 2 * math.tanh(self.shiny_streak / 100)) / 4096 def determine_shiny(self, species): if self.shiny_hunt != species.dex_number: return random.randint(1, 4096) == 1 else: return random.random() < self.shiny_hunt_chance
class Action(EmbeddedDocument): """ :ivar typing.List[str] text: :ivar List[Dict] operations: :ivar isQuestion bool: :ivar immediatlyNext bool: """ text = fields.ListField(fields.StringField(), required=True, null=False) operations = fields.ListField(fields.DictField(), required=False) isQuestion = fields.BooleanField(required=True) immediatlyNext = fields.BooleanField(required=True)
class User(Document): name = fields.StringField(required=True) email = fields.EmailField(required=True, unique=True) password = fields.StringField() confirm_code = fields.StringField() reset_code = fields.StringField(default="") is_admin = fields.BooleanField(default=False) is_math_basic = fields.BooleanField(default=True) class Meta: collection = db.user
class Payment(Document): id_order = fields.ReferenceField(Order) status = fields.BooleanField() del_dtime = fields.DateTimeField() class Meta: collection = db.employee
class MemberWarning(Document): id = fields.IntegerField(attribute="_id") member_id = fields.IntegerField(required=True) guild_id = fields.IntegerField(required=True) reason = fields.StringField(default=None) active = fields.BooleanField(default=True) date_issued = fields.DateTimeField(default=datetime.min)
class Guild(Document): _id = fields.IntegerField(unique=True) title = fields.StrField() reactions_status = fields.BooleanField() class Meta: collection_name = 'guild'
class Reaction(Document): string = fields.StrField(attribute='_id', unique=True) reaction = fields.StrField() is_emb = fields.BooleanField() guild = fields.ReferenceField(document=Guild) class Meta: collection_name = 'reaction'
class User(Document): name = fields.StringField(required=True, unique=True) admin = fields.BooleanField(required=True) password_hash = fields.StringField(required=True) salt = fields.StringField(required=True) class Meta: collection = db.tawep.user
class Route(Document, metaclass=MetaBaseTemplate): author = fields.UUIDField(required=True) title = fields.StringField(validate=validate.Length(max=255), required=True) vectors = fields.ListField(fields.EmbeddedField(Vector), missing=list) is_public = fields.BooleanField(missing=False, default=False) created = fields.DateTimeField(missing=datetime.utcnow) class Meta: collection_name = "routes"
class MySchema(Schema): string = fields.StringField() uuid = fields.UUIDField() number = fields.NumberField() integer = fields.IntegerField() decimal = fields.DecimalField() boolean = fields.BooleanField() float = fields.FloatField() url = fields.UrlField() email = fields.EmailField() constant = fields.ConstantField("const")
class Project(Document): projectId = fields.StrField(required=True) name = fields.StrField(required=True) ownerName = fields.StrField(required=True) ownerORCID = fields.StrField(required=True) description = fields.StrField() createdDate = fields.DateTimeField(default=datetime.now) updatedDate = fields.DateTimeField(default=datetime.now) samples = fields.ListField(fields.ReferenceField("Sample")) isLocked = fields.BooleanField(default="false") class Meta: collection_name = "project"
class MySchema(EmbeddedSchema): string = fields.StringField() uuid = fields.UUIDField() number = fields.NumberField() integer = fields.IntegerField() decimal = fields.DecimalField() boolean = fields.BooleanField() formattedstring = fields.FormattedStringField('Hello {to_format}') float = fields.FloatField() # localdatetime = fields.LocalDateTimeField() url = fields.UrlField() email = fields.EmailField() constant = fields.ConstantField("const")
class User(Document): class Meta: collection_name = 'users' indexes = [] id = fields.IntField(required=True, unique=True, attribute='_id') process_flag = fields.BooleanField(default=False) created = fields.DateTimeField(required=True) visited = fields.DateTimeField(required=True) username = fields.StrField(required=True, allow_none=True) first_name = fields.StrField(required=True) last_name = fields.StrField(required=True, allow_none=True, default=None) language_code = fields.StrField(required=True, allow_none=True) language = fields.StrField(required=True)
class MLmodel(Document): # description = fields.StringField(required=True) # to remember the functionality of the pkl file filename = fields.StringField(required=True) # plk file name path = fields.StringField(required=True) # path of the plk file version = fields.StringField(required=True) # plk file version department = fields.StringField(required=True) # assign the model to department team = fields.StringField(required=True) # assign the model to team features = fields.StringField(required=True) # features have to be assigned name = fields.StringField(required=True) # model name isDeployed = fields.BooleanField(required=True,default=False) createDate = fields.DateTimeField(validate=validate.Range(min=pd.Timestamp(1990,1,1)),required=True) updateDate = fields.DateTimeField(validate=validate.Range(min=pd.Timestamp(1990,1,1)),required=True) class Meta(): collection = db.mlmodel
class CustomerRepayDetail(Document): customer = fields.ReferenceField(Customer) # 顾客 money = fields.StringField() # 金额 time = fields.StringField() # 付款时间 is_active = fields.BooleanField(missing=True) # 记录有效性 created_time = fields.DateTimeField(missing=datetime.datetime.now) # 记录时间 @classmethod async def new_repay(cls, customer_id='', money='', time=''): customer = await Customer.find_one({'id': ObjectId(customer_id)}) try: await cls(customer=customer, money=money, time=time).commit() return {'errcode': 0, 'msg': '添加成功'} except: return {'errcode': 1, 'msg': '添加失败'} @classmethod async def get_repay_list(cls, customer_id=''): return await cls.find({'customer': ObjectId(customer_id)}).to_list(length=None)
class Customer(Document): name = fields.StrField() # 姓名 address = fields.StringField() # 住址 tel = fields.StringField() # 电话号码 remarks = fields.StringField() # 备注 is_active = fields.BooleanField(missing=True) # 记录有效性 created_time = fields.DateTimeField(missing=datetime.datetime.now) # 记录时间 @classmethod async def new_customer(cls, name='', address='', tel='', remarks=''): return await cls(name=name, address=address, tel=tel, remarks=remarks).commit() @classmethod async def get_customers(cls, is_active=None): if is_active == None or is_active == 'true': return await cls.find({"is_active": True}).sort([('created_time', -1)]).to_list(length=None) return await cls.find({"is_active": is_active}).sort([('created_time', -1)]).to_list(length=None) @classmethod async def get_customer(cls, id=''): try: return await cls.find_one({"id": ObjectId(id)}) except: return None @classmethod async def update_customer(cls, id='', address='', tel='', remarks=''): customer = await cls.find_one({"id": ObjectId(id)}) if customer: customer.address = address customer.tel = tel customer.remarks = remarks await customer.commit() return {'errcode': 0, 'msg': '修改成功'} return {'errcode': 1, 'msg': '修改失败,请稍后再试'}
class CustomerGoodsDetail(Document): customer = fields.ReferenceField(Customer) # 顾客 stock_name = fields.StringField() # 货物 stock_num = fields.IntField(missing=0) # 数量 stock_price = fields.FloatField(missing=0) # 单价 stock_amount = fields.FloatField(missing=0) # 金额 is_active = fields.BooleanField(missing=True) # 记录有效性 created_time = fields.DateTimeField(missing=datetime.datetime.now) # 记录时间 @classmethod async def new_c_detail(cls, customer_id='', stock_name=''): customer = await Customer.find_one({'id': ObjectId(customer_id)}) stock = await Stock.find_one({'name': stock_name}) detail = await cls.find_one({'customer': ObjectId(customer_id), 'stock_name': stock_name}) if customer and stock: if detail: pass else: c_detail = await cls(customer=customer, stock_name=stock_name, stock_price=stock.price).commit() return {'id': str(c_detail.inserted_id),'stock_name': stock_name, 'stock_num': 0,'stock_price': stock.price, 'stock_amount': 0} return None @classmethod async def get_customer_goods(cls, customer_id=''): return await cls.find({'customer': ObjectId(customer_id)}).to_list(length=None) @classmethod async def update_customer_goods(cls, id='', customer_id='', num=0, price=0): customer_goods = await cls.find_one({'id': ObjectId(id), 'customer': ObjectId(customer_id)}) if customer_goods: customer_goods.stock_num = num customer_goods.stock_price = price customer_goods.stock_amount = num * price await customer_goods.commit()
class BaseDocument(Document): modified = fields.DateTimeField() active = fields.BooleanField(default=True) meta = {'abstract': True}
class Pokemon(EmbeddedDocument): class Meta: strict = False id = fields.ObjectIdField(attribute="_id") species_id = fields.IntegerField(required=True) level = fields.IntegerField(required=True) xp = fields.IntegerField(required=True) nature = fields.StringField(required=True) iv_hp = fields.IntegerField(required=True) iv_atk = fields.IntegerField(required=True) iv_defn = fields.IntegerField(required=True) iv_satk = fields.IntegerField(required=True) iv_sdef = fields.IntegerField(required=True) iv_spd = fields.IntegerField(required=True) nickname = fields.StringField(default=None) favorite = fields.BooleanField(default=False) shiny = fields.BooleanField(required=True) held_item = fields.IntegerField(default=None) moves = fields.ListField(fields.IntegerField, default=list) idx = None _hp = None @classmethod def random(cls, **kwargs): return cls( iv_hp=random_iv(), iv_atk=random_iv(), iv_defn=random_iv(), iv_satk=random_iv(), iv_sdef=random_iv(), iv_spd=random_iv(), nature=random_nature(), shiny=random.randint(1, 4096) == 1, **kwargs, ) @property def species(self): return self.bot.data.species_by_number(self.species_id) @property def max_xp(self): return 250 + 25 * self.level @property def max_hp(self): if self.species_id == 292: return 1 return ((2 * self.species.base_stats.hp + self.iv_hp + 5) * self.level // 100 + self.level + 10) @property def hp(self): if self._hp is None: return self.max_hp return self._hp @hp.setter def hp(self, value): self._hp = value @property def atk(self): return math.floor( ((2 * self.species.base_stats.atk + self.iv_atk + 5) * self.level // 100 + 5) * constants.NATURE_MULTIPLIERS[self.nature]["atk"]) @property def defn(self): return math.floor( ((2 * self.species.base_stats.defn + self.iv_defn + 5) * self.level // 100 + 5) * constants.NATURE_MULTIPLIERS[self.nature]["defn"]) @property def satk(self): return math.floor( ((2 * self.species.base_stats.satk + self.iv_satk + 5) * self.level // 100 + 5) * constants.NATURE_MULTIPLIERS[self.nature]["satk"]) @property def sdef(self): return math.floor( ((2 * self.species.base_stats.sdef + self.iv_sdef + 5) * self.level // 100 + 5) * constants.NATURE_MULTIPLIERS[self.nature]["sdef"]) @property def spd(self): return math.floor( ((2 * self.species.base_stats.spd + self.iv_spd + 5) * self.level // 100 + 5) * constants.NATURE_MULTIPLIERS[self.nature]["spd"]) @property def iv_percentage(self): return (self.iv_hp / 31 + self.iv_atk / 31 + self.iv_defn / 31 + self.iv_satk / 31 + self.iv_sdef / 31 + self.iv_spd / 31) / 6 def get_next_evolution(self, is_day): if self.species.evolution_to is None or self.held_item == 13001: return None possible = [] for evo in self.species.evolution_to.items: if not isinstance(evo.trigger, models.LevelTrigger): continue can = True if evo.trigger.level and self.level < evo.trigger.level: can = False if evo.trigger.item and self.held_item != evo.trigger.item_id: can = False if evo.trigger.move_id and evo.trigger.move_id not in self.moves: can = False if evo.trigger.move_type_id and not any([ self.bot.data.move_by_number(x).type_id == evo.trigger.move_type_id for x in self.moves ]): can = False if (evo.trigger.time == "day" and not is_day or evo.trigger.time == "night" and is_day): can = False if evo.trigger.relative_stats == 1 and self.atk <= self.defn: can = False if evo.trigger.relative_stats == -1 and self.defn <= self.atk: can = False if evo.trigger.relative_stats == 0 and self.atk != self.defn: can = False if can: possible.append(evo.target) if len(possible) == 0: return None return random.choice(possible) def can_evolve(self, ctx): return self.get_next_evolution() is not None
class PokemonBase(MixinDocument): class Meta: strict = False abstract = True # General id = fields.ObjectIdField(attribute="_id") timestamp = fields.DateTimeField(default=datetime.utcnow) owner_id = fields.IntegerField(required=True) idx = fields.IntegerField(required=True) # Details species_id = fields.IntegerField(required=True) level = fields.IntegerField(required=True) xp = fields.IntegerField(required=True) nature = fields.StringField(required=True) shiny = fields.BooleanField(required=True) # Stats iv_hp = fields.IntegerField(required=True) iv_atk = fields.IntegerField(required=True) iv_defn = fields.IntegerField(required=True) iv_satk = fields.IntegerField(required=True) iv_sdef = fields.IntegerField(required=True) iv_spd = fields.IntegerField(required=True) iv_total = fields.IntegerField(required=False) # Customization nickname = fields.StringField(default=None) favorite = fields.BooleanField(default=False) held_item = fields.IntegerField(default=None) moves = fields.ListField(fields.IntegerField, default=list) has_color = fields.BooleanField(default=False) color = fields.IntegerField(default=None) _hp = None ailments = None stages = None def __format__(self, spec): if self.shiny: name = "✨ " else: name = "" if "l" in spec: name += f"Level {self.level} " elif "L" in spec: name += f"L{self.level} " if "p" in spec: name += f"{self.iv_percentage:.2%} " if self.bot.sprites.status and "i" in spec: sprite = self.bot.sprites.get(self.species.dex_number, shiny=self.shiny) name = sprite + " " + name name += str(self.species) if self.nickname is not None and "n" in spec: name += ' "' + self.nickname + '"' if self.favorite and "f" in spec: name += " ❤️" return name def __str__(self): return f"{self}" @classmethod def random(cls, **kwargs): ivs = [random_iv() for i in range(6)] return cls( iv_hp=ivs[0], iv_atk=ivs[1], iv_defn=ivs[2], iv_satk=ivs[3], iv_sdef=ivs[4], iv_spd=ivs[5], iv_total=sum(ivs), nature=random_nature(), shiny=random.randint(1, 4096) == 1, **kwargs, ) @property def species(self): return self.bot.data.species_by_number(self.species_id) @property def max_xp(self): return 250 + 25 * self.level @property def max_hp(self): if self.species_id == 292: return 1 return ((2 * self.species.base_stats.hp + self.iv_hp + 5) * self.level // 100 + self.level + 10) @property def hp(self): if self._hp is None: return self.max_hp return self._hp @hp.setter def hp(self, value): self._hp = value @property def atk(self): return calc_stat(self, "atk") @property def defn(self): return calc_stat(self, "defn") @property def satk(self): return calc_stat(self, "satk") @property def sdef(self): return calc_stat(self, "sdef") @property def spd(self): return calc_stat(self, "spd") @property def iv_percentage(self): return (self.iv_hp / 31 + self.iv_atk / 31 + self.iv_defn / 31 + self.iv_satk / 31 + self.iv_sdef / 31 + self.iv_spd / 31) / 6 def get_next_evolution(self, is_day): if self.species.evolution_to is None or self.held_item == 13001: return None possible = [] for evo in self.species.evolution_to.items: if not isinstance(evo.trigger, models.LevelTrigger): continue can = True if evo.trigger.level and self.level < evo.trigger.level: can = False if evo.trigger.item and self.held_item != evo.trigger.item_id: can = False if evo.trigger.move_id and evo.trigger.move_id not in self.moves: can = False if evo.trigger.move_type_id and not any([ self.bot.data.move_by_number(x).type_id == evo.trigger.move_type_id for x in self.moves ]): can = False if evo.trigger.time == "day" and not is_day or evo.trigger.time == "night" and is_day: can = False if evo.trigger.relative_stats == 1 and self.atk <= self.defn: can = False if evo.trigger.relative_stats == -1 and self.defn <= self.atk: can = False if evo.trigger.relative_stats == 0 and self.atk != self.defn: can = False if can: possible.append(evo.target) if len(possible) == 0: return None return random.choice(possible) def can_evolve(self, ctx): return self.get_next_evolution() is not None
class Stock(Document): name = fields.StringField(unique=True, required=True) # 名称 num = fields.IntField(missing=0) # 数量 unit = fields.StringField() # 单位 opening_price = fields.FloatField() # 进价 price = fields.FloatField() # 单价 opening_amount = fields.FloatField() # 进价总额 amount = fields.FloatField() # 总额 remarks = fields.StringField() # 备注 is_active = fields.BooleanField(missing=True) # 记录有效性 created_time = fields.DateTimeField(missing=datetime.datetime.now) # 记录时间 class Meta: collection_name = 'stock' @classmethod async def create_stock(cls, name='', num=0, unit='', opening_price=0, price=0, remarks=''): stock = await cls.find_one({"name": name}) if stock: return {'errcode': 1, 'msg': '已经有了物料,换个名字吧'} await cls(name=name, num=num, unit=unit, opening_price=opening_price, price=price, opening_amount=opening_price * num, amount=price * num, remarks=remarks).commit() return {'errcode': 0, 'msg': '添加成功'} # 获取物料列表 @classmethod async def get_stocks(cls, is_active=None): if is_active == 'true' or is_active == True: return await cls.find({"is_active": True}).sort([('created_time', 1)]).to_list(length=None) return await cls.find({"is_active": False}).sort([('created_time', 1)]).to_list(length=None) @classmethod async def get_stocks_count(cls): return await cls.find({"is_active": True}).count() # 获取物料 @classmethod async def get_stock(cls, id=''): try: return await cls.find_one({'id': ObjectId(id)}) except: return None # 删除物料 @classmethod async def delete_stock(cls, id=''): try: stock = await cls.get_stock(id) stock.is_active = False await stock.commit() return {'errcode': 0, 'msg': '已删除'} except: return {'errcode': 1, 'msg': '没有此物料,请检查物料列表'} # 修改物料 @classmethod async def update_stock(cls, name='', num=0, unit='', opening_price=0, price=0, remarks=''): stock = await cls.find_one({"name": name}) if stock: if stock.num == num and stock.unit == unit and stock.opening_price == opening_price and stock.price == price and stock.remarks == remarks: return {'errcode': 1, 'msg': '您没有任何修改'} stock.num = num stock.unit = unit stock.opening_price = opening_price stock.price = price stock.opening_amount = opening_price * num stock.amount = price * num stock.remarks = remarks await stock.commit() return {'errcode': 0, 'msg': '已修改'} return {'errcode': 1, 'msg': '没有此货物'}
class Users(Document): uid = fields.StringField(unique=True, required=True) # 管理员uid token = fields.StrField(unique=True, required=True) # 管理员登录token user = fields.StringField(unique=True, required=True) # 管理员登录用户名 password = fields.StringField() # 管理员登录密码 type = fields.StringField() # 管理员类型 -- 超级管理员/普通管理员 real_name = fields.StringField() # 管理员真实姓名 department = fields.StringField() # 管理员部门 position = fields.StringField() # 管理员职位 tel = fields.StringField() # 移动电话 email = fields.StringField() # 邮箱 qq = fields.StringField() # qq号 wechat = fields.StringField() # 微信 is_active = fields.BooleanField(missing=True) # 记录有效性 expires_time = fields.IntegerField() # token过期时间 created_time = fields.DateTimeField(missing=datetime.datetime.now) # 记录时间 class Meta: collection_name = 'users' # 新建管理员 @classmethod async def new_user(cls, uid='', token='', user='', password='', real_name='', department='', position='', tel='', email='', qq='', wechat='', type='普通管理员',expires_time=''): ifuser = await cls.find_one({"user": user}) if ifuser: return {'errcode': 1, 'msg': '已经有了该用户,换个名字吧'} await cls(uid=uid, token=token, user=user, password=password, type=type, real_name=real_name, department=department, position=position, tel=tel, email=email, qq=qq, wechat=wechat, expires_time=expires_time).commit() return {'errcode': 0, 'msg': '添加成功'} # 查找管理员 用户登录 @classmethod async def user_login(cls, user_name='', password=''): try: user = await cls.find_one({'user': user_name}) if user.password == password: type = COMMON_USER_TYPE if user.type == '普通管理员' else SUPER_USER_TYPE user_login = str(type) + str(int(time.time())) + random_str() userToken = generateUserToken(user.uid, user_login) user.token = userToken['token'] user.expires_time = userToken['expiretime'] await user.commit() return {'errcode': 0, 'msg': '用户登录成功', 'data': {'user': user.user,'token':user.token}} else: return {'errcode': 1, 'msg': '密码错误,请重新输入密码'} except: return {'errcode': 1, 'msg': '没有该用户'} # 更新管理员 @classmethod async def update_user(cls, id='', department='', position='', tel='', email='', qq='', wechat=''): ifuser = await cls.find_one({"id": ObjectId('id')}) if ifuser: ifuser.department = department ifuser.position = position ifuser.tel = tel ifuser.email = email ifuser.qq = qq ifuser.wechat = wechat await ifuser.commit() return {'errcode': 0, 'msg': '已修改'} return {'errcode': 1, 'msg': '没有此管理员'} # 获取管理员列表 @classmethod async def get_users(cls): return await cls.find({"is_active": True}).sort([('created_time', -1)]).to_list(length=None) # 用户token @classmethod async def get_user_token(cls, user='',token=''): try: return await cls.find_one({"user": user, 'token': token}) except: return None # 获取管理员列表 @classmethod async def get_user(cls, id=''): try: return await cls.find_one({"id": ObjectId(id)}) except: return None # 删除管理员 @classmethod async def delete_user(cls, id=''): try: user = await cls.find_one({"id": ObjectId(id)}) user.is_active = False await user.commit() return {'errcode': 0, 'msg': '已删除'} except: return {'errcode': 1, 'msg': '没有此管理员,请检查管理员列表'}
class Member(Document): class Meta: strict = False # General id = fields.IntegerField(attribute="_id") joined_at = fields.DateTimeField(default=None) suspended = fields.BooleanField(default=False) # Pokémon next_idx = fields.IntegerField(default=1) selected_id = fields.ObjectIdField(required=True) order_by = fields.StringField(default="number") # Pokédex pokedex = fields.DictField(fields.StringField(), fields.IntegerField(), default=dict) shinies_caught = fields.IntegerField(default=0) # Shop balance = fields.IntegerField(default=0) premium_balance = fields.IntegerField(default=0) redeems = fields.IntegerField(default=0) redeems_purchased = fields.DictField(fields.IntegerField(), fields.IntegerField(), default=dict) embed_colors = fields.IntegerField(default=0) # Shiny Hunt shiny_hunt = fields.IntegerField(default=None) shiny_streak = fields.IntegerField(default=0) # Boosts boost_expires = fields.DateTimeField(default=datetime.min) shiny_charm_expires = fields.DateTimeField(default=datetime.min) # Voting last_voted = fields.DateTimeField(default=datetime.min) need_vote_reminder = fields.BooleanField(default=False) vote_total = fields.IntegerField(default=0) vote_streak = fields.IntegerField(default=0) gifts_normal = fields.IntegerField(default=0) gifts_great = fields.IntegerField(default=0) gifts_ultra = fields.IntegerField(default=0) gifts_master = fields.IntegerField(default=0) # Settings show_balance = fields.BooleanField(default=True) silence = fields.BooleanField(default=False) # Events halloween_tickets = fields.IntegerField(default=0) hquests = fields.DictField(fields.StringField(), fields.BooleanField(), default=dict) hquest_progress = fields.DictField(fields.StringField(), fields.IntegerField(), default=dict) halloween_badge = fields.BooleanField(default=False) @property def selected_pokemon(self): try: return next( filter(lambda x: x.number == int(self.selected), self.pokemon)) except StopIteration: return None @property def boost_active(self): return datetime.utcnow() < self.boost_expires @property def shiny_charm_active(self): return datetime.utcnow() < self.shiny_charm_expires @property def shiny_hunt_multiplier(self): # NOTE math.log is the natural log (log base e) return 1 + math.log(1 + self.shiny_streak / 30) def determine_shiny(self, species): chance = 1 / 4096 if self.shiny_charm_active: chance *= 1.2 if self.shiny_hunt == species.dex_number: chance *= self.shiny_hunt_multiplier return random.random() < chance
class User(Document): login = fields.StrField() password = fields.StrField() disabled = fields.BooleanField() is_superuser = fields.BooleanField()
class NormalizerExtTempl(NormalizerTempl): editable = fields.BooleanField(required=True)
class Guild(Document): id = fields.IntegerField(attribute="_id") channel = fields.IntegerField(default=None) channels = fields.ListField(fields.IntegerField, default=list) prefix = fields.StringField(default=None) silence = fields.BooleanField(default=False)
class AdvancedUser(self.User): name = fields.StrField(default='1337') is_left_handed = fields.BooleanField()
class GoodsTemplate(Document): name = fields.StrField(unique=True, required=True) # 名称 goods = fields.ListField(fields.ReferenceField(Stock)) # 用料列表 remarks = fields.StringField() # 备注 is_active = fields.BooleanField(missing=True) # 记录有效性 created_time = fields.DateTimeField(missing=datetime.datetime.now) # 记录时间 @classmethod async def new_goods_template(cls, name='', remarks='', goods=[]): stock = await cls.find_one({"name": name}) if stock: return {'errcode': 1, 'msg': '模板已存在,换个名字吧'} list = [] for item in goods: stock = await Stock.find_one({'name': item}) list.append(stock) # print('new_goods_template', list) await cls(name=name, goods=list, remarks=remarks).commit() return {'errcode': 0, 'msg': '添加成功'} # 获取模板信息 @classmethod async def get_tem_goods_list(cls, id=''): try: data = await cls.find_one({'id': ObjectId(id)}) list = [] for good in data.goods: stock = await Stock.get_stock(good.pk) list.append(stock.name) return {'name': data.name, 'remarks': data.remarks, 'list': list} except: return None # 模板列表 @classmethod async def goods_template_list(cls, is_active=None): if is_active == None or is_active == 'true': return await cls.find({"is_active": True}).sort([('created_time', -1)]).to_list(length=None) return await cls.find({"is_active": is_active}).sort([('created_time', -1)]).to_list(length=None) # 更新模板 @classmethod async def update_goods_template(cls, name='', remarks='', good=[]): goods_tem = await cls.find_one({"name": name}) if goods_tem: list = [] for item in good: stock = await Stock.find_one({'name': item}) list.append(stock) goods_tem.goods = list goods_tem.remarks = remarks await goods_tem.commit() return {'errcode': 0, 'msg': '修改成功'} return {'errcode': 1, 'msg': '没有此模板'} # 删除模板 @classmethod async def delete_goods_template(cls, id=''): try: goods_tem = await cls.find_one({'id': ObjectId(id)}) goods_tem.is_active = False await goods_tem.commit() return {'errcode': 0, 'msg': '已删除'} except: return {'errcode': 1, 'msg': '没有此模板,请仔细检查模板'}