Skip to content
Open

Beta #21

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions Dwindle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@
if ENV:
TOKEN = os.environ.get('BOT_TOKEN', None)
WEBHOOK = bool(os.environ.get('WEBHOOK', False))
URL = os.environ.get('PUBLIC_URL',"")
URL = os.environ.get('PUBLIC_URL', "")
PORT = int(os.environ.get('PORT', 5000))
GpApi = os.environ.get('GpLinksApi')
GpBase = "https://gplinks.in/api?api={}&url=".format(GpApi)
bitlyApi = os.environ.get('BitLy_Api')
bitlybase = "https://api-ssl.bitly.com/v3/shorten?access_token={}&uri=".format(bitlyApi)

else:
from Dwindle import Config
TOKEN = Config.TOKEN
WEBHOOK = Config.Webhook
PORT = int(os.environ.get('PORT', 5000))
GpBase= Config.GpBase
bitlybase = Config.bitlybase
import Dwindle.config

TOKEN = config.TOKEN
WEBHOOK = config.Webhook
URL = config.URL
PORT = config.PORT
try:
bitlyApi = config.bitlyapi
except:
bitlyApi = null

updater = telegram.ext.Updater(TOKEN)
dispatcher = updater.dispatcher
Expand Down
22 changes: 10 additions & 12 deletions Dwindle/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from telegram.ext import Updater, CommandHandler, dispatcher, MessageHandler, Filters, CallbackQueryHandler
import emoji
import telegram
from bs4 import BeautifulSoup
from Dwindle import TOKEN, modules, LOGGER, PORT, WEBHOOK , URL
from Dwindle.modules.short import short_buttons, platforms
from Dwindle.modules import *

# Enable logging
Expand All @@ -15,22 +15,22 @@
def start(update, context):
update.message.reply_text(
"<b>Hi {} {} ! \n\nI'm <a href=\"tg://user?id=1451118099\">Dwindle</a> - A Simple URL shortener bot."
"\n\nSend me any link , I can short it for You."
"\n\nSend me any link.I can short it for You."
"\n\nHit </b>/help<b> to find out more about how to use me.</b>".format(update.effective_user.first_name, (
emoji.emojize(":wave:", use_aliases=True))), parse_mode='html',
reply_to_message_id=update.message.message_id)


def help(update, context):
def assist(update, context):
update.message.reply_text("*Hey! My name is Dwindle.* "
"\n\nI am a link shortener bot, here to help you to shorten your links!"
"\nI have lots of handy features to help You"
"\n\n*Helpful commands:*"
"\n\t\t- /start: Starts me! You've probably already used this."
"\n\t\t- /help: Sends this message; I'll tell you more about myself!"
"\n - /short <platform> <url> : Shortens the given URL"
"\n *Ex:* `/short bitly https://t.me/dwindle_bot/`"
"\n - /unshort <url> : Unshorts the given URL"
"\n\t\t- /short <url> : Shortens the given URL"
"\n\t\t- /unshort <url> : Unshorts the given URL"
"\n\t\t- /about : About the bot."
"\n\t\t- /donate: Gives you info on how to support me and my creator.",
parse_mode=telegram.ParseMode.MARKDOWN, reply_to_message_id=update.message.message_id)

Expand All @@ -42,7 +42,7 @@ def aboutTheBot(update, context):
[
telegram.InlineKeyboardButton((emoji.emojize(":loop:", use_aliases=True)) + "Channel",
url="t.me/theostrich"),
telegram.InlineKeyboardButton("👥Support Group", callback_data='2'),
telegram.InlineKeyboardButton("👥Support Group", url="t.me/ostrichdiscussion"),
],
[telegram.InlineKeyboardButton((emoji.emojize(":bookmark:", use_aliases=True)) + "Add Me In Group",
url="https://t.me/dwindle_Bot?startgroup=new")],
Expand Down Expand Up @@ -84,9 +84,7 @@ def donate(update, context):
reply_markup = telegram.InlineKeyboardMarkup(keyboard)
update.message.reply_text("Thank you for your wish to contribute. I hope you enjoyed using our services. Make a small donation/contribute to let this project alive." , reply_markup=reply_markup)

def button(update, context):
query = update.callback_query
query.answer()



def error(update, context):
Expand All @@ -97,10 +95,10 @@ def error(update, context):
def main():
updater = Updater(TOKEN, use_context=True)
dispatcher = updater.dispatcher
updater.dispatcher.add_handler(CallbackQueryHandler(button))

dispatcher.add_handler(CallbackQueryHandler(short_buttons))
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(CommandHandler("help", help))
dispatcher.add_handler(CommandHandler("help", assist))
dispatcher.add_handler(CommandHandler("short", short.short))
dispatcher.add_handler(CommandHandler("unshort", unshort.unshort))
dispatcher.add_handler(CommandHandler("screen", screen.screen))
Expand Down
79 changes: 65 additions & 14 deletions Dwindle/modules/short.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,76 @@
from Dwindle import GpBase, bitlybase, TOKEN
from Dwindle import bitlyApi
import requests
from Dwindle import dispatcher
from telegram.ext import CommandHandler
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
import pyshorteners
import re

platforms = ['bitly', 'chilpit', 'nullpointer']

shortmessage = "<b>Your URL : </b> {} \n\n<b>Shortened URL :</b> \n\n<b> - </b> {}"
''' '''
def short(update, context):
platforms = ['bitly', 'gplinks']
gpintext = requests.get(GpBase + context.args[1]).json()
bitlyintext = requests.get(bitlybase + context.args[1]).json()
bi = bitlyintext['data']
link = context.args[0]

if context.args[0] in platforms:
if context.args[0] == "bitly":
update.message.reply_text("<b>Your URL : </b>" + context.args[1] + "\n\n<b>Shortened URL :</b>"+
"\n\n<b> - </b>" + bi['url'] , parse_mode='html',reply_to_message_id=update.message.message_id)
validurl = r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))"
if len(context.args) > 1:
if context.args[0] == 'bitly':
update.message.reply_text(shortmessage.format(context.args[1], bitly(bitlyApi, context.args[1])),
parse_mode='html',
reply_to_message_id=update.message.message_id)
elif context.args[0] == 'nullpointer':
update.message.reply_text(shortmessage.format(context.args[1], nullpointer(context.args[1])),
parse_mode='html',
reply_to_message_id=update.message.message_id)
elif context.args[0] == 'chilpit':
update.message.reply_text(shortmessage.format(context.args[1], chilpit(context.args[1])),
parse_mode='html',
reply_to_message_id=update.message.message_id)

elif context.args[0] == "gplinks":
update.message.reply_text("<b>Your URL : </b>" + context.args[1] +
"\n\n<b>Shortened URL :</b> "+
"\n\n<b> - </b>" + gpintext['shortenedUrl'] , parse_mode='html',reply_to_message_id=update.message.message_id)
elif len(context.args) == 1:
if re.match(
r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))"
, context.args[0]):
keyboard = [
[
InlineKeyboardButton("bitly", callback_data=f'bitly||{link}'),
InlineKeyboardButton("nullpointer", callback_data=f'nullpointer||{link}'),
],
[InlineKeyboardButton("chilpit", callback_data=f'chilpit||{link}')],
]

reply_markup = InlineKeyboardMarkup(keyboard)

update.message.reply_text('Please choose:', reply_markup=reply_markup)
else:
update.message.reply_text('Provide a valid URL', reply_markup=reply_markup)
else:
update.message.reply_text("Enter A valid Platform")
update.message.reply_text("Provide some url to short")


def bitly(api, url):
return pyshorteners.Shortener(api_key=api).bitly.short(url)

def nullpointer(url):
return pyshorteners.Shortener(domain='https://0x0.st').nullpointer.short(url)

def chilpit(url):
return pyshorteners.Shortener().chilpit.short(url)

def short_buttons(update,context):
query = update.callback_query
query.answer()
platform = (query.data).split("||")[0]
link = (query.data).split("||")[1]
if platform == 'bitly':
shorten = bitly(bitlyApi,link)
query.edit_message_text(text=shortmessage.format(link, shorten), parse_mode='html')

elif platform == 'nullpointer':
shorten = nullpointer(link)
query.edit_message_text(text=shortmessage.format(link, shorten), parse_mode='html')

elif platform == 'chilpit':
shorten = nullpointer(link)
query.edit_message_text(text=shortmessage.format(link, shorten), parse_mode='html')
13 changes: 7 additions & 6 deletions Dwindle/sample-config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
quit(1)

# Create a new config.py file in same dir and import, then extend this class.
# REQUIRED
TOKEN = "" # Your bot Token here
#Recommended
Webhook = False #Set Webhook
PORT = 8443 # Ports currently supported for Webhooks: 443, 80, 88, 8443.

bitlyapi = "" #Get this at https://bitly.is/accesstoken

TOKEN = "" # Your bot Token here
Webhook = "" #webhook url here.(Ex: https://dwindle.heroku.app.If you are using heroku get using the format - https://{your heroku app name here}.herokuapp.com/)
GpApi = "" #Get this at https://bitly.is/accesstoken
GpBase = " https://gplinks.in/api?api={}&url=".format(GpApi)
bitlyapi = "" #Get this at https://bitly.is/accesstoken
bitlybase = "https://api-ssl.bitly.com/v3/shorten?access_token={}&uri=".format(bitlyapi)
4 changes: 0 additions & 4 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
"BitLy_Api": {
"description": "Get this value from https://dev.bitly.com/",
"value": ""
},
"GpLinksApi": {
"description": "Get this value from https://gplinks.in/",
"value": ""
}
},
"formation": {
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ python-telegram-bot==13.1
requests==2.25.1
urllib3==1.26.2
lxml==4.6.2
selenium==3.141.0
selenium==3.141.0
pyshorteners==1.0.1