Created
August 7, 2014 22:34
-
-
Save DavidRyan/a1a518f5d374e28f847e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from google.appengine.ext import db | |
from random import randint | |
from google.appengine.api import users | |
import json | |
import urllib2 | |
import urllib | |
from flask import Flask | |
from flask import request | |
from threading import Timer | |
app = Flask(__name__) | |
post_url = 'https://api.groupme.com/v3/bots/post' | |
ban_url = "https://api.groupme.com/v3/token/5bb6de9a1000ea590bc5a4cee0/groups/9345883/members/3026882/remove" | |
bot_id = '5bb6de9a1000ea590bc5a4cee0' | |
class User(db.Model): | |
name = db.StringProperty(required = True) | |
user_id = db.StringProperty(required = True) | |
post_count = db.IntegerProperty(required = True) | |
join_date = db.DateProperty() | |
if __name__ == "__main__": | |
app.run() | |
@app.route('/trolljamie', methods=['GET', 'POST']) | |
def jamie_troll(): | |
rand = randint(1,6) | |
# post(jamie_trolls[6]) | |
jamie_trolls = { | |
1:"Jamie...", | |
2:"I'm watching you Jamie...", | |
3:"You have no idea whats coming Jamie.", | |
4:"Big things Jamie..", | |
5:"Be careful Jamie...", | |
6:"Watch your back Jamie." | |
} | |
@app.route('/', methods=['GET', 'POST']) | |
def bot(): | |
if request.method == 'POST': | |
msg = json.loads(request.data) | |
user_id = msg['user_id'] | |
if user_id == '164428': | |
pass | |
elif user_id == '3021181': | |
if "podbot" in msg['text'].lower(): | |
post("Fuck you jamie") | |
return | |
else: | |
route(msg) | |
q = User.all() | |
q.filter('user_id =', user_id) | |
poster = q.get() | |
if poster is None: | |
new_member = User(name=msg['name'].lower(), user_id=msg['user_id'], post_count = 1) | |
new_member.join_date = datetime.datetime.now().date() | |
new_member.put() | |
else: | |
posts = poster.post_count; | |
new_posts = posts+1 | |
poster.post_count = posts+1 | |
if poster.name != msg['name']: | |
poster.name = msg['name'].lower() | |
poster.put() | |
else: | |
return "Home of PodBot" | |
return " " | |
def get_ball(): | |
i = randint(1,20) | |
post(ball[i]) | |
def fish(message): | |
end = message[5:] | |
if '/slap' in end: | |
return | |
post("*slaps" + end + " around a bit with a large trout*") | |
def cockslap(message): | |
end = message[9:] | |
if '/cockslap' in end: | |
return | |
post("*cock slaps" + end + " a bit*") | |
def post(message): | |
payload = get_payload(message) | |
data = urllib.urlencode(payload) | |
req = urllib2.Request(post_url, data) | |
response = urllib2.urlopen(req) | |
def cats(): | |
post('http://i.imgur.com/hfmy8.jpg') | |
def get_payload(msg): | |
payload= {'text' : msg, | |
'bot_id' : bot_id} | |
return payload | |
def numbers(message): | |
number = message[8:] | |
url = 'http://numbersapi.com/' + number | |
response = urllib2.urlopen(url) | |
html = response.read() | |
post(html) | |
def get_user(user): | |
q = User.all() | |
q.filter('name =', "" + user + "") | |
poster = q.get() | |
return poster | |
def post_count(user): | |
poster = get_user(user) | |
if poster is None: | |
return(user + " not found") | |
else: | |
posts = poster.post_count | |
return posts | |
def get_posts(user): | |
post(user + " Posts: " + str(post_count(user))) | |
def post_per_day(user): | |
count = post_count(user) | |
today = datetime.datetime.now().date() | |
joined = get_user(user).join_date | |
diff = (today - joined) | |
days = diff.total_seconds() / (60 * 60 * 24) | |
days = days+1 | |
if days is 0: | |
return 0 | |
avg = count / days | |
return avg | |
def total_posts(): | |
q = User.all() | |
i = 0 | |
for user in q: | |
i += post_count(user.name) | |
return i | |
def ppd(): | |
q = User.all() | |
i = 0 | |
today = datetime.datetime.now().date() | |
joined = get_user(q.get().name).join_date | |
diff = (today - joined) | |
days = diff.total_seconds() / (60 * 60 * 24) | |
i = total_posts() | |
avg = i / days | |
def ban(user): | |
response = urllib2.urlopen(ban_url) | |
html = response.read() | |
post(html) | |
#Timer(14000, unban, user).start() | |
def unban(user): | |
payload = {"members": [{"nickname": "banned faggot", "user_id": user}]} | |
def leaderboard(): | |
q = User.all() | |
q.order('-post_count') | |
i = 0 | |
for user in q: | |
posts = str(format(post_per_day(user.name), ".1f")) | |
if user.name != 'groupme' and user.name != 'podbot': | |
if i == 0: | |
try: | |
post("LEADER: " + user.name + " PPD: " + posts) | |
except UnicodeEncodeError: | |
post("Faggot with stupid name " + " PPD: " + posts) | |
pass | |
else: | |
try: | |
post(user.name + " PPD: " + posts) | |
except UnicodeEncodeError: | |
post("Faggot with stupid name " + " PPD: " + posts) | |
pass | |
i+=1 | |
def random(): | |
q = User.all() | |
i = 0 | |
rand = randint(0,8) | |
for user in q: | |
if i == rand: | |
post ("I choose " + user.name) | |
i+=1 | |
def insult(text): | |
url = 'http://quandyfactory.com/insult/json' | |
page = urllib.urlopen(url) | |
contents = page.read() | |
insult = json.loads(contents) | |
print insult | |
post(text + ", " + insult['insult']) | |
ball = { | |
1:'It is decidedly so', | |
2:'Without a doubt', | |
3:'Yes definitely', | |
4:'You may rely on it', | |
5:'As I see it, yes', | |
6:'Most likely', | |
7:'Outlook good', | |
8:'Yes', | |
9:'Signs point to yes', | |
10:'Reply hazy try again', | |
11:'Ask again later', | |
12:'Better not tell you now', | |
13:'Cannot predict now', | |
14:'Concentrate and ask again', | |
15:'Don\'t count on it', | |
16:'My reply is no', | |
17:'My sources say no', | |
18:'Outlook not so good', | |
19:'Very doubtful', | |
20:'It is certain' | |
} | |
def route(msg): | |
text = msg['text'].lower() | |
if 'i love you podbot' in text: | |
post("<3") | |
return " " | |
if 'choose a faggot' in text: | |
random() | |
return " " | |
if '/leaderboard' in text: | |
leaderboard() | |
return " " | |
if '/8ball' in text: | |
get_ball() | |
return " " | |
if 'hey podbot,' in text: | |
get_ball() | |
return " " | |
if '/posts' in text: | |
get_posts(text[7:]) | |
return " " | |
if '/insult' in text: | |
insult(text[8:]) | |
return " " | |
if '/postavg' in text: | |
post("Post Per Day: " + str(post_per_day(text[9:]))) | |
return " " | |
if 'im gay' in text: | |
post("ur gay") | |
return " " | |
if 'tribe' in text: | |
post("No one cares") | |
return " " | |
if 'indians' in text: | |
post("No one cares") | |
return " " | |
if 'amirite' in text: | |
post("You are right") | |
return " " | |
if 'just you and me' in text: | |
post("Forever") | |
return " " | |
if '/slap' in text: | |
fish(text) | |
return " " | |
if '/cockslap' in text: | |
cockslap(text) | |
return " " | |
if 'ugh' in text: | |
if text.__len__() != 3: | |
return " " | |
return " " | |
if 'i\'m gay' in text: | |
post("ur gay") | |
return " " | |
if 'jamie' in text: | |
#post("ugh") | |
return " " | |
if 'cleveland' in text: | |
post("sage") | |
return " " | |
if 'existenz' in text: | |
post("sage") | |
return " " | |
if 'podbot' in text: | |
if text.__len__() != 6: | |
return " " | |
if 'love' not in text: | |
post("Yes?") | |
return " " | |
if 'browns' in text: | |
post("sage") | |
return " " | |
if 'blasterjaxx' in text: | |
post("sage") | |
return " " | |
if 'the council has spoken' in text: | |
cats() | |
return " " | |
if '/number' in text: | |
numbers(text) | |
return " " | |
if '/total_posts' in text: | |
post("Total Posts: " + str(total_posts())) | |
return " " | |
if '/total_ppd' in text: | |
post("Pod PPD: " + str(ppd())) | |
return " " | |
if '/stats' in text: | |
post("Total Posts: " + str(total_posts())) | |
leaderboard() | |
return " " | |
if ':large' in text: | |
new_text = msg['text'].split(':') | |
post(new_text[0] + ":" + new_text[1]) | |
return " " | |
if '/ban' in text: | |
ban("asdf") | |
return " " | |
return " " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment