def __init__(self, opts=None):
     self.opts = {
         'mode': None,
     }
     self.db = connect_db()
     if opts:
         self.opts = deepcopy(opts)
         self.check_opts_integrity()
Ejemplo n.º 2
0
def main():
    setup_logging()
    db = connect_db()
    wallet_address = '0x0039f22efb07a647557c7c5d17854cfd6d489ef3'
    token_address = '0x6422b80dc6fcb795402f17ad347d8ad31e4ad0a6'
    channel_id = -1001263856479  # gambit-test

    bot = GambitBot()
    bot.set_setting('wallet', wallet_address)
    bot.set_setting('token', token_address)
    bot.set_setting('channel', channel_id)
    logging.debug('Config has set. Config is:')
    logging.debug(bot.get_settings())
def main():
    setup_logging()
    opts = process_cli()
    db = connect_db()

    bot = GambitBot(opts=opts)
    tg_bot = bot.init_bot()
    bot.check_settings()

    block_id = 1 + load_recent_processed_block_id(db)
    recp_address = bot.get_setting('wallet')
    token_address = bot.get_setting('token')
    channel_id = bot.get_setting('channel')

    for tx, op in find_op(recp_address, token_address, start_block=block_id):
        op_item = prepare_op_item(tx, op)
        old_item = db.op.find_one({'_id': op_item['_id']})
        if old_item:
            logging.debug('Found duplicate for operation %s' % op_item['_id'])
        if not old_item or not old_item['_notified']:
            db.op.save(op_item)
            tx_id = re.sub(r'-0$', '', op['transactionId'])
            try:
                decimals = op['contract']['decimals']
            except KeyError:
                decimals = 18
            try:
                symbol = op['contract']['symbol']
            except KeyError:
                symbol = ''
            value_norm = format_float(int(op['value']) / (10**decimals), 2)
            msg = MSG_TEMPLATE % {
                'to': op['to'],
                'from': op['from'],
                'value': value_norm,
                'tx_id': tx_id,
                'symbol': symbol,
            }
            logging.debug(msg)
            logging.debug('Notyfing channel #%s about operation #%s' % (
                channel_id,
                op_item['_id'],
            ))
            try_limit = 3
            for try_count in range(try_limit):
                try:
                    tg_bot.send_message(channel_id,
                                        msg,
                                        parse_mode=ParseMode.MARKDOWN,
                                        disable_web_page_preview=True)
                except telegram.error.TimedOut as ex:
                    if try_count >= (try_limit - 1):
                        raise
                    else:
                        logging.error('[ERROR] %s' % ex)
                        logging.debug('Retrying to send tg message again...')
                else:
                    break

            time.sleep(0.5)
            db.op.find_one_and_update(
                {'_id': op_item['_id']},
                {'$set': {
                    'notified': True
                }},
            )
Ejemplo n.º 4
0
 def before_start_processing(self):
     self.bot_id = self.bot.get_me().id
     self.db = connect_db()
Ejemplo n.º 5
0
*Questions, Feedback*

Email: lorien @ lorien . name

*Open Source*

The source code is available at [github.com/lorien/watchdog_robot](https://github.com/lorien/watchdog_robot)

*My Other Projects*

[@daysandbox_bot](https://t.me/daysandbox_bot) - bot that fights with spam messages in chat groups
[@nosticker_bot](https://t.me/nosticker_bot) - bot to delete stickers posted to group
[@joinhider_bot](https://t.me/joinhider_bot) - removes messages about new user joined the group
[@coinsignal_robot](https://t.me/coinsignal_robot) - bot to be notified when price of specific coin reaches the level you have set, also you can use this bot just to see price of coins.
"""
db = connect_db()
ADMIN_IDS_CACHE = {}
SUPERUSER_IDS = set([
    46284539,  # @madspectator
])
RE_ALLOW_COMMAND = re.compile('^/watchdog_allow (\w+)$')
RE_BLOCK_COMMAND = re.compile('^/watchdog_block (\w+)$')
RE_SET_COMMAND = re.compile('^/watchdog_set (\w+)=(\w+)$')
OPTION_CACHE = {}
DEFAULT_IS_ALLOWED = True
DEFAULT_SETTINGS = {
    'notify_actions': True,
}
VALID_SETTINGS = ('notify_actions', )
MSG_TYPES = (
    'link',