From 3955a9b811ad43df8dc6688f00a6beb280cf1632 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Tue, 3 Sep 2024 17:23:26 +0200 Subject: [PATCH] better system for deployment --- bot.py | 86 +++++++++++++++++++++++++++++++++++++++++++ config.py | 6 +++ main.py | 96 +++++++----------------------------------------- requirements.txt | 2 + run.py | 14 ------- 5 files changed, 108 insertions(+), 96 deletions(-) create mode 100644 bot.py create mode 100644 config.py create mode 100644 requirements.txt delete mode 100644 run.py diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..502379c --- /dev/null +++ b/bot.py @@ -0,0 +1,86 @@ +from aura import * +from config import * +import discord +from discord import app_commands +from discord.ext import commands + +aura = Aura('aura.json') +client = discord.Client(intents=discord.Intents.all()) +# bot = commands.Bot(command_prefix="!", intents=discord.Intents.all()) +tree = app_commands.CommandTree(client) + +@client.event +async def on_ready(): + print(client.user) + for guild in client.guilds: + async for member in guild.fetch_members(limit=None): + user = aura.get(str(member.id)) + if user==None: + aura.add(str(member.id)) + aura.save() + print(await tree.sync()) + +@client.event +async def on_message(msg: discord.Message): + user = aura.get(str(msg.author.id)) + user.balance += 3 + aura.save() + +@client.event +async def on_member_join(member: discord.Member): + user = aura.get(str(member.id)) + if not user: + user = aura.add(str(member.id)) + if USE_INVITE_SERVER: + member.send(embed=discord.Embed(color=member.color, title='✨ Welcome to ORUS! ✨', description=f'**Aura: {user.balance}\nInvite URL: {INVITE_SERVER_URL+member.id}\nShare this Invite URL to get 120+ aura per person**')) + +@tree.command(name='aura', description='Check the amount of aura a member has') +async def get_aura(interaction: discord.Interaction, member: discord.Member = None): + aura.load() + if member == None: + member = interaction.user + user = aura.get(str(member.id)) + embed = discord.Embed(color=member.color, title=f'{member.name}\'s Aura', description=user.to_md()) + await interaction.response.send_message(embed=embed) + +@tree.command(name='send', description='Send aura to a member') +async def send(interaction: discord.Interaction, to: discord.Member, amount: int, reason: str = ""): + aura.load() + user = aura.get(str(interaction.user.id)) + user_to = aura.get(str(to.id)) + if amount < 0: + amount = -amount + for r in interaction.user.roles: + if r.id in PUNISH_ROLES: + if user_to.balance >= amount: + user_to.balance -= amount + user.balance += 10 + await to.send(embed=discord.Embed( + color=interaction.user.color, + title="Punished!", + description=f'**By: {interaction.user.name}\nAmount: {amount}\nReason: {reason}**' + )) + await interaction.response.send_message(f'Punished! You gained 10+ aura!', ephemeral=True) + aura.save() + else: + await interaction.response.send_message(f'Cannot punish. {to.name} only has {user_to.balance} aura!', ephemeral=True) + return + if user.balance >= 10: + user.balance -= 10 + await interaction.response.send_message(f'Cannot punish. You are not a developer.{" -10 aura!" if user.balance>=10 else""}', ephemeral=True) + return + else: + if user.balance >= amount: + user.balance -= amount + user_to.balance += amount + await to.send(embed=discord.Embed( + color=interaction.user.color, + title="Aura received!", + description=f'**From: {interaction.user.name}\nAmount: {amount}**' + )) + await interaction.response.send_message(f'Sent! You now have {user.balance} aura!', ephemeral=True) + aura.save() + else: + await interaction.response.send_message(f'Cannot send. You only have {user.balance} aura!', ephemeral=True) + +client.run(BOT_TOKEN) \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..387b6a9 --- /dev/null +++ b/config.py @@ -0,0 +1,6 @@ +import os +BOT_TOKEN=os.environ['BOT_TOKEN'] +USE_INVITE_SERVER=os.environ['USE_INVITE']=='true' +INVITE_SERVER_URL='127.0.0.1' +INVITE=os.environ['INVITE'] +PUNISH_ROLES=(1279588925257683014,) \ No newline at end of file diff --git a/main.py b/main.py index 502379c..f9d2352 100644 --- a/main.py +++ b/main.py @@ -1,86 +1,18 @@ -from aura import * from config import * -import discord -from discord import app_commands -from discord.ext import commands +from subprocess import run as run_start +from threading import Thread -aura = Aura('aura.json') -client = discord.Client(intents=discord.Intents.all()) -# bot = commands.Bot(command_prefix="!", intents=discord.Intents.all()) -tree = app_commands.CommandTree(client) +env = os.environ.copy() -@client.event -async def on_ready(): - print(client.user) - for guild in client.guilds: - async for member in guild.fetch_members(limit=None): - user = aura.get(str(member.id)) - if user==None: - aura.add(str(member.id)) - aura.save() - print(await tree.sync()) +run = lambda a: run_start(a, env=env) -@client.event -async def on_message(msg: discord.Message): - user = aura.get(str(msg.author.id)) - user.balance += 3 - aura.save() - -@client.event -async def on_member_join(member: discord.Member): - user = aura.get(str(member.id)) - if not user: - user = aura.add(str(member.id)) - if USE_INVITE_SERVER: - member.send(embed=discord.Embed(color=member.color, title='✨ Welcome to ORUS! ✨', description=f'**Aura: {user.balance}\nInvite URL: {INVITE_SERVER_URL+member.id}\nShare this Invite URL to get 120+ aura per person**')) - -@tree.command(name='aura', description='Check the amount of aura a member has') -async def get_aura(interaction: discord.Interaction, member: discord.Member = None): - aura.load() - if member == None: - member = interaction.user - user = aura.get(str(member.id)) - embed = discord.Embed(color=member.color, title=f'{member.name}\'s Aura', description=user.to_md()) - await interaction.response.send_message(embed=embed) - -@tree.command(name='send', description='Send aura to a member') -async def send(interaction: discord.Interaction, to: discord.Member, amount: int, reason: str = ""): - aura.load() - user = aura.get(str(interaction.user.id)) - user_to = aura.get(str(to.id)) - if amount < 0: - amount = -amount - for r in interaction.user.roles: - if r.id in PUNISH_ROLES: - if user_to.balance >= amount: - user_to.balance -= amount - user.balance += 10 - await to.send(embed=discord.Embed( - color=interaction.user.color, - title="Punished!", - description=f'**By: {interaction.user.name}\nAmount: {amount}\nReason: {reason}**' - )) - await interaction.response.send_message(f'Punished! You gained 10+ aura!', ephemeral=True) - aura.save() - else: - await interaction.response.send_message(f'Cannot punish. {to.name} only has {user_to.balance} aura!', ephemeral=True) - return - if user.balance >= 10: - user.balance -= 10 - await interaction.response.send_message(f'Cannot punish. You are not a developer.{" -10 aura!" if user.balance>=10 else""}', ephemeral=True) - return - else: - if user.balance >= amount: - user.balance -= amount - user_to.balance += amount - await to.send(embed=discord.Embed( - color=interaction.user.color, - title="Aura received!", - description=f'**From: {interaction.user.name}\nAmount: {amount}**' - )) - await interaction.response.send_message(f'Sent! You now have {user.balance} aura!', ephemeral=True) - aura.save() - else: - await interaction.response.send_message(f'Cannot send. You only have {user.balance} aura!', ephemeral=True) - -client.run(BOT_TOKEN) \ No newline at end of file +t1 = Thread(target=run, args=(['./.venv/bin/python3', 'invite_sys.py'],)) +t2 = Thread(target=run, args=(['./.venv/bin/python3', 'bot.py'],)) +t1.daemon = True +t2.daemon = True +if USE_INVITE_SERVER:t1.start() +t2.start() +while 1: + if input() == 'q': + if USE_INVITE_SERVER:t1.join(0) + t2.join(0) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b630490 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask +discord.py \ No newline at end of file diff --git a/run.py b/run.py deleted file mode 100644 index 617482a..0000000 --- a/run.py +++ /dev/null @@ -1,14 +0,0 @@ -from config import * -from subprocess import run -from threading import Thread - -t1 = Thread(target=run, args=(['./.venv/bin/python3', 'invite_sys.py'],)) -t2 = Thread(target=run, args=(['./.venv/bin/python3', 'main.py'],)) -t1.daemon = True -t2.daemon = True -if USE_INVITE_SERVER:t1.start() -t2.start() -while 1: - if input() == 'q': - if USE_INVITE_SERVER:t1.join(0) - t2.join(0) \ No newline at end of file