File size: 2,502 Bytes
edfc350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# SOURCE https://github.com/Team-ProjectCodeX
# CREATED BY https://t.me/O_okarma
# PROVIDED BY https://t.me/ProjectCodeX

# <============================================== IMPORTS =========================================================>
import random
import re

from telegram import Update
from telegram.constants import ParseMode
from telegram.ext import CommandHandler, ContextTypes

from Mikobot import function

# <=======================================================================================================>


# <================================================ FUNCTION =======================================================>
# Define the command handler for the "/pickwinner" command
async def pick_winner(update: Update, context: ContextTypes.DEFAULT_TYPE):
    # Get the list of participants
    participants = context.args

    if participants:
        # Select a random winner
        winner = random.choice(participants)

        # Send the winner as a reply
        await update.message.reply_text(f"πŸŽ‰ The winner is: {winner}")
    else:
        # If no participants are provided
        await update.message.reply_text("Please provide a list of participants.")


# Define the command handler for the "/hyperlink" command
async def hyperlink_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
    args = context.args
    if len(args) >= 2:
        text = " ".join(args[:-1])
        link = args[-1]
        hyperlink = f"[{text}]({link})"
        await update.message.reply_text(
            text=hyperlink, parse_mode="Markdown", disable_web_page_preview=True
        )
    else:
        match = re.search(r"/hyperlink ([^\s]+) (.+)", update.message.text)
        if match:
            text = match.group(1)
            link = match.group(2)
            hyperlink = f"[{text}]({link})"
            await update.message.reply_text(
                text=hyperlink, parse_mode=ParseMode.HTML, disable_web_page_preview=True
            )
        else:
            await update.message.reply_text(
                "❌ Invalid format! Please use the format: /hyperlink <text> <link>."
            )


# <================================================ HANDLER =======================================================>
function(CommandHandler("pickwinner", pick_winner, block=False))
function(CommandHandler("hyperlink", hyperlink_command, block=False))
# <================================================ END =======================================================>