-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
35 lines (27 loc) · 951 Bytes
/
bot.py
File metadata and controls
35 lines (27 loc) · 951 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import telebot
from telebot import types
import time
import sys, re, os, random
TOKEN = str(open("../../APIKEY.txt", 'r').read()).replace("\n","")
bot = telebot.TeleBot(TOKEN)
def listener(messages):
for m in messages:
cid = m.chat.id
if m.content_type == 'text': # Sólo saldrá en el log los mensajes tipo texto
if cid > 0:
mensaje = str(m.chat.first_name) + " [" + str(cid) + "]: " + m.text
else:
mensaje = str(m.from_user.first_name) + "[" + str(cid) + "]: " + m.text
f = open('log.txt', 'a')
f.write(mensaje + "\n")
f.close()
print mensaje
bot.set_update_listener(listener)
@bot.message_handler(commands=['x'])
def command_hola(m):
cid = m.chat.id
#bot.send_photo(cid, open("s.jpg", 'rb'))
bot.send_message(cid, "hola")
bot.polling(none_stop=True)