Spaces:
Sleeping
Sleeping
File size: 8,216 Bytes
ca4eb6d 007891e 11ae35a 87abec5 0006686 11ae35a c62ca93 11ae35a ca4eb6d 11ae35a ca4eb6d 74b62cb ca4eb6d 6087453 ca4eb6d 51e1c40 ca4eb6d af1662b ca4eb6d a57e3b8 ca4eb6d 89ad488 ca4eb6d aef1161 89ad488 aef1161 ca4eb6d a57e3b8 bd54dc6 ca4eb6d 085077d c62ca93 aef1161 085077d ca4eb6d 2681f9e bb1bfd1 ea508b7 2681f9e 0006686 bb1bfd1 c62ca93 0006686 2681f9e 89ad488 ca4eb6d c62ca93 ca4eb6d fb30481 2421595 ca4eb6d c330dc1 ca4eb6d 6cef7ec ca4eb6d 89a7a7a ca4eb6d 89a7a7a ca4eb6d 89a7a7a ca4eb6d 51e1c40 ca4eb6d 11ae35a ca4eb6d 11ae35a af1662b 89ad488 ca4eb6d 89ad488 7eeba00 51e1c40 6087453 b4a5cf9 7eeba00 11ae35a d120eb5 ca4eb6d f0f9ad9 |
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
from html import escape
from secrets import choice
from traceback import format_exc
from pyrogram.errors import RPCError
from pyrogram.types import CallbackQuery, Message
from Powers import HELP_COMMANDS, LOGGER, OWNER_ID, SUPPORT_CHANNEL
from Powers.bot_class import Gojo
from Powers.database.chats_db import Chats
from Powers.database.notes_db import Notes
from Powers.database.rules_db import Rules
from Powers.utils.cmd_senders import send_cmd
from Powers.utils.kbhelpers import ikb
from Powers.utils.msg_types import Types
from Powers.utils.string import (build_keyboard,
escape_mentions_using_curly_brackets,
parse_button)
from Powers.vars import Config
# Initialize
notes_db = Notes()
async def gen_cmds_kb(m: Message or CallbackQuery):
"""Generate the keyboard"""
if isinstance(m, CallbackQuery):
m = m.message
cmds = sorted(list(HELP_COMMANDS.keys()))
kb = [cmd.lower() for cmd in cmds]
return [kb[i: i + 3] for i in range(0, len(kb), 3)]
async def gen_start_kb(q: Message or CallbackQuery):
"""Generate keyboard with start menu options."""
return ikb(
[
[
(
"➕ Add me to a chat!",
f"https://t.me/{Config.BOT_USERNAME}?startgroup=new",
"url",
),
("Bot Staffs 🚔", "give_bot_staffs"),
],
[
("📚 Commands & Help", "commands"),
("Bot info 👾", "bot_curr_info"),
],
[
(
"🗃️ Source Code",
"https://github.com/Gojo-Bots/Gojo_Satoru",
"url",
),
(
"Owner ❤️",
OWNER_ID,
"user_id",
),
],
[
(
"❗️ Essential",
"https://t.me/+PcVYvdzNt4E1YjM1",
"url",
),
(
"Powered by ⚡️",
f"https://{SUPPORT_CHANNEL}.t.me",
"url",
),
],
]
)
async def get_private_note(c: Gojo, m: Message, help_option: str):
"""Get the note in pm of user, with parsing enabled."""
help_lst = help_option.split("_")
if len(help_lst) == 2:
chat_id = int(help_lst[1])
all_notes = notes_db.get_all_notes(chat_id)
chat_title = Chats.get_chat_info(chat_id)["chat_name"]
rply = f"Notes in {chat_title}:\n\n"
note_list = [
f"- [{note[0]}](https://t.me/{c.me.username}?start=note_{chat_id}_{note[1]})"
for note in all_notes
]
rply = f"Available notes in {chat_title}\n"
rply += "\n".join(note_list)
rply += "\n\nYou can retrieve these notes by tapping on the notename."
await m.reply_text(rply, disable_web_page_preview=True, quote=True)
return
if len(help_lst) != 3:
return
note_hash = help_option.split("_")[2]
getnotes = notes_db.get_note_by_hash(note_hash)
if not getnotes:
await m.reply_text("Note does not exist", quote=True)
return
msgtype = getnotes["msgtype"]
if not msgtype:
await m.reply_text(
"<b>Error:</b> Cannot find a type for this note!!",
quote=True,
)
return
try:
# support for random notes texts
splitter = "%%%"
note_reply = getnotes["note_value"].split(splitter)
note_reply = choice(note_reply)
except KeyError:
note_reply = ""
parse_words = [
"first",
"last",
"fullname",
"username",
"id",
"chatname",
"mention",
]
text = await escape_mentions_using_curly_brackets(m, note_reply, parse_words)
if msgtype == Types.TEXT:
teks, button = await parse_button(text)
button = await build_keyboard(button)
button = ikb(button) if button else None
if not teks:
teks = "Here is your note"
if button:
try:
await m.reply_text(
teks,
reply_markup=button,
disable_web_page_preview=True,
quote=True,
)
return
except RPCError as ef:
await m.reply_text(
"An error has occured! Cannot parse note.",
quote=True,
)
LOGGER.error(ef)
LOGGER.error(format_exc())
return
else:
await m.reply_text(teks, quote=True, disable_web_page_preview=True)
return
elif msgtype in (
Types.STICKER,
Types.VIDEO_NOTE,
Types.CONTACT,
Types.ANIMATED_STICKER,
):
await (await send_cmd(c, msgtype))(m.chat.id, getnotes["fileid"])
else:
if getnotes["note_value"]:
teks, button = await parse_button(getnotes["note_value"])
button = await build_keyboard(button)
button = ikb(button) if button else None
else:
teks = ""
button = None
if button:
try:
await (await send_cmd(c, msgtype))(
m.chat.id,
getnotes["fileid"],
caption=teks,
reply_markup=button,
)
return
except RPCError as ef:
await m.reply_text(
teks,
quote=True,
reply_markup=button,
disable_web_page_preview=True,
)
LOGGER.error(ef)
LOGGER.error(format_exc())
return
else:
await (await send_cmd(c, msgtype))(
m.chat.id,
getnotes["fileid"],
caption=teks,
)
return
async def get_private_rules(_, m: Message, help_option: str):
chat_id = int(help_option.split("_")[1])
rules = Rules(chat_id).get_rules()
chat_title = Chats.get_chat_info(chat_id)["chat_name"]
if not rules:
await m.reply_text(
"The Admins of that group have not setup any rules, that dosen't mean you break the decorum of the chat!",
quote=True,
)
return ""
teks, button = await parse_button(rules)
button = await build_keyboard(button)
button = ikb(button) if button else None
textt = teks
await m.reply_text(
f"""The rules for <b>{escape(chat_title)} are</b>:\n
{textt}
""",
quote=True,
disable_web_page_preview=True,
reply_markup=button
)
return ""
async def get_help_msg(c: Gojo, m: Message or CallbackQuery, help_option: str):
"""Helper function for getting help_msg and it's keyboard."""
help_msg = None
help_kb = None
help_cmd_keys = sorted(
k
for j in [HELP_COMMANDS[i]["alt_cmds"] for i in list(HELP_COMMANDS.keys())]
for k in j
)
if help_option in help_cmd_keys:
help_option_name = next(
HELP_COMMANDS[i]
for i in HELP_COMMANDS
if help_option in HELP_COMMANDS[i]["alt_cmds"]
)
help_option_value = help_option_name["help_msg"]
ou = next(
HELP_COMMANDS[i]["buttons"]
for i in HELP_COMMANDS
if help_option in HELP_COMMANDS[i]["alt_cmds"]
)
help_kb = ikb(ou, True, "commands")
help_msg = f"**{(help_option_value)}:**"
else:
mes = m.message if isinstance(m, CallbackQuery) else m
help_msg = f"""
Hey **[{mes.from_user.first_name}](http://t.me/{mes.from_user.username})**!I am {c.me.first_name}✨.
I'm here to help you manage your groups!
Commands available:
× /start: Start the bot
× /help: Give's you this message."""
ou = await gen_cmds_kb(m)
help_kb = ikb(ou, True)
return help_msg, help_kb
|