-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpammerBot.py
53 lines (44 loc) · 1.58 KB
/
SpammerBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import tweepy
import telebot
from config import *
telegram = telebot.TeleBot(tgToken)
auth = tweepy.OAuthHandler(twConsumerKey, twConsumerSecret)
auth.secure = True
auth.set_access_token(twAccessToken, twAccessTokenSecret)
twitter = tweepy.API(auth)
registeredUser = True
# SCRIPT
def listener(messages):
global registeredUser
for message in messages:
tgContact = message.chat.username
tgChatID = message.chat.id
text = message.text
print tgContact + ": " + text
if message.content_type == "text" and tgContact == tgUsername:
registeredUser = True
print "Registered user"
else:
registeredUser = False
telegram.send_message(tgChatID, "Sorry, you are not allowed to use this bot")
print "Unregistered user, access denied"
@telegram.message_handler(commands=['tweet'])
def command_tweet(tweet):
global registeredUser
tgChatID = tweet.chat.id
twText = tweet.text
twText = twText.replace("/tweet ", "")
if registeredUser:
if len(twText) <= 140 and registeredUser:
twitter.update_status(status=twText)
telegram.send_message(tgChatID, "Tweet successful")
print "Tweet successful"
else:
telegram.send_message(tgChatID, "Sorry, wrong Twitter API Keys or message too long (max: 140 char.)")
print "Sorry, wrong Twitter API Keys or message too long (max: 140 char.)"
telegram.set_update_listener(listener)
telegram.polling()
telegram.polling(none_stop=True)
telegram.polling(interval=1)
while True:
pass