Skip to content

Commit e9e011c

Browse files
committed
🤖BPaste_bot on Bale.ai
1 parent e43f57e commit e9e011c

File tree

3 files changed

+145
-3
lines changed

3 files changed

+145
-3
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# [BPaste_bot](https://t.me/bpaste_bot)
2-
### This is a telegram bot has been written with [python-telegram-bot](https://python-telegram-bot.org/) that paste long text in [BeePaste](https:beepaste.io)
1+
# 🤖 BPaste_bot
2+
### This is a bot that paste long text in [BeePaste](https:beepaste.io)
33

44
# It can :
55
- ## paste direct text
66
- ## paste file content
7-
- ## paste inline mode
7+
- ## paste inline mode (just on Telegram)
88
- ## expand a paste content via link
9+
10+
# [@BPaste_bot on Telegram](https://t.me/bpaste_bot)
11+
# [@BPaste_bot on Bale](https://bale.ai/bpaste_bot)

bp_bale.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import requests
2+
import threading
3+
from balebot.filters import *
4+
from balebot.handlers import *
5+
from balebot.config import Config
6+
from balebot.updater import Updater
7+
from balebot.models.messages import *
8+
from balebot.models.base_models import Peer
9+
from requests.packages.urllib3.exceptions import InsecureRequestWarning
10+
11+
12+
updater = Updater(token="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
13+
dispatcher = updater.dispatcher
14+
bot = updater.bot
15+
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
16+
17+
18+
# get token
19+
def tokenize():
20+
global headers
21+
threading.Timer(850, tokenize).start()
22+
23+
try:
24+
tokenRequest = requests.post(
25+
'https://beepaste.io/api/v1/auth',
26+
headers={'Content-Type': 'application/json'}, verify=False)
27+
token_json = tokenRequest.json()
28+
if token_json['status'] == 'success':
29+
token = token_json['X-TOKEN']
30+
headers = {'X-TOKEN': token}
31+
print(headers)
32+
return True
33+
except Exception as e:
34+
print('\nError: ' + e)
35+
36+
37+
# main function , paste to beepaste.io
38+
def paste(text, author):
39+
data = {
40+
'raw': text,
41+
'title': 'A new paste',
42+
'author': author + ' via 🤖@BPaste_bot on Bale '
43+
}
44+
try:
45+
r = requests.post(
46+
'https://beepaste.io/api/v1/paste',
47+
headers=headers, json=data, verify=False)
48+
except Exception as e:
49+
print('\n\nE: ' + e + '\n\n')
50+
rj = r.json()
51+
if rj['status'] == 'success':
52+
rjp = rj['paste']
53+
return rjp
54+
else:
55+
print('E')
56+
return False
57+
tokenize()
58+
59+
60+
# expand paste
61+
@dispatcher.message_handler(
62+
filters=[
63+
TextFilter(pattern="https://beepaste.io/paste/view\S+"),
64+
TemplateResponseFilter()
65+
])
66+
def expand(bot, update):
67+
m = update.get_effective_message()
68+
pid = m.text.split('/')[5].split(' ')[0]
69+
70+
try:
71+
r = requests.get(
72+
'https://beepaste.io/api/v1/paste/' + pid,
73+
headers=headers
74+
)
75+
except Exception as e:
76+
print(e)
77+
rj = r.json()
78+
if rj['status'] == 'success':
79+
res = '🔗 https://beepaste.io/paste/view/' + rj['paste']['uri'] + \
80+
'\n👤 ' + rj['paste']['author'] + \
81+
'\n```\n\n' + rj['paste']['raw'] + '\n```'
82+
bot.reply(update, res)
83+
return True
84+
else:
85+
return False
86+
tokenize()
87+
88+
89+
@dispatcher.message_handler(DocumentFilter())
90+
def download_file(bot, update):
91+
def final_download_success(result, user_data):
92+
stream = user_data.get("byte_stream", None)
93+
# call paste function
94+
p = paste(stream.decode('utf-8'), 'Anonymous')
95+
# replay the url to user
96+
res = '🔗 https://beepaste.io/paste/view/' + p['uri'] + \
97+
'\n🔗 ' + p['shorturl']
98+
bot.reply(update, res)
99+
100+
user_id = update.body.sender_user.peer_id
101+
file_id = update.body.message.file_id
102+
bot.download_file(
103+
file_id=file_id,
104+
user_id=user_id,
105+
file_type="file",
106+
success_callback=final_download_success
107+
)
108+
109+
110+
@dispatcher.command_handler('/start')
111+
def conversation_starter(bot, update):
112+
message = TextMessage("سلام, یک متن طولانی یا یک فایل متنی بلند را برای من بفرستید تا آن را پیست کنم همچنین اگر لینک پیستی را برای من بفرستید همینجا آن را می‌گشایم")
113+
user_peer = update.get_effective_user()
114+
bot.send_message(message, user_peer)
115+
116+
117+
# About function
118+
@dispatcher.command_handler('/about')
119+
def about(bot, update):
120+
abouttext = "@BPaste_bot , Can Paste Long Text and File Content or Expand your Paste \n🆓 This Bot , Totaly Free , Libre and OpenSource \n 🌐 https://github.com/mostafaasadi/bpastebot "
121+
bot.reply(update, abouttext)
122+
123+
124+
@dispatcher.message_handler(filters=[TextFilter()])
125+
def text(bot, update):
126+
m = update.get_effective_message()
127+
p = paste(m.text, 'Anonymous user')
128+
res = '🔗 https://beepaste.io/paste/view/' + p['uri'] + \
129+
'\n🔗 ' + p['shorturl']
130+
bot.reply(update, res)
131+
132+
133+
def main():
134+
tokenize()
135+
updater.run()
136+
137+
138+
if __name__ == '__main__':
139+
main()
File renamed without changes.

0 commit comments

Comments
 (0)