def updateChatList(bot, job):
logger.debug("-----------------------updatedChatList--------------------")
logger.info("Updating the chat list")
results = MDB.groups.find()
for doc in results:
try:
chat = bot.getChat(chat_id = doc['_id'])
logger.info("Chat %s (%s) responded." % (chat.title, chat.id))
admins = [chatmember.user.id for chatmember in bot.getChatAdministrators(chat_id=doc['_id'])]
MDB.groups.find_one_and_update({'_id':doc['_id']},
{ '$set' : {'title':chat.title, "admins":admins}})
except TelegramError as te:
logger.warning("Removing %s (%s) from the database, it is not responding, re-add the bot if this is incorrect." % (doc['title'],doc['_id']))
logger.debug("Error received: %s" % (str(te)))
MDB.groups.remove({'_id':doc['_id']})
except:
logger.info("Other error when checking %s (%s), check networking" % (doc['title'],doc['_id']))
评论列表
文章目录