-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
65 lines (43 loc) · 1.31 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
"""OOFS
Usage:
main.py upload <filename>
main.py download <filename>
main.py delete <filename>
Options:
-h --help Shows this screen.
--about Shows what this is about.
--version Shows version.
"""
from docopt import docopt
import io
import discord
from discord import File
from diskcollections.iterables import FileList
import splitter
from database import DBwrapper
import argparse
BotChannel = 642818966825336835
db = DBwrapper("db.json")
client = discord.Client()
async def upload(filename, VirtualPath):
chunks = splitter.chunk(filename, 1000000)
db.addFile(VirtualPath, [], [])
i = 0
for chunk in chunks:
i += 1
m = await client.guilds[0].text_channels[0].send(file=File(chunk, filename=str(i)))
db.addChunk(VirtualPath, m.id)
async def download(VirtualPath):
Ids = db.getChunks(VirtualPath) # List of message IDs
tosave = io.BytesIO()
for id in Ids:
message = await client.get_channel(BotChannel).fetch_message(id)
await message.attachments[0].save(tosave, seek_begin=False, use_cached=False)
return tosave
@client.event
async def on_ready():
flist = FileList()
if __name__ == "__main__":
arguments = docopt(__doc__, version="OOFS v1.0.0")
print(arguments)
client.run(open(".env", "r").read())