-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.py
149 lines (144 loc) · 5.22 KB
/
run.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
from config.emoji_unicodefix import *
#import above is a fix i found so emojis dont make it crash^^
from config.config import *
import os
import shutil
import sys
import discord
import datetime
import requests
client = discord.Client()
@client.event
async def on_ready():
print("Ready, logged messages: ")
#Check if a the given directory exists, if not create it
def createFolder(directory):
try:
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
print ('Error: Creating directory. ' + directory)
#messy ass code soz in advance
@client.event
async def on_message(message):
image = "/image"
now = datetime.datetime.now()
now = now.strftime("%m-%d-%y %H;%M;%S")
m = str(message.content)
a = str(message.author)
for att in message.attachments:
attachment = att.get("url").lower()
filename = attachment.split('/')[-1]
if message.channel.is_private:
if filename.find(".png") != -1:
r = requests.get(attachment, allow_redirects=True)
open('./PMS/image/'+a+" - "+now+".png", 'wb').write(r.content)
if filename.find(".jpg") != -1:
r = requests.get(attachment, allow_redirects=True)
open('./PMS/image/'+a+" - "+now+".jpg", 'wb').write(r.content)
if filename.find(".gif") != -1:
r = requests.get(attachment, allow_redirects=True)
open('./PMS/image/'+a+" - "+now+".gif", 'wb').write(r.content)
if filename.find(".mp4") != -1:
r = requests.get(attachment, allow_redirects=True)
open('./PMS/image/'+a+" - "+now+".mp4", 'wb').write(r.content)
if filename.find(".mov") != -1:
r = requests.get(attachment, allow_redirects=True)
open('./PMS/image/'+a+" - "+now+".mov", 'wb').write(r.content)
if filename.find(".webm") != -1:
r = requests.get(attachment, allow_redirects=True)
open('./PMS/image/'+a+" - "+now+".webm", 'wb').write(r.content)
if filename.find(".txt") != -1:
r = requests.get(attachment, allow_redirects=True)
open('./PMS/image/'+a+" - "+now+".txt", 'wb').write(r.content)
else:
s = message.server.name
if filename.find(".png") != -1:
r = requests.get(attachment, allow_redirects=True)
open(s +'/image/'+a+" - "+now+".png", 'wb').write(r.content)
if filename.find(".jpg") != -1:
r = requests.get(attachment, allow_redirects=True)
open(s +'/image/'+a+" - "+now+".jpg", 'wb').write(r.content)
if filename.find(".gif") != -1:
r = requests.get(attachment, allow_redirects=True)
open(s +'/image/'+a+" - "+now+".gif", 'wb').write(r.content)
elif filename.find(".mp4") != -1:
r = requests.get(attachment, allow_redirects=True)
open(s +'/image/'+a+" - "+now+".mp4", 'wb').write(r.content)
elif filename.find(".mov") != -1:
r = requests.get(attachment, allow_redirects=True)
open(s +'/image/'+a+" - "+now+".mov", 'wb').write(r.content)
elif filename.find(".webm") != -1:
r = requests.get(attachment, allow_redirects=True)
open(s +'/image/'+a+" - "+now+".webm", 'wb').write(r.content)
elif filename.find(".txt") != -1:
r = requests.get(attachment, allow_redirects=True)
open(s +'/image/'+a+" - "+now+".txt", 'wb').write(r.content)
#check if message has an attachment, if it does save it and print the url
if message.attachments:
#pms
if message.channel.is_private:
#create folders
createFolder("PMS")
createFolder("PMS"+image)
#print logged message & attachment URL.
maintsr = now+ "(PM) " + str(a) + ': ' + str(m) + " " + att.get("url")
print(maintsr)
#write logged message & attachemnt URL to file
writepath = "PMS/pms.txt"
mode = 'a' if os.path.exists(writepath) else 'w'
aaa = open(writepath, mode, encoding='utf-8')
aaa.write(maintsr +'\n')
aaa.close()
#servers
else:
s = str(message.server.name)
c = str(message.channel.name)
#create folders
createFolder(s)
createFolder(s+image)
e = ".txt"
#print logged message & attachment URL.
maintsr = "["+now+"] "+"(" + message.server.name +"/" +message.channel.name +") " + str(a) + ': ' + str(m) + " " + att.get("url")
print(maintsr)
#write logged message & attachemnt URL to file
writepath = s + "/" + s + e
mode = 'a' if os.path.exists(writepath) else 'w'
text_file = open(writepath, mode, encoding='utf-8')
text_file.write(maintsr +'\n')
text_file.close()
#no attachments:
else:
#pms
if message.channel.is_private:
#print logged message
maintsr = "["+now+"] "+"(PM) " + str(a) + ': ' + str(m)
print(maintsr)
#create folders
createFolder("PMS")
createFolder("PMS"+image)
#write logged messages to file
writepath = "PMS/pms.txt"
mode = 'a' if os.path.exists(writepath) else 'w'
aaa = open(writepath, mode, encoding='utf-8')
aaa.write(maintsr +'\n')
aaa.close()
#servers
else:
s = message.server.name
c = message.channel.name
f = s
#create folders
createFolder(s)
createFolder(s+image)
#print logged message
maintsr = "["+now+"] "+"(" + message.server.name +"/" +message.channel.name +") " + str(a) + ': ' + str(m)
print(maintsr)
#write logged messages to file
e = ".txt"
writepath = f + "/" + s + e
mode = 'a' if os.path.exists(writepath) else 'w'
text_file = open(writepath, mode, encoding='utf-8')
text_file.write(maintsr +'\n')
text_file.close()
client.run(token, bot=False)