mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Add some checks and fix some bugs
This commit is contained in:
parent
6666331a15
commit
ef485086ce
9 changed files with 25 additions and 13 deletions
|
@ -1,3 +1,4 @@
|
|||
python-telegram-bot>=11.1.0
|
||||
websockets>=7.0
|
||||
pytest>=4.3.1
|
||||
psycopg2-binary>=2.8
|
||||
|
|
|
@ -63,8 +63,8 @@ class TelegramBot:
|
|||
.replace("[/i]", "</i>") \
|
||||
.replace("[u]", "<b>") \
|
||||
.replace("[/u]", "</b>") \
|
||||
.replace("[c]", "<pre>") \
|
||||
.replace("[/c]", "</pre>")
|
||||
.replace("[c]", "<code>") \
|
||||
.replace("[/c]", "</code>")
|
||||
await asyncify(call.channel.send_message, escaped_text, parse_mode="HTML")
|
||||
|
||||
async def net_request(call, message: Message, destination: str):
|
||||
|
|
|
@ -14,4 +14,4 @@ class DebugAuthorCommand(Command):
|
|||
author = await call.get_author()
|
||||
if author is None:
|
||||
await call.reply(f"☁️ L'autore di questa chiamata è sconosciuto.")
|
||||
await call.reply(f"🌞 [c]{str(author)}[/c] è l'autore di questa chiamata.")
|
||||
await call.reply(f"🌞 {str(author)} è l'autore di questa chiamata.")
|
||||
|
|
|
@ -13,7 +13,7 @@ class DebugCreateCommand(Command):
|
|||
async def common(self, call: Call):
|
||||
royal = call.alchemy.Royal(username=call.args[0], role="Member")
|
||||
call.session.add(royal)
|
||||
alias = call.alchemy.Alias(royal=royal, alias=royal.username)
|
||||
alias = call.alchemy.Alias(royal=royal, alias=royal.username.lower())
|
||||
call.session.add(alias)
|
||||
await asyncify(call.session.commit)
|
||||
await call.reply(f"✅ Utente [c]{royal}[/c] creato!")
|
||||
await call.reply(f"✅ Utente {royal} creato!")
|
||||
|
|
|
@ -9,7 +9,7 @@ class DiarioCommand(Command):
|
|||
|
||||
command_name = "diario"
|
||||
command_title = "Aggiungi una citazione al Diario."
|
||||
command_syntax = "\"(testo)\" --[autore], [contesto]"
|
||||
command_syntax = "[!] \"(testo)\" --[autore], [contesto]"
|
||||
|
||||
require_alchemy_tables = {Royal, Diario, Alias}
|
||||
|
||||
|
@ -36,12 +36,23 @@ class DiarioCommand(Command):
|
|||
quoted = None
|
||||
context = None
|
||||
timestamp = datetime.datetime.now()
|
||||
# Ensure there is some text
|
||||
if not text:
|
||||
raise InvalidInputError("Missing text.")
|
||||
# Or a quoted
|
||||
if not quoted:
|
||||
quoted = None
|
||||
if not context:
|
||||
context = None
|
||||
# Find if there's a Royalnet account associated with the quoted name
|
||||
if quoted is not None:
|
||||
quoted_alias = await asyncify(call.session.query(call.alchemy.Alias).filter_by(alias=quoted.lower()).one_or_none)
|
||||
else:
|
||||
quoted_alias = None
|
||||
quoted_account = quoted_alias.royal if quoted_alias is not None else None
|
||||
if quoted_alias is not None and quoted_account is None:
|
||||
await call.reply("⚠️ Il nome dell'autore è ambiguo, quindi la riga non è stata aggiunta.\nPer piacere, ripeti il comando con un nome più specifico!")
|
||||
return
|
||||
# Create the diario quote
|
||||
diario = call.alchemy.Diario(creator=creator,
|
||||
quoted_account=quoted_account,
|
||||
|
|
|
@ -37,13 +37,13 @@ class SyncCommand(Command):
|
|||
tg_last_name=user.last_name,
|
||||
tg_username=user.username)
|
||||
call.session.add(telegram)
|
||||
await call.reply(f"✅ Connessione completata: [c]{str(royal)}[/c] ⬌ [c]{str(telegram)}[/c]")
|
||||
await call.reply(f"✅ Connessione completata: {str(royal)} ⬌ {str(telegram)}")
|
||||
else:
|
||||
# Update the Telegram data
|
||||
# Avatar is WIP
|
||||
telegram.tg_first_name = user.first_name
|
||||
telegram.tg_last_name = user.last_name
|
||||
telegram.tg_username = user.username
|
||||
await call.reply(f"✅ Dati di [c]{str(telegram)}[/c] aggiornati.")
|
||||
await call.reply(f"✅ Dati di {str(telegram)} aggiornati.")
|
||||
# Commit the session
|
||||
await asyncify(call.session.commit)
|
||||
|
|
|
@ -32,15 +32,15 @@ class Diario:
|
|||
def __str__(self):
|
||||
# TODO: support media_url
|
||||
text = f"Riga #{self.diario_id}"
|
||||
text += f" (salvata da {self.creator.username}"
|
||||
text += f" alle {self.timestamp.strftime('%Y-%m-%d %H:%M')}):\n"
|
||||
text += f" (salvata da {str(self.creator)}"
|
||||
text += f" il {self.timestamp.strftime('%Y-%m-%d %H:%M')}):\n"
|
||||
if self.spoiler:
|
||||
hidden = re.sub("\w", "█", self.text)
|
||||
text += f"\"{hidden}\"\n"
|
||||
else:
|
||||
text += f"[b]\"{self.text}\"[/b]\n"
|
||||
if self.quoted_account is not None:
|
||||
text += f" —{self.quoted_account.username}"
|
||||
text += f" —{str(self.quoted_account)}"
|
||||
elif self.quoted is not None:
|
||||
text += f" —{self.quoted}"
|
||||
else:
|
||||
|
|
|
@ -17,4 +17,4 @@ class Royal:
|
|||
return f"<Royal {self.username}>"
|
||||
|
||||
def __str__(self):
|
||||
return f"royalnet:{self.username}"
|
||||
return f"[c]royalnet:{self.username}[/c]"
|
||||
|
|
|
@ -24,7 +24,7 @@ class Telegram:
|
|||
return f"<Telegram {str(self)}>"
|
||||
|
||||
def __str__(self):
|
||||
return f"telegram:{self.mention()}"
|
||||
return f"[c]telegram:{self.mention()}[/c]"
|
||||
|
||||
def mention(self) -> str:
|
||||
if self.tg_username is not None:
|
||||
|
|
Loading…
Reference in a new issue