Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #22 from justice47/master
Browse files Browse the repository at this point in the history
* Added checking for posts with copyrights and group name to reposts
  • Loading branch information
alcortazzo authored Feb 3, 2021
2 parents 8801895 + 76a3e1b commit d26bf13
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
35 changes: 31 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Made by @alcortazzo
# v2.0
# v2.1

import os
import sys
Expand Down Expand Up @@ -108,6 +108,12 @@ def parsePosts(items, last_id):
f"[id:{item['id']}]Post was skipped because it was flagged as ad",
)
continue
if config.skipPostsWithCopyright and "copyright" in item:
addLog(
"i",
f"[id:{item['id']}]Post was skipped because it has copyright",
)
continue
addLog("i", f"[id:{item['id']}] Bot is working with this post")

def getLink(attachment):
Expand Down Expand Up @@ -183,6 +189,19 @@ def getDoc(attachment):
doc_title = attachment["doc"]["title"]
return docurl

def getPublicNameById(id):
try:
data = requests.get(
f"https://api.vk.com/method/groups.getById?access_token={config.vkToken}&v=5.103&group_id={id}"
)
return data.json()["response"][0]["name"]
except Exception as ex:
addLog(
"e",
f'[id:{item["id"]}] Something [{type(ex).__name__}] went wrong in parsePosts() --> getPublicNameById(): {str(ex)}',
)
return ""

"""
def getGif(attachment):
docurl = attachment['doc']['url']
Expand Down Expand Up @@ -224,10 +243,15 @@ def parseAttachments(item, linklist, vidlist, photolist, docslist):
item, links_list, videos_list, photo_url_list, docs_list
)
textOfPost = compileLinksAndText(
item["id"], textOfPost, links_list, videos_list, "post"
item["id"],
textOfPost,
links_list,
videos_list,
"post",
)
if "copy_history" in item and textOfPost != "":
textOfPost = f"""{textOfPost}\n\nREPOST ↓"""
groupName = getPublicNameById(abs(item["copy_history"][0]["owner_id"]))
textOfPost = f"""{textOfPost}\n\nREPOST ↓ {groupName}"""
sendPosts(
item["id"], textOfPost, photo_url_list, docs_list, gif_link, "post"
)
Expand All @@ -246,6 +270,8 @@ def parseAttachments(item, linklist, vidlist, photolist, docslist):
photo_url_list_rep = []
docs_list_rep = []
gif_link_rep = ""
group_id = abs(item_repost["owner_id"])
group_name = getPublicNameById(group_id)

if "attachments" in item_repost:
parseAttachments(
Expand All @@ -262,6 +288,7 @@ def parseAttachments(item, linklist, vidlist, photolist, docslist):
videos_list_rep,
"repost",
link_to_reposted_post,
group_name,
)
sendPosts(
item["id"],
Expand Down Expand Up @@ -539,7 +566,7 @@ def addLink():
addVideo()
addLink()
if repost[0] == "repost":
textOfPost = f'<a href="{repost[1]}"><b>REPOST ↓</b></a>\n\n<i>{textOfPost}</i>'
textOfPost = f'<a href="{repost[1]}"><b>REPOST ↓ {repost[2]}</b></a>\n\n<i>{textOfPost}</i>'
return textOfPost


Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
timeSleep = 60 * 2 # time in seconds
isPinned = False
skipAdsPosts = True
skipPostsWithCopyright = True

proxyEnable = False # Set True if telegram is not available in your country
proxyLogin = "bot" # Login for Socks5 proxy
Expand Down

0 comments on commit d26bf13

Please sign in to comment.