First unstable commit

unstable
Boris Daniel Martinez Millán 2 years ago
parent 71906d2c7d
commit 25542f702b

@ -12,6 +12,8 @@ from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update,ReplyMar
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, CallbackContext, MessageHandler, Filters, CallbackContext
#Importandk Friendica
from friendica_module import log_friend,logout_friend,publish,notifications
#Importando Uptime
from uptime_module import uptime
#Importando la base
import requests,io,random,re,api,crud,datetime,time,telegram
from os import remove
@ -22,7 +24,11 @@ def typing(chat):
ua = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:60.0) Gecko/20100101'
ua += ' Firefox/60.0'
HEADERS = {'user-agent': ua}
help1=''
def log_function(dispatcher,name,function1):
global help1
dispatcher.add_handler(CommandHandler(name,function1))
help1=help1+str('/'+name)+' -> '+function1.__doc__+'\n\n'
#Idioma español
es={'help':'''/start - Inicia el bot
@ -100,6 +106,7 @@ except:
bot=Bot(token)
def start(update:Update, context: CallbackContext) -> None:
"""Inicia el Bot"""
typing(update.message.chat_id)
try:
lan=io.open(update.effective_user.username,"r")
@ -113,6 +120,7 @@ def start(update:Update, context: CallbackContext) -> None:
update.message.reply_text(welcome['es'])
def sugerir(update:Update, context: CallbackContext) -> None:
"""Sugiere que aladan algo o mejoren algo"""
bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
try:
lan=io.open(update.effective_user.username,"r")
@ -124,17 +132,12 @@ def sugerir(update:Update, context: CallbackContext) -> None:
update.reply_text(return_string('finish',))
def help(update:Update, context: CallbackContext) -> None:
bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
try:
lan=io.open(update.effective_user.username,"r")
lang=lang.read()
lan.close()
except:
lang="es"
update.message.reply_text(return_string('help',lang))
"""Devuelve esta ayuda"""
update.message.reply_text(help1)
def set(update:Update, context: CallbackContext) -> None:
"""Establece alguna configuraciones"""
if update.message.text.replace("/set ","").split(" ")[0]=="language":
if "en" in update.message.text.replace("/set ","").split(" "):
f=io.open(update.effective_user.username,"w")
@ -151,15 +154,15 @@ def set(update:Update, context: CallbackContext) -> None:
if __name__=='__main__':
updater=Updater(token=token)
dispatcher=updater.dispatcher
dispatcher.add_handler(CommandHandler('start', start))
dispatcher.add_handler(CommandHandler('sugerencia', sugerir))
dispatcher.add_handler(CommandHandler('login_f', log_friend))
dispatcher.add_handler(CommandHandler('logout_f', logout_friend))
dispatcher.add_handler(CommandHandler('publish', publish))
dispatcher.add_handler(CommandHandler('help',help))
dispatcher.add_handler(CommandHandler('set',set))
dispatcher.add_handler(CommandHandler('notifications',notifications))
log_function(dispatcher,'start', start)
log_function(dispatcher,'sugerencia', sugerir)
log_function(dispatcher,'login_f', log_friend)
log_function(dispatcher,'logout_f', logout_friend)
log_function(dispatcher,'publish', publish)
log_function(dispatcher,'help',help)
log_function(dispatcher,'set',set)
log_function(dispatcher,'notifications',notifications)
log_function(dispatcher,'uptime',uptime)
updater.start_polling()
updater.idle()

@ -43,13 +43,14 @@ def return_string(string,lang):
return es[string]
def log_friend(update: Update, context: CallbackContext) -> None:
"""Permite el logueo en tu instancia de friendica"""
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)
context.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))
@ -65,16 +66,17 @@ def log_friend(update: Update, context: CallbackContext) -> None:
crud.save();crud.close()
except ValueError:
update.message.reply_text(return_string('usu_l_f',lang))
context.bot.delete_message(chat_id = update.message.chat_id, message_id = update.message.message_id)
context.context.bot.delete_message(chat_id = update.message.chat_id, message_id = update.message.message_id)
def logout_friend(update: Update, context: CallbackContext) -> None:
"""Borra la cuenta de tu instancia de friendica"""
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)
context.bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
crud.connect("friend_users.db")
if len(crud.read("users","telegram",update.message.chat_id))==1:
crud.delete("users","telegram",str(update.message.chat_id))
@ -84,13 +86,14 @@ def logout_friend(update: Update, context: CallbackContext) -> None:
else:
update.message.reply_text(return_string('not_l_f',lang))
def publish(update: Update, context: CallbackContext) -> None:
"""Publica en tu cuenta, requiere estar logueado"""
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)
context.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)
@ -124,7 +127,7 @@ def publish(update: Update, context: CallbackContext) -> None:
rex.replace("!hora!",horavar)
friend.share(rex,contexto.replace(rex,'').replace('/publish','')+"\n#telegram")
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)
context.context.bot.delete_message(chat_id = update.message.chat_id, message_id = update.message.message_id)
else:
friend=api.FriendApi("https://friendicarg.nsupdate.info/",r[0][1],r[0][2])
contexto=update.message.text
@ -157,13 +160,14 @@ def publish(update: Update, context: CallbackContext) -> None:
else:
update.message.reply_text(return_string('not_l_f',lang))
def notifications(update:Update,context:CallbackContext):
"""Devuelve las notificaciones de tu cuenta"""
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)
context.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:
@ -173,13 +177,14 @@ def notifications(update:Update,context:CallbackContext):
update.message.reply_text(return_string('not_l_f',lang))
def get_5(update:Update,context:CallbackContext):
"""Devuelve los ultimos 5 posts del apartado network"""
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)
context.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:

@ -0,0 +1,8 @@
import subprocess
from telegram import Update
from telegram.ext import Updater, CallbackContext
def uptime(update: Update,context: CallbackContext):
"""Uptime es un modulo solo compatible con linux que permite ver el tiempo desde que se encendio la pc"""
update.message.reply_text(subprocess_output('uptime',shell=True))
Loading…
Cancel
Save