Beispiel #1
0
 def start(self):
     url = 'https://www.donationalerts.com/r/xoma163'
     attachments = self.bot.upload_photos(
         f"{STATIC_ROOT}/bot/img/donate.jpg", peer_id=self.event.peer_id)
     if self.event.platform == Platform.TG:
         return {
             'text': get_tg_formatted_url("Задонатить", url),
             'attachments': attachments
         }
     return {'text': url, 'attachments': attachments}
Beispiel #2
0
    def get_reddit_attachment(self, url):
        rs = RedditSaver()
        attachment = rs.get_from_reddit(url)
        if rs.is_image or rs.is_images:
            attachments = self.bot.upload_photos(attachment,
                                                 peer_id=self.event.peer_id)
        elif rs.is_video:
            attachments = self.bot.upload_video(attachment,
                                                peer_id=self.event.peer_id)
        elif rs.is_text or rs.is_link:
            text = attachment
            if self.event.platform == Platform.TG:
                text = text.replace("​",
                                    "").replace("​",
                                                "").replace("&",
                                                            "&").strip()
                p = re.compile(r"\[(.*)\]\((.*)\)")
                for item in reversed(list(p.finditer(text))):
                    start_pos = item.start()
                    end_pos = item.end()
                    link_text = text[item.regs[1][0]:item.regs[1][1]]
                    link = text[item.regs[2][0]:item.regs[2][1]]
                    tg_url = get_tg_formatted_url(link_text, link)
                    text = text[:start_pos] + tg_url + text[end_pos:]
                regexps_with_static = ((r"https.*player", "Видео"),
                                       (r"https://preview\.redd\.it/.*",
                                        "Фото"))
                for regexp, _text in regexps_with_static:
                    p = re.compile(regexp)
                    for item in reversed(list(p.finditer(text))):
                        start_pos = item.start()
                        end_pos = item.end()
                        link = text[start_pos:end_pos]
                        tg_url = get_tg_formatted_url(_text, link)
                        text = text[:start_pos] + tg_url + text[end_pos:]

            return [], f"{rs.title}\n\n{text}"
        else:
            raise PWarning("Я хз чё за контент")
        return attachments, rs.title
Beispiel #3
0
 def get_music_results(self, query):
     spotify_api = SpotifyAPI()
     musics = spotify_api.search_music(query, limit=5)
     if not musics:
         raise PWarning("Ничего не нашёл по музыке")
     message = []
     for music_info in musics:
         music = f"{', '.join(music_info['artists'])} — {music_info['name']}"
         if self.event.platform == Platform.TG:
             message.append(get_tg_formatted_url(music, music_info['url']))
         else:
             message.append(f"{music} ({music_info['url']})")
     return {'text': "\n".join(message)}
Beispiel #4
0
    def set_telegram_html(self):
        urls_regexp = r"(http|ftp|https|tg)(:\/\/)([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])"
        if self.text:
            p = re.compile(urls_regexp)  # Ссылки
            if p.search(self.text):
                self.kwargs = {'parse_mode': "html"}

            p = re.compile("<pre>[\s\S]*</pre>")  # tg formatting
            if p.search(self.text):
                self.kwargs = {'parse_mode': "html"}

            p = re.compile("<code>[\s\S]*</code>")  # tg formatting
            if p.search(self.text):
                self.kwargs = {'parse_mode': "html"}

            if self.kwargs.get('parse_mode'):
                # Врапим ссылки без явного их врапа если у нас уже html
                url_poss = re.finditer(urls_regexp,
                                       self.text)  # Ссылки не в скобках
                url_poss = reversed(
                    list(url_poss)
                )  # Заменяем всё в строке с конца, чтобы были корректные позиции
                for url_pos in url_poss:
                    start_pos = url_pos.start()
                    end_pos = url_pos.end()

                    url = self.text[start_pos:end_pos]

                    # Если ссылка уже враплена, то продолжаем просто дальше
                    left_part = None
                    right_part = None
                    if start_pos >= 9:
                        left_part = self.text[start_pos - 9:start_pos]
                    if len(self.text) > end_pos:
                        right_part = self.text[end_pos:end_pos + 2]
                    if left_part == '<a href="' and right_part == '">':
                        continue

                    self.text = self.text[:start_pos] + get_tg_formatted_url(
                        url, url) + self.text[end_pos:]
Beispiel #5
0
    def handle(self, *args, **options):
        chat_pks = options['chat_id'][0].split(',')

        ylc_api = YoutubeLiveCheckerAPI()
        livestream_info = ylc_api.get_stream_info_if_online()
        if not livestream_info:
            return

        stream, _ = Service.objects.get_or_create(name="stream")
        if stream.value == livestream_info['video_url']:
            return

        stream.value = livestream_info['video_url']
        stream.save()

        for chat_pk in chat_pks:
            chat = Chat.objects.get(pk=chat_pk)
            bot = get_bot_by_platform(chat.get_platform_enum())
            url = stream.value
            if bot.platform == Platform.TG:
                text = get_tg_formatted_url("стрим", url)
            else:
                text = f"Ктап подрубил стрим\n{url}"
            bot.parse_and_send_msgs(text, chat.chat_id)
Beispiel #6
0
 def start(self):
     url = "https://github.com/Xoma163/petrovich/issues"
     if self.event.platform == Platform.TG:
         url = get_tg_formatted_url("Ишюс", url)
     return url
Beispiel #7
0
    def start(self):
        url = 'https://github.com/Xoma163/petrovich/'

        if self.event.platform == Platform.TG:
            url = get_tg_formatted_url("Гитхаб", url)
        return url
Beispiel #8
0
    def start(self):
        url = 'https://diary.andrewsha.net/'

        if self.event.platform == Platform.TG:
            url = get_tg_formatted_url("Ежедневник", url)
        return url
Beispiel #9
0
    def start(self):
        url = 'https://discord.gg/kYGSNzv'

        if self.event.platform == Platform.TG:
            url = get_tg_formatted_url("Дискорд", url)
        return url
Beispiel #10
0
 def start(self):
     url = f"https://www.google.com/search?q={quote(self.event.message.args_str_case)}"
     if self.event.platform == Platform.TG:
         url = get_tg_formatted_url(
             f"Окей Гугл {self.event.message.args_str_case}", url)
     return url
Beispiel #11
0
 def get_mention(self, profile: Profile, name=None):
     """
     Получение меншона пользователя
     """
     user = profile.get_user_by_platform(self.platform)
     return get_tg_formatted_url(str(profile), f"tg://user?id={user.user_id}")
Beispiel #12
0
 def start(self):
     url = 'https://github.com/Xoma163/petrovich/wiki/1.1-Документация-для-пользователей'
     if self.event.platform == Platform.TG:
         url = get_tg_formatted_url("Документация", url)
     return url