Пример #1
0
async def set_default_city(city):
    if city.fwd_from:
        return
    if not Config.OPEN_WEATHER_MAP_APPID:
        return await edit_or_reply(
            city, "`Get an API key from` https://openweathermap.org/ `first.`")
    if not city.pattern_match.group(1):
        CITY = gvarstatus("DEFCITY") or "Delhi"
    else:
        CITY = city.pattern_match.group(1)
    timezone_countries = {
        timezone: country
        for country, timezones in c_tz.items() for timezone in timezones
    }
    if "," in CITY:
        newcity = CITY.split(",")
        if len(newcity[1]) == 2:
            CITY = newcity[0].strip() + "," + newcity[1].strip()
        else:
            country = await get_tz((newcity[1].strip()).title())
            try:
                countrycode = timezone_countries[f"{country}"]
            except KeyError:
                return await edit_or_reply(city, "`Invalid country.`")
            CITY = newcity[0].strip() + "," + countrycode.strip()
    url = f"https://api.openweathermap.org/data/2.5/weather?q={CITY}&appid={Config.OPEN_WEATHER_MAP_APPID}"
    request = requests.get(url)
    result = json.loads(request.text)
    if request.status_code != 200:
        return await edit_or_reply(city, "`Invalid country.`")
    addgvar("DEFCITY", CITY)
    cityname = result["name"]
    country = result["sys"]["country"]
    fullc_n = c_n[f"{country}"]
    await edit_or_reply(city, f"`Set default city as {cityname}, {fullc_n}.`")
Пример #2
0
async def lang(value):
    if value.fwd_from:
        return
    arg = value.pattern_match.group(1).lower()
    if arg in LANGUAGES:
        addgvar("TRT_LANG", arg)
        LANG = LANGUAGES[arg]
    else:
        await edit_or_reply(
            value,
            f"`Invalid Language code !!`\n`Available language codes for TRT`:\n\n`{LANGUAGES}`",
        )
        return
    await edit_or_reply(
        value, f"`Language for Translator changed to {LANG.title()}.`")
    if BOTLOG:
        await value.client.send_message(
            BOTLOG_CHATID,
            f"`Language for Translator changed to {LANG.title()}.`")
Пример #3
0
async def set_grplog(event):
    if event.fwd_from:
        return
    input_str = event.pattern_match.group(1)
    if input_str == "off":
        h_type = False
    elif input_str == "on":
        h_type = True
    if gvarstatus("GRPLOG") and gvarstatus("GRPLOG") == "false":
        GRPLOG = False
    else:
        GRPLOG = True
    if GRPLOG:
        if h_type:
            await event.edit("`Group logging is already enabled`")
        else:
            addgvar("GRPLOG", h_type)
            await event.edit("`Group logging is disabled`")
    else:
        if h_type:
            addgvar("GRPLOG", h_type)
            await event.edit("`Group logging is enabled`")
        else:
            await event.edit("`Group logging is already disabled`")