mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Disable Mm
This commit is contained in:
parent
ecd4c92bb2
commit
02b73bce1d
4 changed files with 95 additions and 82 deletions
|
@ -132,6 +132,12 @@ class DiscordBot(GenericBot):
|
||||||
error_message += '\n'.join(e.args)
|
error_message += '\n'.join(e.args)
|
||||||
await data.reply(error_message)
|
await data.reply(error_message)
|
||||||
|
|
||||||
|
async def on_connect(cli):
|
||||||
|
log.debug("Connected to Discord")
|
||||||
|
|
||||||
|
async def on_disconnect(cli):
|
||||||
|
log.error("Disconnected from Discord!")
|
||||||
|
|
||||||
async def on_ready(cli) -> None:
|
async def on_ready(cli) -> None:
|
||||||
log.debug("Connection successful, client is ready")
|
log.debug("Connection successful, client is ready")
|
||||||
await cli.change_presence(status=discord.Status.online)
|
await cli.change_presence(status=discord.Status.online)
|
||||||
|
@ -196,7 +202,6 @@ class DiscordBot(GenericBot):
|
||||||
await self.client.login(token)
|
await self.client.login(token)
|
||||||
log.info(f"Connecting to Discord")
|
log.info(f"Connecting to Discord")
|
||||||
await self.client.connect()
|
await self.client.connect()
|
||||||
# TODO: how to stop?
|
|
||||||
|
|
||||||
async def add_to_music_data(self, dfiles: typing.List[YtdlDiscord], guild: discord.Guild):
|
async def add_to_music_data(self, dfiles: typing.List[YtdlDiscord], guild: discord.Guild):
|
||||||
"""Add a list of :py:class:`royalnet.audio.YtdlDiscord` to the corresponding music_data object."""
|
"""Add a list of :py:class:`royalnet.audio.YtdlDiscord` to the corresponding music_data object."""
|
||||||
|
|
|
@ -75,7 +75,7 @@ class TelegramBot(GenericBot):
|
||||||
if error_if_none:
|
if error_if_none:
|
||||||
raise CommandError("No command caller for this message")
|
raise CommandError("No command caller for this message")
|
||||||
return None
|
return None
|
||||||
query = data.interface.session.query(self.master_table)
|
query = data.session.query(self.master_table)
|
||||||
for link in self.identity_chain:
|
for link in self.identity_chain:
|
||||||
query = query.join(link.mapper.class_)
|
query = query.join(link.mapper.class_)
|
||||||
query = query.filter(self.identity_column == user.id)
|
query = query.filter(self.identity_column == user.id)
|
||||||
|
@ -90,7 +90,7 @@ class TelegramBot(GenericBot):
|
||||||
for key in keyboard:
|
for key in keyboard:
|
||||||
press_id = uuid.uuid4()
|
press_id = uuid.uuid4()
|
||||||
tg_keyboard.append([telegram.InlineKeyboardButton(key, callback_data=str(press_id))])
|
tg_keyboard.append([telegram.InlineKeyboardButton(key, callback_data=str(press_id))])
|
||||||
data.interface.register_keyboard_key(key_name=str(press_id), callback=keyboard[key])
|
data._interface.register_keyboard_key(key_name=str(press_id), callback=keyboard[key])
|
||||||
await TelegramBot.safe_api_call(data.update.effective_chat.send_message,
|
await TelegramBot.safe_api_call(data.update.effective_chat.send_message,
|
||||||
telegram_escape(text),
|
telegram_escape(text),
|
||||||
reply_markup=telegram.InlineKeyboardMarkup(tg_keyboard),
|
reply_markup=telegram.InlineKeyboardMarkup(tg_keyboard),
|
||||||
|
@ -109,8 +109,7 @@ class TelegramBot(GenericBot):
|
||||||
try:
|
try:
|
||||||
return await asyncify(f, *args, **kwargs)
|
return await asyncify(f, *args, **kwargs)
|
||||||
except telegram.error.TimedOut as error:
|
except telegram.error.TimedOut as error:
|
||||||
log.debug(f"Timed out during {f.__qualname__} (retrying in 15s): {error}")
|
log.debug(f"Timed out during {f.__qualname__} (retrying immediatly): {error}")
|
||||||
await asyncio.sleep(15)
|
|
||||||
continue
|
continue
|
||||||
except telegram.error.NetworkError as error:
|
except telegram.error.NetworkError as error:
|
||||||
log.debug(f"Network error during {f.__qualname__} (skipping): {error}")
|
log.debug(f"Network error during {f.__qualname__} (skipping): {error}")
|
||||||
|
@ -179,6 +178,8 @@ class TelegramBot(GenericBot):
|
||||||
error_message = f"🦀 [b]{e.__class__.__name__}[/b] 🦀\n"
|
error_message = f"🦀 [b]{e.__class__.__name__}[/b] 🦀\n"
|
||||||
error_message += '\n'.join(e.args)
|
error_message += '\n'.join(e.args)
|
||||||
await data.reply(error_message)
|
await data.reply(error_message)
|
||||||
|
if __debug__:
|
||||||
|
raise
|
||||||
|
|
||||||
async def _handle_callback_query(self, update: telegram.Update):
|
async def _handle_callback_query(self, update: telegram.Update):
|
||||||
query: telegram.CallbackQuery = update.callback_query
|
query: telegram.CallbackQuery = update.callback_query
|
||||||
|
@ -204,6 +205,9 @@ class TelegramBot(GenericBot):
|
||||||
error_text = f"⛔️ {e.__class__.__name__}\n"
|
error_text = f"⛔️ {e.__class__.__name__}\n"
|
||||||
error_text += '\n'.join(e.args)
|
error_text += '\n'.join(e.args)
|
||||||
await self.safe_api_call(query.answer, text=error_text)
|
await self.safe_api_call(query.answer, text=error_text)
|
||||||
|
if __debug__:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
await self.safe_api_call(query.answer, text=response)
|
await self.safe_api_call(query.answer, text=response)
|
||||||
|
|
|
@ -61,11 +61,11 @@ class CvCommand(Command):
|
||||||
elif member.status == discord.Status.online:
|
elif member.status == discord.Status.online:
|
||||||
message += "🔵 "
|
message += "🔵 "
|
||||||
elif member.status == discord.Status.idle:
|
elif member.status == discord.Status.idle:
|
||||||
message += "⚫️ "
|
message += "⚫ "
|
||||||
elif member.status == discord.Status.dnd:
|
elif member.status == discord.Status.dnd:
|
||||||
message += "🔴 "
|
message += "🔴 "
|
||||||
elif member.status == discord.Status.offline:
|
elif member.status == discord.Status.offline:
|
||||||
message += "⚪️ "
|
message += "⚪ "
|
||||||
# Voice
|
# Voice
|
||||||
if channel != 0:
|
if channel != 0:
|
||||||
# Voice status
|
# Voice status
|
||||||
|
@ -75,14 +75,14 @@ class CvCommand(Command):
|
||||||
message += "🔇 "
|
message += "🔇 "
|
||||||
elif member.voice.self_mute or member.voice.mute:
|
elif member.voice.self_mute or member.voice.mute:
|
||||||
message += "🔈 "
|
message += "🔈 "
|
||||||
elif member.voice.self_video:
|
elif member.voice.self_video or member.voice.self_stream:
|
||||||
message += "📺 "
|
message += "🖥 "
|
||||||
else:
|
else:
|
||||||
message += "🔊 "
|
message += "🔊 "
|
||||||
# Nickname
|
# Nickname
|
||||||
if member.nick is not None:
|
# if member.nick is not None:
|
||||||
message += f"[i]{member.nick}[/i]"
|
# message += f"[i]{member.nick}[/i]"
|
||||||
else:
|
# else:
|
||||||
message += member.name
|
message += member.name
|
||||||
# Game or stream
|
# Game or stream
|
||||||
if member.activity is not None:
|
if member.activity is not None:
|
||||||
|
|
|
@ -18,7 +18,7 @@ class MmCommand(Command):
|
||||||
Requires the MM_CHANNEL_ID envvar to be set."""
|
Requires the MM_CHANNEL_ID envvar to be set."""
|
||||||
name: str = "mm"
|
name: str = "mm"
|
||||||
|
|
||||||
aliases = ["matchmaking", "matchmake"]
|
aliases = ["matchmaking", "matchmake", "lfg", "lookingforgroup"]
|
||||||
|
|
||||||
description: str = "Trova giocatori per una partita a qualcosa."
|
description: str = "Trova giocatori per una partita a qualcosa."
|
||||||
|
|
||||||
|
@ -117,33 +117,33 @@ class MmCommand(Command):
|
||||||
async def decision_yes(data: CommandData):
|
async def decision_yes(data: CommandData):
|
||||||
royal = await data.get_author()
|
royal = await data.get_author()
|
||||||
mmdecision: MMDecision = await asyncify(
|
mmdecision: MMDecision = await asyncify(
|
||||||
data.session.query(self.interface.alchemy.MMDecision).filter_by(mmevent=mmevent,
|
session.query(self.interface.alchemy.MMDecision).filter_by(mmevent=mmevent,
|
||||||
royal=royal).one_or_none)
|
royal=royal).one_or_none)
|
||||||
if mmdecision is None:
|
if mmdecision is None:
|
||||||
mmdecision: MMDecision = self.interface.alchemy.MMDecision(royal=royal,
|
mmdecision: MMDecision = self.interface.alchemy.MMDecision(royal=royal,
|
||||||
mmevent=mmevent,
|
mmevent=mmevent,
|
||||||
decision="YES")
|
decision="YES")
|
||||||
data.session.add(mmdecision)
|
session.add(mmdecision)
|
||||||
else:
|
else:
|
||||||
mmdecision.decision = "YES"
|
mmdecision.decision = "YES"
|
||||||
await asyncify(data.session.commit)
|
await asyncify(session.commit)
|
||||||
await update_message()
|
await update_message()
|
||||||
return "🔵 Hai detto che ci sarai!"
|
return "🔵 Hai detto che ci sarai!"
|
||||||
|
|
||||||
async def decision_maybe(data: CommandData):
|
async def decision_maybe(data: CommandData):
|
||||||
royal = await data.get_author()
|
royal = await data.get_author()
|
||||||
mmdecision: MMDecision = await asyncify(
|
mmdecision: MMDecision = await asyncify(
|
||||||
data.session.query(self.interface.alchemy.MMDecision).filter_by(mmevent=mmevent,
|
session.query(self.interface.alchemy.MMDecision).filter_by(mmevent=mmevent,
|
||||||
royal=royal).one_or_none)
|
royal=royal).one_or_none)
|
||||||
if mmdecision is None:
|
if mmdecision is None:
|
||||||
mmdecision: MMDecision = self.interface.alchemy.MMDecision(royal=royal,
|
mmdecision: MMDecision = self.interface.alchemy.MMDecision(royal=royal,
|
||||||
mmevent=mmevent,
|
mmevent=mmevent,
|
||||||
decision="MAYBE")
|
decision="MAYBE")
|
||||||
data.session.add(mmdecision)
|
session.add(mmdecision)
|
||||||
else:
|
else:
|
||||||
mmdecision.decision = "MAYBE"
|
mmdecision.decision = "MAYBE"
|
||||||
# Can't asyncify this
|
# Can't asyncify this
|
||||||
data.session.commit()
|
session.commit()
|
||||||
await update_message()
|
await update_message()
|
||||||
return f"⚫️ Hai detto che forse ci sarai." \
|
return f"⚫️ Hai detto che forse ci sarai." \
|
||||||
f"Rispondi al messaggio di conferma {self._cycle_duration} minuti prima dell'inizio!"
|
f"Rispondi al messaggio di conferma {self._cycle_duration} minuti prima dell'inizio!"
|
||||||
|
@ -151,17 +151,17 @@ class MmCommand(Command):
|
||||||
async def decision_no(data: CommandData):
|
async def decision_no(data: CommandData):
|
||||||
royal = await data.get_author()
|
royal = await data.get_author()
|
||||||
mmdecision: MMDecision = await asyncify(
|
mmdecision: MMDecision = await asyncify(
|
||||||
data.session.query(self.interface.alchemy.MMDecision).filter_by(mmevent=mmevent,
|
session.query(self.interface.alchemy.MMDecision).filter_by(mmevent=mmevent,
|
||||||
royal=royal).one_or_none)
|
royal=royal).one_or_none)
|
||||||
if mmdecision is None:
|
if mmdecision is None:
|
||||||
mmdecision: MMDecision = self.interface.alchemy.MMDecision(royal=royal,
|
mmdecision: MMDecision = self.interface.alchemy.MMDecision(royal=royal,
|
||||||
mmevent=mmevent,
|
mmevent=mmevent,
|
||||||
decision="NO")
|
decision="NO")
|
||||||
data.session.add(mmdecision)
|
session.add(mmdecision)
|
||||||
else:
|
else:
|
||||||
mmdecision.decision = "NO"
|
mmdecision.decision = "NO"
|
||||||
# Can't asyncify this
|
# Can't asyncify this
|
||||||
data.session.commit()
|
session.commit()
|
||||||
await update_message()
|
await update_message()
|
||||||
return "🔴 Hai detto che non ti interessa."
|
return "🔴 Hai detto che non ti interessa."
|
||||||
|
|
||||||
|
@ -185,11 +185,11 @@ class MmCommand(Command):
|
||||||
async def response_yes(data: CommandData):
|
async def response_yes(data: CommandData):
|
||||||
royal = await data.get_author()
|
royal = await data.get_author()
|
||||||
mmresponse: MMResponse = await asyncify(
|
mmresponse: MMResponse = await asyncify(
|
||||||
data.session.query(self.interface.alchemy.MMResponse).filter_by(mmevent=mmevent,
|
session.query(self.interface.alchemy.MMResponse).filter_by(mmevent=mmevent,
|
||||||
royal=royal).one_or_none)
|
royal=royal).one_or_none)
|
||||||
mmresponse.response = "YES"
|
mmresponse.response = "YES"
|
||||||
# Can't asyncify this
|
# Can't asyncify this
|
||||||
data.session.commit()
|
session.commit()
|
||||||
await update_message()
|
await update_message()
|
||||||
return "✅ Sei pronto!"
|
return "✅ Sei pronto!"
|
||||||
|
|
||||||
|
@ -201,11 +201,11 @@ class MmCommand(Command):
|
||||||
async def response_later(data: CommandData):
|
async def response_later(data: CommandData):
|
||||||
royal = await data.get_author()
|
royal = await data.get_author()
|
||||||
mmresponse: MMResponse = await asyncify(
|
mmresponse: MMResponse = await asyncify(
|
||||||
data.session.query(self.interface.alchemy.MMResponse).filter_by(mmevent=mmevent,
|
session.query(self.interface.alchemy.MMResponse).filter_by(mmevent=mmevent,
|
||||||
royal=royal).one_or_none)
|
royal=royal).one_or_none)
|
||||||
mmresponse.response = "LATER"
|
mmresponse.response = "LATER"
|
||||||
# Can't asyncify this
|
# Can't asyncify this
|
||||||
data.session.commit()
|
session.commit()
|
||||||
await self.interface.bot.safe_api_call(client.send_message,
|
await self.interface.bot.safe_api_call(client.send_message,
|
||||||
chat_id=mmevent.creator.telegram[0].tg_id,
|
chat_id=mmevent.creator.telegram[0].tg_id,
|
||||||
text=telegram_escape(later_string(royal)),
|
text=telegram_escape(later_string(royal)),
|
||||||
|
@ -217,11 +217,11 @@ class MmCommand(Command):
|
||||||
async def response_no(data: CommandData):
|
async def response_no(data: CommandData):
|
||||||
royal = await data.get_author()
|
royal = await data.get_author()
|
||||||
mmresponse: MMResponse = await asyncify(
|
mmresponse: MMResponse = await asyncify(
|
||||||
data.session.query(self.interface.alchemy.MMResponse).filter_by(mmevent=mmevent,
|
session.query(self.interface.alchemy.MMResponse).filter_by(mmevent=mmevent,
|
||||||
royal=royal).one_or_none)
|
royal=royal).one_or_none)
|
||||||
mmresponse.response = "NO"
|
mmresponse.response = "NO"
|
||||||
# Can't asyncify this
|
# Can't asyncify this
|
||||||
data.session.commit()
|
session.commit()
|
||||||
await update_message()
|
await update_message()
|
||||||
return "❌ Hai detto che non ci sarai."
|
return "❌ Hai detto che non ci sarai."
|
||||||
|
|
||||||
|
@ -344,57 +344,61 @@ class MmCommand(Command):
|
||||||
|
|
||||||
def __init__(self, interface):
|
def __init__(self, interface):
|
||||||
super().__init__(interface)
|
super().__init__(interface)
|
||||||
if self.interface.name != "telegram":
|
# if self.interface.name != "telegram":
|
||||||
return
|
# return
|
||||||
log.debug("Loading pending MMEvents from the database")
|
# log.debug("Loading pending MMEvents from the database")
|
||||||
session = interface.alchemy.Session()
|
# session = interface.alchemy.Session()
|
||||||
mmevents = session.query(self.interface.alchemy.MMEvent) \
|
# mmevents = session.query(self.interface.alchemy.MMEvent) \
|
||||||
.filter(self.interface.alchemy.MMEvent.datetime > datetime.datetime.now()) \
|
# .filter(self.interface.alchemy.MMEvent.datetime > datetime.datetime.now()) \
|
||||||
.all()
|
# .all()
|
||||||
log.info(f"Found {len(mmevents)} pending MMEvents")
|
# log.info(f"Found {len(mmevents)} pending MMEvents")
|
||||||
for mmevent in mmevents:
|
# for mmevent in mmevents:
|
||||||
session = self.interface.alchemy.Session()
|
# session = interface.alchemy.Session()
|
||||||
interface.loop.create_task(self._run_mm(mmevent, session))
|
# new_mmevent = session.query(MMEvent).get(mmevent.mmid)
|
||||||
|
# interface.loop.create_task(self._run_mm(new_mmevent, session, close_at_end=True))
|
||||||
|
# session.close()
|
||||||
|
|
||||||
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||||
if self.interface.name != "telegram":
|
raise UnsupportedError("MmCommand è attualmente disabilitato per via di bug introdotti da cambiamenti nella"
|
||||||
raise UnsupportedError("mm is supported only on Telegram")
|
" gestione del database del bot.")
|
||||||
client: telegram.Bot = self.interface.bot.client
|
# if self.interface.name != "telegram":
|
||||||
creator = await data.get_author(error_if_none=True)
|
# raise UnsupportedError("mm is supported only on Telegram")
|
||||||
try:
|
# client: telegram.Bot = self.interface.bot.client
|
||||||
timestring, title, description = args.match(r"\[\s*([^]]+)\s*]\s*([^\n]+)\s*\n?\s*(.+)?\s*", re.DOTALL)
|
# creator = await data.get_author(error_if_none=True)
|
||||||
except InvalidInputError:
|
# try:
|
||||||
timestring, title, description = args.match(r"\s*(.+?)\s*\n\s*([^\n]+)\s*\n?\s*(.+)?\s*", re.DOTALL)
|
# timestring, title, description = args.match(r"\[\s*([^]]+)\s*]\s*([^\n]+)\s*\n?\s*(.+)?\s*", re.DOTALL)
|
||||||
try:
|
# except InvalidInputError:
|
||||||
dt: typing.Optional[datetime.datetime] = dateparser.parse(timestring, settings={
|
# timestring, title, description = args.match(r"\s*(.+?)\s*\n\s*([^\n]+)\s*\n?\s*(.+)?\s*", re.DOTALL)
|
||||||
"PREFER_DATES_FROM": "future"
|
# try:
|
||||||
})
|
# dt: typing.Optional[datetime.datetime] = dateparser.parse(timestring, settings={
|
||||||
except OverflowError:
|
# "PREFER_DATES_FROM": "future"
|
||||||
dt = None
|
# })
|
||||||
if dt is None:
|
# except OverflowError:
|
||||||
await data.reply("⚠️ La data che hai specificato non è valida.")
|
# dt = None
|
||||||
return
|
# if dt is None:
|
||||||
if dt <= datetime.datetime.now():
|
# await data.reply("⚠️ La data che hai specificato non è valida.")
|
||||||
await data.reply("⚠️ La data che hai specificato è nel passato.")
|
# return
|
||||||
return
|
# if dt <= datetime.datetime.now():
|
||||||
mmevent: MMEvent = self.interface.alchemy.MMEvent(creator=creator,
|
# await data.reply("⚠️ La data che hai specificato è nel passato.")
|
||||||
datetime=dt,
|
# return
|
||||||
title=title,
|
# mmevent: MMEvent = self.interface.alchemy.MMEvent(creator=creator,
|
||||||
description=description,
|
# datetime=dt,
|
||||||
state="WAITING")
|
# title=title,
|
||||||
data.session.add(mmevent)
|
# description=description,
|
||||||
await asyncify(data.session.commit)
|
# state="WAITING")
|
||||||
|
# data.session.add(mmevent)
|
||||||
message: telegram.Message = await self.interface.bot.safe_api_call(client.send_message,
|
# await asyncify(data.session.commit)
|
||||||
chat_id=-1001224004974,
|
#
|
||||||
text=telegram_escape(
|
# message: telegram.Message = await self.interface.bot.safe_api_call(client.send_message,
|
||||||
self._main_text(mmevent)),
|
# chat_id=-1001287169422,
|
||||||
parse_mode="HTML",
|
# text=telegram_escape(
|
||||||
disable_webpage_preview=True,
|
# self._main_text(mmevent)),
|
||||||
reply_markup=self._main_keyboard(mmevent))
|
# parse_mode="HTML",
|
||||||
|
# disable_webpage_preview=True,
|
||||||
mmevent.message_id = message.message_id
|
# reply_markup=self._main_keyboard(mmevent))
|
||||||
# Can't asyncify this
|
#
|
||||||
await asyncify(data.session.commit)
|
# mmevent.message_id = message.message_id
|
||||||
|
# # Can't asyncify this
|
||||||
await self._run_mm(mmevent, data.session)
|
# await asyncify(data.session.commit)
|
||||||
|
#
|
||||||
|
# await self._run_mm(mmevent, data.session)
|
||||||
|
|
Loading…
Reference in a new issue