Subversion Repositories navi

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
286 muzer 1
#! /usr/bin/env python
2
#    This file is part of Tsim Apiak.
3
#
4
#    Tsim Apiak is free software: you can redistribute it and/or modify
5
#    it under the terms of the GNU General Public Licence as published by
6
#    the Free Software Foundation, either version 3 of the Licence, or
7
#    (at your option) any later version.
8
#
9
#    In addition to this, you must also comply with clause 4 of the
10
#    Apache Licence, version 2.0, concerning attribution. Where there
11
#    is a contradiction between the two licences, the GPL
12
#    takes preference.
13
#
14
#    Tsim Apiak is distributed in the hope that it will be useful,
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
#    GNU General Public License for more details.
18
#
19
#    You should have received a copy of the GNU General Public License
20
#    along with Tsim Apiak.  If not, see <http://www.gnu.org/licenses/>.#
21
 
22
import os
23
 
24
import discord
25
import dotenv
26
from typing import Optional
27
 
28
from tsimapiak import translate
29
 
30
dotenv.load_dotenv(dotenv.find_dotenv())
31
 
32
intents = discord.Intents.default()
33
client = discord.Client(intents=intents)
34
tree = discord.app_commands.CommandTree(client)
35
 
36
@client.event
37
async def on_ready():
38
    print(f"{client.user} Connected to discord")
39
    await tree.sync()
40
 
41
@tree.command(
42
    name="translate",
43
    description="Translate (gloss) Na'vi to English"
44
)
45
async def on_translate(interaction: discord.Interaction, argument: str, language: Optional[str]):
46
    if not language:
47
        language = "en"
48
    translated = []
49
    for word in translate.translatesent(argument, language):
50
        translated.append(word["translated"])
51
 
52
    await interaction.response.send_message(argument + "\n" + " | ".join(translated))
53
 
54
def main():
55
    TOKEN = os.getenv('DISCORD_TOKEN')
56
 
57
    client.run(TOKEN)
58
 
59
if __name__ == "__main__":
60
    main()