Karma
commited on
Commit
Β·
edfc350
1
Parent(s):
dd073da
hyperlink and pickwinner
Browse files- Mikobot/plugins/hyperlink.py +63 -0
Mikobot/plugins/hyperlink.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# SOURCE https://github.com/Team-ProjectCodeX
|
2 |
+
# CREATED BY https://t.me/O_okarma
|
3 |
+
# PROVIDED BY https://t.me/ProjectCodeX
|
4 |
+
|
5 |
+
# <============================================== IMPORTS =========================================================>
|
6 |
+
import random
|
7 |
+
import re
|
8 |
+
|
9 |
+
from telegram import Update
|
10 |
+
from telegram.constants import ParseMode
|
11 |
+
from telegram.ext import CommandHandler, ContextTypes
|
12 |
+
|
13 |
+
from Mikobot import function
|
14 |
+
|
15 |
+
# <=======================================================================================================>
|
16 |
+
|
17 |
+
|
18 |
+
# <================================================ FUNCTION =======================================================>
|
19 |
+
# Define the command handler for the "/pickwinner" command
|
20 |
+
async def pick_winner(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
21 |
+
# Get the list of participants
|
22 |
+
participants = context.args
|
23 |
+
|
24 |
+
if participants:
|
25 |
+
# Select a random winner
|
26 |
+
winner = random.choice(participants)
|
27 |
+
|
28 |
+
# Send the winner as a reply
|
29 |
+
await update.message.reply_text(f"π The winner is: {winner}")
|
30 |
+
else:
|
31 |
+
# If no participants are provided
|
32 |
+
await update.message.reply_text("Please provide a list of participants.")
|
33 |
+
|
34 |
+
|
35 |
+
# Define the command handler for the "/hyperlink" command
|
36 |
+
async def hyperlink_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
37 |
+
args = context.args
|
38 |
+
if len(args) >= 2:
|
39 |
+
text = " ".join(args[:-1])
|
40 |
+
link = args[-1]
|
41 |
+
hyperlink = f"[{text}]({link})"
|
42 |
+
await update.message.reply_text(
|
43 |
+
text=hyperlink, parse_mode="Markdown", disable_web_page_preview=True
|
44 |
+
)
|
45 |
+
else:
|
46 |
+
match = re.search(r"/hyperlink ([^\s]+) (.+)", update.message.text)
|
47 |
+
if match:
|
48 |
+
text = match.group(1)
|
49 |
+
link = match.group(2)
|
50 |
+
hyperlink = f"[{text}]({link})"
|
51 |
+
await update.message.reply_text(
|
52 |
+
text=hyperlink, parse_mode=ParseMode.HTML, disable_web_page_preview=True
|
53 |
+
)
|
54 |
+
else:
|
55 |
+
await update.message.reply_text(
|
56 |
+
"β Invalid format! Please use the format: /hyperlink <text> <link>."
|
57 |
+
)
|
58 |
+
|
59 |
+
|
60 |
+
# <================================================ HANDLER =======================================================>
|
61 |
+
function(CommandHandler("pickwinner", pick_winner, block=False))
|
62 |
+
function(CommandHandler("hyperlink", hyperlink_command, block=False))
|
63 |
+
# <================================================ END =======================================================>
|