mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 11:34:18 +00:00
many things
This commit is contained in:
parent
6510b59ecd
commit
483591f633
6 changed files with 50 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@ libopus-0.dll
|
|||
music.opus
|
||||
opusfiles/
|
||||
ignored/*
|
||||
markovmodel.json
|
3
db.py
3
db.py
|
@ -891,7 +891,8 @@ class GameOrigins(enum.Enum):
|
|||
class LibraryGame(Base):
|
||||
__tablename__ = "librarygames"
|
||||
|
||||
owner_id = Column(Integer, ForeignKey("royals_id"), nullable=False)
|
||||
id = Column(BigInteger, primary_key=True)
|
||||
owner_id = Column(Integer, ForeignKey("royals.id"), nullable=False)
|
||||
owner = relationship("Royal", lazy="joined")
|
||||
name = Column(String)
|
||||
platform = Column(String)
|
||||
|
|
|
@ -10,4 +10,5 @@ async_timeout
|
|||
raven
|
||||
bcrypt
|
||||
markdown2
|
||||
pygments
|
||||
pygments
|
||||
markovify
|
|
@ -1,6 +1,5 @@
|
|||
import datetime
|
||||
import random
|
||||
import math
|
||||
import typing
|
||||
import db
|
||||
import errors
|
||||
|
@ -14,9 +13,20 @@ import os
|
|||
import time
|
||||
import cast
|
||||
import re
|
||||
import logging
|
||||
import configparser
|
||||
import markovify
|
||||
|
||||
# Markov model
|
||||
try:
|
||||
with open("markovmodel.json") as file:
|
||||
model = markovify.Text.from_json(file.read())
|
||||
except Exception:
|
||||
model = None
|
||||
|
||||
logging.getLogger().setLevel(level=20)
|
||||
|
||||
# Init the config reader
|
||||
import configparser
|
||||
config = configparser.ConfigParser()
|
||||
config.read("config.ini")
|
||||
|
||||
|
@ -561,8 +571,30 @@ def cmd_calendar(bot: Bot, update: Update):
|
|||
bot.send_message(update.message.chat.id, msg, parse_mode="HTML", disable_web_page_preview=True)
|
||||
|
||||
|
||||
def cmd_markov(bot: Bot, update: Update):
|
||||
if model is None:
|
||||
bot.send_message(update.message.chat.id, "⚠️ Il modello Markov non è disponibile.")
|
||||
return
|
||||
try:
|
||||
_, first_word = update.message.text.split(" ", 1)
|
||||
except IndexError:
|
||||
sentence = model.make_sentence(tries=1000)
|
||||
if sentence is None:
|
||||
bot.send_message(update.message.chat.id, "⚠ Complimenti! Hai vinto la lotteria di Markov!\n"
|
||||
"O forse l'hai persa.\n"
|
||||
"Non sono riuscito a generare una frase, riprova.")
|
||||
return
|
||||
bot.send_message(update.message.chat.id, sentence)
|
||||
else:
|
||||
sentence = model.make_sentence_with_start(first_word, tries=1000)
|
||||
if sentence is None:
|
||||
bot.send_message(update.message.chat.id, "⚠ Non è stato possibile generare frasi partendo da questa"
|
||||
" parola.")
|
||||
return
|
||||
bot.send_message(update.message.chat.id, sentence)
|
||||
|
||||
|
||||
def process(arg_discord_connection):
|
||||
print("Telegrambot starting...")
|
||||
if arg_discord_connection is not None:
|
||||
global discord_connection
|
||||
discord_connection = arg_discord_connection
|
||||
|
@ -586,7 +618,9 @@ def process(arg_discord_connection):
|
|||
u.dispatcher.add_handler(CommandHandler("wheel", cmd_wheel))
|
||||
u.dispatcher.add_handler(CommandHandler("newevent", cmd_newevent))
|
||||
u.dispatcher.add_handler(CommandHandler("calendar", cmd_calendar))
|
||||
u.dispatcher.add_handler(CommandHandler("markov", cmd_markov))
|
||||
u.dispatcher.add_handler(CallbackQueryHandler(on_callback_query))
|
||||
logging.info("Handlers registered.")
|
||||
u.bot.send_message(config["Telegram"]["main_group"],
|
||||
f"ℹ Royal Bot avviato e pronto a ricevere comandi!\n"
|
||||
f"Ultimo aggiornamento: `{version}: {commit_msg}`",
|
||||
|
@ -594,11 +628,12 @@ def process(arg_discord_connection):
|
|||
while True:
|
||||
try:
|
||||
u.start_polling()
|
||||
logging.info("Polling started.")
|
||||
u.idle()
|
||||
except telegram.error.TimedOut:
|
||||
print("Telegrambot timed out.")
|
||||
logging.warning("Timed out, restarting in 1 minute.")
|
||||
time.sleep(60)
|
||||
print("Telegrambot restarting...")
|
||||
logging.info("Now restarting...")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
Bio
|
||||
</div>
|
||||
<div class="lower-box">
|
||||
{{ css.bio }}
|
||||
{{ bio }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -84,8 +84,10 @@ def page_profile(name: str):
|
|||
tg = db_session.query(db.Telegram).filter_by(royal=user).one_or_none()
|
||||
discord = db_session.execute(query_discord_music.one_query, {"royal": user.id}).fetchone()
|
||||
db_session.close()
|
||||
converted_bio = Markup(markdown2.markdown(css.bio.replace("<", "<"),
|
||||
extras=["spoiler", "tables", "smarty-pants", "fenced-code-blocks"]))
|
||||
return render_template("profile.html", ryg=user, css=css, osu=osu, rl=rl, dota=dota, lol=lol, steam=steam, ow=ow,
|
||||
tg=tg, discord=discord, config=config)
|
||||
tg=tg, discord=discord, config=config, bio=converted_bio)
|
||||
|
||||
|
||||
@app.route("/login")
|
||||
|
@ -248,7 +250,7 @@ def page_wiki(key: str):
|
|||
f' modificata da'
|
||||
f' <a href="https://ryg.steffo.eu/profile/{user.username}">{user.username}</a>:'
|
||||
f' {"<i>Nessun motivo specificato.</i>" if not edit_reason else edit_reason}\n',
|
||||
parse_mode="HTML")
|
||||
parse_mode="HTML", disable_web_page_preview=True, disable_notification=True)
|
||||
except Exception:
|
||||
pass
|
||||
return redirect(url_for("page_wiki", key=key))
|
||||
|
|
Loading…
Reference in a new issue