Untitled

 avatar
unknown
plain_text
2 years ago
3.4 kB
13
Indexable
import os
from time import sleep, time
from datetime import datetime, timedelta
try:
    from ujson import loads, dumps
    import asyncio
    import aiofiles
    from nextcord import Embed, Interaction
    from nextcord.ext import commands
    import nextcord

except ImportError:
    os.system("pip install -U nextcord aiofiles asyncio ujson")
    from ujson import loads, dumps
    import asyncio
    import aiofiles
    from nextcord import Embed, Interaction
    from nextcord.ext import commands
    import nextcord

intents = nextcord.Intents.default()
intents.message_content = True
intents.members = False

bot = commands.Bot(command_prefix = "/", intents = intents)
users: dict = None
    

async def getusers():
    global users

    async with aiofiles.open("./users.json", "r+", encoding="utf-8", errors="ignore") as file:
        users = loads(await file.read())

async def appendUser():
    global users

    async with aiofiles.open("./users.json", "w+", encoding='utf-8', errors='ignore') as file:
        await file.seek(0)
        await file.truncate()
        await file.write(dumps(users, indent = 4, ensure_ascii=False))
        

class verificationButton(nextcord.ui.View):

    def __init__(self) -> None:
        super().__init__(timeout = None)

    @nextcord.ui.button(label = "☑️", style = nextcord.ButtonStyle.green, custom_id = "verify_button")
    async def onVerifyClicked(self, button = nextcord.ui.Button, interaction = Interaction):
        global users
        await interaction.response.defer()

        role = nextcord.utils.get(interaction.guild.roles, name = "✔️Verified✔️")

        if interaction.user.id == users.get(interaction.user.name, None) or role in interaction.user.roles:
            await interaction.followup.send("You are already verified", ephemeral = True)
            return

        try:
            users.update({interaction.user.name: interaction.user.id})
            await appendUser()
            await interaction.user.add_roles(role)
            await interaction.followup.send("Verification Success", ephemeral = True)
        except Exception as e:
            print(e)
            del users[interaction.user.name]
            retry_after = 60 # in seconds
            retry_after_time = datetime.utcnow() + timedelta(seconds=retry_after)
            headers = {
                "Retry-After": str(retry_after)
            }
            await interaction.followup.send(f"Verification Failed. Please try again after {retry_after} seconds.", ephemeral=True, headers=headers)
            await interaction.followup.send("Verification Failed", ephemeral = True)

@bot.slash_command(name = "verify", description = "Verify to access Anime Empire")
async def verify(interaction: Interaction):

    if not interaction.permissions.administrator:
        await interaction.response.send_message("This command is only or admins")
        return

    embed = Embed(
        title = "Verification",
        description = "none",
        color = 0x00ff00)
    
    view = verificationButton()
    await interaction.send(embed = embed, view = view)
    await view.wait()

if __name__ == "__main__":
    Token = ""
    print("Running")
    asyncio.get_event_loop().run_until_complete(getusers())
    asyncio.get_event_loop().run_until_complete(bot.start(Token))
Editor is loading...