Skip to content

Commit

Permalink
time & weather: fix inconsistency (#179)
Browse files Browse the repository at this point in the history
* time: fix inconsistency with weather module

- command "ctime" replaced with "settime"
- edited strings to match with weather module

* weather: fix inconsistency with time module

- fix broken set country hint message
- replace errors with "Invalid country." (won't show details if it's weather provider server side problem)
- make every string monospace
  • Loading branch information
hugwalk authored and Baalaji committed Aug 26, 2019
1 parent 64deace commit f25949d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
19 changes: 9 additions & 10 deletions userbot/modules/time.py
Expand Up @@ -53,7 +53,7 @@ async def get_tz(con):
async def time_func(tdata):
""" For .time command, return the time of
1. The country passed as an argument,
2. The default userbot country(set it by using .ctime),
2. The default userbot country(set it by using .settime),
3. The server where the userbot runs.
"""
if not tdata.text[0].isalpha() and tdata.text[0] not in (
Expand All @@ -74,7 +74,7 @@ async def time_func(tdata):

time_zone = await get_tz(con)
if not time_zone:
await tdata.edit("` Wrong country given! Try again! `")
await tdata.edit("`Invaild country.`")
return

try:
Expand All @@ -90,7 +90,7 @@ async def time_func(tdata):
async def date_func(dat):
""" For .date command, return the date of
1. The country passed as an argument,
2. The default userbot country(set it by using .ctime),
2. The default userbot country(set it by using .settime),
3. The server where the userbot runs.
"""
if not dat.text[0].isalpha() and dat.text[0] not in ("/", "#", "@", "!"):
Expand All @@ -110,7 +110,7 @@ async def date_func(dat):

time_zone = await get_tz(con)
if not time_zone:
await dat.edit("` Wrong country given! Try again! `")
await dat.edit("`Invaild country.`")
return

try:
Expand All @@ -121,18 +121,18 @@ async def date_func(dat):
await dat.edit(f"`It's` **{dt.now().strftime(d_form)}** `in {c_name}`")


@register(outgoing=True, pattern="^.ctime (.*)")
@register(outgoing=True, pattern="^.settime (.*)")
@errors_handler
async def set_time_country(loc):
""" For .ctime command, change the default userbot
""" For .settime command, change the default userbot
country for date and time commands. """
if not loc.text[0].isalpha() and loc.text[0] not in ("/", "#", "@", "!"):
global COUNTRY
temp_country = loc.pattern_match.group(1).title()

time_zone = await get_tz(temp_country)
if not time_zone:
await loc.edit("` Wrong country given! Try again! `")
await loc.edit("`Invaild country.`")
return

try:
Expand All @@ -142,8 +142,7 @@ async def set_time_country(loc):

COUNTRY = c_name

await loc.edit(f"` Default country for date "
"and time set to {COUNTRY} successfully! `")
await loc.edit(f"`Set default country as {COUNTRY}. `")


CMD_HELP.update({
Expand All @@ -155,6 +154,6 @@ async def set_time_country(loc):
\nUsage: Get the date of a country."
})
CMD_HELP.update({
"ctime": ".ctime <country name/code>\
"settime": ".settime <country name/code>\
\nUsage: Set the default country for .time and .date command."
})
19 changes: 9 additions & 10 deletions userbot/modules/weather.py
Expand Up @@ -41,16 +41,15 @@ async def get_weather(weather):
return

if len(OWM_API) < 1:
await weather.edit("Get an API key from "
"https://openweathermap.org/ first.")
await weather.edit("`Get an API key from` https://openweathermap.org/ `first.`")
return

APPID = OWM_API

if not weather.pattern_match.group(1):
CITY = DEFCITY
if not CITY:
await weather.edit("Please specify a city or set one as default.")
await weather.edit("`Please specify a city or set one as default.`")
return
else:
CITY = weather.pattern_match.group(1)
Expand All @@ -68,7 +67,7 @@ async def get_weather(weather):
try:
countrycode = timezone_countries[f'{country}']
except KeyError:
await weather.edit("Invalid country.")
await weather.edit("`Invalid country.`")
return
CITY = newcity[0].strip() + "," + countrycode.strip()

Expand All @@ -77,7 +76,7 @@ async def get_weather(weather):
result = json.loads(request.text)

if request.status_code != 200:
await weather.edit(f"{result['message']}")
await weather.edit(f"`Invalid country.`")
return

cityname = result['name']
Expand Down Expand Up @@ -139,7 +138,7 @@ async def set_default_city(city):
return

if len(OWM_API) < 1:
await city.edit("Get an API key from https://openweathermap.org/ first.")
await city.edit("`Get an API key from` https://openweathermap.org/ `first.`")
return

global DEFCITY
Expand All @@ -148,7 +147,7 @@ async def set_default_city(city):
if not city.pattern_match.group(1):
CITY = DEFCITY
if not CITY:
await city.edit("Please specify a city to set one as default.")
await city.edit("`Please specify a city to set one as default.`")
return
else:
CITY = city.pattern_match.group(1)
Expand All @@ -166,7 +165,7 @@ async def set_default_city(city):
try:
countrycode = timezone_countries[f'{country}']
except KeyError:
await city.edit("Invalid country.")
await city.edit("`Invalid country.`")
return
CITY = newcity[0].strip() + "," + countrycode.strip()

Expand All @@ -175,7 +174,7 @@ async def set_default_city(city):
result = json.loads(request.text)

if request.status_code != 200:
await city.edit(f"{result['message']}")
await city.edit(f"`Invalid country.`")
return

DEFCITY = CITY
Expand All @@ -184,7 +183,7 @@ async def set_default_city(city):

fullc_n = c_n[f"{country}"]

await city.edit(f"Set default city as {cityname}, {fullc_n}.")
await city.edit(f"`Set default city as {cityname}, {fullc_n}.`")


CMD_HELP.update({
Expand Down

0 comments on commit f25949d

Please sign in to comment.