<commit_before>'''
import sys
import time
import pprint
import telepot

def handle(msg):
    pprint.pprint(msg)
    # Do your stuff here ...


# Getting the token from command-line is better than embedding it in code,
# because tokens are supposed to be kept secret.
TOKEN = sys.argv[1]

# bot = telepot.Bot("<KEY>")
bot = telepot.Bot(TOKEN)
bot.message_loop(handle)
print ('Listening ...')

# Keep the program running.
while 1:
    time.sleep(10)
'''
import sys
import time
import telepot
import pprint

TOKEN = '<KEY>'
bot = telepot.Bot(TOKEN)


def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    print (content_type, chat_type, chat_id)
    if (content_type == "text"):
        show_keyboard = {'keyboard': [['Yes', 'No'], ['Maybe', 'Maybe not']]}
        bot.sendMessage(chat_id, "Bro, you just sent me a " +
                        content_type + "?", reply_markup=show_keyboard)
    else:
        bot.sendMessage(chat_id, "Bro, you sent something?")


bot.message_loop(handle)
print ('Listening ...')

# Keep the program running.
while 1:
    time.sleep(10)<commit_msg>Added a few programs to NUSQuestions.py<commit_after>import sys
import time
import telepot
import pprint

from pprint import pprint

TOKEN = '<KEY>'
'''
bot = telepot.Bot(TOKEN)


def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    print (content_type, chat_type, chat_id)
    if (content_type == "text"):
        show_keyboard = {'keyboard': [['Yes', 'No'], ['Maybe', 'Maybe not']]}
        bot.sendMessage(chat_id, "Bro, you just sent me a " +
                        content_type + "?", reply_markup=show_keyboard)

        # How do I store the user's reply here so that I can print it
        # Need to learn how to echo?

        hide_keyboard = {'hide_keyboard': True}
        bot.sendMessage(chat_id, "Im hiding the keyboard",
                        reply_markup=hide_keyboard)
    else:
        bot.sendMessage(chat_id, "Bro, you sent something?")


bot.message_loop(handle)
print ('Listening ...')

# Keep the program running.
while 1:
    time.sleep(10)
'''

# Message counter
"""
from telepot.delegate import per_chat_id, create_open


class MessageCounter(telepot.helper.ChatHandler):
    def __init__(self, seed_tuple, timeout):
        super(MessageCounter, self).__init__(seed_tuple, timeout)
        self._count = 0

    def on_chat_message(self, msg):
        self._count += 1
        self.sender.sendMessage(self._count)

bot = telepot.DelegatorBot(TOKEN, [
    (per_chat_id(), create_open(MessageCounter, timeout=10)),
])

bot.message_loop(run_forever=True)
print ('Listening ...')

# Keep the program running.
while 1:
    time.sleep(10)
"""

# Guess a number game
import random
import traceback
from telepot.delegate import per_chat_id, create_open
'''
class Player(telepot.helper.ChatHandler):
    def __init__(self, seed_tuple, timeout):
        super(Player, self).__init__(seed_tuple, timeout)
        self._answer = random.randint(0, 99)

    def _hint(self, answer, guess):
        if answer > guess:
            return 'larger'
        else:
            return 'smaller'

    def open(self, initial_msg, seed):
        self.sender.sendMessage('Guess my number')
        pprint(vars(self))
        pprint(vars(telepot.helper.ChatHandler))
        return True
        # prevent on_message() from being called on the initial message

    def on_chat_message(self, msg):
        content_type, chat_type, chat_id = telepot.glance(msg)

        if content_type != 'text':
            self.sender.sendMessage('Give me a number, please.')
            return

        try:
            guess = int(msg['text'])
        except ValueError:
            self.sender.sendMessage('Give me a number, please.')
            return

        # check the guess against the answer ...
        if guess != self._answer:
            # give a descriptive hint
            hint = self._hint(self._answer, guess)
            self.sender.sendMessage(hint)
        else:
            self.sender.sendMessage('Correct!')
            self.close()

    def on_close(self, exception):
        if isinstance(exception, telepot.exception.WaitTooLong):
            self.sender.sendMessage(
                'Game expired. The answer is %d' % self._answer)
'''


class TestShit(telepot.helper.ChatHandler):
    def __init__(self, seed_tuple, timeout):
        super(TestShit, self).__init__(seed_tuple, timeout)
        print("---- Initialization ----")
        print(seed_tuple)
        print("Timeout is " + str(timeout))

    def _hint(self, answer, guess):
        print "Is this supposed to reply to my messages?"

    def open(self, initial_msg, seed):
        print "---- Open function ----"
        self.sender.sendMessage("Your seed is " + str(seed))
        return True  # To prevent on_chat_message from being exec

    def on_chat_message(self, msg):
        print "More hello worlds since you are talking to me!"

    def on_close(self, exception):
        if isinstance(exception, telepot.exception.WaitTooLong):
            self.sender.sendMessage(
                'Expired. Try again')

bot = telepot.DelegatorBot(TOKEN, [
    (per_chat_id(), create_open(TestShit, timeout=10)),
])
bot.message_loop(run_forever=True)

{'fraction_non_alphanumeric': 0.11705367339170156, 'fraction_numerical': 0.004187285877426722, 'mean_word_length': 2.8052136133236787, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '62777', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1586, 'n_words': 436}