-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstdBot.py
186 lines (145 loc) · 4.76 KB
/
stdBot.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
###################################
# stdBot Module
###################################
# Module where the Bot class is defined
# and some variants
#
#
# For twiting bots
#
# All the authentication is now done with oauth
from oauth import oauth
from oauthtwitter import OAuthApi
#import pprint
#import os
#
# For facebookers
#
#import facebook
import random
import time
# Gravatar stuff yet to be implemented
# Check http://en.gravatar.com/site/implement/python
# import urllib, hashlib
# skynetready
try:
import skynet
except ImportError:
print 'Skynet still unavailable'
# the Bot class
class Bot:
# its supposed that all bots will interact using twitter and
# facebook apps
# tw_data={'mood':10, # mood affects the behaviour
# 'tuser':'', # twitter username
# 'tpass':'', # twitter password
# 'consumer_key':'',
# 'consumer_secret':'',
# 'atoken':'',
# 'stoken':''}
mood = 10.0 # mood affects the behaviour
tuser = '' # twitter username
tpass = '' # twitter password
consumer_key = ''
consumer_secret = ''
atoken = ''
stoken = ''
tApi = OAuthApi(consumer_key,consumer_secret) # Api
email = '' # respectable bots have a valid email
# Should be a service providing an API
emailpass = ''
message = '' # for messages construction
def random_item(self,token):
"""Picks a random item from a list.
"""
return token[int(random.random()*len(token))]
def twit_authenticate(self):
"""Begin a twitter session.
"""
self.tApi= OAuthApi(self.consumer_key, self.consumer_secret, self.atoken, self.stoken)
def twit_deauthenticate(self):#deprecated
#self.tApi.ClearCredentials()
"""Deprecated.
Left for compatibility with older versions.
"""
pass
def twit_twit(self,token):
"""Post a new status.
"""
self.tApi.UpdateStatus(token[0:140])
def twit_get_user_updates(self,usrname,num):
"""Get the last updates from a specific user.
"""
return self.tApi.GetUserTimeline(user=usrname,count=num)
def Bot_sleep_random(self,ctime,sigtime):
""" Sleep a randomized amount of time.
"""
time.sleep(random.gauss(mu=ctime,sigma=sigtime))
def Bot_sleep(self,token):
""" Sleep a fixed amount of time
"""
time.sleep(token) # token in seconds
# DO NOT UNCOMMENT Skynet stuff
# yes it is a common feature of all bots to be able
# to get linked to Skynet
# def connect_to_Skynet(self):
# Skynet.TakeOverBotMind(self)
# presenting the RantBot
class RantBot(Bot):
# some string lists so it can play with them
rantstuff={ 'rants':[''],
'phrases':[''],
'nouns':[''],
'enemys':['']}
def RandomTwitRant(self):
"""Generate a random rant and post it.
"""
# Construct a 140 char message
while (1):
self.message = (self.random_item(self.rantstuff['rants'])+' '
+self.random_item(self.rantstuff['phrases']))
if len(self.message)<=140:
break
self.tApi.UpdateStatus(self.message)
def RandomFakeRTwit(self,target):
"""Generate a random fake retweet
"""
# Construct a 140 char message
while (1):
self.message = ('RT @'+target+': '+self.random_item(self.rantstuff['rants'])+
' '+self.random_item(self.rantstuff['phrases']))
if len(self.message)<=140:
break
self.tApi.UpdateStatus(self.message)
# SPAM Bot
class SpamBot(Bot):
# some string lists so it can play with them
products = ['viagra','cialis']
targets = ['']
nouns = ['']
retailers = ['']
def RandomTwitSpam(self):
# Construct a 140 char message
while (1):
self.message = 'Buy '+self.random_item(self.product)+' at '+self.random_item(self.retailers)
if len(self.message)<=140:
break
self.tApi.UpdateStatus(self.message)
def RandomDirectTwitSpam(self,target):
# Construct a 140 char message
while (1):
self.message = ('@'+target+' Buy '+self.random_item(self.product)
+' at '+self.random_item(self.retailers))
if len(self.message)<=140: break
self.tApi.UpdateStatus(self.message)
#
# MegaBot
#
# A bot that gets the abilities of those who defeats
# NO RECURSION PLEASE!!
class MegaBot(Bot):
beatenBots = [] # a list of beatenBots
maxHP = 100.0
currHp= 100.0
def TakePowers(self,beatBot):
self.beatenBots.append(beatBot)