async def shitpost(msg: Message) -> None: if msg.room is None: return phrase = utils.remove_diacritics(msg.arg.strip()) if len(phrase) > 50: await msg.reply("Testo troppo lungo") return text0 = "" text1 = "" text2 = "" if phrase == "": if not msg.room.is_private: return phrase = "SHITPOST" if not msg.room.is_private and ("x" in phrase or "X" in phrase): phrase = "lolno" for i in phrase: if i in LETTERS: if text0 != "": text0 += " " text1 += " " text2 += " " text0 += LETTERS[i][0] text1 += LETTERS[i][1] text2 += LETTERS[i][2] html = e.Pre(style="margin: 0; overflow-x: auto") html.add(text0 + e.Br() + text1 + e.Br() + text2) await msg.reply_htmlbox(html)
async def tell(msg: Message) -> None: if not msg.arg: await msg.reply("Cosa devo inviare?") return author = msg.user.roomname(msg.parametrized_room) html = e.B(to_obfuscated_html(msg.arg)) + e.Br() html += e.Div( f"[inviato da {author}]", style="display: inline-block; color: #888; font-size: 8pt", ) await msg.parametrized_room.send_htmlbox(html)
async def commands(msg: Message) -> None: cmd = msg.arg.lower() if cmd in msg.conn.commands and msg.conn.commands[cmd].helpstr: # asking for a specific command html = e.B(cmd) + e.RawTextNode(f" {msg.conn.commands[cmd].helpstr}") await msg.reply_htmlbox(html) elif cmd == "": # asking for a list of every command helpstrings = Command.get_all_helpstrings() if not helpstrings: return html = BaseElement() for key, helpstring in helpstrings.items(): html.add(e.B(key) + e.RawTextNode(f" {helpstring}") + e.Br()) await msg.reply_htmlbox(html) else: await msg.reply("Comando non trovato")
def __init__( self, *, avatar_dir: str, avatar_name: str, username: str, badges: list[d.Badges], description: str | None, pokemon_icon: str | None, ) -> None: super().__init__() with self.doc, e.Div(): with e.Div(style=self._get_css("avatar")): e.Img( src=( "https://play.pokemonshowdown.com/sprites/" f"{avatar_dir}/{avatar_name}.png" ), width=80, height=80, ) with e.Div(style=self._get_css("main")): ce.Username(username) e.Br() for badge in badges: e.Img( src=badge.image, width=13, height=13, title=badge.label, style=self._get_css("badge"), ) if description: e.Hr(style=self._get_css("hr")) e.Div(description, style=self._get_css("description")) if pokemon_icon: with e.Div(style=self._get_css("pokemon_icon")): ce.Psicon(pokemon=pokemon_icon)
async def card(msg: Message) -> None: if not msg.arg: await msg.reply("Che carta devo cercare?") return query = urllib.parse.quote(msg.arg) url = "https://api.scryfall.com/cards/search?include_multilingual=true&q=" + query json_body = await query_scryfall(url, "list") # If the search didn't match any cards, broaden the scope to include extras (tokens, # planes, ...). if json_body is None: url += "&include_extras=true" json_body = await query_scryfall(url, "list") if json_body is None: await msg.reply("Nome non valido") return cards = json_body["data"] # Scryfall lists are always non-empty. if len(cards) == 1: card_ = cards[0] else: # If there is an exact match, discard other results. # Use case: "Black Lotus" -> ["Black Lotus", "Blacker Lotus"] my_card_id = to_card_id(msg.arg) card_ = next((c for c in cards if to_card_id(c["name"]) == my_card_id), None) if card_: # Show card thumbnail(s) if there's only 1 query result. await msg.reply_htmlbox(to_card_thumbnail(card_)) elif len(cards) <= 40: # Show a list of all query results. html = BaseElement() for c in cards: html.add(e.A(c["name"], href=c["scryfall_uri"]) + e.Br()) await msg.reply_htmlbox(html) else: await msg.reply(f"**{len(cards)}** risultati! Usa un nome più specifico...")
async def setprofile(msg: Message) -> None: if not msg.arg: await msg.reply("Specifica una frase da inserire nel tuo profilo") return if len(msg.arg) > 250: await msg.reply("Errore: lunghezza massima 250 caratteri") return # authorized: True if msg.user can approve new descriptions. authorized = msg.user.has_role("driver", msg.conn.main_room) db = Database.open() with db.get_session() as session: userid = msg.user.userid session.add(d.Users(userid=userid)) stmt = update(d.Users).filter_by(userid=userid) if authorized: # Authorized users skip the validation process. stmt = stmt.values(description=msg.arg, description_pending="") else: stmt = stmt.values(description_pending=msg.arg) session.execute(stmt) await msg.reply("Salvato") if not authorized: username = msg.user.username botname = msg.conn.username cmd = f"{msg.conn.command_character}pendingdescriptions" html = f"{username} ha aggiornato la sua frase del profilo." + e.Br() html += ( "Usa " + e.Button(cmd, name="send", value=f"/pm {botname}, {cmd}") + " per approvarla o rifiutarla" ) await msg.conn.main_room.send_rankhtmlbox("%", html)