Beispiel #1
0
import json
import time
import threading
import config

app = Flask(__name__)
app.config.from_pyfile("config.py")
TOKEN = app.config['TOKEN']
timeout = app.config['MESSAGE_TIMEOUT']

# this to register new agents on doing /start
initialize_chat_ids()
bot = telepot.DelegatorBot(TOKEN, [
    pave_event_space()(per_chat_id(), create_open, AlertsStarter, timeout=3),
    pave_event_space()(
        per_callback_query_origin(), create_open, Alerter, timeout=5),
])
agent_chooser = AgentChooser()

message_loop = MessageLoop(bot)


def update_agents():

    agent_chooser.pull_repo()
    agent_chooser.update_agents()
    time.sleep(app.config.get("PULL_REPO_PERIOD", 1800))


agent_thread = threading.Thread(name="update_agents", target=update_agents)
agent_thread.start()
Beispiel #2
0
                self._show_next_state('Я хожу:')
                if not (self._stop or self._winner):
                    self._bot_answer()
                    self._show_next_state('Ты ходишь:')
            else:
                self._counter += 1
                self._show_next_state('Ты слепой? ({}):'.format(self._counter))

    def on__idle(self, event):
        self.editor.editMessageText('Слишком долго думаешь :(\nЯ пошёл 👋',
                                    reply_markup=None)
        time.sleep(5)
        self.editor.deleteMessage()
        self.close()


if __name__ == "__main__":
    TOKEN = '705103229:AAF20n1fAtMQn-1Askb9BKwdKEGyylBG51U'

    bot = telepot.DelegatorBot(TOKEN, [
        pave_event_space()(per_chat_id(), create_open, GameStarter, timeout=3),
        pave_event_space()(
            per_callback_query_origin(), create_open, Gamer, timeout=10),
    ])

    MessageLoop(bot).run_as_thread()
    print('Listening ...')

    while 1:
        time.sleep(10)
Beispiel #3
0
    def on_idle(self, event):
        self.editor.editMessageText('\n\nThis message will disappear in 5 seconds to test deleteMessage',
                                    reply_markup=None)
        time.sleep(5)
        self.editor.deleteMessage()
        self.close()

    """
        casos = {'hClase':hClase, 'hCurso':hCurso,'profesores':profesores, 'clases':clases, 'fichas':fichas}
        query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
        casos[query_data](int(from_id),msg)
        text = str(casos[query_data])
        bot.answerCallbackQuery(query_id, text)
"""


TOKEN = "423194965:AAFJtn4HcgYQmR0oN6WoSAEHZljARFlBSeI"

bot = telepot.DelegatorBot(TOKEN, [
    pave_event_space()(
        per_chat_id(), create_open, BotMentorStarter, timeout=60),
    pave_event_space()(
        per_callback_query_origin(), create_open, BotMentor, timeout=300),
])

MessageLoop(bot).run_as_thread()
print('Ejecutando BotMentor...')

# Keep the program running.
while 1:
    time.sleep(10)
Beispiel #4
0
        lat2 = float(locat[0])
        lng2 = float(locat[1])
        lat1 = float(uLoc[0])
        lng1 = float(uLoc[1])
        rad = math.pi / 180
        dlat = lat2 - lat1
        dlng = lng2 - lng1
        R = 6367.45  #media geometrica
        a = (math.sin(rad * dlat / 2))**2 + math.cos(rad * lat1) * math.cos(
            rad * lat2) * (math.sin(rad * dlng / 2))**2
        distance = 2 * R * math.asin(math.sqrt(a))  #kilometers
        return distance * 1000  #meters

    def on__idle(self, event):
        steps.saveStep(self.chat_id, self.state)
        self.close()

    def on_close(self, event):
        self.close()


TOKEN = '366092875:AAFQUuXo7qz-oK1xdmGWQQEoporpGPunNSA'

bot = telepot.DelegatorBot(TOKEN, [
    pave_event_space()(per_chat_id(), create_open, UserHandler, timeout=180),
    pave_event_space()(
        per_callback_query_origin(), create_open, ButtonHandler, timeout=180),
])

bot.message_loop(run_forever='Listening')
Beispiel #5
0
        if query_data == 'd36':
            self.editor.editMessageText(Sukho_thai)

        elif query_data == 'mc':
            self._next = self._show_50th_option()

        elif query_data == 'dc':
            self._next = self._show_50th_option()

        if query_data == 'd37':
            self.editor.editMessageText(Medical_centre)

        elif query_data == 'next':
            self._next = self._show_eleventh2_option()


TOKEN = 'Insert token here'

bot = telepot.DelegatorBot(TOKEN, [
    pave_event_space()(per_chat_id(), create_open, ConvoStarter, timeout=30),
    pave_event_space()(
        per_callback_query_origin(), create_open, Convo, timeout=30),
])

MessageLoop(bot).run_as_thread()
print('Listening ...')

while 1:
    time.sleep(30)
Beispiel #6
0
        time.sleep(1)
        self.editor.editMessageText(self._msg_sent, reply_markup=None)

        time.sleep(20)
        self.editor.deleteMessage()
        self.close()

    def on__idle(self, event):
        '''Handles the bot when user is idle for 10 seconds.'''
        pass

    def on_close(self, ex):
        pass


if __name__ == '__main__':
    TOKEN = '425956090:AAFzuvErNrhomansNwzid3u0wr8oYtLhaxU'

    bot = telepot.DelegatorBot(TOKEN, [
        pave_event_space()(per_chat_id(), create_open, FoodStarter, timeout=3),
        pave_event_space()(
            per_callback_query_origin(), create_open, Fooder, timeout=30),
    ])
    MessageLoop(bot).run_as_thread()
    print('Listening ...')

    # Keep the program running.
    while True:
        time.sleep(10)
Beispiel #7
0
                inline_keyboard=[list(map(lambda c: InlineKeyboardButton(text=str(c), callback_data=str(c)), choices))]
            ),
        )
        return answer

    def on_callback_query(self, msg):
        query_id, from_id, query_data = telepot.glance(msg, flavor="callback_query")

        if query_data != "start":
            self._score[self._answer == int(query_data)] += 1

        self._answer = self._show_next_question()

    def on__idle(self, event):
        text = "%d out of %d" % (self._score[True], self._score[True] + self._score[False])
        self.editor.editMessageText(text, reply_markup=None)
        self.close()


TOKEN = sys.argv[1]

bot = telepot.DelegatorBot(
    TOKEN,
    [
        pave_event_space()(per_chat_id(), create_open, QuizStarter, timeout=3),
        pave_event_space()(per_callback_query_origin(), create_open, Quizzer, timeout=10),
    ],
)

bot.message_loop(run_forever="Listening ...")
Beispiel #8
0
        else:
            if self.query_data == 'Jogar':
               self._answer = self.gameMat()
            else:
                result = (self._answer == int(self.query_data))
                self._score[result] += 1
                self._answer = self.gameMat()
                cfg.API.answerCallbackQuery(self.query_id, text=self.lang['gameresult'][0][result])


    def on__idle(self, event):
        self.editor.editMessageText(self.lang['stopinggame'].format(self._score[True], (self._score[False]),(self._score[True]+self._score[False])))
    def gameMat(self):
        try:
            x, y = random.randint(1,50), random.randint(1,30)
            sign, op = random.choice([('+', lambda a,b: a+b),('-', lambda a,b: a-b),('x', lambda a,b: a*b)])
            answer = op(x,y)
            choices = sorted(list(map(random.randint, [answer-6]*3, [answer]*2)) + [answer])
            self.editor.editMessageText(cfg.answerite(self.lang, x, y, sign), reply_markup=InlineKeyboardMarkup(inline_keyboard=[
                                            list(map(lambda cpy: InlineKeyboardButton(text=str(cpy), callback_data=str(cpy)), choices)),[
                                            InlineKeyboardButton(text=self.lang['buttonstatistics'], callback_data='status'),
                                            InlineKeyboardButton(text=self.lang['buttonback'], callback_data='startinggame')]]))
            return answer
        except Exception:
            cfg.API.answerCallbackQuery(self.query_id, text=self.lang['buttonss'], show_alert=True)

if __name__ == '__main__':
    tp = 3600
    while True:
        cfg.TLP.DelegatorBot(os.environ['TOKEN'], [pave_event_space()(per_chat_id(), create_open, message_, timeout=tp*3600),pave_event_space()(per_callback_query_origin(), create_open, Callback, timeout=60)]).message_loop(run_forever=cfg.LN.__starting__)
Beispiel #9
0
        
        reply = ''
        
        if query_data == "copa":
            reply = str(random.randint(1,8))
        elif query_data == "mapas":
            maps = [str(i)+'-'+str(j) for i in range(1,9) for j in range(1,5)]
            chosen = random.sample(maps, 4)
            reply = '\n'.join(chosen)
        
        if reply!="":
            self._editor.editMessageText(reply, reply_markup=None)





TOKEN = getConfigs()

bot = telepot.DelegatorBot(TOKEN, [
    pave_event_space()(
        per_chat_id(), create_open, MessageHandler, timeout=10),
    pave_event_space()(
        per_callback_query_origin(), create_open, QueryHandler, timeout=10),
])
MessageLoop(bot).run_as_thread()
log('Listening '+datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

while 1:
    time.sleep(10)