1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Award fiorygi for wiki edits > +500

This commit is contained in:
Steffo 2019-02-26 16:24:28 +01:00
parent d43e1e7552
commit cfb3e53ff4
5 changed files with 32 additions and 25 deletions

View file

@ -256,3 +256,4 @@ SMECDS = "🤔 Secondo me, è colpa {ds}."
class WIKI: class WIKI:
PAGE_LOCKED = '🔒 La pagina wiki <a href="https://ryg.steffo.eu/wiki/{key}">{key}</a> è stata bloccata da <b>{user}</b>.' PAGE_LOCKED = '🔒 La pagina wiki <a href="https://ryg.steffo.eu/wiki/{key}">{key}</a> è stata bloccata da <b>{user}</b>.'
PAGE_UNLOCKED = '🔓 La pagina wiki <a href="https://ryg.steffo.eu/wiki/{key}">{key}</a> è stata sbloccata da <b>{user}</b>.' PAGE_UNLOCKED = '🔓 La pagina wiki <a href="https://ryg.steffo.eu/wiki/{key}">{key}</a> è stata sbloccata da <b>{user}</b>.'
PAGE_UPDATED = '📖 La pagina wiki <a href="https://ryg.steffo.eu/wiki/{key}">{key}</a> è stata modificata da <b>{user}</b>.\n{reason} [{change}]'

View file

@ -2,7 +2,7 @@ import datetime
import random import random
import typing import typing
import db import db
from utils import smecds, cast, errors, emojify from utils import smecds, cast, errors, emojify, reply_msg
# python-telegram-bot has a different name # python-telegram-bot has a different name
# noinspection PyPackageRequirements # noinspection PyPackageRequirements
import telegram import telegram
@ -56,13 +56,6 @@ sentry = raven.Client(config["Sentry"]["token"],
hook_libraries=[]) hook_libraries=[])
def reply_msg(bot: telegram.Bot, chat_id: int, string: str, ignore_escaping=False, disable_web_page_preview=True, **kwargs) -> telegram.Message:
string = strings.safely_format_string(string, ignore_escaping=ignore_escaping, words=kwargs)
return bot.send_message(chat_id, string,
parse_mode="HTML",
disable_web_page_preview=disable_web_page_preview)
def reply(bot: telegram.Bot, update: telegram.Update, string: str, ignore_escaping=False, disable_web_page_preview=True, **kwargs) -> telegram.Message: def reply(bot: telegram.Bot, update: telegram.Update, string: str, ignore_escaping=False, disable_web_page_preview=True, **kwargs) -> telegram.Message:
while True: while True:
try: try:

View file

@ -3,5 +3,6 @@ from .mmstatus import MatchmakingStatus
from .cast import Spell from .cast import Spell
from .stagismo import smecds from .stagismo import smecds
from .emojify import emojify from .emojify import emojify
from .telegramstuff import reply_msg
__all__ = ["Dirty", "DirtyDelta", "MatchmakingStatus", "Spell", "smecds", "emojify"] __all__ = ["Dirty", "DirtyDelta", "MatchmakingStatus", "Spell", "smecds", "emojify", "reply_msg"]

9
utils/telegramstuff.py Normal file
View file

@ -0,0 +1,9 @@
import telegram
import strings
def reply_msg(bot: telegram.Bot, chat_id: int, string: str, ignore_escaping=False, disable_web_page_preview=True, **kwargs) -> telegram.Message:
string = strings.safely_format_string(string, ignore_escaping=ignore_escaping, words=kwargs)
return bot.send_message(chat_id, string,
parse_mode="HTML",
disable_web_page_preview=disable_web_page_preview)

View file

@ -15,6 +15,7 @@ import functools
import strings import strings
from sqlalchemy.orm.collections import InstrumentedList from sqlalchemy.orm.collections import InstrumentedList
from raven.contrib.flask import Sentry from raven.contrib.flask import Sentry
from utils import reply_msg
app = Flask(__name__) app = Flask(__name__)
@ -274,28 +275,30 @@ def page_wiki_edit(key: str):
difference = len(new_content) - len(wiki_page.content) difference = len(new_content) - len(wiki_page.content)
wiki_page.content = new_content wiki_page.content = new_content
# Award fiorygi # Award fiorygi
if difference > 50: if difference > 500:
fioryg_chance = -(5000/difference) + 100 fiorygi = difference // 500
fioryg_roll = random.randrange(0, 100) fiorygi_word = "fioryg" + ("i" if fiorygi != 1 else "")
if fioryg_roll > fioryg_chance: fl_g.user.fiorygi += fiorygi
fl_g.user.fiorygi += 1
else: else:
fioryg_chance = -1 fiorygi = 0
fioryg_roll = -2 fiorygi_word = ""
edit_reason = request.form.get("reason") edit_reason = request.form.get("reason")
new_log = db.WikiLog(editor=fl_g.user, edited_key=key, timestamp=datetime.datetime.now(), reason=edit_reason) new_log = db.WikiLog(editor=fl_g.user, edited_key=key, timestamp=datetime.datetime.now(), reason=edit_reason)
fl_g.session.add(new_log) fl_g.session.add(new_log)
fl_g.session.commit() fl_g.session.commit()
message = f' La pagina wiki <a href="https://ryg.steffo.eu/wiki/{key}">{key}</a> è stata' \
f' modificata da' \
f' <a href="https://ryg.steffo.eu/profile/{fl_g.user.username}">{fl_g.user.username}</a>' \
f' {"(" + edit_reason + ")" if edit_reason else ""}' \
f' [{"+" if difference > 0 else ""}{difference}]\n'
if fioryg_roll > fioryg_chance:
message += f"⭐️ {fl_g.user.username} è stato premiato con 1 fioryg per la modifica!"
try: try:
telegram_bot.send_message(config["Telegram"]["main_group"], message, reply_msg(telegram_bot, config["Telegram"]["main_group"], strings.WIKI.PAGE_UPDATED,
parse_mode="HTML", disable_web_page_preview=True, disable_notification=True) key=key,
user=fl_g.user.telegram.mention(),
reason=edit_reason,
change=f"+{str(difference)}" if difference > 0 else str(difference))
if fiorygi > 0:
reply_msg(telegram_bot, config["Telegram"]["main_group"], strings.TELEGRAM.FIORYGI_AWARDED,
mention=fl_g.user.telegram.mention(),
number=fiorygi,
fiorygi=fiorygi_word,
reason="aver contribuito alla wiki Royal Games")
except Exception: except Exception:
pass pass
return redirect(url_for("page_wiki", key=key)) return redirect(url_for("page_wiki", key=key))