First Commit

This commit is contained in:
Boris Daniel Martinez Millán 2021-03-08 14:05:09 -05:00
parent 137333613c
commit 7c80206bcc
4 changed files with 43 additions and 12 deletions

View File

@ -1,4 +1,4 @@
# telefricabot
#Telefricabot
Es un proyecto hecho en python para utilizar telegram
como cliente de friendica, nacio desde la idea de un
@ -7,5 +7,3 @@ y entre esas estaba friendica, decidimos hacerlo publico
con la licencia GPL v3 para que otras instancias se lo
montaran en su pc o movil y tuviesen un bot propio sin
anuncios y sin saber programar.

17
api.py
View File

@ -1,3 +1,4 @@
import requests,io,random,re
ua = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101'
@ -38,4 +39,18 @@ class FriendApi():
else:
out=out+'\n'+'\n'+i.replace(re.findall('"><img src=".*" aria-hidden="true" class="notif-image">',i)[0],' ').replace('<span class="notif-when">','').replace('</span></a>','')
return out
def network(self,limit):
texto=self.session.get('https://friendicarg.nsupdate.info/network').text
exp=re.findall('<div class="wall-item-body e-content p-name">.*</div>',texto)
exp1=re.findall('"display/.*"',texto)
out=[]
for i in re.findall('<a href=".*" class="tag" title=".*">',texto):
texto=texto.replace(i,'')
for i in re.findall('<img src=".*" alt=".*" title=".*">',texto):
texto.replace(i,'')
for i in range(0,limit):
try:
out.append(exp[i].replace('</a>','').replace('</div>','').replace('<div class="wall-item-body e-content p-name">','').replace('<br>','')+'\n'+self.url+exp1[i].replace('"','').replace('><i class=icon-link icon-large><span class=ser-only','')+'\n\n')
except:
break
return out

View File

@ -6,8 +6,8 @@ name='Reisub-Bot -> Friendicarg'
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update,ReplyMarkup,Bot,user
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, CallbackContext, MessageHandler, Filters, CallbackContext
from include import friendica_u,token
import api,crud,re,io,telegram
token="1531348810:AAG_ZWBHHPI4qxjeWvyWOwwy3xPXsN_2KJ0"
bot=Bot(token)
es={'pub':'Publicado con exito 😉',
@ -50,11 +50,12 @@ def log_friend(update: Update, context: CallbackContext) -> None:
except:
lang="es"
bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
print(context.args)
if len(context.args)<=1:
update.message.reply_text(return_string('log_s_f',lang))
else:
try:
friend=api.FriendApi(friendica_u,context.args[0],context.args[1])
friend=api.FriendApi("https://friendicarg.nsupdate.info/",context.args[0],context.args[1])
crud.connect("friend_users.db")
if len(crud.read("users","telegram",update.message.chat_id))==0:
crud.create("users","'"+str(update.message.chat_id)+"','"+context.args[0]+"','"+context.args[1]+"'")
@ -90,12 +91,14 @@ def publish(update: Update, context: CallbackContext) -> None:
except:
lang="es"
bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
print(lang)
crud.connect("friend_users.db")
r=crud.read("users","telegram",update.message.chat_id)
if len(r)==1:
try:
if '-' in str(update.message.chat_id):
friend=api.FriendApi(friendica_u,r[0][1],r[0][2])
print('LOGGING DEBUG: RUNNING IN A GROUP, if this work please remove the line 93 of the code')
friend=api.FriendApi("https://friendicarg.nsupdate.info/",r[0][1],r[0][2])
contexto=update.message.text
rex=re.findall("#!.*!#",contexto)
if rex:
@ -123,7 +126,7 @@ def publish(update: Update, context: CallbackContext) -> None:
update.message.reply_text(rex+'\n'+contexto.replace('/publish@reisub_bot','').replace('/publish ','').replace('#!'+rex+'!#',''))
context.bot.delete_message(chat_id = update.message.chat_id, message_id = update.message.message_id)
else:
friend=api.FriendApi(friendica_u,r[0][1],r[0][2])
friend=api.FriendApi("https://friendicarg.nsupdate.info/",r[0][1],r[0][2])
contexto=update.message.text
rex=re.findall("#!.*!#",contexto)
if rex:
@ -164,8 +167,24 @@ def notifications(update:Update,context:CallbackContext):
crud.connect("friend_users.db")
r=crud.read("users","telegram",update.message.chat_id)
if len(r)==1:
friend=api.FriendApi(friendica_u,r[0][1],r[0][2])
friend=api.FriendApi("https://friendicarg.nsupdate.info/",r[0][1],r[0][2])
update.message.reply_text(friend.notifications(5))
else:
update.message.reply_text(return_string('not_l_f',lang))
def get_5(update:Update,context:CallbackContext):
try:
lan=io.open(update.effective_user.username,"r")
lang=lan.read()
lan.close()
except:
lang="es"
bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
crud.connect("friend_users.db")
r=crud.read("users","telegram",update.message.chat_id)
if len(r)==1:
friend=api.FriendApi("https://friendicarg.nsupdate.info/",r[0][1],r[0][2])
for i in range(0,4):
update.message.reply_text(friend.network(5)[i].replace('><i class=icon-link icon-large><span class=sr-only',''))
else:
update.message.reply_text(return_string('not_l_f',lang))

View File

@ -1,7 +1,6 @@
friendica_u='https://friendicarg.nsupdate.info/'
friendica_u='https://myfriendi.ca/'
welcome={
'es':'Hola bienvenido, ya cambia esto por favor',
'en':'Hi, and welcome, if you can, please change this!'
}
admin_id='123456789'
token='1654011024:AAEajJrasZ4GiKJr1LjzN-zFbaDmIhlkwnc'