Compare commits

..

No commits in common. 'unstable' and 'master' have entirely different histories.

@ -12,26 +12,16 @@ 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
#Funcion base, no eliminar
def typing(chat):
context.bot.send_chat_action(chat_id=chat, action=telegram.ChatAction.TYPING)
bot.send_chat_action(chat_id=chat, action=telegram.ChatAction.TYPING)
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))
try:
help1=help1+str('/'+name)+' -> '+function1.__doc__+'\n\n'
except:
help1=help1+str('/'+name)+' -> Not documented\n\n'
#Idioma español
es={'help':'''/start - Inicia el bot
@ -107,9 +97,10 @@ try:
except:
pass
bot=Bot(token)
def start(update:Update, context: CallbackContext) -> None:
"""Inicia el Bot"""
context.bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
typing(update.message.chat_id)
try:
lan=io.open(update.effective_user.username,"r")
lang=lan.read()
@ -122,20 +113,25 @@ 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"""
context.bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
try:
lan=io.open(update.effective_user.username,"r")
lang=io.read()
lan.close()
except:
lang="es"
context.bot.send_message(chat_id=admin_id,text="El personaje: @"+update.effective_user.username+" hizo una sugerencia: "+" ".join(context.args))
bot.send_message(chat_id=admin_id,text="El personaje: @"+update.effective_user.username+" hizo una sugerencia: "+" ".join(context.args))
update.reply_text(return_string('finish',))
def help(update:Update, context: CallbackContext) -> None:
"""Devuelve esta ayuda"""
update.message.reply_text(help1)
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))
def set(update:Update, context: CallbackContext) -> None:
@ -155,15 +151,15 @@ def set(update:Update, context: CallbackContext) -> None:
if __name__=='__main__':
updater=Updater(token=token)
dispatcher=updater.dispatcher
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)
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))
updater.start_polling()
updater.idle()

@ -43,14 +43,13 @@ 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"
context.bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
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))
@ -69,14 +68,13 @@ def log_friend(update: Update, context: CallbackContext) -> None:
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"
context.bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
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))
@ -86,14 +84,13 @@ 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"
context.bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
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)
@ -160,14 +157,13 @@ 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"
context.bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
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:
@ -177,14 +173,13 @@ 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"
context.bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
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:

@ -1,8 +0,0 @@
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.check_output('uptime',shell=True,universal_newlines=True))
Loading…
Cancel
Save