init commit

This commit is contained in:
Zergling_man 2023-01-02 21:34:54 +11:00
commit 309c4111ef
3 changed files with 79 additions and 0 deletions

49
birds.py Normal file
View File

@ -0,0 +1,49 @@
#!/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()

5
example_conf.py Normal file
View File

@ -0,0 +1,5 @@
instance='nigge.rs'
token='XxXXxXxxxxxXXXXxxxxXXXxxxXXXXxxXXXxxXxX'
gelb={"api_key": "fagfagfagfagfagfag", "user_id":9001}
tags=['your_mum','lwmmg_(girls_frontline)']

25
gelb.py Normal file
View File

@ -0,0 +1,25 @@
import aiohttp as ah
import json as j
from os import path
#conf=j.load(open(path.join(path.dirname(__file__),'config.json')))[path.splitext(path.basename(__file__))[0]]
baseurl='https://gelbooru.com/index.php'
async def getgelbimg(tags):
params={'page':'dapi','s':'post','q':'index','limit':1,'json':1}
params|=conf
if isinstance(tags,str): params['tags']=f'{tags} sort:random'
if isinstance(tags,list): params['tags']=' '.join(tags+['sort:random'])
async with ah.ClientSession() as sess:
async with sess.get(baseurl,params=params) as resp:
try: data=(await resp.json())['post'][0]
except KeyError: print('no result'); return None,None,None,None
async with sess.get(data['file_url']) as resp:
img=await resp.read()
src=f'https://gelbooru.com/index.php?page=post&s=view&id={data["id"]}'
ecchi=(data['rating']!="general") #lmao they changed it, need to fix this now
name=data['image']
return img,name,src,ecchi
#Gelb needs to put more API endpoints. Like edits.