@@ -33,6 +33,17 @@ def __init__(self, bot):
33
33
self .translator = Translator ()
34
34
self .threshold = 0.75
35
35
36
+ @staticmethod
37
+ def pronunciation (message ):
38
+ """
39
+ Static Method. Call with GoogleTranslate.pronunciation(message)
40
+ Looks up the pronunciation from the extra data
41
+ """
42
+ if message :
43
+ message = [* filter (None , message [0 ])]
44
+ return f"\n pronunciation: ({ message [0 ].lower ()} )"
45
+ return ""
46
+
36
47
@commands .Cog .listener ()
37
48
async def on_message (self , message ):
38
49
"""
@@ -75,15 +86,20 @@ async def on_message(self, message):
75
86
# translate message
76
87
translation = self .translator .translate (message .content , dest = 'en' )
77
88
89
+ if translation .text .strip ().lower () == message .content .strip ().lower ():
90
+ """
91
+ Check to see if the result is the same as the original. If so, do not print
92
+ This is to avoid spamming random haha's and hehehe's. (Thanks Crambor!)
93
+ """
94
+ return
95
+
78
96
# send results of translation as embed
79
97
embed = discord .Embed (
80
98
title = f"{ message .content } :" ,
81
99
description = f"{ translation .text } " )
82
100
83
101
footer = f"translated from { detected_language } \n confidence: { confidence * 100 :0.2f} %"
84
- pronunciation = translation .extra_data ["translation" ][1 :]
85
- if pronunciation :
86
- footer += f"\n pronunciation: ({ pronunciation [0 ][- 1 ].lower ()} )"
102
+ footer += GoogleTranslate .pronunciation (translation .extra_data ["translation" ][1 :2 ])
87
103
88
104
embed .set_footer (text = footer )
89
105
await message .channel .send (embed = embed )
@@ -95,15 +111,13 @@ async def translate(self, ctx, destination_language, text):
95
111
"""
96
112
logger .info ("%s used the %s command." , ctx .author .name , ctx .command )
97
113
try :
98
- translated = self .translator .translate (text , dest = destination_language )
114
+ translation = self .translator .translate (text , dest = destination_language )
99
115
embed = discord .Embed (
100
116
title = f"{ text } :" ,
101
- description = translated .text
117
+ description = translation .text
102
118
)
103
- footer = f"translated from { LANGUAGES [translated .src ]} "
104
- pronunciation = translated .extra_data ["translation" ][1 :]
105
- if pronunciation :
106
- footer += f"\n pronunciation: ({ pronunciation [0 ][- 1 ].lower ()} )"
119
+ footer = f"translated from { LANGUAGES [translation .src ]} "
120
+ footer += GoogleTranslate .pronunciation (translation .extra_data ["translation" ][1 :2 ])
107
121
108
122
embed .set_footer (text = footer )
109
123
await ctx .respond (embed = embed )
0 commit comments