from telegram import Update
from telegram.ext import *
import requests
import json


def hand_online(update: Update, context: CallbackContext) -> None:
    # if Update.message.text == ".online":
    data = requests.get("https://ts.segfault.party/json").json()
    msg = "Online:\n"
    for i, p in enumerate(data['people']):
        msg += f"{p}{' [speakers muted]' if data['output_muted'][i] else ''}{' [mic muted]' if data['input_muted'][i] else ''}\n"
    update.message.reply_text(msg)

def hand_offline(update: Update, context: CallbackContext) -> None:
    # if Update.message.text == ".online":
    data = requests.get("https://ts.segfault.party/json").json()
    update.message.reply_text(f"U - {{{', '.join(data['people'])}}}")

updater = Updater('613157406:AAHbHDhKqPiBLUhpSuhZyjyqhU_hgWgw8UM')

updater.dispatcher.add_handler(CommandHandler('online', hand_online))

updater.dispatcher.add_handler(CommandHandler('offline', hand_offline))


# updater.dispatcher.add_handler(MessageHandler(Filters.text(), hand_online))

updater.start_polling()
updater.idle()
