Skip to content

Commit 879a844

Browse files
committed
[UPDATE] tweepy to v4.3.0 and fix Security Inline Bugs
1 parent 59da069 commit 879a844

File tree

15 files changed

+243
-175
lines changed

15 files changed

+243
-175
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.env
2+
*.session
3+
4+
__pycache__\
5+
downloads\
6+
7+
twitterbot/plugins/test*

Configs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class Var:
55
API_ID = config("API_ID", default=6)
6-
API_HASH = config("API_HASH", None)
6+
API_HASH = config("API_HASH", default="eb06d4abfb49dc3eeb1aeb98ae0f581e")
77
BOT_TOKEN = config("BOT_TOKEN", None)
88
CONSUMER_KEY = config("CONSUMER_KEY", None)
99
CONSUMER_SECRET = config("CONSUMER_SECRET", None)

requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pyrogram
2-
python-decouple
3-
tgcrypto
4-
tweepy==3.10.0
1+
pyrogram<=1.2.20
2+
python-decouple<=3.3
3+
tgcrypto==1.2.2
4+
tweepy==4.3.0

runtime.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
python-3.9.5
1+
python-3.9.9

twitterbot/__init__.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
# You should have received a copy of the GNU Affero General Public License
55
# along with this program. If not, see <https://www.gnu.org/licenses/>.
66

7+
import logging
8+
9+
logging.basicConfig(level=logging.INFO)
10+
711
import tweepy
812
from Configs import Var
913
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton as Button
1014

15+
LOGGER = logging.getLogger("TGTwitterBot")
1116

12-
AUTH = list(int(a) for a in Var.AUTHUSERS.split(" "))
17+
AUTH = list(set(int(a) for a in Var.AUTHUSERS.split()))
1318
HNDLR = Var.HNDLR
1419

1520
auth = tweepy.OAuthHandler(Var.CONSUMER_KEY, Var.CONSUMER_SECRET)
@@ -20,13 +25,11 @@
2025
TLOGO = "https://telegra.ph/file/845054582c76963620311.jpg"
2126

2227
HELP_MARKUP = InlineKeyboardMarkup(
23-
[[Button(text="Home Tweets",
24-
switch_inline_query_current_chat="home")],
25-
[Button(text="Favorites",
26-
switch_inline_query_current_chat="favorites")],
27-
[Button(text="Mentions",
28-
switch_inline_query_current_chat="mentions")],
29-
[Button(text="Search Tweets",
30-
switch_inline_query_current_chat="search quote")],
31-
[Button(text="Search User",
32-
switch_inline_query_current_chat="user NewDev0")]])
28+
[
29+
[Button(text="Home Tweets", switch_inline_query_current_chat="home")],
30+
[Button(text="Favorites", switch_inline_query_current_chat="favorites")],
31+
[Button(text="Mentions", switch_inline_query_current_chat="mentions")],
32+
[Button(text="Search Tweets", switch_inline_query_current_chat="search quote")],
33+
[Button(text="Search User", switch_inline_query_current_chat="user NewDev0")],
34+
]
35+
)

twitterbot/__main__.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@
44
# You should have received a copy of the GNU Affero General Public License
55
# along with this program. If not, see <https://www.gnu.org/licenses/>.
66

7+
from . import LOGGER
78
from Configs import Var
89
from pyrogram import Client, idle
910

10-
import logging
11-
logging.basicConfig(level=logging.WARNING)
12-
13-
Client = Client("TgTwitterBot",
14-
api_id=Var.API_ID,
15-
api_hash=Var.API_HASH,
16-
bot_token=Var.BOT_TOKEN,
17-
plugins=dict(
18-
root="twitterbot/plugins"
19-
)
20-
)
11+
Client = Client(
12+
"TgTwitterBot",
13+
api_id=Var.API_ID,
14+
api_hash=Var.API_HASH,
15+
bot_token=Var.BOT_TOKEN,
16+
plugins=dict(root="twitterbot/plugins"),
17+
)
2118

2219
Client.start()
2320

2421
Client = Client.get_me()
25-
print(f"@{Client.username} Deployed Successfully!")
26-
print("Your Tg-Twitter-Bot is Alive 🎉")
22+
LOGGER.info(f"@{Client.username} Deployed Successfully!")
23+
LOGGER.info("Your Tg-Twitter-Bot is Alive 🎉")
2724

2825
idle()

twitterbot/funcs.py

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
InlineKeyboardButton,
99
InlineKeyboardMarkup,
1010
InlineQueryResultArticle,
11-
InputTextMessageContent
11+
InputTextMessageContent,
1212
)
1313

1414

@@ -22,7 +22,7 @@ def mkease(counts, cstatus):
2222

2323

