forked from gooberinc/goober
added permission wrapper
This commit is contained in:
parent
f7042ed8a7
commit
f186e079da
29 changed files with 860 additions and 788 deletions
|
@ -3,7 +3,9 @@ import discord.context_managers
|
|||
from discord.ext import commands
|
||||
import logging
|
||||
from typing import Literal, get_args, cast
|
||||
from modules.permission import requires_admin
|
||||
from modules.settings import Settings as SettingsManager
|
||||
|
||||
settings_manager = SettingsManager()
|
||||
settings = settings_manager.settings
|
||||
|
||||
|
@ -12,6 +14,7 @@ logger = logging.getLogger("goober")
|
|||
|
||||
AvailableModes = Literal["r", "s"]
|
||||
|
||||
|
||||
class FileSync(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot: discord.Client = bot
|
||||
|
@ -19,24 +22,21 @@ class FileSync(commands.Cog):
|
|||
self.peer_id = None
|
||||
self.awaiting_file = False
|
||||
|
||||
@requires_admin()
|
||||
@commands.command()
|
||||
async def syncfile(self, ctx: commands.Context, mode: str, peer: discord.User):
|
||||
if self.mode not in get_args(AvailableModes):
|
||||
await ctx.send("Invalid mode, use 's' or 'r'.")
|
||||
return
|
||||
|
||||
|
||||
self.mode = cast(AvailableModes, mode.lower())
|
||||
self.peer_id = peer.id
|
||||
|
||||
if ctx.author.id not in settings["bot"]["owner_ids"]:
|
||||
await ctx.send("You don't have permission to execute this command.")
|
||||
return
|
||||
|
||||
if self.mode == "s":
|
||||
await ctx.send(f"<@{self.peer_id}> FILE_TRANSFER_REQUEST")
|
||||
await ctx.send(file=discord.File("memory.json"))
|
||||
await ctx.send("File sent in this channel.")
|
||||
|
||||
|
||||
elif self.mode == "r":
|
||||
await ctx.send("Waiting for incoming file...")
|
||||
self.awaiting_file = True
|
||||
|
@ -53,12 +53,11 @@ class FileSync(commands.Cog):
|
|||
logger.info("Ping received. Awaiting file...")
|
||||
if not message.attachments:
|
||||
return
|
||||
|
||||
|
||||
for attachment in message.attachments:
|
||||
if not attachment.filename.endswith(".json"):
|
||||
continue
|
||||
|
||||
|
||||
filename = "received_memory.json"
|
||||
with open(filename, "wb") as f:
|
||||
await attachment.save(f)
|
||||
|
@ -67,5 +66,6 @@ class FileSync(commands.Cog):
|
|||
await message.channel.send("File received and saved.")
|
||||
self.awaiting_file = False
|
||||
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(FileSync(bot))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue