Exemple #1
0
    def __init__(self):

        self.logger = Logger.get_logger()
        self.async_loop = asyncio.get_event_loop()
        self.my_bot = None
        self.bot = None
        self.dispatcher = None
        self.updater = None
        self.database_handler = db

        self.check_next = True
        self.running = True

        self.perform_check_failure_counter = 0
        self.total_send_failure_counter = 0
    def __init__(self, token, incoming_queue=None, outgoing_queue=None, loop=None):

        self.logger = Logger.get_logger()
        self._base_url = Config.base_url
        self._token = token
        self._running = False
        self._incoming_queue = incoming_queue or asyncio.Queue()
        self._outgoing_queue = outgoing_queue or asyncio.Queue()
        self._session = None
        self._ws = None
        self._loop = loop

        self._listener_task = None
        self._sender_task = None
        self._heartbeat = Config.heartbeat
        self._receive_timeout = Config.receive_timeout
Exemple #3
0
    def __init__(self,
                 token,
                 incoming_queue=None,
                 outgoing_queue=None,
                 loop=None):

        self.logger = Logger.get_logger()
        self._base_url = Config.base_url
        self._token = token
        self._running = False
        self._incoming_queue = incoming_queue or asyncio.Queue()
        self._outgoing_queue = outgoing_queue or asyncio.Queue()
        self._session = None
        self._ws = None
        self._loop = loop

        self._listener_task = None
        self._sender_task = None
Exemple #4
0
    def __init__(self, json):
        self.logger = Logger.get_logger()

        if isinstance(json, dict):
            json_dict = json
        elif isinstance(json, str):
            json_dict = json_handler.loads(json)
        else:
            raise ValueError(Error.unacceptable_json)

        self._id = json_dict.get("id", None)
        self.body_json = json_dict.get("body", None)

        if self.body_json.get("tag", None):
            self.body = BotError(self.body_json)
            del self.body_json
        else:
            self.body = None
Exemple #5
0
    def __init__(self, token, loop=None):

        self.logger = Logger.get_logger()

        if not token:
            raise ValueError("`token` did't passed")

        self.token = token
        self.timeout = Config.request_timeout

        self.bale_futures = []

        self._loop = asyncio.get_event_loop() if not loop else loop

        self.dispatcher = Dispatcher(loop=self._loop,
                                     token=self.token,
                                     bale_futures=self.bale_futures)

        self.running = False
    def __init__(self, token, loop=None):

        self.logger = Logger.get_logger()

        if not token:
            raise ValueError("`token` did't passed")

        self.token = token
        self.timeout = Config.request_timeout

        self.bale_futures = []

        self._loop = asyncio.get_event_loop() if not loop else loop

        self.dispatcher = Dispatcher(loop=self._loop,
                                     token=self.token,
                                     bale_futures=self.bale_futures)

        self.running = False
    def __init__(self, loop, token, base_url, bale_futures):

        self.logger = Logger.get_logger()
        self.incoming_queue = asyncio.Queue()
        self.outgoing_queue = asyncio.Queue()
        self.timeout = Config.request_timeout
        self.token = token
        self.bot = Bot(loop=loop,
                       token=token,
                       base_url=base_url,
                       incoming_queue=self.incoming_queue,
                       outgoing_queue=self.outgoing_queue,
                       bale_futures=bale_futures,
                       timeout=self.timeout)

        self._bale_futures = bale_futures
        self.message_handlers = []
        self.error_handlers = []
        self.read_handler_object = None
        self.default_handler_object = None

        self.conversation_next_step_handlers = {}
        self.conversation_data = {}

        self.running = False

        self.is_batch_updates_processed = True
        self.last_seq = None
        self.real_time_fetch_updates = Config.real_time_fetch_updates
        self.continue_last_processed_seq = Config.continue_last_processed_seq
        self.timeInterval = Config.timeInterval
        self.last_poll_request_time = 0
        self.updates_number = Config.updates_number

        @self.message_handler(
            TextFilter(pattern=r"{}*".format(Config.monitoring_hash)))
        def handle_monitoring_msg(bot, update):
            monitoring_message = update.get_effective_message()
            monitoring_text = monitoring_message.text
            result_text = str(monitoring_text.split(Config.monitoring_hash)[1])
            result_message = TextMessage(text=result_text)
            bot.respond(update=update, message=result_message)
    def __init__(self, loop, token, bale_futures):

        self.logger = Logger.get_logger()
        self.incoming_queue = asyncio.Queue()
        self.outgoing_queue = asyncio.Queue()
        self.timeout = Config.request_timeout
        self.token = token
        self.bot = Bot(loop=loop,
                       token=token,
                       incoming_queue=self.incoming_queue,
                       outgoing_queue=self.outgoing_queue,
                       bale_futures=bale_futures,
                       timeout=self.timeout)

        self._bale_futures = bale_futures
        self.message_handlers = []
        self.error_handlers = []
        self.read_handler_object = None
        self.default_handler_object = None

        self.conversation_next_step_handlers = {}
        self.conversation_data = {}

        self.running = False

        self.is_batch_updates_processed = True
        self.last_seq = None
        self.real_time_fetch_updates = Config.real_time_fetch_updates
        self.continue_last_processed_seq = Config.continue_last_processed_seq
        self.timeInterval = Config.timeInterval
        self.last_poll_request_time = 0
        self.updates_number = Config.updates_number

        @self.message_handler(TextFilter(pattern=r"{}*".format(Config.monitoring_hash)))
        def handle_monitoring_msg(bot, update):
            monitoring_message = update.get_effective_message()
            monitoring_text = monitoring_message.text
            result_text = str(monitoring_text.split(Config.monitoring_hash)[1])
            result_message = TextMessage(text=result_text)
            bot.respond(update=update, message=result_message)
    def __init__(self,
                 token,
                 base_url,
                 incoming_queue=None,
                 outgoing_queue=None,
                 loop=None):

        self.logger = Logger.get_logger()
        self._base_url = base_url
        self._token = token
        self._running = False
        self._incoming_queue = incoming_queue or asyncio.Queue()
        self._outgoing_queue = outgoing_queue or asyncio.Queue()
        self._session = None
        self._ws = None
        self._loop = loop

        self._listener_task = None
        self._sender_task = None
        self._heartbeat = Config.heartbeat
        self._receive_timeout = Config.receive_timeout
        self.retry = 0
"""Voice and Photo simple conversation with bot."""
import asyncio
import base64

from balebot.filters import *
from balebot.handlers import MessageHandler
from balebot.models.messages import *
from balebot.updater import Updater
from balebot.utils.logger import Logger

# Bale Bot Authorization Token
updater = Updater(token="PUT YOUR TOKEN HERE", loop=asyncio.get_event_loop())
dispatcher = updater.dispatcher
my_logger = Logger.get_logger()  # Create a logger and name it my_logger


def success_send_message(response, user_data):
    kwargs = user_data['kwargs']
    update = kwargs["update"]
    user_peer = update.get_effective_user()
    my_logger.info("Your message has been sent successfully.",
                   extra={
                       "user_id": user_peer.peer_id,
                       "tag": "info"
                   })


def failure_send_message(response, user_data):
    kwargs = user_data['kwargs']
    update = kwargs["update"]
    user_peer = update.get_effective_user()
Exemple #11
0
"""Purchase message simple conversation with bot."""
import asyncio

from balebot.filters import *
from balebot.handlers import MessageHandler
from balebot.models.messages import *
from balebot.models.messages.banking.money_request_type import MoneyRequestType
from balebot.updater import Updater
from balebot.utils.logger import Logger

# Bale Bot Authorization Token
updater = Updater(token="TOKEN", loop=asyncio.get_event_loop())
dispatcher = updater.dispatcher

# Enable logging
logger = Logger.get_logger()


def success_send_message(response, user_data):
    kwargs = user_data['kwargs']
    update = kwargs["update"]
    user_peer = update.get_effective_user()
    logger.info("Your message has been sent successfully.",
                extra={
                    "user_id": user_peer.peer_id,
                    "tag": "info"
                })


def failure_send_message(response, user_data):
    kwargs = user_data['kwargs']
"""Voice and Photo simple conversation with bot."""
import asyncio
import base64

from balebot.filters import *
from balebot.handlers import MessageHandler
from balebot.models.messages import *
from balebot.updater import Updater
from balebot.utils.logger import Logger

# Bale Bot Authorization Token
updater = Updater(token="PUT YOUR TOKEN HERE",
                  loop=asyncio.get_event_loop())
dispatcher = updater.dispatcher
my_logger = Logger.get_logger()  # Create a logger and name it my_logger


def success_send_message(response, user_data):
    kwargs = user_data['kwargs']
    update = kwargs["update"]
    user_peer = update.get_effective_user()
    my_logger.info("Your message has been sent successfully.", extra={"user_id": user_peer.peer_id, "tag": "info"})


def failure_send_message(response, user_data):
    kwargs = user_data['kwargs']
    update = kwargs["update"]
    user_peer = update.get_effective_user()
    my_logger.error("Sending message has been failed", extra={"user_id": user_peer.peer_id, "tag": "error"})

Exemple #13
0
import os
from datetime import datetime
from urllib.parse import urlparse
from collections import OrderedDict

import ibm_db
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from balebot.utils.logger import Logger
from bot_template.exeptions import DB2Exception


logger = Logger().get_logger()


class AbstractDBHandler:

    def __init__(self, db_url=None):
        self.db_url = db_url
        self.db_name = urlparse(self.db_url).path.lstrip('/')
        self.engine = create_engine(self.db_url)

    def create_database_if_not_exist(self):
        if self.database_exists():
            self.create_database()

    def database_exists(self):
        raise NotImplemented

    def create_database(self):