Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time & weather: fix inconsistency #179

Merged
merged 2 commits into from Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.`")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to even edit this line...

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.`")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have it there to tell what msg the page give out alongside 200 error.

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.`")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint this.

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.`")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have it there to tell what msg the page give out alongside 200 error.

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