2424
def simstuff(user):
25-
uname = user['screen_name']
25+
uname = user["screen_name"]
2626
text = "#User #Twitterbot\n\n"
2727
text += "**⫸ Details\nName** -> " + user["name"]
2828
text += f"\n**Username** -> [@{uname}](https://twitter.com/{uname})\n\n"
@@ -40,14 +40,17 @@ def tweeteazy(bunch):
4040
ds = "#Tweet"
4141
ds += "\n\n" + ct["text"] + "\n" + cm
4242
reply_markup = status_reply_markup(one)
43-
results.append(InlineQueryResultArticle(
44-
title=ct["text"],
45-
description=f"@{uname}",
46-
thumb_url=ct["user"]["profile_image_url"],
47-
reply_markup=InlineKeyboardMarkup(reply_markup),
48-
input_message_content=InputTextMessageContent(
49-
ds,
50-
disable_web_page_preview=True)))
43+
results.append(
44+
InlineQueryResultArticle(
45+
title=ct["text"],
46+
description=f"@{uname}",
47+
thumb_url=ct["user"]["profile_image_url"],
48+
reply_markup=InlineKeyboardMarkup(reply_markup),
49+
input_message_content=InputTextMessageContent(
50+
ds, disable_web_page_preview=True
51+
),
52+
)
53+
)
5154
return results[:50]
5255

5356

@@ -56,16 +59,20 @@ def user_eazy(bunch):
5659
for one in bunch:
5760
user = one._json
5861
text = simstuff(user)
59-
uname = user['screen_name']
62+
uname = user["screen_name"]
6063
reply_markup = InlineKeyboardMarkup(user_reply_markup(one))
61-
result.append(InlineQueryResultArticle(
62-
title=user["name"],
63-
description=f"@{uname}",
64-
url="https://twitter.com/" + uname,
65-
thumb_url=user["profile_image_url"],
66-
reply_markup=reply_markup,
67-
input_message_content=InputTextMessageContent(
68-
text, disable_web_page_preview=True)))
64+
result.append(
65+
InlineQueryResultArticle(
66+
title=user["name"],
67+
description=f"@{uname}",
68+
url="https://twitter.com/" + uname,
69+
thumb_url=user["profile_image_url"],
70+
reply_markup=reply_markup,
71+
input_message_content=InputTextMessageContent(
72+
text, disable_web_page_preview=True
73+
),
74+
)
75+
)
6976
return result[:50]
7077

7178

@@ -83,15 +90,18 @@ def status_reply_markup(status):
8390
rt_ = "rt"
8491
rt_btn = "Re-Tweet"
8592
Link = "https://twitter.com/" + user["screen_name"]
86-
Link += "/status/" + str(status['id'])
87-
COL_1 = [InlineKeyboardButton("View", url=Link),
88-
InlineKeyboardButton("User", callback_data=f"user{user['id']}")]
93+
Link += "/status/" + str(status["id"])
94+
COL_1 = [
95+
InlineKeyboardButton("View", url=Link),
96+
InlineKeyboardButton("User", callback_data=f"user{user['id']}"),
97+
]
8998
OUT.append(COL_1)
90-
OUT.append([InlineKeyboardButton(
91-
favbutn,
92-
callback_data=f"favr_{is_fav}_{status['id']}")])
93-
OUT.append([InlineKeyboardButton(
94-
rt_btn, callback_data=f"rtt_{rt_}_{status['id']}")])
99+
OUT.append(
100+
[InlineKeyboardButton(favbutn, callback_data=f"favr_{is_fav}_{status['id']}")]
101+
)
102+
OUT.append(
103+
[InlineKeyboardButton(rt_btn, callback_data=f"rtt_{rt_}_{status['id']}")]
104+
)
95105
return OUT
96106

97107

@@ -103,11 +113,12 @@ def user_reply_markup(user):
103113
if user["following"]:
104114
fl = "fl"
105115
fl_but = "UnFollow"
106-
Link = "https://twitter.com/" + user['screen_name']
107-
OUT.append([InlineKeyboardButton("View", url=Link),
108-
InlineKeyboardButton(
109-
fl_but,
110-
callback_data=f"fuflow_{fl}_{user['id']}")])
111-
OUT.append([InlineKeyboardButton(
112-
text="Help Menu", callback_data="openmenu")])
116+
Link = "https://twitter.com/" + user["screen_name"]
117+
OUT.append(
118+
[
119+
InlineKeyboardButton("View", url=Link),
120+
InlineKeyboardButton(fl_but, callback_data=f"fuflow_{fl}_{user['id']}"),
121+
]
122+
)
123+
OUT.append([InlineKeyboardButton(text="Help Menu", callback_data="openmenu")])
113124
return OUT

