From 309b4989e749865b4c0eba29d9716ed332be3012 Mon Sep 17 00:00:00 2001 From: Ching Date: Thu, 8 Feb 2024 15:46:44 +0800 Subject: [PATCH] feat(models): Add deactivate_friend command and active field to Friend model --- .vscode/settings.json | 5 +++++ discord_bot.py | 12 ++++++++++++ dota.py | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3cdd50f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "conventionalCommits.scopes": [ + "models" + ] +} diff --git a/discord_bot.py b/discord_bot.py index 2249ac4..f8da974 100644 --- a/discord_bot.py +++ b/discord_bot.py @@ -85,6 +85,18 @@ async def add_friend(ctx, steam_id, name): friend = dota.Friend.create(steam_id=steam_id, name=name) await ctx.respond(content=f'添加成功 {steam_id} {name}') +@bot.command(description='禁用朋友', name='deactivate_friend') +async def deactivate_friend(ctx, steam_id): + logger.info(f'deactivate_friend {steam_id}') + friend = dota.Friend.get_or_none(steam_id=steam_id) + if friend: + friend.active = False + friend.save() + await ctx.respond(content=f'禁用成功 {steam_id}') + else: + await ctx.respond(content=f'找不到 {steam_id}') + + @tasks.loop(minutes=1) async def heartbeat(): utils.heartbeat() diff --git a/dota.py b/dota.py index cacfef2..7d2f46e 100644 --- a/dota.py +++ b/dota.py @@ -75,6 +75,7 @@ class Match(BaseModel): class Friend(BaseModel): steam_id = peewee.IntegerField(primary_key=True) name = peewee.CharField() + active = peewee.BooleanField(default=True) def get_recent_matches(self, limit=1): try: @@ -156,7 +157,7 @@ class Friend(BaseModel): def get_friends_recent_matches(): matches = [] - for friend in Friend.select(): + for friend in Friend.select(active=True): for match_ in friend.get_recent_matches(): if not Match.select().where(Match.match_id == match_.match_id).exists(): logger.info('create match, match info: %s' % match_.__dict__)