Skip to content

Commit 9f176fa

Browse files
committed
First
1 parent 8af23ab commit 9f176fa

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

bp.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python3
2+
# coding=utf-8
3+
4+
from telegram.ext import Updater
5+
from telegram.ext import CommandHandler
6+
from telegram.ext import MessageHandler, Filters ,ConversationHandler
7+
import requests,json
8+
9+
# main function , paste to beepaste.io
10+
def paste(text,author):
11+
# json data
12+
data = {'api-key': 'AAAAAAAAAAAAAAAAAAAA', 'pasteRaw': text, 'pasteLanguage': 'text', 'pasteTitle': 'My Paste', 'pasteAuthor': author + ' , From @bpaste_bot '}
13+
# request
14+
rp = requests.post('https://beepaste.io/api', json=data)
15+
# get url as json
16+
rpj = rp.json()
17+
url = rpj["url"]
18+
return url
19+
20+
# access bot via token
21+
updater = Updater(token='NNNNNNNNN:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA')
22+
dispatcher = updater.dispatcher
23+
second = 2
24+
25+
# start_handler function
26+
def start(bot, update):
27+
update.message.reply_text('Hi, Get me your long text')
28+
return second
29+
30+
# get text and call paste function
31+
def second(bot, update):
32+
# get text
33+
txt = update.message.text
34+
# get user name for author
35+
author = update.message.from_user.first_name + " " + update.message.from_user.last_name
36+
# call paste function
37+
url = paste(txt , author)
38+
# replay the url to user
39+
bot.sendMessage(chat_id=update.message.chat_id,text=url)
40+
41+
# cancel function
42+
def cancel(bot,update):
43+
bot.sendMessage(chat_id=update.message.chat_id,text="canceled")
44+
# About function
45+
def about(bot,update):
46+
abouttext = " @bpaste_bot is a Free Software that developed by Mostafa Asadi \n\n 🌐 https://github.com/mostafaasadi/bpastebot "
47+
bot.sendMessage(chat_id=update.message.chat_id,text=abouttext)
48+
49+
# manage conversation
50+
conv_handler = ConversationHandler(
51+
entry_points=[CommandHandler('start', start)],
52+
states={
53+
second: [MessageHandler(Filters.text,second)],
54+
},
55+
fallbacks=[CommandHandler('cancel', cancel)])
56+
57+
# it handle start command
58+
start_handler = CommandHandler('start', start)
59+
# handle all text
60+
second_handler = MessageHandler(Filters.text , second)
61+
# handle cancel
62+
cancel_handler = CommandHandler('cancel', cancel)
63+
# handle cancel
64+
about_handler = CommandHandler('about', about)
65+
66+
# handle dispatcher
67+
dispatcher.add_handler(start_handler)
68+
dispatcher.add_handler(second_handler)
69+
dispatcher.add_handler(conv_handler)
70+
dispatcher.add_handler(cancel_handler)
71+
dispatcher.add_handler(about_handler)
72+
73+
# run
74+
updater.start_polling()
75+
updater.idle()
76+
updater.stop()

0 commit comments

Comments
 (0)