This repository has been archived on 2024-07-28. You can view files and clone it, but cannot push or open issues or pull requests.
moderator-bot/utils/reload_users.py

31 lines
911 B
Python
Raw Normal View History

2023-01-04 15:14:32 -05:00
async def reload_users_data():
import config
from database import Member
from load import tgc, bot
members = await tgc.members_list(config.group_id)
for member in members:
user = Member.get_or_none(Member.user_id == member["id"])
first_name = member["first_name"]
if (not first_name):
first_name = "NULL"
if (not user):
Member.create(
2023-02-18 08:16:54 -05:00
user_id=member["id"],
first_name=first_name,
username=member["username"],
2023-01-04 15:14:32 -05:00
)
else:
user.first_name = first_name
2023-02-18 08:16:54 -05:00
user.username = member["username"]
2023-01-04 15:14:32 -05:00
user.save()
group = await bot.get_chat(config.group_id)
2023-02-18 08:16:54 -05:00
group_permissions = group.permissions.__dict__
2023-01-04 15:14:32 -05:00
for permission in group_permissions.keys():
config.group_permissions[permission] = group_permissions[permission]