49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
|
#!/bin/python
|
||
|
|
||
|
from fedibot import main, api
|
||
|
import gelb
|
||
|
import conf
|
||
|
import random
|
||
|
api.instance=conf.instance
|
||
|
api.token=conf.token
|
||
|
gelb.conf=conf.gelb
|
||
|
|
||
|
tags=conf.tags
|
||
|
pointer=int(random.random()*len(tags))
|
||
|
|
||
|
@main.loop(20*60)
|
||
|
async def shitpost():
|
||
|
global pointer
|
||
|
tag=tags[pointer]
|
||
|
pointer+=1; pointer%=len(tags)
|
||
|
img,name,src,ecchi=await gelb.getgelbimg(tag)
|
||
|
await api.post(f'#{tag} {src}',[(name,img)],{'sensitive':ecchi})
|
||
|
|
||
|
def unescape(thing):
|
||
|
out=[]
|
||
|
m=len(thing)
|
||
|
i=0
|
||
|
while i<m:
|
||
|
if thing[i]=='_':
|
||
|
try:
|
||
|
out.append(chr(int(thing[i+1:i+3],16)))
|
||
|
i+=3
|
||
|
continue
|
||
|
except ValueError: pass
|
||
|
out.append(thing[i])
|
||
|
i+=1
|
||
|
return ''.join(out)
|
||
|
|
||
|
@main.loop(30)
|
||
|
async def reeepost():
|
||
|
async for notif in api.stream('GET','notifications',{'included_types[]':['mention'],'types[]':['mention']},lambda x:{'max_id':x[-1]['id']}):
|
||
|
s=notif['status']
|
||
|
tag=s['tags']
|
||
|
if not tag: continue
|
||
|
tag=unescape(tag[0]['name'])
|
||
|
img,name,src,ecchi=await gelb.getgelbimg(tag)
|
||
|
if not img: await api.post(f'no images in {tag}, maybe you got the name backwards',json={'in_reply_to_id':s['id']}); continue
|
||
|
await api.post(f'#{tag} {src}',[(name,img)],{'sensitive':ecchi,'in_reply_to_id':s['id']})
|
||
|
await api.call('POST','notifications/clear')
|
||
|
|
||
|
main.run()
|