twitterbot/plugins/_helper.py

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
InlineQueryResultArticle,
1212
InputTextMessageContent,
1313
InlineKeyboardButton,
14-
InlineKeyboardMarkup
14+
InlineKeyboardMarkup,
1515
)
1616

1717

@@ -24,53 +24,59 @@
2424
Send {HLR}help to explore !
2525
"""
2626

27+
2728
def limit_check(client, query):
28-
if len(query.query)==0:
29+
if len(query.query) == 0:
2930
return True
3031
return False
3132

3233

3334
@Client.on_inline_query(~filters.user(AUTH))
3435
async def _andshow(client, query):
35-
res = InlineQueryResultArticle(title="❌ Un-Authorised User",
36+
res = InlineQueryResultArticle(
37+
title="❌ Un-Authorised User",
3638
description="© New-dev0",
3739
url=REPO,
38-
input_message_content=InputTextMessageContent("You are not Authorized To Use Me!"),
39-
reply_markup=InlineKeyboardMarkup([[InlineKeyboardButton(text="Deploy Your own",url=REPO)]]))
40-
await query.answer([res], switch_pm_text="🤖 TgTwitterBot!",
41-
switch_pm_parameter="start")
42-
43-
44-
@Client.on_message(filters.command("start", prefixes=HNDLR)
45-
& filters.user(AUTH))
40+
input_message_content=InputTextMessageContent(
41+
"You are not Authorized To Use Me!"
42+
),
43+
reply_markup=InlineKeyboardMarkup(
44+
[[InlineKeyboardButton(text="Deploy Your own", url=REPO)]]
45+
),
46+
)
47+
await query.answer(
48+
[res], is_personal=True,
49+
switch_pm_text="🤖 TgTwitterBot!", switch_pm_parameter="start"
50+
)
51+
52+
53+
@Client.on_message(filters.command("start", prefixes=HNDLR) & filters.user(AUTH))
4654
async def startmsg(client, message):
47-
reply_markup = InlineKeyboardMarkup([
48-
[InlineKeyboardButton(text="Support Group",
49-
url="t.me/FutureCodesChat")],
50-
[InlineKeyboardButton(
51-
text="Repo",
52-
url=REPO)]])
55+
reply_markup = InlineKeyboardMarkup(
56+
[
57+
[InlineKeyboardButton(text="Support Group", url="t.me/FutureCodesChat")],
58+
[InlineKeyboardButton(text="Repo", url=REPO)],
59+
]
60+
)
5361
await message.reply_text(
54-
START_MSG.format(frm=message.from_user.mention,
55-
HLR=HNDLR),
62+
START_MSG.format(frm=message.from_user.mention, HLR=HNDLR),
5663
reply_markup=reply_markup,
57-
quote=True)
64+
quote=True,
65+
)
5866

5967

6068
@Client.on_inline_query(filters.user(AUTH) & limit_check)
6169
async def myinline(client, query):
62-
if query.from_user.id not in AUTH:
63-
return
64-
out = [InlineQueryResultArticle(
65-
title="TwitterBot",
66-
description="Help Menu",
67-
thumb_url=TLOGO,
68-
input_message_content=InputTextMessageContent(
69-
"Telegram - Twitter - Bot"),
70-
reply_markup=HELP_MARKUP)]
71-
await query.answer(out,
72-
switch_pm_text="HELP Portal",
73-
switch_pm_parameter="start")
70+
out = [
71+
InlineQueryResultArticle(
72+
title="TwitterBot",
73+
description="Help Menu",
74+
thumb_url=TLOGO,
75+
input_message_content=InputTextMessageContent("Telegram - Twitter - Bot"),
76+
reply_markup=HELP_MARKUP,
77+
)
78+
]
79+
await query.answer(out, is_personal=True, switch_pm_text="HELP Portal", switch_pm_parameter="start")
7480

7581

7682
HEMENU = f"""
@@ -81,11 +87,9 @@ async def myinline(client, query):
8187
"""
8288

8389

84-
@Client.on_message(filters.command("help", prefixes=HNDLR)
85-
& filters.user(AUTH))
90+
@Client.on_message(filters.command("help", prefixes=HNDLR) & filters.user(AUTH))
8691
async def shelpmsg(client, message):
87-
reply_markup = InlineKeyboardMarkup([
88-
[InlineKeyboardButton(text="INLINE HELP", callback_data="openmenu")]])
89-
await message.reply_text(HEMENU,
90-
reply_markup=reply_markup,
91-
quote=True)
92+
reply_markup = InlineKeyboardMarkup(
93+
[[InlineKeyboardButton(text="INLINE HELP", callback_data="openmenu")]]
94+
)
95+
await message.reply_text(HEMENU, is_personal=True, reply_markup=reply_markup, quote=True)

0 commit comments

Comments
 (0)