forked from gooberinc/goober
updated fileshare.py
This commit is contained in:
parent
18aa1c998f
commit
93b6589643
1 changed files with 19 additions and 10 deletions
|
@ -1,4 +1,5 @@
|
||||||
import discord
|
import discord
|
||||||
|
import discord.context_managers
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from modules.globalvars import ownerid
|
from modules.globalvars import ownerid
|
||||||
class FileSync(commands.Cog):
|
class FileSync(commands.Cog):
|
||||||
|
@ -9,7 +10,7 @@ class FileSync(commands.Cog):
|
||||||
self.awaiting_file = False
|
self.awaiting_file = False
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def syncfile(self, ctx, mode: str, peer: discord.User):
|
async def syncfile(self, ctx: commands.Context, mode: str, peer: discord.User):
|
||||||
self.mode = mode.lower()
|
self.mode = mode.lower()
|
||||||
self.peer_id = peer.id
|
self.peer_id = peer.id
|
||||||
if ctx.author.id != ownerid:
|
if ctx.author.id != ownerid:
|
||||||
|
@ -27,22 +28,30 @@ class FileSync(commands.Cog):
|
||||||
|
|
||||||
|
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_message(self, message):
|
async def on_message(self, message: discord.Message):
|
||||||
if message.author == self.bot.user or not self.awaiting_file:
|
if message.author == self.bot.user or not self.awaiting_file:
|
||||||
return
|
return
|
||||||
|
|
||||||
if message.author.id != self.peer_id:
|
if message.author.id != self.peer_id:
|
||||||
return
|
return
|
||||||
|
|
||||||
if message.content == "FILE_TRANSFER_REQUEST":
|
if message.content == "FILE_TRANSFER_REQUEST":
|
||||||
print("Ping received. Awaiting file...")
|
print("Ping received. Awaiting file...")
|
||||||
if message.attachments:
|
if not message.attachments:
|
||||||
for attachment in message.attachments:
|
return
|
||||||
if attachment.filename.endswith(".json"):
|
|
||||||
filename = "received_memory.json"
|
|
||||||
await attachment.save(filename)
|
for attachment in message.attachments:
|
||||||
print(f"File saved as {filename}")
|
if not attachment.filename.endswith(".json"):
|
||||||
await message.channel.send("File received and saved.")
|
continue
|
||||||
self.awaiting_file = False
|
|
||||||
|
filename = "received_memory.json"
|
||||||
|
with open(filename, "wb") as f:
|
||||||
|
await attachment.save(f)
|
||||||
|
|
||||||
|
print(f"File saved as {filename}")
|
||||||
|
await message.channel.send("File received and saved.")
|
||||||
|
self.awaiting_file = False
|
||||||
|
|
||||||
async def setup(bot):
|
async def setup(bot):
|
||||||
await bot.add_cog(FileSync(bot))
|
await bot.add_cog(FileSync(bot))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue