Skip to content

Commit

Permalink
FreqLimiter for weibo
Browse files Browse the repository at this point in the history
  • Loading branch information
王见思 committed May 21, 2020
1 parent a02c9f2 commit e1b8dda
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hoshino/modules/weibo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
}]
'''

lmt = util.FreqLimiter(5)

def _load_config(services_config):
for sv_config in services_config:
sv.logger.debug(sv_config)
Expand Down Expand Up @@ -78,6 +81,11 @@ def wb_to_message(wb):
# @bot 看微博 alias
@sv.on_command('看微博', only_to_me=True)
async def get_last_5_weibo(session):
uid = session.ctx['user_id']
if not lmt.check(uid):
session.finish('您查询得过于频繁,请稍等片刻', at_sender=True)
lmt.start_cd(uid)

alias = session.current_arg_text
if alias not in alias_dic:
await session.finish(f"未找到微博: {alias}")
Expand All @@ -88,6 +96,7 @@ async def get_last_5_weibo(session):
spiders = subr_dic[service_name]["spiders"]
for spider in spiders:
if spider.get_user_id() == user_id:
await spider.get_latest_weibos()
last_5_weibos = spider.get_last_5_weibos()
formatted_weibos = [wb_to_message(wb) for wb in last_5_weibos]
for wb in formatted_weibos:
Expand Down

0 comments on commit e1b8dda

Please sign in to comment.