Skip to content

Instantly share code, notes, and snippets.

@firstspring1845
Last active January 2, 2016 00:28
Show Gist options
  • Save firstspring1845/8223138 to your computer and use it in GitHub Desktop.
Save firstspring1845/8223138 to your computer and use it in GitHub Desktop.
あぷでねーむ
# -*- encoding:utf-8 -*-
import re,threading
import twitter,util
t = {34:None,60:None,62:None,12288:None,65288:40,65289:41,10:None,65312:64} #全角スペース等の除去とか一部全角記号を半角に変換とか
r = re.compile('\([^(]*?@' + twitter.account.name + '.*?\)')
def on_data(data):
if 'friends' in data:
global ids
ids = set(data['friends'])
return
if(util.is_mention(data)):
if not data['user']['screen_name'] == twitter.account.name and not data['user']['id'] in ids:
return
if 'retweeted_status' in data:
return #リツイートは窓から投げ捨てろ
s = data['text']
s = s.translate(t)
un = u'@' + twitter.account.name + u' update_name '
#re.matchはstrとunicodeで挙動が違うっぽい
if re.search(r,s) != None:
s = re.sub(r,'',s)
threading.Thread(target=update_name,args=[data,s]).start()
print(u'他者紹介ですね')
elif un in s:
s = s.replace(un,u'')
threading.Thread(target=update_name,args=[data,s]).start()
print('mention_me')
def update_name(data,name):
t = twitter.get(1,1)
j = t.post('account/update_profile.json',data={'name':name}).json()
if 'errors' in j:
t.post('statuses/update.json',data={'status':u'@' + data['user']['screen_name'] + u' 名前が入力されてないか文字数が多すぎます','in_reply_to_status_id':data['id']})
else:
name = name.replace(u'@',u'@\u200c')
t.post('statuses/update.json',data={'status':u'@' + data['user']['screen_name'] + u' ' + name + u'に改名しました','in_reply_to_status_id':data['id']})
t.post('favorites/create.json',data={'id':data['id']})
def reply(t,data,text):
t.post('statuses/update.json',data={'status':text,'in_reply_to_status_id':data['id']})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment