diff --git a/Dwindle/__init__.py b/Dwindle/__init__.py
index d239843..b33d080 100644
--- a/Dwindle/__init__.py
+++ b/Dwindle/__init__.py
@@ -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
diff --git a/Dwindle/__main__.py b/Dwindle/__main__.py
index 5beb2cc..5beef62 100644
--- a/Dwindle/__main__.py
+++ b/Dwindle/__main__.py
@@ -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
@@ -15,22 +15,22 @@
def start(update, context):
update.message.reply_text(
"Hi {} {} ! \n\nI'm Dwindle - 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 /help to find out more about how to use me.".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 : Shortens the given URL"
- "\n *Ex:* `/short bitly https://t.me/dwindle_bot/`"
- "\n - /unshort : Unshorts the given URL"
+ "\n\t\t- /short : Shortens the given URL"
+ "\n\t\t- /unshort : 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)
@@ -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")],
@@ -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):
@@ -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))
diff --git a/Dwindle/modules/short.py b/Dwindle/modules/short.py
index 9e9d9ae..966718e 100644
--- a/Dwindle/modules/short.py
+++ b/Dwindle/modules/short.py
@@ -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 = "Your URL : {} \n\nShortened URL : \n\n - {}"
+''' '''
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("Your URL : " + context.args[1] + "\n\nShortened URL :"+
- "\n\n - " + 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("Your URL : " + context.args[1] +
- "\n\nShortened URL : "+
- "\n\n - " + 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')
diff --git a/Dwindle/sample-config.py b/Dwindle/sample-config.py
index 5677aea..30de5ad 100644
--- a/Dwindle/sample-config.py
+++ b/Dwindle/sample-config.py
@@ -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)
diff --git a/app.json b/app.json
index 2b28a0d..741a521 100644
--- a/app.json
+++ b/app.json
@@ -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": {
diff --git a/requirements.txt b/requirements.txt
index 96fae6a..faa1fca 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -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
\ No newline at end of file
+selenium==3.141.0
+pyshorteners==1.0.1