feat(models): Add deactivate_friend command and active field to Friend model

This commit is contained in:
Ching 2024-02-08 15:46:44 +08:00
parent fa94f38536
commit 309b4989e7
3 changed files with 19 additions and 1 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"conventionalCommits.scopes": [
"models"
]
}

View File

@ -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()

View File

@ -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__)