feat: Cleanup code and command perms
All checks were successful
Build Docker / Build Image (push) Successful in 40s
All checks were successful
Build Docker / Build Image (push) Successful in 40s
This commit is contained in:
100
bot.py
100
bot.py
@@ -36,50 +36,10 @@ if LOCAL:
|
|||||||
faucet_roles = 'faucet.json'
|
faucet_roles = 'faucet.json'
|
||||||
verified_roles = 'roles.json'
|
verified_roles = 'roles.json'
|
||||||
|
|
||||||
# Commands
|
# region Admin Commands
|
||||||
@tree.command(name="faucet", description="Get a free domain")
|
|
||||||
async def faucet(ctx, email:str):
|
|
||||||
# Check if a DM
|
|
||||||
if ctx.guild is None:
|
|
||||||
await ctx.response.send_message("You can not claim from the faucet in DMs")
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
roles = {}
|
|
||||||
if os.path.exists(faucet_roles):
|
|
||||||
with open(faucet_roles, 'r') as f:
|
|
||||||
roles = json.load(f)
|
|
||||||
if str(ctx.guild.id) in roles:
|
|
||||||
if roles[str(ctx.guild.id)] in [role.id for role in ctx.user.roles]:
|
|
||||||
await ctx.response.send_message("The faucet will gift you a domain when someone approves your request",ephemeral=True)
|
|
||||||
message = await ctx.channel.send(f"Faucet request from {ctx.user.name} (<@{ctx.user.id}>)\n\nThis is a gift from the faucet. You will receive a domain when someone approves your request.\n\nPlease approve this gift by reacting to this message with a 👍")
|
|
||||||
faucet_messages.append({
|
|
||||||
"id": message.id,
|
|
||||||
"email": email,
|
|
||||||
"user": ctx.user.id,
|
|
||||||
"time": datetime.datetime.now()
|
|
||||||
})
|
|
||||||
print(faucet_messages)
|
|
||||||
await message.add_reaction("👍")
|
|
||||||
return
|
|
||||||
await ctx.response.send_message("You can't claim from the faucet",ephemeral=True)
|
|
||||||
|
|
||||||
@tree.command(name="setfaucetrole", description="Change the role that can use the faucet")
|
|
||||||
async def faucetrole(ctx,role:discord.Role):
|
|
||||||
if ctx.user.id != ADMINID:
|
|
||||||
await ctx.response.send_message("You don't have permission to do that",ephemeral=True)
|
|
||||||
return
|
|
||||||
await ctx.response.send_message("Faucet role set to " + role.name + " for server " + ctx.guild.name,ephemeral=True)
|
|
||||||
roles = {}
|
|
||||||
if os.path.exists(faucet_roles):
|
|
||||||
with open(faucet_roles, 'r') as f:
|
|
||||||
roles = json.load(f)
|
|
||||||
|
|
||||||
roles[str(ctx.guild.id)] = role.id
|
|
||||||
with open(faucet_roles, 'w') as f:
|
|
||||||
json.dump(roles, f)
|
|
||||||
|
|
||||||
@tree.command(name="setverifiedrole", description="Set the role that verified users get")
|
@tree.command(name="setverifiedrole", description="Set the role that verified users get")
|
||||||
|
@app_commands.default_permissions(administrator=True)
|
||||||
async def setverifiedrole(ctx,role:discord.Role):
|
async def setverifiedrole(ctx,role:discord.Role):
|
||||||
# Check user has manage guild permission
|
# Check user has manage guild permission
|
||||||
if not ctx.user.guild_permissions.manage_guild:
|
if not ctx.user.guild_permissions.manage_guild:
|
||||||
@@ -107,6 +67,25 @@ async def setverifiedrole(ctx,role:discord.Role):
|
|||||||
|
|
||||||
await ctx.response.send_message("Verified role set to " + role.name + " for server " + ctx.guild.name,ephemeral=True)
|
await ctx.response.send_message("Verified role set to " + role.name + " for server " + ctx.guild.name,ephemeral=True)
|
||||||
|
|
||||||
|
@tree.command(name="setfaucetrole", description="Change the role that can use the faucet")
|
||||||
|
@app_commands.default_permissions(administrator=True)
|
||||||
|
async def faucetrole(ctx,role:discord.Role):
|
||||||
|
if ctx.user.id != ADMINID:
|
||||||
|
await ctx.response.send_message("You don't have permission to do that",ephemeral=True)
|
||||||
|
return
|
||||||
|
await ctx.response.send_message("Faucet role set to " + role.name + " for server " + ctx.guild.name,ephemeral=True)
|
||||||
|
roles = {}
|
||||||
|
if os.path.exists(faucet_roles):
|
||||||
|
with open(faucet_roles, 'r') as f:
|
||||||
|
roles = json.load(f)
|
||||||
|
|
||||||
|
roles[str(ctx.guild.id)] = role.id
|
||||||
|
with open(faucet_roles, 'w') as f:
|
||||||
|
json.dump(roles, f)
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
# region User Commands
|
||||||
@tree.command(name="verify", description="Verifies your ownership of a Handshake name and sets your nickname.")
|
@tree.command(name="verify", description="Verifies your ownership of a Handshake name and sets your nickname.")
|
||||||
async def verify(ctx:discord.Interaction, domain:str):
|
async def verify(ctx:discord.Interaction, domain:str):
|
||||||
# Verify not a DM
|
# Verify not a DM
|
||||||
@@ -165,8 +144,36 @@ async def verify(ctx:discord.Interaction, domain:str):
|
|||||||
|
|
||||||
await ctx.followup.send(message,ephemeral=True)
|
await ctx.followup.send(message,ephemeral=True)
|
||||||
|
|
||||||
|
@tree.command(name="faucet", description="Get a free domain")
|
||||||
|
async def faucet(ctx, email:str):
|
||||||
|
# Check if a DM
|
||||||
|
if ctx.guild is None:
|
||||||
|
await ctx.response.send_message("You can not claim from the faucet in DMs")
|
||||||
|
return
|
||||||
|
|
||||||
# When the bot is ready
|
|
||||||
|
roles = {}
|
||||||
|
if os.path.exists(faucet_roles):
|
||||||
|
with open(faucet_roles, 'r') as f:
|
||||||
|
roles = json.load(f)
|
||||||
|
if str(ctx.guild.id) in roles:
|
||||||
|
if roles[str(ctx.guild.id)] in [role.id for role in ctx.user.roles]:
|
||||||
|
await ctx.response.send_message("The faucet will gift you a domain when someone approves your request",ephemeral=True)
|
||||||
|
message = await ctx.channel.send(f"Faucet request from {ctx.user.name} (<@{ctx.user.id}>)\n\nThis is a gift from the faucet. You will receive a domain when someone approves your request.\n\nPlease approve this gift by reacting to this message with a 👍")
|
||||||
|
faucet_messages.append({
|
||||||
|
"id": message.id,
|
||||||
|
"email": email,
|
||||||
|
"user": ctx.user.id,
|
||||||
|
"time": datetime.datetime.now()
|
||||||
|
})
|
||||||
|
print(faucet_messages)
|
||||||
|
await message.add_reaction("👍")
|
||||||
|
return
|
||||||
|
await ctx.response.send_message("You can't claim from the faucet",ephemeral=True)
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
# region Bot Events
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
global ADMINID
|
global ADMINID
|
||||||
@@ -189,7 +196,10 @@ async def on_message(message):
|
|||||||
if message.author == client.user:
|
if message.author == client.user:
|
||||||
return
|
return
|
||||||
if not message.guild:
|
if not message.guild:
|
||||||
await message.channel.send('Invite this bot into your server by using this link:\nhttps://discord.com/api/oauth2/authorize?client_id=1073940877984153692&permissions=402653184&scope=bot')
|
await message.channel.send('Invite this bot into your server by using this link:')
|
||||||
|
# Generate a link to add the bot to a server
|
||||||
|
await message.channel.send(f"https://discord.com/api/oauth2/authorize?client_id={client.application_id}&permissions=402653184&scope=bot")
|
||||||
|
|
||||||
|
|
||||||
# On reaction
|
# On reaction
|
||||||
@client.event
|
@client.event
|
||||||
@@ -242,6 +252,8 @@ async def on_reaction_add(reaction, user):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if not TOKEN:
|
if not TOKEN:
|
||||||
print("No token found")
|
print("No token found")
|
||||||
|
|||||||
Reference in New Issue
Block a user