def saveWikiPage(page, page_id, group=group_id): logger.debug("Saving a wiki_page ({})".format(page_id)) vk(api.pages.save, suspend_time=1, text=page, user_id=my_id, page_id=page_id, group_id=group)
def sendMessages(users, message): """ int[] users, str message """ for user in users: try: vk(api.messages.send, user_id=user, message=message) logger.debug("Succesfully sent the message to {}".format(user)) except: logger.debug("Failed to send the message to {}".format(user))
def getEweekPostComments(): """ Возвращает список комментариев зарегистрировавшихся на еженедельник игроков """ search_results = vk(api.wall.search, owner_id=-group_id, query="#aottg83_reg", count=1) post_id = search_results['items'][0]['id'] comments = vk(api.wall.getComments, owner_id=-group_id, post_id=post_id, count=30) return comments['items']
def getComments(topic, amount): """ Получение последних комментариев в обсуждении topic """ count = vk(api.board.getComments, group_id=topic.group, topic_id=topic.id, count=amount)['count'] if count >= amount: offset = count - amount else: offset = 0 response = vk(api.board.getComments, group_id=topic.group, topic_id=topic.id, offset=offset, count=amount) return response['items']
def _makePage(name): """ У любой гильдии есть вики-страница в ВК """ page_id = vk(api.pages.save, text="", title=name, user_id=my_id, group_id=group_id) return page_id
def getCommentsFromResultTopic(): """ Берет комменты из обсуждения, где мы пишем результаты участников """ topic_id = 35693273 response = vk(api.board.getComments, topic_id=topic_id, group_id=test_id, count=50) return response['items']
def post(post_text, post_time, group_id=group_id): """ Публикует пост с таймером """ logger.debug("Publishing a post...") try: post_id = vk(api.wall.post, owner_id=-group_id, from_group=1, message=post_text, publish_date=post_time) except: logger.debug("Wrong time. Retrying...") return post(post_text, post_time + 120) else: return post_id['post_id']
def sendErrorMessage(name, exception=None): """ Использует либо полученную ошибку, либо ту, что возникла последней """ logger.debug("Sending error message...") exception = format_error(exception) message = "{}:\n{}".format(name, exception) vk(api.messages.send, user_id=emergency_id, message=message)
def getPostComments(post_id): comments = vk(api.wall.getComments, owner_id=-group_id, post_id=post_id, count=30) return comments['items']
def getEweekPostId(): post = vk(api.wall.search, owner_id=-group_id, query="#aottg83_reg", count=1) return post['items'][0]['id']