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

__screams__ I BROKE EVERYTHING

This commit is contained in:
Steffo 2020-08-21 03:43:39 +02:00
parent 8281702706
commit 5181fde3e6
6 changed files with 52 additions and 75 deletions

21
poetry.lock generated
View file

@ -26,17 +26,16 @@ python-versions = ">=3.5.3"
[[package]] [[package]]
name = "attrs" name = "attrs"
version = "19.3.0" version = "20.1.0"
description = "Classes Without Boilerplate" description = "Classes Without Boilerplate"
category = "main" category = "main"
optional = false optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[package.extras] [package.extras]
azure-pipelines = ["coverage", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface", "pytest-azurepipelines"] dev = ["coverage (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface", "sphinx", "sphinx-rtd-theme", "pre-commit"]
dev = ["coverage", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface", "sphinx", "pre-commit"] docs = ["sphinx", "sphinx-rtd-theme", "zope.interface"]
docs = ["sphinx", "zope.interface"] tests = ["coverage (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface"]
tests = ["coverage", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "zope.interface"]
[[package]] [[package]]
name = "bcrypt" name = "bcrypt"
@ -369,7 +368,7 @@ requests = "*"
[[package]] [[package]]
name = "royalnet" name = "royalnet"
version = "5.11.0" version = "5.11.2"
description = "A multipurpose bot and web framework" description = "A multipurpose bot and web framework"
category = "main" category = "main"
optional = false optional = false
@ -623,7 +622,7 @@ multidict = ">=4.0"
[metadata] [metadata]
lock-version = "1.0" lock-version = "1.0"
python-versions = "^3.8" python-versions = "^3.8"
content-hash = "b45296e9be3f2ad43dd04bc9359fd9bfce913970a0dc06dd6027726bfa8c9858" content-hash = "18a585dcd6662c69d9fd39c9c683270e55ff4636addc591f539385f844a9f9d9"
[metadata.files] [metadata.files]
aiohttp = [ aiohttp = [
@ -645,8 +644,8 @@ async-timeout = [
{file = "async_timeout-3.0.1-py3-none-any.whl", hash = "sha256:4291ca197d287d274d0b6cb5d6f8f8f82d434ed288f962539ff18cc9012f9ea3"}, {file = "async_timeout-3.0.1-py3-none-any.whl", hash = "sha256:4291ca197d287d274d0b6cb5d6f8f8f82d434ed288f962539ff18cc9012f9ea3"},
] ]
attrs = [ attrs = [
{file = "attrs-19.3.0-py2.py3-none-any.whl", hash = "sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c"}, {file = "attrs-20.1.0-py2.py3-none-any.whl", hash = "sha256:2867b7b9f8326499ab5b0e2d12801fa5c98842d2cbd22b35112ae04bf85b4dff"},
{file = "attrs-19.3.0.tar.gz", hash = "sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72"}, {file = "attrs-20.1.0.tar.gz", hash = "sha256:0ef97238856430dcf9228e07f316aefc17e8939fc8507e18c6501b761ef1a42a"},
] ]
bcrypt = [ bcrypt = [
{file = "bcrypt-3.2.0-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:c95d4cbebffafcdd28bd28bb4e25b31c50f6da605c81ffd9ad8a3d1b2ab7b1b6"}, {file = "bcrypt-3.2.0-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:c95d4cbebffafcdd28bd28bb4e25b31c50f6da605c81ffd9ad8a3d1b2ab7b1b6"},
@ -920,8 +919,8 @@ riotwatcher = [
{file = "riotwatcher-3.0.0.tar.gz", hash = "sha256:bf8b8eb7e13c794730c18cd7846513cf22295a068204433117ce4d83a25b0fd2"}, {file = "riotwatcher-3.0.0.tar.gz", hash = "sha256:bf8b8eb7e13c794730c18cd7846513cf22295a068204433117ce4d83a25b0fd2"},
] ]
royalnet = [ royalnet = [
{file = "royalnet-5.11.0-py3-none-any.whl", hash = "sha256:cb2ed753044ae563b73389acce4c9c0b0b4a4cb2cb5bc2bc0197a91478a12575"}, {file = "royalnet-5.11.2-py3-none-any.whl", hash = "sha256:443c5e27dd60767ed88530f5c16d349a7353fbdd9177e0c6260d230565db2bc1"},
{file = "royalnet-5.11.0.tar.gz", hash = "sha256:aab356a1a845a893c2f1c4e96ec01faf799c9efb5041451a25aa3264f8926859"}, {file = "royalnet-5.11.2.tar.gz", hash = "sha256:95368b1f0ffa3390876643d3958dc3e8d62c788d78a5487213a204ebe4f3dfe7"},
] ]
royalspells = [ royalspells = [
{file = "royalspells-3.2.tar.gz", hash = "sha256:2bd4a9a66514532e35c02c3907425af48c7cb292364c4843c795719a82b25dfe"}, {file = "royalspells-3.2.tar.gz", hash = "sha256:2bd4a9a66514532e35c02c3907425af48c7cb292364c4843c795719a82b25dfe"},

View file

@ -28,7 +28,7 @@
itsdangerous = "^1.1.0" itsdangerous = "^1.1.0"
[tool.poetry.dependencies.royalnet] [tool.poetry.dependencies.royalnet]
version = "~5.11.0" version = "~5.11.2"
# Maybe... there is a way to make these selectable? # Maybe... there is a way to make these selectable?
extras = [ extras = [
"telegram", "telegram",

View file

@ -22,7 +22,7 @@ from .help import HelpCommand
from .leagueoflegends import LeagueoflegendsCommand from .leagueoflegends import LeagueoflegendsCommand
from .magickfiorygi import MagickfiorygiCommand from .magickfiorygi import MagickfiorygiCommand
from .magicktreasure import MagicktreasureCommand from .magicktreasure import MagicktreasureCommand
from .matchmaking import MatchmakingCommand # from .matchmaking import MatchmakingCommand
from .ping import PingCommand from .ping import PingCommand
from .pmots import PmotsCommand from .pmots import PmotsCommand
from .dog import DogCommand from .dog import DogCommand
@ -63,7 +63,7 @@ available_commands = [
LeagueoflegendsCommand, LeagueoflegendsCommand,
MagickfiorygiCommand, MagickfiorygiCommand,
MagicktreasureCommand, MagicktreasureCommand,
MatchmakingCommand, # MatchmakingCommand,
PingCommand, PingCommand,
PmotsCommand, PmotsCommand,
DogCommand, DogCommand,

View file

@ -1,25 +1,11 @@
# Imports go here! # Imports go here!
from .discord_cv import DiscordCvEvent from .discord_cv import DiscordCvEvent
from .discord_summon import DiscordSummonEvent
from .discord_play import DiscordPlayEvent
from .discord_skip import DiscordSkipEvent
from .discord_queue import DiscordQueueEvent
from .discord_pause import DiscordPauseEvent
from .discord_playable import DiscordPlaymodeEvent
from .discord_lazy_play import DiscordLazyPlayEvent
from .telegram_message import TelegramMessageEvent from .telegram_message import TelegramMessageEvent
from .pong import PongEvent from .pong import PongEvent
# Enter the commands of your Pack here! # Enter the commands of your Pack here!
available_events = [ available_events = [
DiscordCvEvent, DiscordCvEvent,
DiscordSummonEvent,
DiscordPlayEvent,
DiscordSkipEvent,
DiscordQueueEvent,
DiscordPauseEvent,
DiscordPlaymodeEvent,
DiscordLazyPlayEvent,
TelegramMessageEvent, TelegramMessageEvent,
PongEvent, PongEvent,
] ]

View file

@ -1,9 +1,5 @@
from .royalqueue import RoyalQueue # from .mmtask import MMTask
from .royalpool import RoyalPool
from .mmtask import MMTask
__all__ = [ __all__ = [
"RoyalQueue", # "MMTask",
"RoyalPool",
"MMTask",
] ]

View file

@ -162,17 +162,19 @@ class MMTask:
user = await data.get_author(error_if_none=True) user = await data.get_author(error_if_none=True)
# Get the related MMEvent # Get the related MMEvent
mmevent: MMEvent = await ru.asyncify(data.session.query(self._EventT).get, self.mmid) async with data.session_acm() as session:
mmevent: MMEvent = await ru.asyncify(session.query(self._EventT).get, self.mmid)
# Check if the user had already responded # Check if the user had already responded
mmresponse: MMResponse = await ru.asyncify( mmresponse: MMResponse = await ru.asyncify(
data.session.query(self._ResponseT).filter_by(user=user, mmevent=mmevent).one_or_none session.query(self._ResponseT).filter_by(user=user, mmevent=mmevent).one_or_none
) )
if mmresponse is None: if mmresponse is None:
# If they didn't respond, create a new MMResponse # If they didn't respond, create a new MMResponse
# noinspection PyArgumentList
mmresponse = self._ResponseT(user=user, mmevent=mmevent, choice=choice) mmresponse = self._ResponseT(user=user, mmevent=mmevent, choice=choice)
data.session.add(mmresponse) session.add(mmresponse)
# Drop fiorygi # Drop fiorygi
if random.randrange(100) < self.command.config["Matchmaking"]["fiorygi_award_chance"]: if random.randrange(100) < self.command.config["Matchmaking"]["fiorygi_award_chance"]:
@ -181,7 +183,7 @@ class MMTask:
# Change their response # Change their response
mmresponse.choice = choice mmresponse.choice = choice
try: try:
await data.session_commit() await ru.asyncify(session.commit)
except psycopg2.Error: except psycopg2.Error:
raise rc.UserError("Hai già risposto nello stesso modo a questo matchmaking.") raise rc.UserError("Hai già risposto nello stesso modo a questo matchmaking.")
@ -196,7 +198,8 @@ class MMTask:
user = await data.get_author(error_if_none=True) user = await data.get_author(error_if_none=True)
# Get the related MMEvent # Get the related MMEvent
mmevent: MMEvent = await ru.asyncify(data.session.query(self._EventT).get, self.mmid) async with data.session_acm() as session:
mmevent: MMEvent = await ru.asyncify(session.query(self._EventT).get, self.mmid)
# Ensure the user has the required roles to start the matchmaking # Ensure the user has the required roles to start the matchmaking
if user != mmevent.creator and "admin" not in user.roles: if user != mmevent.creator and "admin" not in user.roles:
@ -214,7 +217,8 @@ class MMTask:
user = await data.get_author(error_if_none=True) user = await data.get_author(error_if_none=True)
# Get the related MMEvent # Get the related MMEvent
mmevent: MMEvent = await ru.asyncify(data.session.query(self._EventT).get, self.mmid) async with data.session_acm() as session:
mmevent: MMEvent = await ru.asyncify(session.query(self._EventT).get, self.mmid)
# Ensure the user has the required roles to start the matchmaking # Ensure the user has the required roles to start the matchmaking
if user != mmevent.creator and "admin" not in user.roles: if user != mmevent.creator and "admin" not in user.roles:
@ -233,19 +237,16 @@ class MMTask:
rows.append([ rows.append([
rc.KeyboardKey( rc.KeyboardKey(
interface=self.command.interface,
short=f"{MMChoice.YES.value}", short=f"{MMChoice.YES.value}",
text="Ci sarò!", text="Ci sarò!",
callback=self.get_answer_callback(MMChoice.YES) callback=self.get_answer_callback(MMChoice.YES)
), ),
rc.KeyboardKey( rc.KeyboardKey(
interface=self.command.interface,
short=f"{MMChoice.MAYBE.value}", short=f"{MMChoice.MAYBE.value}",
text="Forse...", text="Forse...",
callback=self.get_answer_callback(MMChoice.MAYBE) callback=self.get_answer_callback(MMChoice.MAYBE)
), ),
rc.KeyboardKey( rc.KeyboardKey(
interface=self.command.interface,
short=f"{MMChoice.NO.value}", short=f"{MMChoice.NO.value}",
text="Non mi interessa.", text="Non mi interessa.",
callback=self.get_answer_callback(MMChoice.NO) callback=self.get_answer_callback(MMChoice.NO)
@ -255,19 +256,16 @@ class MMTask:
if self._mmevent.datetime is not None: if self._mmevent.datetime is not None:
rows.append([ rows.append([
rc.KeyboardKey( rc.KeyboardKey(
interface=self.command.interface,
short=f"{MMChoice.LATE_SHORT.value}", short=f"{MMChoice.LATE_SHORT.value}",
text="10 min", text="10 min",
callback=self.get_answer_callback(MMChoice.LATE_SHORT) callback=self.get_answer_callback(MMChoice.LATE_SHORT)
), ),
rc.KeyboardKey( rc.KeyboardKey(
interface=self.command.interface,
short=f"{MMChoice.LATE_MEDIUM.value}", short=f"{MMChoice.LATE_MEDIUM.value}",
text="30 min", text="30 min",
callback=self.get_answer_callback(MMChoice.LATE_MEDIUM) callback=self.get_answer_callback(MMChoice.LATE_MEDIUM)
), ),
rc.KeyboardKey( rc.KeyboardKey(
interface=self.command.interface,
short=f"{MMChoice.LATE_LONG.value}", short=f"{MMChoice.LATE_LONG.value}",
text="60 min", text="60 min",
callback=self.get_answer_callback(MMChoice.LATE_LONG) callback=self.get_answer_callback(MMChoice.LATE_LONG)
@ -276,13 +274,11 @@ class MMTask:
rows.append([ rows.append([
rc.KeyboardKey( rc.KeyboardKey(
interface=self.command.interface,
short=f"🗑", short=f"🗑",
text="Elimina", text="Elimina",
callback=self.get_delete_callback() callback=self.get_delete_callback()
), ),
rc.KeyboardKey( rc.KeyboardKey(
interface=self.command.interface,
short=f"🚩", short=f"🚩",
text="Inizia", text="Inizia",
callback=self.get_start_callback() callback=self.get_start_callback()
@ -319,13 +315,13 @@ class MMTask:
for x, row in enumerate(inkm.inline_keyboard): for x, row in enumerate(inkm.inline_keyboard):
for y, key in enumerate(row): for y, key in enumerate(row):
key: InKB key: InKB
self.command.interface.serf.register_keyboard_key(key.callback_data, key=royalnet_keyboard[x][y]) self.command.serf.register_keyboard_key(key.callback_data, key=royalnet_keyboard[x][y])
def unregister_telegram_keyboard(self, inkm: InKM): def unregister_telegram_keyboard(self, inkm: InKM):
for row in inkm.inline_keyboard: for row in inkm.inline_keyboard:
for key in row: for key in row:
key: InKB key: InKB
self.command.interface.serf.unregister_keyboard_key(key.callback_data) self.command.serf.unregister_keyboard_key(key.callback_data)
async def wait_until_due(self): async def wait_until_due(self):
"""When the event is due, interrupt the MMTask with the TIME_RAN_OUT reason.""" """When the event is due, interrupt the MMTask with the TIME_RAN_OUT reason."""
@ -356,8 +352,8 @@ class MMTask:
if self._mmevent.interface_data is None: if self._mmevent.interface_data is None:
# Send the channel message # Send the channel message
log.debug(f"Sending message for: {self.mmid}") log.debug(f"Sending message for: {self.mmid}")
message: PTBMessage = await self.command.interface.serf.api_call( message: PTBMessage = await self.command.serf.api_call(
self.command.interface.serf.client.send_message, self.command.serf.client.send_message,
chat_id=self.telegram_channel_id, chat_id=self.telegram_channel_id,
text=rst.escape(self.channel_text), text=rst.escape(self.channel_text),
parse_mode="HTML", parse_mode="HTML",
@ -377,8 +373,8 @@ class MMTask:
# Delete the channel message # Delete the channel message
log.debug(f"Deleting message for: {self.mmid}") log.debug(f"Deleting message for: {self.mmid}")
await self.command.interface.serf.api_call( await self.command.serf.api_call(
self.command.interface.serf.client.delete_message, self.command.serf.client.delete_message,
chat_id=self._mmevent.interface_data.chat_id, chat_id=self._mmevent.interface_data.chat_id,
message_id=self._mmevent.interface_data.message_id message_id=self._mmevent.interface_data.message_id
) )
@ -391,7 +387,7 @@ class MMTask:
log.debug(f"Updating message for: {self.mmid}") log.debug(f"Updating message for: {self.mmid}")
try: try:
await ru.asyncify( await ru.asyncify(
self.command.interface.serf.client.edit_message_text, self.command.serf.client.edit_message_text,
chat_id=self._mmevent.interface_data.chat_id, chat_id=self._mmevent.interface_data.chat_id,
text=rst.escape(self.channel_text), text=rst.escape(self.channel_text),
message_id=self._mmevent.interface_data.message_id, message_id=self._mmevent.interface_data.message_id,
@ -403,8 +399,8 @@ class MMTask:
log.warning(f"TelegramError during update: {e}") log.warning(f"TelegramError during update: {e}")
async def telegram_group_message_start(self): async def telegram_group_message_start(self):
await self.command.interface.serf.api_call( await self.command.serf.api_call(
self.command.interface.serf.client.send_message, self.command.serf.client.send_message,
chat_id=self.telegram_group_id, chat_id=self.telegram_group_id,
text=rst.escape(self.start_text), text=rst.escape(self.start_text),
parse_mode="HTML", parse_mode="HTML",
@ -412,8 +408,8 @@ class MMTask:
) )
async def telegram_group_message_delete(self): async def telegram_group_message_delete(self):
await self.command.interface.serf.api_call( await self.command.serf.api_call(
self.command.interface.serf.client.send_message, self.command.serf.client.send_message,
chat_id=self.telegram_group_id, chat_id=self.telegram_group_id,
text=rst.escape(self.delete_text), text=rst.escape(self.delete_text),
parse_mode="HTML", parse_mode="HTML",