Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
does what it seems. for VK
#!/usr/bin/python
# -*- coding: utf-8 -*-
# v 0.1.3
#
# __ ___ _ __ __
# / |/ /___ (_)___/ /___ ____ / / ___ _ ___
# / /|_/ // -_)/ // _ // _ \/ __// _ \/ _ `// _ \
# /_/ /_/ \__//_/ \_,_/ \___/\__//_//_/\_,_//_//_/
#
# © Akasaka Ryuunosuke, 2014
# vk.com/akasaka
#
# ____ __ _ ____ _
# / ___| ___ _ __ / _|(_) __ _ | __ ) ___ | | ___ __ __
# | | / _ \ | '_ \ | |_ | | / _` | | _ \ / _ \| | / _ \\ \ /\ / /
# | |___| (_) || | | || _|| || (_| | | |_) || __/| || (_) |\ V V /
# \____|\___/ |_| |_||_| |_| \__, | |____/ \___||_| \___/ \_/\_/
# |___/
APIID = '' # VK app id
SECRET = '' # VK api secret
LOGIN = '' # Your phone
PASW = '' # Ur password
BLACKLIST = [200197676, 264777279] # Fuckers that hate your scripted shit
HRS_DELAY = 7 # If an autoreply happened within THIS hours, don't annoy again
MIN_IDLE = 20 # Minimal idle in minutes to consider that an autoreply is needed
MAX_IDLE = 30 # Maximal idle to consider that u kinda died and its too late to reply
ATTACH = 'photo174350119_307520355' # What bullshit to show as a reply
TITLE = '** AUTOMATED RESPONSE FROM SERVER **' # Bold bullshit in message
MESSEJI = '** AUTOMATED RESPONSE FROM SERVER **' # Not bold bullshit (enclose russki bullshit in u'' instead)
#
# _ _
# | \ | | ___ __ __
# | \| | / _ \\ \ /\ / /
# | |\ || (_) |\ V V /
# |_| \_| \___/ \_/\_/
# __ _
# / _| _ _ ___ | | __
# | |_ | | | | / __|| |/ /
# | _|| |_| || (__ | <
# |_| \__,_| \___||_|\_\
# __ __ _
# ___ / _| / _| __ _ _ __ __| |
# / _ \ | |_ | |_ / _` || '_ \ / _` |
# | (_) || _|| _| | (_| || | | || (_| |
# \___/ |_| |_| \__,_||_| |_| \__,_|
# _ _ _
# _ __ _ _ _ __ | |_ | |__ (_) ___
# | '__|| | | || '_ \ | __|| '_ \ | |/ __|
# | | | |_| || | | | | |_ | | | || |\__ \
# |_| \__,_||_| |_| \__||_| |_||_||___/
# _ _ _ _ _
# | | | |__ (_)| |_ | |
# / __)| '_ \ | || __|| |
# \__ \| | | || || |_ |_|
# ( /|_| |_||_| \__|(_)
# |_|
# Dependencies
import vk_api, datetime
from vk_api import upload
import pdb
import json, urllib, random
def canPM(user):
return (vk.method('users.get', {'user_ids':str(user), 'fields':'can_write_private_message'})[0]['can_write_private_message'] == 1)
try:
vk = vk_api.VkApi(login=LOGIN,password=PASW,app_id=APIID, token=SECRET )
except:
print "SAS"
def seekHistory(hist):
now = datetime.datetime.now()
for hitm in hist:
mins = (now - datetime.datetime.fromtimestamp(int(hitm['date']))).seconds /60
if MESSEJI in hitm['body'] and mins < 60*HRS_DELAY and hitm['out'] > 0:
return True
return False
def findOldestUnread(hist):
for hitm in hist:
if hitm['out'] == 0 and hitm['read_state'] == 0:
# find the first incoming unread
prev = hitm
break
for hitm in hist:
# seek thru all
if hitm['out'] == 0 and hitm['read_state'] == 0 and hitm['date'] < prev['date']:
# remember the message if it is older than previous and is incoming and unread
prev = hitm
if hitm['out'] == 0 and hitm['read_state'] == 1:
# if we hit a read incoming message, unlikely to find an unread after it
break
return prev
dias = vk.method('messages.getDialogs', {'unread':1})['items']
for dia in dias:
if 'chat_id' in dia['message']:
continue
if int(dia['message']['user_id']) in BLACKLIST:
continue
if not canPM(dia['message']['user_id']):
continue
dh = vk.method('messages.getHistory', {'user_id':dia['message']['user_id']})['items']
now = datetime.datetime.now()
mins= (now - datetime.datetime.fromtimestamp(int( findOldestUnread(dh)['date'] ))).seconds /60
if not seekHistory(dh) and mins > MIN_IDLE and mins < MAX_IDLE:
vk.method('messages.send', {'user_id':dia['message']['user_id'], 'attachment':ATTACH,'title':TITLE,'message':MESSEJI})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment