Beispiel #1
0
 def process_ajax(sub, req):
     try:
         if sub == 'telegram_test':
             ret = ToolBaseNotify.send_telegram_message(
                 req.form['text'],
                 bot_token=req.form['bot_token'],
                 chat_id=req.form['chat_id'])
             return jsonify(ret)
         elif sub == 'discord_test':
             ret = ToolBaseNotify.send_discord_message(
                 req.form['text'], webhook_url=req.form['url'])
             return jsonify(ret)
         elif sub == 'advanced_test':
             ret = ToolBaseNotify.send_advanced_message(
                 req.form['text'],
                 policy=req.form['policy'],
                 message_id=req.form['message_id'])
             return jsonify(ret)
         elif sub == 'scheduler':
             go = request.form['scheduler']
             logger.debug('scheduler :%s', go)
             if go == 'true':
                 SystemLogicTelegramBot.scheduler_start()
             else:
                 SystemLogicTelegramBot.scheduler_stop()
             return jsonify(go)
     except Exception as exception:
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
         return jsonify('exception')
Beispiel #2
0
    def receive_callback(msg):
        try:
            content_type, chat_type, chat_id = glance(msg)
            #logger.debug(chat_id)
            try:
                if content_type == 'text' and msg['text'][0] == '^':
                    if SystemModelSetting.get_bool('telegram_resend'):
                        chat_list = SystemModelSetting.get_list(
                            'telegram_resend_chat_id')
                        #logger.debug(chat_list)
                        if str(chat_id) not in chat_list:
                            for c in chat_list:
                                ToolBaseNotify.send_telegram_message(
                                    msg['text'],
                                    SystemModelSetting.get(
                                        'telegram_bot_token'),
                                    chat_id=c)
            except Exception as exception:
                logger.error('Exception:%s', exception)
                logger.error(traceback.format_exc())

            if content_type == 'text':
                text = msg['text']
                if msg['text'] == '/bot':
                    text = json.dumps(TelegramBot.bot.getMe(), indent=2)
                    TelegramBot.bot.sendMessage(chat_id, text)
                elif msg['text'] == '/me':
                    text = json.dumps(msg, indent=2)
                    TelegramBot.bot.sendMessage(chat_id, text)
                elif msg['text'][0] == '^':
                    TelegramBot.process_receive_data(msg['text'][1:])
                elif msg['text'] == '/call':
                    data = TelegramBot.bot.getMe()
                    #logger.debug(data)
                    from framework import version

                    text = 'call : %s / %s / %s / %s / %s / %s' % (
                        data['username'], data['id'], data['first_name'],
                        version, SystemModelSetting.get('sjva_me_user_id'),
                        SystemModelSetting.get('sjva_id'))
                    TelegramBot.bot.sendMessage(chat_id, text)
                elif msg['text'].startswith('call'):
                    logger.debug(msg['text'])
        except Exception as exception:
            logger.error('Exception:%s', exception)
            logger.error(traceback.format_exc())
Beispiel #3
0
 def process_ajax(sub, req):
     try:
         if sub == 'telegram_test':
             ret = ToolBaseNotify.send_telegram_message(
                 req.form['text'],
                 bot_token=req.form['bot_token'],
                 chat_id=req.form['chat_id'])
             return jsonify(ret)
         elif sub == 'discord_test':
             ret = ToolBaseNotify.send_discord_message(
                 req.form['text'], webhook_url=req.form['url'])
             return jsonify(ret)
         elif sub == 'advanced_test':
             ret = ToolBaseNotify.send_advanced_message(
                 req.form['text'],
                 policy=req.form['policy'],
                 message_id=req.form['message_id'])
             return jsonify(ret)
     except Exception as exception:
         logger.error('Exception:%s', exception)
         logger.error(traceback.format_exc())
         return jsonify('exception')