Ejemplo n.º 1
0
 async def wrapper(*args, **kwargs):
     member_id = -1
     group_id = -1
     for i in args:
         if isinstance(i, Member):
             member_id = i.id
         if isinstance(i, Group):
             group_id = i.id
     if member_id == -1 or group_id == -1 or not await get_setting(
             group_id, Setting.frequency_limit):
         if asyncio.iscoroutinefunction(func):
             return await func(*args, **kwargs)
         return func(*args, **kwargs)
     frequency_limit_instance = GlobalFrequencyLimitDict()
     frequency_limit_instance.add_record(group_id, member_id, weight)
     if frequency_limit_instance.blacklist_judge(group_id, member_id):
         if not frequency_limit_instance.announce_judge(
                 group_id, member_id):
             frequency_limit_instance.blacklist_announced(
                 group_id, member_id)
             raise FrequencyLimitExceededAddBlackList
         else:
             raise FrequencyLimitExceededDoNothing
     if frequency_limit_instance.get(group_id) + weight >= 10:
         raise FrequencyLimitExceeded
     else:
         frequency_limit_instance.update(group_id, weight)
         if asyncio.iscoroutinefunction(func):
             return await func(*args, **kwargs)
         return func(*args, **kwargs)
Ejemplo n.º 2
0
 async def wrapper(*args, **kwargs):
     member_id = -1
     group_id = -1
     for i in args:
         if isinstance(i, Member):
             member_id = i.id
         if isinstance(i, Group):
             group_id = i.id
     if member_id == -1 or group_id == -1:
         if asyncio.iscoroutinefunction(func):
             return await func(*args, **kwargs)
         return func(*args, **kwargs)
     frequency_limit_instance = GlobalFrequencyLimitDict()
     frequency_limit_instance.add_record(group_id, member_id, weight)
     if frequency_limit_instance.blacklist_judge(group_id, member_id):
         if not frequency_limit_instance.announce_judge(
                 group_id, member_id):
             frequency_limit_instance.blacklist_announced(
                 group_id, member_id)
             return MessageItem(
                 MessageChain.create(
                     [Plain(text="检测到大量请求,警告一次,加入黑名单一小时!")]),
                 QuoteSource(GroupStrategy()))
         else:
             return MessageItem(MessageChain.create([]),
                                DoNoting(GroupStrategy()))
     if frequency_limit_instance.get(group_id) + weight >= 10:
         return MessageItem(
             MessageChain.create([
                 Plain(
                     text="Frequency limit exceeded every 10 seconds!")
             ]), QuoteSource(GroupStrategy()))
     else:
         frequency_limit_instance.update(group_id, weight)
         if asyncio.iscoroutinefunction(func):
             return await func(*args, **kwargs)
         return func(*args, **kwargs)