Compare commits

..

6 Commits

Author SHA1 Message Date
Boris Daniel Martinez Millán b86e1710e3 Security Update 2
2 years ago
Boris Daniel Martinez Millán 9970729ade Ahora si un comando no esta documentado t
2 years ago
Boris Daniel Martinez Millán 860ba28049 Fix of uptime command
2 years ago
Boris Daniel Martinez Millán b56932fcf0 Second unstable commit
2 years ago
Boris Daniel Martinez Millán 25542f702b First unstable commit
2 years ago
borisd93 71906d2c7d Create
2 years ago

@ -12,16 +12,26 @@ 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):
bot.send_chat_action(chat_id=chat, action=telegram.ChatAction.TYPING)
context.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
@ -97,10 +107,9 @@ try:
except:
pass
bot=Bot(token)
def start(update:Update, context: CallbackContext) -> None:
typing(update.message.chat_id)
"""Inicia el Bot"""
context.bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
try:
lan=io.open(update.effective_user.username,"r")
lang=lan.read()
@ -113,25 +122,20 @@ def start(update:Update, context: CallbackContext) -> None:
update.message.reply_text(welcome['es'])
def sugerir(update:Update, context: CallbackContext) -> None:
bot.send_chat_action(chat_id=update.message.chat_id, action=telegram.ChatAction.TYPING)
"""Sugiere que aladan algo o mejoren algo"""
context.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"
bot.send_message(chat_id=admin_id,text="El personaje: @"+update.effective_user.username+" hizo una sugerencia: "+" ".join(context.args))
context.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:
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:
@ -151,15 +155,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))
@ -68,13 +69,14 @@ 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"
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)
@ -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.check_output('uptime',shell=True,universal_newlines=True))
Loading…
Cancel
Save