Spaces:
Sleeping
Sleeping
Captain Ezio
commited on
Commit
·
c330dc1
1
Parent(s):
6babc85
fixed bugs
Browse files- Powers/plugins/flood.py +4 -1
- Powers/plugins/formatting.py +66 -62
- Powers/utils/start_utils.py +2 -0
- Powers/utils/string.py +6 -7
Powers/plugins/flood.py
CHANGED
@@ -329,7 +329,10 @@ dic = {}
|
|
329 |
async def flood_watcher(c: Gojo, m: Message):
|
330 |
c_id = m.chat.id
|
331 |
Flood = Floods()
|
332 |
-
|
|
|
|
|
|
|
333 |
is_flood = Flood.is_chat(c_id)
|
334 |
if not is_flood:
|
335 |
return # return of chat is not in anti flood protection
|
|
|
329 |
async def flood_watcher(c: Gojo, m: Message):
|
330 |
c_id = m.chat.id
|
331 |
Flood = Floods()
|
332 |
+
try:
|
333 |
+
u_id = m.from_user.id
|
334 |
+
except AttributeError:
|
335 |
+
return # Get this error when the message received is not by an user and return
|
336 |
is_flood = Flood.is_chat(c_id)
|
337 |
if not is_flood:
|
338 |
return # return of chat is not in anti flood protection
|
Powers/plugins/formatting.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
from pyrogram import enums, filters
|
2 |
from pyrogram.errors import MediaCaptionTooLong
|
3 |
from pyrogram.types import CallbackQuery, Message
|
@@ -5,6 +7,7 @@ from pyrogram.types import CallbackQuery, Message
|
|
5 |
from Powers import LOGGER
|
6 |
from Powers.bot_class import Gojo
|
7 |
from Powers.utils.custom_filters import command
|
|
|
8 |
from Powers.utils.kbhelpers import ikb
|
9 |
|
10 |
|
@@ -26,8 +29,9 @@ async def gen_formatting_kb(m):
|
|
26 |
command(["markdownhelp", "formatting"]) & filters.private,
|
27 |
)
|
28 |
async def markdownhelp(_, m: Message):
|
29 |
-
await m.
|
30 |
-
|
|
|
31 |
quote=True,
|
32 |
reply_markup=(await gen_formatting_kb(m)),
|
33 |
)
|
@@ -43,28 +47,28 @@ async def get_formatting_info(c: Gojo, q: CallbackQuery):
|
|
43 |
if cmd == "md_formatting":
|
44 |
|
45 |
txt = """<b>Markdown Formatting</b>
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
try:
|
66 |
-
await q.
|
67 |
-
|
68 |
reply_markup=kb,
|
69 |
parse_mode=enums.ParseMode.HTML,
|
70 |
)
|
@@ -74,46 +78,46 @@ async def get_formatting_info(c: Gojo, q: CallbackQuery):
|
|
74 |
text=txt,
|
75 |
parse_mode=enums.ParseMode.HTML,)
|
76 |
elif cmd == "fillings":
|
77 |
-
await q.
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
reply_markup=kb,
|
92 |
parse_mode=enums.ParseMode.HTML,
|
93 |
)
|
94 |
elif cmd == "random_content":
|
95 |
-
await q.
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
reply_markup=kb,
|
118 |
parse_mode=enums.ParseMode.HTML,
|
119 |
)
|
@@ -124,10 +128,10 @@ async def get_formatting_info(c: Gojo, q: CallbackQuery):
|
|
124 |
|
125 |
@Gojo.on_callback_query(filters.regex("^back."))
|
126 |
async def send_mod_help(_, q: CallbackQuery):
|
127 |
-
await q.
|
128 |
-
|
129 |
|
130 |
-
|
131 |
reply_markup=(await gen_formatting_kb(q.message)),
|
132 |
)
|
133 |
await q.answer()
|
|
|
1 |
+
from random import choice
|
2 |
+
|
3 |
from pyrogram import enums, filters
|
4 |
from pyrogram.errors import MediaCaptionTooLong
|
5 |
from pyrogram.types import CallbackQuery, Message
|
|
|
7 |
from Powers import LOGGER
|
8 |
from Powers.bot_class import Gojo
|
9 |
from Powers.utils.custom_filters import command
|
10 |
+
from Powers.utils.extras import StartPic
|
11 |
from Powers.utils.kbhelpers import ikb
|
12 |
|
13 |
|
|
|
29 |
command(["markdownhelp", "formatting"]) & filters.private,
|
30 |
)
|
31 |
async def markdownhelp(_, m: Message):
|
32 |
+
await m.reply_photo(
|
33 |
+
photo=str(choice(StartPic)),
|
34 |
+
caption=f"{__HELP__}",
|
35 |
quote=True,
|
36 |
reply_markup=(await gen_formatting_kb(m)),
|
37 |
)
|
|
|
47 |
if cmd == "md_formatting":
|
48 |
|
49 |
txt = """<b>Markdown Formatting</b>
|
50 |
+
You can format your message using <b>bold</b>, <i>italic</i>, <u>underline</u>, <strike>strike</strike> and much more. Go ahead and experiment!
|
51 |
+
|
52 |
+
**Note**: It supports telegram user based formatting as well as html and markdown formattings.
|
53 |
+
<b>Supported markdown</b>:
|
54 |
+
- <code>`code words`</code>: Backticks are used for monospace fonts. Shows as: <code>code words</code>.
|
55 |
+
- <code>__italic__</code>: Underscores are used for italic fonts. Shows as: <i>italic words</i>.
|
56 |
+
- <code>**bold**</code>: Asterisks are used for bold fonts. Shows as: <b>bold words</b>.
|
57 |
+
- <code>```pre```</code>: To make the formatter ignore other formatting characters inside the text formatted with '```', like: <code>**bold** | *bold*</code>.
|
58 |
+
- <code>--underline--</code>: To make text <u>underline</u>.
|
59 |
+
- <code>~~strike~~</code>: Tildes are used for strikethrough. Shows as: <strike>strike</strike>.
|
60 |
+
- <code>||spoiler||</code>: Double vertical bars are used for spoilers. Shows as: <spoiler>Spoiler</spoiler>.
|
61 |
+
- <code>[hyperlink](example.com)</code>: This is the formatting used for hyperlinks. Shows as: <a href="https://example.com/">hyperlink</a>.
|
62 |
+
- <code>[My Button](buttonurl://example.com)</code>: This is the formatting used for creating buttons. This example will create a button named "My button" which opens <code>example.com</code> when clicked.
|
63 |
+
If you would like to send buttons on the same row, use the <code>:same</code> formatting.
|
64 |
+
<b>Example:</b>
|
65 |
+
<code>[button 1](buttonurl:example.com)</code>
|
66 |
+
<code>[button 2](buttonurl://example.com:same)</code>
|
67 |
+
<code>[button 3](buttonurl://example.com)</code>
|
68 |
+
This will show button 1 and 2 on the same line, while 3 will be underneath."""
|
69 |
try:
|
70 |
+
await q.edit_message_caption(
|
71 |
+
caption=txt,
|
72 |
reply_markup=kb,
|
73 |
parse_mode=enums.ParseMode.HTML,
|
74 |
)
|
|
|
78 |
text=txt,
|
79 |
parse_mode=enums.ParseMode.HTML,)
|
80 |
elif cmd == "fillings":
|
81 |
+
await q.edit_message_caption(
|
82 |
+
caption="""<b>Fillings</b>
|
83 |
+
|
84 |
+
You can also customise the contents of your message with contextual data. For example, you could mention a user by name in the welcome message, or mention them in a filter!
|
85 |
+
You can use these to mention a user in notes too!
|
86 |
+
|
87 |
+
<b>Supported fillings:</b>
|
88 |
+
- <code>{first}</code>: The user's first name.
|
89 |
+
- <code>{last}</code>: The user's last name.
|
90 |
+
- <code>{fullname}</code>: The user's full name.
|
91 |
+
- <code>{username}</code>: The user's username. If they don't have one, mentions the user instead.
|
92 |
+
- <code>{mention}</code>: Mentions the user with their firstname.
|
93 |
+
- <code>{id}</code>: The user's ID.
|
94 |
+
- <code>{chatname}</code>: The chat's name.""",
|
95 |
reply_markup=kb,
|
96 |
parse_mode=enums.ParseMode.HTML,
|
97 |
)
|
98 |
elif cmd == "random_content":
|
99 |
+
await q.edit_message_caption(
|
100 |
+
caption="""<b>Random Content</b>
|
101 |
+
|
102 |
+
Another thing that can be fun, is to randomise the contents of a message. Make things a little more personal by changing welcome messages, or changing notes!
|
103 |
+
|
104 |
+
How to use random contents:
|
105 |
+
- %%%: This separator can be used to add "random" replies to the bot.
|
106 |
+
For example:
|
107 |
+
<code>hello
|
108 |
+
%%%
|
109 |
+
how are you</code>
|
110 |
+
This will randomly choose between sending the first message, "hello", or the second message, "how are you".
|
111 |
+
Use this to make Gojo feel a bit more customised! (only works in filters/notes)
|
112 |
+
|
113 |
+
Example welcome message::
|
114 |
+
- Every time a new user joins, they'll be presented with one of the three messages shown here.
|
115 |
+
-> /filter "hey"
|
116 |
+
hello there <code>{first}</code>!
|
117 |
+
%%%
|
118 |
+
Ooooh, <code>{first}</code> how are you?
|
119 |
+
%%%
|
120 |
+
Sup? <code>{first}</code>""",
|
121 |
reply_markup=kb,
|
122 |
parse_mode=enums.ParseMode.HTML,
|
123 |
)
|
|
|
128 |
|
129 |
@Gojo.on_callback_query(filters.regex("^back."))
|
130 |
async def send_mod_help(_, q: CallbackQuery):
|
131 |
+
await q.edit_message_caption(
|
132 |
+
caption="""Formatting
|
133 |
|
134 |
+
Gojo supports a large number of formatting options to make your messages more expressive. Take a look by clicking the buttons below!""",
|
135 |
reply_markup=(await gen_formatting_kb(q.message)),
|
136 |
)
|
137 |
await q.answer()
|
Powers/utils/start_utils.py
CHANGED
@@ -139,6 +139,8 @@ async def get_private_note(c: Gojo, m: Message, help_option: str):
|
|
139 |
teks, button = await parse_button(text)
|
140 |
button = await build_keyboard(button)
|
141 |
button = ikb(button) if button else None
|
|
|
|
|
142 |
if button:
|
143 |
try:
|
144 |
await m.reply_text(
|
|
|
139 |
teks, button = await parse_button(text)
|
140 |
button = await build_keyboard(button)
|
141 |
button = ikb(button) if button else None
|
142 |
+
if not teks:
|
143 |
+
teks = "Here is your note"
|
144 |
if button:
|
145 |
try:
|
146 |
await m.reply_text(
|
Powers/utils/string.py
CHANGED
@@ -1,6 +1,6 @@
|
|
|
|
1 |
from html import escape
|
2 |
from re import compile as compile_re
|
3 |
-
from time import time
|
4 |
from typing import List
|
5 |
|
6 |
from pyrogram.enums import ChatType
|
@@ -19,13 +19,13 @@ async def extract_time(m: Message, time_val: str):
|
|
19 |
if not time_num.isdigit():
|
20 |
await m.reply("Unspecified amount of time.")
|
21 |
return ""
|
22 |
-
|
23 |
if unit == "m":
|
24 |
-
bantime =
|
25 |
elif unit == "h":
|
26 |
-
bantime =
|
27 |
-
elif unit == "
|
28 |
-
bantime =
|
29 |
else:
|
30 |
# how even...?
|
31 |
return ""
|
@@ -62,7 +62,6 @@ async def parse_button(text: str):
|
|
62 |
prev = match.start(1) - 1
|
63 |
else:
|
64 |
note_data += markdown_note[prev:]
|
65 |
-
|
66 |
return note_data, buttons
|
67 |
|
68 |
|
|
|
1 |
+
from datetime import datetime, timedelta
|
2 |
from html import escape
|
3 |
from re import compile as compile_re
|
|
|
4 |
from typing import List
|
5 |
|
6 |
from pyrogram.enums import ChatType
|
|
|
19 |
if not time_num.isdigit():
|
20 |
await m.reply("Unspecified amount of time.")
|
21 |
return ""
|
22 |
+
initial_time = datetime.now()
|
23 |
if unit == "m":
|
24 |
+
bantime = initial_time + timedelta(minutes=int(time_num))
|
25 |
elif unit == "h":
|
26 |
+
bantime = initial_time + timedelta(hours=int(time_num))
|
27 |
+
elif unit == "d":
|
28 |
+
bantime = initial_time + timedelta(days=int(time_num))
|
29 |
else:
|
30 |
# how even...?
|
31 |
return ""
|
|
|
62 |
prev = match.start(1) - 1
|
63 |
else:
|
64 |
note_data += markdown_note[prev:]
|
|
|
65 |
return note_data, buttons
|
66 |
|
67 |
|