taslim19 commited on
Commit
6f39b38
·
1 Parent(s): 1d2866f

feat: add story downloader, poll move, and various plugin improvements

Browse files
DragMusic/plugins/kuri/poll.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ /poll <question> | <option1> | <option2> | ... [| key=value ...]
3
+
4
+ Create a poll in the group. Only admins/owner can use this command.
5
+ Supports all Pyrogram send_poll options via key=value pairs after the options.
6
+ Example:
7
+ /poll What's your favorite color? | Red | Blue | Green | is_anonymous=False | allows_multiple_answers=True
8
+ """
9
+
10
+ from pyrogram import filters
11
+ from pyrogram.types import Message
12
+ from DragMusic import app
13
+
14
+ async def is_admin(client, chat_id, user_id):
15
+ member = await client.get_chat_member(chat_id, user_id)
16
+ return member.status in ("administrator", "creator")
17
+
18
+ @app.on_message(filters.command("poll", prefixes=["/", "!"]) & filters.group)
19
+ async def poll_command(client, message: Message):
20
+ if not await is_admin(client, message.chat.id, message.from_user.id):
21
+ return await message.reply_text("Only group admins and the owner can use this command.")
22
+ if len(message.command) == 1:
23
+ return await message.reply_text(
24
+ "Usage:\n/poll <question> | <option1> | <option2> | ... [| key=value ...]\n"
25
+ "Example:\n/poll What's your favorite color? | Red | Blue | Green | is_anonymous=False | allows_multiple_answers=True"
26
+ )
27
+ # Join the rest of the message and split by |
28
+ parts = message.text.split(None, 1)[1].split("|")
29
+ parts = [p.strip() for p in parts if p.strip()]
30
+ if len(parts) < 3:
31
+ return await message.reply_text("You must provide a question and at least two options.")
32
+ question = parts[0]
33
+ options = []
34
+ kwargs = {}
35
+ for part in parts[1:]:
36
+ if "=" in part:
37
+ key, value = part.split("=", 1)
38
+ key = key.strip()
39
+ value = value.strip()
40
+ # Convert value to correct type
41
+ if value.lower() == "true":
42
+ value = True
43
+ elif value.lower() == "false":
44
+ value = False
45
+ elif value.isdigit():
46
+ value = int(value)
47
+ kwargs[key] = value
48
+ else:
49
+ options.append(part)
50
+ if len(options) < 2:
51
+ return await message.reply_text("You must provide at least two options.")
52
+ try:
53
+ poll_msg = await app.send_poll(
54
+ chat_id=message.chat.id,
55
+ question=question,
56
+ options=options,
57
+ **kwargs
58
+ )
59
+ await message.reply_text(f"Poll created: [Jump to poll]({poll_msg.link})", disable_web_page_preview=True)
60
+ except Exception as e:
61
+ await message.reply_text(f"Failed to create poll: {e}")
DragMusic/plugins/kuri/storydl.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ /story <username or userid> <story_id>
3
+
4
+ Download a Telegram story (video or photo) from a user by username/userid and story id, using the userbot. The story will be sent to the chat where the command was used.
5
+
6
+ Example:
7
+ /story @Itzabhi16 1
8
+ /story 123456789 2
9
+ """
10
+
11
+ import tempfile
12
+ import os
13
+ from pyrogram import filters
14
+ from pyrogram.types import Message
15
+ from DragMusic import userbot, app
16
+
17
+ @app.on_message(filters.command("story", prefixes=["/", "!"]))
18
+ async def story_download_handler(client, message: Message):
19
+ if len(message.command) < 3:
20
+ return await message.reply_text("Usage: /story <username or userid> <story_id>")
21
+ target = message.command[1]
22
+ try:
23
+ story_id = int(message.command[2])
24
+ except ValueError:
25
+ return await message.reply_text("Story ID must be an integer.")
26
+ try:
27
+ stories = await userbot.one.get_stories(target, [story_id])
28
+ # If only one story is returned, wrap in a list for uniformity
29
+ if not isinstance(stories, list):
30
+ stories = [stories]
31
+ sent = False
32
+ for s in stories:
33
+ temp_dir = tempfile.gettempdir()
34
+ if hasattr(s, "video") and s.video:
35
+ file = await userbot.one.download_media(s.video.file_id, file_name=os.path.join(temp_dir, f"story_{s.id}.mp4"))
36
+ await userbot.one.send_video(message.chat.id, file, caption=f"Story ID: {s.id}")
37
+ sent = True
38
+ elif hasattr(s, "photo") and s.photo:
39
+ file = await userbot.one.download_media(s.photo.file_id, file_name=os.path.join(temp_dir, f"story_{s.id}.jpg"))
40
+ await userbot.one.send_photo(message.chat.id, file, caption=f"Story ID: {s.id}")
41
+ sent = True
42
+ if sent:
43
+ await message.reply_text("Story sent to this chat!")
44
+ else:
45
+ await message.reply_text("No video or photo found in the specified story.")
46
+ except Exception as e:
47
+ await message.reply_text(f"Failed to download story: {e}")
DragMusic/plugins/kuri/title.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Plugin to set a custom admin title in a supergroup using /title <user> <title>.
3
+ Only group owner and admins can use this command.
4
+ Usable by the bot (not userbot).
5
+ """
6
+
7
+ from pyrogram import filters
8
+ from pyrogram.types import Message
9
+ from DragMusic import app
10
+
11
+ async def is_admin(client, chat_id, user_id):
12
+ member = await client.get_chat_member(chat_id, user_id)
13
+ return member.status in ("administrator", "creator")
14
+
15
+ @app.on_message(filters.command("title", prefixes=["/", "!"]) & filters.group)
16
+ async def set_admin_title(client, message: Message):
17
+ if not await is_admin(client, message.chat.id, message.from_user.id):
18
+ await message.reply_text("Only group admins and the owner can use this command.")
19
+ return
20
+ if len(message.command) < 3:
21
+ await message.reply_text("Usage: /title <user> <title>")
22
+ return
23
+ user = message.command[1]
24
+ title = " ".join(message.command[2:])
25
+ try:
26
+ # Try to get user_id from mention, username, or ID
27
+ if message.reply_to_message:
28
+ user_id = message.reply_to_message.from_user.id
29
+ else:
30
+ try:
31
+ user_id = int(user)
32
+ except ValueError:
33
+ user_obj = await client.get_users(user)
34
+ user_id = user_obj.id
35
+ await client.set_administrator_title(message.chat.id, user_id, title)
36
+ await message.reply_text(f"Successfully set admin title to: {title}")
37
+ except Exception as e:
38
+ await message.reply_text(f"Failed to set admin title: {e}")