Skip to content

Instantly share code, notes, and snippets.

@mquezada
Created November 23, 2016 22:24
Show Gist options
  • Save mquezada/d63af5b4c6aca07a842dfc2a96ff7bb2 to your computer and use it in GitHub Desktop.
Save mquezada/d63af5b4c6aca07a842dfc2a96ff7bb2 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
import telepot
from pprint import pprint
import time
import random
import string
import sys
saludo = set(("wena", "hola", "buenas", "holi"))
miguel_saludo = ("bonita compadre",
"buena man",
'buena master',
'ooh grande maestro',
'alegale 420',
"bonita master",
"bonita man",
"hola man",
"mmm",
"cerveza?",
'what',
"que onda maestro?",
"que onda maestro que le paso?",
'bonita man',
'que onda?',
"que wea mmm",
'pkmn go?')
mensajes = ("mmm",
"que latita man",
'conchetumadre mi primo',
'alegale 420',
'cerveza?',
'xasta pibe',
'dalep',
'llevo chelas a chile?',
'xd',
'clarop',
'eeeh',
'Oooh',
'Mmm',
':(',
'ok',
"yep",
"nop",
"en 15",
"hahaha")
def sendMessage(bot, chat_id):
def send(message_set, threshold=0.4):
if isinstance(message_set, basestring):
message = message_set
else:
i = random.randint(0, len(message_set) - 1)
message = message_set[i]
if random.random() > threshold:
pprint("sending message " + message)
bot.sendMessage(chat_id, message)
else:
pprint("not triggered")
return send
def handle(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
flavor = telepot.flavor(msg)
pprint(msg)
pprint("flavor " + flavor)
if flavor != 'chat':
return
send_from = sendMessage(bot, chat_id)
if 'text' in msg:
text = msg['text']
else:
text = ''
tokens = set(map(string.lower, text.split()))
if content_type == "text":
if 'miguel' in tokens:
send_from(mensajes, threshold=0.5)
elif tokens.intersection(saludo) or random.random() > 0.999:
send_from(miguel_saludo)
elif '<3' in text or '❤️' in text or '@miguelthebot' in tokens: # no se triggerea con el ❤️
send_from("❤", threshold=0)
elif text.endswith('?') and 'tiempo' in text:
send_from("yo paso, 0 tiempo", threshold=0.3)
token = sys.argv[1]
bot = telepot.Bot(token)
print 'Listening ...'
bot.message_loop(handle)
while 1:
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment