Compare commits
2 Commits
585a8ac749
...
90ed10f25b
| Author | SHA1 | Date | |
|---|---|---|---|
| 90ed10f25b | |||
| 4d0027bbb7 |
7
Dockerfile
Normal file
7
Dockerfile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
FROM python:slim
|
||||||
|
LABEL authors="ENUB"
|
||||||
|
COPY requirements.txt /app/
|
||||||
|
WORKDIR /app
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
COPY . .
|
||||||
|
ENTRYPOINT ["python3", "main.py"]
|
||||||
31
main.py
31
main.py
@ -39,21 +39,21 @@ async def on_ready():
|
|||||||
|
|
||||||
@bot_client.event
|
@bot_client.event
|
||||||
async def on_message(ctx: discord.Message):
|
async def on_message(ctx: discord.Message):
|
||||||
|
|
||||||
if ctx.author.bot:
|
if ctx.author.bot:
|
||||||
return
|
return
|
||||||
|
|
||||||
translator = googletrans.Translator()
|
translator = googletrans.Translator()
|
||||||
detected_language = translator.detect(ctx.content)
|
detected = await translator.detect(ctx.content)
|
||||||
detected_language = detected_language.lang
|
detected_lang = detected.lang
|
||||||
|
|
||||||
|
if detected.confidence < .95:
|
||||||
|
return
|
||||||
|
|
||||||
translator_category = discord.utils.find(lambda c: c.name == "Translatomat", ctx.guild.categories)
|
translator_category = discord.utils.find(lambda c: c.name == "Translatomat", ctx.guild.categories)
|
||||||
|
|
||||||
for channel in translator_category.channels:
|
for channel in translator_category.channels:
|
||||||
language_to_translate_to = channel.name
|
if detected_lang != channel.name:
|
||||||
|
translated_message = await translator.translate(str(ctx.clean_content), channel.name).text
|
||||||
if detected_language != language_to_translate_to:
|
|
||||||
translated_message = translator.translate(str(ctx.clean_content), language_to_translate_to).text
|
|
||||||
|
|
||||||
if str(ctx.clean_content).lower() == str(translated_message).lower():
|
if str(ctx.clean_content).lower() == str(translated_message).lower():
|
||||||
return
|
return
|
||||||
@ -67,27 +67,12 @@ async def on_message(ctx: discord.Message):
|
|||||||
|
|
||||||
await channel.send(embed=embed)
|
await channel.send(embed=embed)
|
||||||
|
|
||||||
await bot_client.process_commands(ctx)
|
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
# Commands
|
# Commands
|
||||||
###
|
###
|
||||||
|
|
||||||
@bot_client.command(name="translate", aliases=['t'], pass_content=True)
|
|
||||||
async def __command_translate(ctx: commands.Context, language: str, *text: str):
|
|
||||||
|
|
||||||
try:
|
|
||||||
translator = googletrans.Translator()
|
|
||||||
|
|
||||||
message_text = " ".join(text)
|
|
||||||
translated_text = translator.translate(message_text, language).text
|
|
||||||
|
|
||||||
await ctx.reply(translated_text)
|
|
||||||
except:
|
|
||||||
await ctx.reply("Error: Translation failed somehow\n"
|
|
||||||
"Format has to be: +translate [language] [text]")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
bot_client.run(discord_bot_token )
|
bot_client.run(discord_bot_token)
|
||||||
Loading…
x
Reference in New Issue
Block a user