def ether(self, bot, update): """ Call for Ether miner status and restarting service. """ chat_id = update.message.chat.id bot.send_chat_action(chat_id=chat_id, action=ChatAction.TYPING) try: Chat.get(id=chat_id) except peewee.DoesNotExist: self.logger.error('Chat unregistered') response_text = 'Configure me first' bot.send_message(chat_id, response_text) else: keyboard = [ [ InlineKeyboardButton("Status", callback_data='[ether_status]'), InlineKeyboardButton("Nanopool", callback_data='[ether_nanopool]') ], [ InlineKeyboardButton("Restart", callback_data='[ether_restart]'), ], ] reply_markup = InlineKeyboardMarkup(keyboard) bot.send_message(chat_id, 'Select an option:', reply_markup=reply_markup)
def miner(self, bot, update): """ Asks for a miner. """ chat_id = update.message.chat.id bot.send_chat_action(chat_id=chat_id, action=ChatAction.TYPING) try: chat = Chat.get(id=chat_id) buttons = [ InlineKeyboardButton(api.name, callback_data=f'[miner_status][{api.id}]') for api in chat.apis if api.superuser ] keyboard = [ buttons[i:max(len(buttons), i + 4)] for i in range(0, len(buttons), 4) ] reply_markup = InlineKeyboardMarkup(keyboard) except peewee.DoesNotExist: self.logger.error('Chat unregistered') response_text = 'Configure me first' bot.send_message(chat_id, response_text) else: if reply_markup: bot.send_message(text='Select miner:', reply_markup=reply_markup, chat_id=chat_id) else: bot.send_message(text='No options available', chat_id=chat_id)
def _remove_api_choice(self, bot, update): """ Asks for removing a Barrenero API already configured. """ chat_id = update.message.chat_id try: chat = Chat.get(id=chat_id) except peewee.DoesNotExist: update.message.reply_text( 'There is not a Barrenero API configured yet') result = self.start(bot, update) else: buttons = [str(i.id) for i in chat.apis] keyboard = [ buttons[i:min(len(buttons), i + 4)] for i in range(0, len(buttons), 4) ] keyboard.append([StartOptions.DONE.value]) markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True) response_text = f'*APIs configured*\n' + '\n'.join( [f'*{a.id}*: `{a.url}`' for a in chat.apis]) update.message.reply_text(response_text, parse_mode=ParseMode.MARKDOWN, reply_markup=markup) result = StartState.CHOICE_REMOVE_API return result
def wallet(self, bot, update): """ Call for Storj miner status and restarting service. """ chat_id = update.message.chat.id bot.send_chat_action(chat_id=chat_id, action=ChatAction.TYPING) try: chat = Chat.get(id=chat_id) api = random.choice(chat.apis) data = Barrenero.wallet(api.url, api.token) response_text = f'*Tokens*\n' response_text += '\n'.join( [f' - {t["name"]}: `{t["balance"]} {t["symbol"]}` ({t.get("balance_usd", "Unknown")} $)' for t in data['tokens'].values()]) for i, tx in zip(range(1, 4), data['transactions']): response_text += f'\n\n*Last transaction #{i}*\n' \ f' - Token: `{tx["token"]["name"]}`\n' \ f' - Hash: `{tx["hash"]}`\n' \ f' - Source: `{tx["source"]}`\n' \ f' - Value: `{tx["value"]} {tx["token"]["symbol"]}`\n' \ f' - Date: `{humanize_iso_date(tx["timestamp"])}`' except peewee.DoesNotExist: self.logger.error('Chat unregistered') response_text = 'Configure me first' except BarreneroRequestException as e: self.logger.exception(e.message) response_text = e.message except: self.logger.exception('Error retrieving wallet info') response_text = 'Cannot retrieve wallet info' bot.send_message(chat_id, response_text, parse_mode=ParseMode.MARKDOWN)
def _remove_api_config(self, bot, update): text = update.message.text chat_id = update.message.chat_id try: chat = Chat.get(id=chat_id) api = API.get(id=text, chat=chat) name = api.name api.delete_instance() update.message.reply_text( f'Barrenero API `{name}` removed successfully', parse_mode=ParseMode.MARKDOWN) except: self.logger.exception('Cannot remove Barrenero API') update.message.reply_text('Cannot remove Barrenero API') return StartState.CHOICE_REMOVE_API
def ether_nanopool(self, bot, update): """ Query for Nanopool account info. """ query = update.callback_query chat_id = query.message.chat_id bot.send_chat_action(chat_id=chat_id, action=ChatAction.TYPING) try: chat = Chat.get(id=chat_id) api = random.choice(chat.apis) data = Barrenero.ether(api.url, api.token) response_text = f'*Ether miner*\n' \ f' - Balance: `{data["nanopool"]["balance"]["confirmed"]} ETH`\n\n' \ f'*Hashrate*\n' \ f' - Current: `{data["nanopool"]["hashrate"]["current"]} MH/s`\n' \ f' - 1 hour: `{data["nanopool"]["hashrate"]["one_hour"]} MH/s`\n' \ f' - 3 hours: `{data["nanopool"]["hashrate"]["three_hours"]} MH/s`\n' \ f' - 6 hours: `{data["nanopool"]["hashrate"]["six_hours"]} MH/s`\n' \ f' - 12 hours: `{data["nanopool"]["hashrate"]["twelve_hours"]} MH/s`\n' \ f' - 24 hours: `{data["nanopool"]["hashrate"]["twenty_four_hours"]} MH/s`\n\n' \ f'*Last payment*\n' \ f' - Date: `{humanize_iso_date(data["nanopool"]["last_payment"]["date"])}`\n' \ f' - Value: `{data["nanopool"]["last_payment"]["value"]} ETH`\n\n' \ f'*Workers*\n' + \ '\n'.join(f' - {w}: `{v} MH/s`' for w, v in data['nanopool']['workers'].items()) except peewee.DoesNotExist: self.logger.error('Chat unregistered') response_text = 'Configure me first' except BarreneroRequestException as e: self.logger.exception(e.message) response_text = e.message except: response_text = 'Cannot retrieve Nanopool info' self.logger.exception( 'Barrenero API wrong response for Nanopool info: %s', str(data)) bot.edit_message_text(text=response_text, parse_mode=ParseMode.MARKDOWN, chat_id=query.message.chat_id, message_id=query.message.message_id)
def _current_config_choice(self, bot, update): """ Shows current config. """ chat_id = update.message.chat_id try: chat = Chat.get(id=chat_id) except peewee.DoesNotExist: response_text = 'No configuration found' else: response_text = f'*Current config*\n' \ f' - Last Transaction: `{chat.last_transaction}`\n\n' for i, api in enumerate(chat.apis, 1): response_text += f'*API #{i}*\n' \ f' - Name: `{api.name}`\n' \ f' - URL: `{api.url}`\n' \ f' - Token: `{api.token}`\n' \ f' - Superuser: `{"Yes" if api.superuser else "No"}`\n\n' update.message.reply_text(response_text, parse_mode=ParseMode.MARKDOWN) return StartState.CHOICE_ROOT
def ether_miner_choice(self, bot, update, groups): """ Call for Ether miner status and restarting service. """ query = update.callback_query action = groups[0] chat_id = query.message.chat_id bot.send_chat_action(chat_id=chat_id, action=ChatAction.TYPING) try: chat = Chat.get(id=chat_id) except peewee.DoesNotExist: chat = False if chat: buttons = [ InlineKeyboardButton( api.name, callback_data=f'[ether_{action}][{api.id}]') for api in chat.apis if api.superuser ] keyboard = [ buttons[i:max(len(buttons), i + 4)] for i in range(0, len(buttons), 4) ] reply_markup = InlineKeyboardMarkup(keyboard) else: reply_markup = None if reply_markup: bot.edit_message_text(text='Select miner:', reply_markup=reply_markup, chat_id=chat_id, message_id=query.message.message_id) else: bot.edit_message_text(text='No options available', chat_id=chat_id, message_id=query.message.message_id)