Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.

Commit

Permalink
Inline Alive 2.0 is Here ⚡️ (#45)
Browse files Browse the repository at this point in the history
* ⚡️ Inline Alive 2.0  ⚡️

- Now Any Media like sticker, video etc can be set as Alive Media
  • Loading branch information
code-rgb authored Oct 20, 2020
1 parent 598da2b commit 8cc720a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 62 deletions.
5 changes: 0 additions & 5 deletions .gitpod.Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
image:
file: .gitpod.Dockerfile
#image:
#file: .gitpod.Dockerfile

tasks:
# Install dependencies first.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Pillow==7.1.0
psutil
pybase64
pymediainfo
pyrogram>=1.0.7
git+https://github.com/code-rgb/pyrogram.git
pySmartDL
python-dotenv
pytz
Expand Down
39 changes: 27 additions & 12 deletions userge/plugins/bot/alive.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Fun plugin"""

from re import search
from pyrogram import filters
from pyrogram.types import CallbackQuery
from userge import userge, Message, Config
from userge.core.ext import RawClient
import asyncio


Expand All @@ -18,7 +18,7 @@ async def alive_inline(message: Message):
result_id=x.results[0].id
)
await message.delete()
await asyncio.sleep(60)
await asyncio.sleep(90)
await userge.delete_messages(message.chat.id, y.updates[0].id)


Expand All @@ -29,24 +29,39 @@ async def alive_cb(_, callback_query: CallbackQuery):
dynos_saver = _parse_arg(Config.RUN_DYNO_SAVER)
else:
dynos_saver = "Not Supported"
alive_s = f"⚙️ 𝗠𝗼𝗱𝗲 : {_get_mode()}\n"
alive_s += "• ➕ 𝗘𝘅𝘁𝗿𝗮 𝗣𝗹𝘂𝗴𝗶𝗻𝘀 : {}\n".format(
_parse_arg(Config.LOAD_UNOFFICIAL_PLUGINS)
)
alive_s += f"• 👥 𝗦𝘂𝗱𝗼 : {_parse_arg(Config.SUDO_ENABLED)}\n"
alive_s += f"• 🚨 𝗔𝗻𝘁𝗶𝘀𝗽𝗮𝗺 : {_parse_arg(Config.ANTISPAM_SENTRY)}\n"
alive_s += f"• ⛽️ 𝗗𝘆𝗻𝗼 𝗦𝗮𝘃𝗲𝗿 : {dynos_saver}\n"
alive_s += f"• 💬 𝗕𝗼𝘁 𝗙𝗼𝗿𝘄𝗮𝗿𝗱𝘀 : {_parse_arg(Config.BOT_FORWARDS)}\n"
alive_s += "• ➕ 𝗘𝘅𝘁𝗿𝗮 𝗣𝗹𝘂𝗴𝗶𝗻𝘀 : {}".format(
_parse_arg(Config.LOAD_UNOFFICIAL_PLUGINS)
)
alive_s = f"• 📝 𝗣𝗠 𝗟𝗼𝗴𝗴𝗲𝗿 : {_parse_arg(Config.PM_LOGGING)}"
await callback_query.answer(alive_s, show_alert=True)


def _parse_arg(arg: bool) -> str:
return " ✅ 𝙴𝚗𝚊𝚋𝚕𝚎𝚍" if arg else " ❌ 𝙳𝚒𝚜𝚊𝚋𝚕𝚎𝚍"


def _get_mode() -> str:
if RawClient.DUAL_MODE:
return " ↕️ 𝗗𝗨𝗔𝗟"
if Config.BOT_TOKEN:
return " 🤖 𝗕𝗢𝗧"
return " 🙍‍♂️ 𝗨𝗦𝗘𝗥"
async def check_media_link(media_link: str):
alive_regex_ = r"http[s]?://(i\.imgur\.com|telegra\.ph/file|t\.me)/(\w+)(?:\.|/)(gif|jpg|png|jpeg|[0-9]+)(?:/([0-9]+))?"
match = search(alive_regex_, media_link)
if not match:
return None, None
if match.group(1) == "i.imgur.com":
link = match.group(0)
link_type = "url_gif" if match.group(3) == "gif" else "url_image"
elif match.group(1) == "telegra.ph/file":
link = match.group(0)
link_type = "url_image"
else:
link_type = "tg_media"
if match.group(2) == "c":
chat_id = int("-100" + str(match.group(3)))
message_id = match.group(4)
else:
chat_id = match.group(2)
message_id = match.group(3)
link = [chat_id, int(message_id)]
return link_type, link
97 changes: 55 additions & 42 deletions userge/plugins/help.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
# pylint: disable=missing-module-docstring
#
# Copyright (C) 2020 by UsergeTeam@Github, < https://github.com/UsergeTeam >.
#
# This file is part of < https://github.com/UsergeTeam/Userge > project,
# and is released under the "GNU v3.0 License Agreement".
# Please see < https://github.com/uaudith/Userge/blob/master/LICENSE >
#
# All rights reserved.
import random
from math import ceil
import asyncio
from typing import List, Callable, Dict, Union, Any
from userge.utils import parse_buttons as pb
from userge.utils import get_file_id_and_ref, parse_buttons as pb
from pyrogram import filters
from pyrogram.types import (
InlineQueryResultArticle, InputTextMessageContent,
InlineKeyboardMarkup, InlineKeyboardButton,
CallbackQuery, InlineQuery, InlineQueryResultPhoto,
InlineQueryResultAnimation)
from pyrogram.errors import MessageNotModified, MessageIdInvalid, MessageEmpty
InlineQueryResultAnimation, InlineQueryResultCachedDocument, InlineQueryResultCachedPhoto)
from pyrogram.errors import MessageNotModified, MessageIdInvalid, MessageEmpty, BadRequest
from userge import userge, Message, Config, get_collection, versions, get_version
import json
import os
import requests
from html_telegraph_poster import TelegraphPoster
import re
from userge.plugins.fun.stylish import font_gen
from .fun.stylish import font_gen
from pymediainfo import MediaInfo
from .misc.redditdl import reddit_thumb_link
import youtube_dl as ytdl
from .bot.utube_inline import ytdl_btn_generator, get_ytthumb, date_formatter

from .bot.alive import check_media_link


MEDIA_TYPE, MEDIA_URL = None, None
Expand Down Expand Up @@ -373,26 +364,29 @@ def filter_data(cur_pos: str):
return text, buttons


def check_url():
async def get_alive_():
global MEDIA_TYPE, MEDIA_URL
media_link = Config.ALIVE_MEDIA
if media_link:
imgur = r"^http[s]?://i\.imgur\.com/(\w+)\.(gif|jpg|png|jpeg)$"
match = re.search(imgur, media_link)
if not match:
telegraph = r"^http[s]?://telegra\.ph/file/(\w+)\.(jpg|png|jpeg)$"
match = re.search(telegraph, media_link)
if match:
media_type = match.group(2)
link = match.group(0)
limit = 1 if media_type == 'gif' else 5
media_info = MediaInfo.parse(media_link)
for track in media_info.tracks:
if track.track_type == 'General':
media_size = (track.file_size / 1000000)
if media_size < limit:
MEDIA_TYPE = media_type
MEDIA_URL = media_link
type_, media_ = await check_media_link(Config.ALIVE_MEDIA)
if not media_:
return
MEDIA_TYPE = type_
if type(media_) == str:
limit = 1 if type_ == 'url_gif' else 5
media_info = MediaInfo.parse(media_)
for track in media_info.tracks:
if track.track_type == 'General':
media_size = (track.file_size / 1000000)
if media_size < limit:
MEDIA_URL = media_
else:
try:
msg = await userge.bot.get_messages(media_[0], media_[1])
f_id, f_ref = get_file_id_and_ref(msg)
if msg.photo:
MEDIA_TYPE = "tg_image"
except BadRequest:
return
MEDIA_URL = [f_id, f_ref]


@userge.bot.on_inline_query()
Expand Down Expand Up @@ -578,30 +572,49 @@ async def inline_answer(_, inline_query: InlineQuery):
• 🧬 𝑿 : `v{get_version()}`
🕔 Uptime : {userge.uptime}
"""
"""

if not MEDIA_URL:
check_url()

await get_alive_()


if MEDIA_URL:
if MEDIA_TYPE == 'gif':
if MEDIA_TYPE == 'url_gif':
results.append(
InlineQueryResultAnimation(
animation_url=MEDIA_URL,
caption=alive_info,
reply_markup=InlineKeyboardMarkup(buttons)
)
)

else:
elif MEDIA_TYPE == 'url_image':
results.append(
InlineQueryResultPhoto(
photo_url=MEDIA_URL,
caption=alive_info,
reply_markup=InlineKeyboardMarkup(buttons)
)
)


elif MEDIA_TYPE == 'tg_image':
results.append(
InlineQueryResultCachedPhoto(
file_id=MEDIA_URL[0],
file_ref=MEDIA_URL[1],
caption=alive_info,
reply_markup=InlineKeyboardMarkup(buttons)
)
)
else:
results.append(
InlineQueryResultCachedDocument(
title="USERGE-X",
file_id=MEDIA_URL[0],
file_ref=MEDIA_URL[1],
caption=alive_info,
description="ALIVE",
reply_markup=InlineKeyboardMarkup(buttons)
)
)
else: #default
random_alive = random.choice(ALIVE_IMGS)
results.append(
Expand Down Expand Up @@ -830,4 +843,4 @@ async def inline_answer(_, inline_query: InlineQuery):
switch_pm_text=f"This bot is only for {owner_name}",
switch_pm_parameter="start"
)

1 comment on commit 8cc720a

@vercel
Copy link

@vercel vercel bot commented on 8cc720a Oct 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.