iamgojoof6eyes commited on
Commit
37da43b
·
1 Parent(s): 9c0772d

Encountered problem while doing changes `reverted`

Browse files
Files changed (1) hide show
  1. Powers/utils/kbhelpers.py +14 -37
Powers/utils/kbhelpers.py CHANGED
@@ -1,42 +1,19 @@
1
- from re import findall
2
- from pykeyboard import InlineKeyboard
3
- from pyrogram.types import InlineKeyboardButton as kb
4
 
 
5
 
6
- # CREDIT WILLIAM BUTCHER BOT
7
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- def is_url(text: str) -> bool:
10
- regex = r"""(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]
11
- [.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(
12
- \([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\
13
- ()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))""".strip()
14
- return [x[0] for x in findall(regex, str(text))]
15
 
16
-
17
- def keyboard(buttons_list, row_width: int = 2):
18
- """
19
- Buttons builder, pass buttons in a list and it will
20
- return pyrogram.types.IKB object
21
- Ex: keyboard([["click here", "https://google.com"]])
22
- if theres, a url, it will make url button, else callback button
23
- """
24
- buttons = InlineKeyboard(row_width=row_width)
25
- data = [
26
- (
27
- kb(text=str(i[0]), callback_data=str(i[1]))
28
- if not is_url(i[1])
29
- else kb(text=str(i[0]), url=str(i[1]))
30
- )
31
- for i in buttons_list
32
- ]
33
- buttons.add(*data)
34
- return buttons
35
-
36
-
37
- def ikb(data: dict, row_width: int = 2):
38
- """
39
- Converts a dict to pyrogram buttons
40
- Ex: dict_to_keyboard({"click here": "this is callback data"})
41
- """
42
- return keyboard(data.items(), row_width=row_width)
 
 
 
 
1
 
2
+ from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
3
 
 
4
 
5
+ def ikb(rows=None):
6
+ if rows is None:
7
+ rows = []
8
+ lines = []
9
+ for row in rows:
10
+ line = []
11
+ for button in row:
12
+ button = btn(*button) # InlineKeyboardButton
13
+ line.append(button)
14
+ lines.append(line)
15
+ return InlineKeyboardMarkup(inline_keyboard=lines)
16
 
 
 
 
 
 
 
17
 
18
+ def btn(text, value, type="callback_data"):
19
+ return InlineKeyboardButton(text, **{type: value})