Skip to content

Commit

Permalink
Update translated.py
Browse files Browse the repository at this point in the history
Fixed deprecated function
  • Loading branch information
skeith committed Nov 28, 2017
1 parent d89aaef commit 826c557
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions translated/translated.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self, bot):
self.bot = bot
self.settings = dataIO.load_json(SETTINGS)
self.cache = dataIO.load_json(CACHE)
self.session = aiohttp.ClientSession()
# These should be supported by translated.net (RFC3066)
self.ISO_LANG = [["Abkhazian", "AB"], ["Afar", "AA"], ["Afrikaans", "AF"], ["Albanian", "SQ"], ["Amharic", "AM"], ["Arabic", "AR"], ["Armenian", "HY"], ["Assamese", "AS"], ["Aymara", "AY"],
["Azerbaijani", "AZ"], ["Bashkir", "BA"], ["Basque", "EU"], ["Bengali, Bangla", "BN"], ["Bhutani", "DZ"], ["Bihari", "BH"], ["Bislama", "BI"], ["Breton", "BR"], ["Bulgarian", "BG"],
Expand All @@ -72,6 +73,9 @@ def __init__(self, bot):
["Thai", "TH"], ["Tibetan", "BO"], ["Tigrinya", "TI"], ["Tonga", "TO"], ["Tsonga", "TS"], ["Turkish", "TR"], ["Turkmen", "TK"], ["Twi", "TW"], ["Ukrainian", "UK"], ["Urdu", "UR"],
["Uzbek", "UZ"], ["Vietnamese", "VI"], ["Volapuk", "VO"], ["Welsh", "CY"], ["Wolof", "WO"], ["Xhosa", "XH"], ["Yiddish", "JI"], ["Yoruba", "YO"], ["Zulu", "ZU"]]

def __unload(self):
self.session.close()


@commands.command(pass_context=True, no_pm=False)
async def translate(self, ctx, languageFrom, languageTo, *text):
Expand All @@ -82,10 +86,10 @@ async def translate(self, ctx, languageFrom, languageTo, *text):
if not self.check_channel_settings(ctx):
await self.bot.say("json Error")
return

replace = self.settings["GUILDS"][gid]["CHANNELS"][chid]["DEL_MSG"]
no_err = self.settings["NO_ERR"]

if text == ():
await send_cmd_help(ctx)
return
Expand Down Expand Up @@ -204,7 +208,7 @@ async def translate_text(self, lang_from, lang_to, text, ctx=None, replace=False
translated = ""
try:
#print(search)
async with aiohttp.get(search) as r:
async with self.session.get(search) as r:
result = await r.json()#responseStatus, responseData[translatedText], exception_code, responseDetails, matches
#print(result)
if "responseStatus" in result:
Expand Down

0 comments on commit 826c557

Please sign in to comment.