def post(post_id): if False == os.path.exists('./jokes'): return False if random.randint(0, 10) == 1: Vk.postComment("", post_id, Joke.__read()) Log.log("Post joke comment") return True return False
def __preCheck(self): for post in Vk.getWall(15, 'owner'): if "attachments" in post: if (datetime.datetime.now() - datetime.timedelta(minutes=self.post_pause) ) < datetime.datetime.fromtimestamp(post["date"]): return False return True
def __preCheck(self): if Log.getWeekday() == 5: return False for post in Vk.getWall(15, 'owner'): if "attachments" in post: if (datetime.datetime.now() - datetime.timedelta(minutes=240) ) < datetime.datetime.fromtimestamp(post["date"]): return False return True
def check(): Log.log("Wall scanning......", "info") try: for post in Vk.getWall(10, 'others'): if str(post["from_id"]) not in Security.access_id: Log.log(Security.__delWall(post["id"])) Log.log(Security.__banUser(post["from_id"])) username = Vk.getUser(post['from_id'], "first_name_gen, last_name_gen")[0] Vk.postMessages( Security.chat_id, "Пользователь @id{} ({} {}) заблокирован. Пост #{} с текстом '{}' удалён" .format(username['id'], username['first_name'], username['last_name'], post["id"], post["text"])) except KeyError as error: Log.log(str(error)) return True return True
def __read(self): randomChat = (random.choice(self.users_id)) item = Vk.getMessages(randomChat, rev=1, count=1) if item is not False: if item['attachments'] == [] and item['fwd_messages'] == []: Vk.delMessage(item['id'], for_all=0) Log.log("Message #" + str(item['id']) + " in #" + str(randomChat) + " chat not forward - deleted") return {} if item['attachments'] != []: try: self.image = item['attachments'][0]['photo']['sizes'][-1][ 'url'] tag = u"" except KeyError as error: Log.log(item) return {} if item['fwd_messages'] != []: self.image = item['fwd_messages'][0]['attachments'][0][ 'photo']['sizes'][-1]['url'] username = Vk.getUser(item['fwd_messages'][0]['from_id'], "first_name_gen, last_name_gen")[0] tag = u"от @id%s (%s %s)" % (username['id'], username['first_name_gen'], username['last_name_gen']) Vk.delMessage(item['id'], for_all=0) return {'key': self.tag(tag)} return {}
import time from os import listdir from importlib import import_module from bash_vk.vk import Vk from bash_vk.log import Log from bash_vk.base import Base from bash_vk.config import Config from bash_vk.config import BashReadError from bash_vk.security import Security from bash_vk.joke import Joke ### Load main classes ### Config.init("./bash.ini") Base.init("./bash.db") Vk.init() Security.init() ### DRATUTI ### Log.log(Config.getCfg("MAIN", "program") + " v." + Config.getCfg("MAIN", "version")) Log.log("=" * len(Config.getCfg("MAIN", "program") + " v." + Config.getCfg("MAIN", "version")) ) ### Dynamic load parsing classes from bash_vk\sites ### classes = [] files = listdir(".\\bash_vk\\sites") sites = filter(lambda x: x.endswith(".py"), files) sites = filter(lambda x: x != "__init__.py", sites) sites = filter(lambda x: x != "site_sample.py", sites) sites = map(lambda x: x[:-3], sites)
def __banUser(user_id): Vk.banUser(user_id, 86400, u"Запрещено постить на стене группы") return "User @id" + str(user_id) + " banned"
def __delWall(post_id): Vk.delWall(post_id) return "Post #" + str(post_id) + " deleted"