-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
180 lines (160 loc) · 5.8 KB
/
main.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
# Aradiabot main file + misc functions.
import discord
import asyncio
import random
import tweepy
import json
import booru
import os
import re
import glitch
import requests
import image
#Please provide your own twitter api keys if you want to make use of the tweeting function.
consumer_key = ""
consumer_secret = ""
access_key = ""
access_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
tapi = tweepy.API(auth)
client = discord.Client()
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0'}
# Most of the things in the loot tables were inside jokes.
# Feel free to feel these in yourself.
lootPrefix=["Ancient"]
lootItem=["Sword"]
lootSuffix=["of Fire"]
def lootgen():
return str(random.choice(lootPrefix) + " " + random.choice(lootItem) + " " + random.choice(lootSuffix))
async def tweet(msg, message):
r = re.search(r'<@(.*)>', msg)
r2 = re.search(r'<@!(.*)>', msg)
if r or r2:
for group in r.groups():
for u in message.channel.server.members:
if str(group) == str(u.id):
msg = re.sub(r'<@(.*)>', "@" + str(u.name), msg)
for group in r2.groups():
for u in message.channel.server.members:
if str(group) == str(u.id):
msg = re.sub(r'<@(.*)>', "@" + str(u.name), msg)
imsg = False
print (message.attachments)
if len(message.attachments) == 1:
j = message.attachments[0]
if j["filename"].lower().endswith('.jpg') or j["filename"].lower().endswith('.jpeg') or j["filename"].lower().endswith('.png') or j["filename"].lower().endswith('.gif'):
import urllib.request
fname = j["filename"]
req = urllib.request.Request(j["url"], None, headers)
html = urllib.request.urlopen(req).read()
with open(fname, 'wb') as f:
f.write(html)
imsg = True
try:
if len(msg) > 140:
msg = msg[:140]
if imsg:
tapi.update_with_media(fname, status=msg)
os.remove(fname)
else:
tapi.update_status(msg)
else:
if imsg:
tapi.update_with_media(fname, status=msg)
os.remove(fname)
else:
tapi.update_status(msg)
return "Your message has been sent."
except tweepy.TweepError as e:
print(json.loads(e.response.text))
return json.loads(e.response.text)['errors'][0]['message']
async def loot():
return "You obtain the \'" + lootgen() + "\'! Beep boop."
async def joke():
table = requests.get("http://tambal.azurewebsites.net/joke/random").json()
return str(table["joke"])
async def imgglitch(message):
if len(message.attachments) == 1:
j = message.attachments[0]
print("Validating!")
if j["filename"].lower().endswith('.jpg') or j["filename"].lower().endswith('.jpeg') or j["filename"].lower().endswith('.png') or j["filename"].lower().endswith('.gif'):
print("Downloading!")
import urllib.request
fname = j["filename"]
req = urllib.request.Request(j["url"], None, headers)
html = urllib.request.urlopen(req).read()
with open(fname, 'wb') as f:
f.write(html)
print("Glitching!" + fname)
glitch.genImg(fname)
print("Sending!")
await client.send_file(message.channel,'new' + fname + '.png')
print("Removing!")
os.remove('new' + fname + '.png')
os.remove(fname)
else:
client.send_message(message.channel, "You did not upload an image, or it is corrupt!")
async def liquid(message):
if len(message.attachments) == 1:
j = message.attachments[0]
print("Validating!")
if j["filename"].lower().endswith('.jpg') or j["filename"].lower().endswith('.jpeg') or j["filename"].lower().endswith('.png') or j["filename"].lower().endswith('.gif'):
print("Downloading!")
import urllib.request
fname = j["filename"]
req = urllib.request.Request(j["url"], None, headers)
html = urllib.request.urlopen(req).read()
with open(fname, 'wb') as f:
f.write(html)
print("Glitching!" + fname)
image.liquid(fname)
print("Sending!")
await client.send_file(message.channel,'liqnew' + fname)
print("Removing!")
os.remove('liqnew' + fname)
os.remove(fname)
else:
client.send_message(message.channel, "You did not upload an image, or it is corrupt!")
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
#Booru commands, listed in booru.py
if message.content.startswith('$mom'):
result = await booru.mom()
await client.send_message(message.channel, result)
elif message.content.startswith('$e621'):
result = await booru.e621(message.content[5:])
await client.send_message(message.channel, result)
elif message.content.startswith('$danbooru'):
result = await booru.danbooru(message.content[9:])
await client.send_message(message.channel, result)
elif message.content.startswith('$derpibooru'):
result = await booru.derpibooru(message.content[11:])
await client.send_message(message.channel, result)
elif message.content.startswith('$r34'):
result = await booru.rule34(message.content[4:])
await client.send_message(message.channel, result)
#Image handling functions, listed in glitch.py and image.py
elif message.content.startswith('$glitch'):
await imgglitch(message)
elif message.content.startswith('$liquid'):
await liquid(message)
#Miscellanious commands.
elif message.content.startswith('$joke'):
joked = await joke()
await client.send_message(message.channel, joked)
elif message.content.startswith('$loot'):
pickedup = await loot()
await client.send_message(message.channel, pickedup)
elif message.content.startswith('$tweet'):
returnstatus = await tweet(message.content[6:], message)
await client.send_message(message.channel, returnstatus)
elif message.content.startswith('$help'):
await client.send_message(message.channel, help)
client.run("Here's where your discord client id goes")