Skip to content

Commit eb0f6d2

Browse files
committed
Clean up
- added README.md - cleaner code - passed every file through black
1 parent 4b4484b commit eb0f6d2

File tree

6 files changed

+94
-49
lines changed

6 files changed

+94
-49
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Pyrogram Session Maker (TelegramBot)
2+
3+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/01a4ef83e3a64a92b24d855aaed05c3a)](https://www.codacy.com/gh/pokurt/Pyrogram-SessionMaker-Bot/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=pokurt/Pyrogram-SessionMaker-Bot&amp;utm_campaign=Badge_Grade) [![>~<](https://img.shields.io/badge/%3E~%3C-nyaaa~-purple)](https://naipofo.com) [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/pokurt/Pyrogram-SessionMaker-Bot) ![Repo Size](https://img.shields.io/github/repo-size/pokurt/Pyrogram-SessionMaker-Bot)
4+
5+
## Disclaimer
6+
- I will not be responsible if your Voip account gets deleted/banned in the process.
7+
- However in previous occasion this never happened to anyone.
8+
- I suggest you to check the Source of this Project before continuing to use it.
9+
- There will be forks of [@PyrogramSessionBot](https://t.me/PyrogramSessionBot) therefore be careful while giving your Confidential Details to random forks of this Source.
10+
11+
### Evil Actions
12+
This project is free to use for Creating Sessions. If you Intend to use this project for Spam/Scam and other evil purposes,
13+
You are not welcome to be here or use the Project.
14+
15+
### Requirments
16+
- See `requirments.txt` in root directory of the Project
17+
- We do not need much of requirements other than `Pyrogram` and `TgCrypto`
18+
19+
### Setup
20+
- Install requirements in `requirements.txt`
21+
- Example of `psm.ini` is in `sample.psm.ini`
22+
- Run the bot: `python3 -m psm`

psm/plugins/clear_cache.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,57 +13,57 @@ async def code_save(client, message):
1313
else:
1414
return
1515
except KeyError:
16-
await message.reply('Try using `/start` and read the instructions')
16+
await message.reply("Try using `/start` and read the instructions")
1717

1818

19-
@psm.on_message(filters.command('appid'))
19+
@psm.on_message(filters.command("appid"))
2020
async def checkid(client, message):
2121
try:
2222
appid = message.text.split(None, 1)[1]
2323
except IndexError:
24-
await message.reply('Must pass args, example: `/appid 12345`')
24+
await message.reply("Must pass args, example: `/appid 12345`")
2525
return
2626
app_ids[message.from_user.id] = appid
27-
await message.reply('Your `APP_ID` variable is set')
27+
await message.reply("Your `APP_ID` variable is set")
2828

2929

30-
@psm.on_message(filters.command('apphash'))
30+
@psm.on_message(filters.command("apphash"))
3131
async def checkhash(client, message):
3232
try:
3333
apphash = message.text.split(None, 1)[1]
3434
except IndexError:
35-
await message.reply('Must pass args, example: `/apphash abCd1234Fghe`')
35+
await message.reply("Must pass args, example: `/apphash abCd1234Fghe`")
3636
return
3737
app_hashs[message.from_user.id] = apphash
38-
await message.reply('Your `APP_HASH` variable is set')
38+
await message.reply("Your `APP_HASH` variable is set")
3939

4040

41-
@psm.on_message(filters.command('password'))
41+
@psm.on_message(filters.command("password"))
4242
async def checkpass(client, message):
4343
try:
4444
password = message.text.split(None, 1)[1]
4545
except IndexError:
46-
await message.reply('Must pass args, example: `/password helloworld`')
46+
await message.reply("Must pass args, example: `/password helloworld`")
4747
return
4848
passwords[message.from_user.id] = password
49-
await message.reply('Your `CLOUD_PASS` variable is set')
49+
await message.reply("Your `CLOUD_PASS` variable is set")
5050

5151

52-
@psm.on_message(filters.command('clear'))
52+
@psm.on_message(filters.command("clear"))
5353
async def clear_dict(_, message):
5454
code_caches.pop(message.from_user.id, None)
55-
m = await message.reply('checking and clearing saved verification codes.')
55+
m = await message.reply("checking and clearing saved verification codes.")
5656
await asyncio.sleep(3)
5757
passwords.pop(message.from_user.id, None)
58-
await m.edit('checking and clearing saved cloud passwords.')
58+
await m.edit("checking and clearing saved cloud passwords.")
5959
await asyncio.sleep(3)
6060
app_ids.pop(message.from_user.id, None)
61-
await m.edit('checking and clearing saved api_id.')
61+
await m.edit("checking and clearing saved api_id.")
6262
await asyncio.sleep(3)
6363
app_hashs.pop(message.from_user.id, None)
64-
await m.edit('checking and clearing saved api_hash.')
64+
await m.edit("checking and clearing saved api_hash.")
6565
await asyncio.sleep(3)
66-
await m.edit('all cleared')
66+
await m.edit("all cleared")
6767
await asyncio.sleep(3)
6868
await message.delete()
69-
await m.delete()
69+
await m.delete()

psm/plugins/dictionaries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
code_caches = {}
22
passwords = {}
33
app_ids = {}
4-
app_hashs = {}
4+
app_hashs = {}

psm/plugins/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
def dynamic_data_filter(data):
55
async def func(flt, _, query):
66
return flt.data == query.data
7-
return filters.create(func, data=data)
7+
8+
return filters.create(func, data=data)

psm/plugins/session_maker.py

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from pyrogram import filters
2-
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, TermsOfService, ForceReply
32
from pyrogram import Client
43
from pyrogram.errors import FloodWait
54
from pyrogram import errors
5+
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ForceReply
6+
67
import asyncio
78

89
from psm import psm
@@ -16,17 +17,18 @@ async def client_session(message):
1617
api_hash=str(app_hashs[message.from_user.id]),
1718
)
1819

19-
@psm.on_message(filters.command('phone'))
20+
21+
@psm.on_message(filters.command("phone"))
2022
async def phone_number(_, message):
2123
try:
2224
app = await client_session(message)
2325
except KeyError:
24-
await message.reply('You did not set Variables correctly, read /start again.')
26+
await message.reply("You did not set Variables correctly, read /start again.")
2527
return
2628
try:
27-
phonenum = message.text.split(None, 1)[1].replace(' ', '')
29+
phonenum = message.text.split(None, 1)[1].replace(" ", "")
2830
except IndexError:
29-
await message.reply('Must pass args, example: `/phone +1234578900`')
31+
await message.reply("Must pass args, example: `/phone +1234578900`")
3032
return
3133
try:
3234
await app.connect()
@@ -36,51 +38,68 @@ async def phone_number(_, message):
3638
try:
3739
sent_code = await app.send_code(phonenum)
3840
except FloodWait as e:
39-
await message.reply(f'I cannot create session for you.\nYou have a floodwait of: `{e.x} seconds`')
41+
await message.reply(
42+
f"I cannot create session for you.\nYou have a floodwait of: `{e.x} seconds`"
43+
)
4044
return
4145
except errors.exceptions.bad_request_400.PhoneNumberInvalid:
42-
await message.reply('Phone number is invalid, Make sure you double check before sending.')
46+
await message.reply(
47+
"Phone number is invalid, Make sure you double check before sending."
48+
)
4349
return
44-
await message.reply('send me your code in 25 seconds, make sure you reply to this message and wait for a response.', reply_markup=ForceReply(True))
50+
await message.reply(
51+
"send me your code in 25 seconds, make sure you reply to this message and wait for a response.",
52+
reply_markup=ForceReply(True),
53+
)
4554
await asyncio.sleep(25)
4655
try:
47-
await app.sign_in(phonenum, sent_code.phone_code_hash, code_caches[message.from_user.id])
56+
await app.sign_in(
57+
phonenum, sent_code.phone_code_hash, code_caches[message.from_user.id]
58+
)
4859
except KeyError:
49-
await message.reply('Timed out, Try again.')
60+
await message.reply("Timed out, Try again.")
5061
return
5162
except errors.exceptions.unauthorized_401.SessionPasswordNeeded:
5263
try:
5364
await app.check_password(passwords[message.from_user.id])
5465
except KeyError:
55-
await message.reply('Timed out, try again later')
66+
await message.reply(
67+
"You have not set your password in the `/variables`, try doing that before you continue"
68+
)
5669
return
5770
except errors.exceptions.bad_request_400.PhoneCodeInvalid:
58-
await message.reply('The code you sent seems Invalid, Try again.')
71+
await message.reply("The code you sent seems Invalid, Try again.")
5972
return
6073
except errors.exceptions.bad_request_400.PhoneCodeExpired:
61-
await message.reply('The Code you sent seems Expired. Try again.')
74+
await message.reply("The Code you sent seems Expired. Try again.")
6275
return
63-
await app.send_message('me', f'```{(await app.export_session_string())}```')
76+
await app.send_message("me", f"```{(await app.export_session_string())}```")
6477
button = InlineKeyboardMarkup(
65-
[[InlineKeyboardButton('Go to Saved Messages', url=f'tg://user?id={message.from_user.id}')]]
78+
[
79+
[
80+
InlineKeyboardButton(
81+
"Go to Saved Messages", url=f"tg://user?id={message.from_user.id}"
82+
)
83+
]
84+
]
6685
)
6786
await message.reply(
68-
'All Done! Check your Saved Messages for your Session String.\n\nMake sure you run /clear to clear caches of your variables',
69-
reply_markup=button
87+
"All Done! Check your Saved Messages for your Session String.\n\nMake sure you run /clear to clear caches of your variables",
88+
reply_markup=button,
7089
)
7190

7291

73-
@psm.on_message(filters.command('token'))
92+
@psm.on_message(filters.command("token"))
7493
async def bot_token(_, message):
7594
try:
7695
app = await client_session(message)
7796
except KeyError:
78-
await message.reply('You did not set Variables correctly, read /start again.')
97+
await message.reply("You did not set Variables correctly, read /start again.")
7998
return
8099
try:
81-
bottoken = message.text.split(None, 1)[1].replace(' ', '')
100+
bottoken = message.text.split(None, 1)[1].replace(" ", "")
82101
except IndexError:
83-
await message.reply('Must pass args, example: `/token 1234:ABCD1234`')
102+
await message.reply("Must pass args, example: `/token 1234:ABCD1234`")
84103
return
85104
try:
86105
await app.connect()
@@ -90,9 +109,10 @@ async def bot_token(_, message):
90109
try:
91110
await app.sign_in_bot(bottoken)
92111
except errors.exceptions.bad_request_400.AccessTokenInvalid:
93-
await message.reply('BotToken Invalid: make sure you are sending a valid BotToken from @BotFather')
112+
await message.reply(
113+
"BotToken Invalid: make sure you are sending a valid BotToken from @BotFather"
114+
)
94115
return
95116
await message.reply(
96-
f'**Here is your Bot Session:**\n```{(await app.export_session_string())}```\n\nMake sure you run /clear to clear caches of your variables'
97-
)
98-
117+
f"**Here is your Bot Session:**\n```{(await app.export_session_string())}```\n\nMake sure you run /clear to clear caches of your variables"
118+
)

psm/psm.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from pyrogram import Client
44

55

6-
API_ID = environ.get('API_ID', None)
7-
API_HASH = environ.get('API_HASH', None)
8-
TOKEN = environ.get('TOKEN', None)
6+
API_ID = environ.get("API_ID", None)
7+
API_HASH = environ.get("API_HASH", None)
8+
TOKEN = environ.get("TOKEN", None)
99

1010

1111
class psm(Client):
@@ -15,13 +15,15 @@ def __init__(self, name):
1515
config_file = f"{name}.ini"
1616
config = ConfigParser()
1717
config.read(config_file)
18-
plugins = dict(root=f"{name}.plugins", )
18+
plugins = dict(
19+
root=f"{name}.plugins",
20+
)
1921

2022
super().__init__(
2123
name,
2224
api_id=API_ID,
2325
api_hash=API_HASH,
24-
bot_token=TOKEN or config.get('pyrogram', 'token'),
26+
bot_token=TOKEN or config.get("pyrogram", "token"),
2527
config_file=config_file,
2628
workers=16,
2729
plugins=plugins,

0 commit comments

Comments
 (0)