Subversion Repositories navi

Compare Revisions

Ignore whitespace Rev 285 → Rev 288

/tsimapiak/dbconnector.py
50,17 → 50,24
FROM `metaInfixes`
ORDER BY CHAR_LENGTH(navi) DESC""")
for row in cur:
endfix = False
if row["navi"] and row["navi"][0] == "-":
ret[2].append({"id": row["id"], "navi": row["navi"].replace("-", ""), "gloss": row["shorthand"].upper()})
elif row["navi"] and row["navi"][-1] in ("-", "+"):
ret[0].append({"id": row["id"], "navi": row["navi"].replace("-", ""), "gloss": row["shorthand"].upper()})
else:
endfix = True
if row["navi"] and row["navi"][-1] in ("-", "+"):
ret[0].append({"id": row["id"], "navi": row["navi"].replace("-", "").replace("+", ""), "gloss": row["shorthand"].upper()})
endfix = True
if not endfix:
if not row["position"] or row["position"] == "NULL":
# not actually an affix
continue
ret[1].append({"id": row["id"], "navi": row["navi"].replace("-", ""), "gloss": row["shorthand"].upper(), "position": int(row["position"])})
ret[1].append({"id": row["id"], "navi": row["navi"], "gloss": row["shorthand"].upper(), "position": int(row["position"])})
cur.close()
db.close()
 
for subret in ret:
subret.sort(key=lambda x: len(x["navi"]), reverse=True)
 
return ret
 
def translate(wid, language):
/tsimapiak/parse.py
167,7 → 167,7
last = u""
while last != posf:
last = posf
for pos, posid in [(x["navi"], None) for x in postfixes] + [(x["navi"], x["id"]) for x in wordlist if x["type"] == "adp."] + list(EXTRAADP):
for pos, posid in sorted([(x["navi"], None) for x in postfixes] + [(x["navi"], x["id"]) for x in wordlist if x["type"] == "adp."] + list(EXTRAADP), key=lambda x: len(x[0]), reverse=True):
if posf != u"":
if posf.startswith(pos):
if (pos, posid) in foundposts[wor]:
/discordbot/README.txt
0,0 → 1,3
This is a Discord bot for TsimApiak.
 
To use it you have to put the tsimapiak directory inside this dir, and run bot.py.
/discordbot/bot.py
0,0 → 1,60
#! /usr/bin/env python
# This file is part of Tsim Apiak.
#
# Tsim Apiak is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public Licence as published by
# the Free Software Foundation, either version 3 of the Licence, or
# (at your option) any later version.
#
# In addition to this, you must also comply with clause 4 of the
# Apache Licence, version 2.0, concerning attribution. Where there
# is a contradiction between the two licences, the GPL
# takes preference.
#
# Tsim Apiak is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Tsim Apiak. If not, see <http://www.gnu.org/licenses/>.#
 
import os
 
import discord
import dotenv
from typing import Optional
 
from tsimapiak import translate
 
dotenv.load_dotenv(dotenv.find_dotenv())
 
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = discord.app_commands.CommandTree(client)
 
@client.event
async def on_ready():
print(f"{client.user} Connected to discord")
await tree.sync()
 
@tree.command(
name="translate",
description="Translate (gloss) Na'vi to English"
)
async def on_translate(interaction: discord.Interaction, argument: str, language: Optional[str]):
if not language:
language = "en"
translated = []
for word in translate.translatesent(argument, language):
translated.append(word["translated"])
 
await interaction.response.send_message(argument + "\n" + " | ".join(translated))
 
def main():
TOKEN = os.getenv('DISCORD_TOKEN')
 
client.run(TOKEN)
 
if __name__ == "__main__":
main()
Property changes:
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property