Exemple #1
0
    async def telegram_group_message_delete(self):
        assert isinstance(self.command.serf, rst.TelegramSerf)

        await self.command.serf.api_call(self.command.serf.client.send_message,
                                         chat_id=self.telegram_group_id,
                                         text=rst.escape(self.delete_text),
                                         parse_mode="HTML",
                                         disable_webpage_preview=True)
Exemple #2
0
 async def _remind(self, reminder):
     await ru.sleep_until(reminder.datetime)
     if isinstance(self.serf, rst.TelegramSerf):
         chat_id: int = pickle.loads(reminder.interface_data)
         client: telegram.Bot = self.serf.client
         await self.serf.api_call(client.send_message,
                                  chat_id=chat_id,
                                  text=rst.escape(f"❗️ {reminder.message}"),
                                  parse_mode="HTML",
                                  disable_web_page_preview=True)
     elif isinstance(self.serf, rsd.DiscordSerf):
         channel_id: int = pickle.loads(reminder.interface_data)
         client: discord.Client = self.serf.client
         channel = client.get_channel(channel_id)
         await channel.send(rsd.escape(f"❗️ {reminder.message}"))
Exemple #3
0
    async def telegram_channel_message_update(self):
        log.debug(f"Updating message for: {self.mmid}")

        assert isinstance(self.command.serf, rst.TelegramSerf)

        try:
            await ru.asyncify(
                self.command.serf.client.edit_message_text,
                chat_id=self._mmevent.interface_data.chat_id,
                text=rst.escape(self.channel_text),
                message_id=self._mmevent.interface_data.message_id,
                parse_mode="HTML",
                disable_web_page_preview=True,
                reply_markup=self.telegram_keyboard)
        except TelegramError as e:
            log.warning(f"TelegramError during update: {e}")
Exemple #4
0
    async def telegram_channel_message(self):
        assert isinstance(self.command.serf, rst.TelegramSerf)

        # Generate the InlineKeyboardMarkup
        inkm = self.telegram_keyboard

        # Bind the Royalnet buttons to the Telegram keyboard
        log.debug(f"Registering keyboard for: {self.mmid}")
        self.register_telegram_keyboard(inkm)

        # If the event has no associated interface data...
        if self._mmevent.interface_data is None:
            # Send the channel message
            log.debug(f"Sending message for: {self.mmid}")
            message: PTBMessage = await self.command.serf.api_call(
                self.command.serf.client.send_message,
                chat_id=self.telegram_channel_id,
                text=rst.escape(self.channel_text),
                parse_mode="HTML",
                disable_webpage_preview=True,
                reply_markup=inkm)

            # Register the interface data on the database
            self._mmevent.interface_data = MMInterfaceDataTelegram(
                chat_id=self.telegram_channel_id,
                message_id=message.message_id)
            self._session.commit()

        # Wait until the event starts
        yield

        # Delete the channel message
        log.debug(f"Deleting message for: {self.mmid}")
        await self.command.serf.api_call(
            self.command.serf.client.delete_message,
            chat_id=self._mmevent.interface_data.chat_id,
            message_id=self._mmevent.interface_data.message_id)

        # Unregister the Telegram keyboard bindings
        log.debug(f"Unregistering keyboard for: {self.mmid}")
        self.unregister_telegram_keyboard(inkm)
Exemple #5
0
 async def notify(self, message):
     await self.serf.api_call(self.serf.client.send_message,
                              chat_id=self.target(),
                              text=rst.escape(message),
                              parse_mode="HTML",
                              disable_webpage_preview=True)