def _subscribe(to_add): channels = read_channels() if to_add in channels: return False channels.append(to_add) write_channels(channels) return True
def _unsubscribe(to_remove): channels = read_channels() try: channels.remove(to_remove) write_channels(channels) return True except ValueError: return False
def list_subscribers(update, context): if update.effective_chat.id != 907198901: return channels = read_channels() text = "%d Subscribers:" % len(channels) for channel_id in channels: if len(text) > 0: text += "\n\n" text += get_chat_info(context.bot, channel_id) if len(text) > 3000: update.message.reply_text(text) text = "" if len(text) > 0: update.message.reply_text(text)
def configure(update, context): if mod_protect(update): return channels = read_channels() chat = update.effective_chat if chat.id not in channels: options = [("Yes", { 'question': 'sub', 'answer': 'yes' }), ("No", { 'question': 'sub', 'answer': 'no' })] update.message.reply_text('Do you want to subscribe for rate updates?', reply_markup=create_keyboard(options)) else: configure_next_source(chat.id, update.message.reply_text, {})
logging.basicConfig( level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') from util import render_rates, get_token, read_channels, get_config, meta, mark_latest_message import telegram bot = telegram.Bot(get_token()) if len(sys.argv) >= 2: changed = sys.argv[1].split(",") else: sys.exit(1) for channel_id in read_channels(): c = get_config(channel_id) found = False for u in changed: notify = meta[u]['default_notify'] if u in c: notify = c[u]['sub'] and c[u]['notify'] if notify: found = True break if not found: continue text = "*Rates updated*:\n\n" + render_rates(channel_id, changed) try: message = bot.send_message(channel_id, text,