-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
69 lines (52 loc) · 2.23 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
""" Bot para el grupo Python_Cientifico """
from telegram import User, TelegramObject, ChatMember
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import logging as log
import json
TOKEN = "445026185:AAEGtZap8RVXlVmi-9AHB_3_6gxIsJCEBi4"
log.basicConfig(level=log.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = log.getLogger(__name__)
#---------Funciones del bot---------------
def new_user(bot, update):
user_name = update.message.from_user.name
mensaje = ("Bienvenido %s al grupo de Python Científico, aquí podrás compartir cosas sobre" % str(user_name) +
"Todo el entorno cientifico de este gran lenguaje")
bot.sendMessage(chat_id=update.message.chat_id, text=mensaje)
bot.ChatMember(user_name)
def normas(bot, update):
user_name = update.message.from_user.name
ChatMember("Estas son las normas bla bla")
def help(bot, update):
user_name = update.message.from_user.name
mensaje = ("Estoy aquí para ayudarte %s") %str(user_name)
bot.sendMessage(chat_id=update.message.chat_id, text=mensaje)
# Test del bot pero con POO
#
# class Bot(object):
# def __init__(self, bot, update):
# self.user_name = update.message.from_user.name
#
#
# def new_user(self, bot, update):
# bot.sendMessage("Bienvenido %s al grupo de Python Científico, aquí podrás compartir cosas sobre" % str(self.user_name) +
# "Todo el entorno cientifico de este gran lenguaje")
#
# def normas(self, bot, update):
# telegram.User.ChatMember(self.user_name, "Estas son las normas bla bla")
#
# def help(self, bot, update):
# bot.sendMessage("Estoy aquí para ayudarte %s") %str(self.user_name)
#--------------COMANDOS--------------
def main():
updater = Updater(TOKEN)
dp = updater.dispatcher
dp.add_handler(CommandHandler("help", help))
dp.add_handler(CommandHandler("normas" or "Normas", normas))
# Mensaje para los nuevos usuarios
dp.add_handler(MessageHandler(Filters.status_update.new_chat_members, new_user))
# Ignora todos los mensajes hasta que se le llama
updater.start_polling(clean=True)
updater.idle()
if __name__ == "__main__":
main()