From 1843ac08d7867aa57ccfdd36733112a314fc1ed3 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Tue, 3 Sep 2024 19:27:19 +0200 Subject: [PATCH] done --- README.md | 5 +-- bot.py | 85 ------------------------------------------ config.py | 3 -- install.py | 16 -------- invite_sys.py | 20 ---------- main.py | 97 +++++++++++++++++++++++++++++++++++++++++------- requirements.txt | 4 +- 7 files changed, 85 insertions(+), 145 deletions(-) delete mode 100644 bot.py delete mode 100644 install.py delete mode 100644 invite_sys.py diff --git a/README.md b/README.md index 114e466..01d1e3e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,4 @@ AruaBot is a economy discord bot! -# Installation -run `python3 install.py` (Windows not supported yet) - -then run `python3 run.py` \ No newline at end of file +run `python3 main.py` \ No newline at end of file diff --git a/bot.py b/bot.py deleted file mode 100644 index 5692dba..0000000 --- a/bot.py +++ /dev/null @@ -1,85 +0,0 @@ -from aura import * -from config import * -import discord -from discord import app_commands -from discord.ext import commands - -aura = Aura() -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)) - print(await tree.sync()) - -@client.event -async def on_message(msg: discord.Message): - user = aura.get(str(msg.author.id)) - user.balance += 3 - aura.update(user) - -@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): - 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 = ""): - 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) - 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) - aura.update(user) - aura.update(user_to) - 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.update(user) - aura.update(user_to) - 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 index 92c3d6e..a8ef81e 100644 --- a/config.py +++ b/config.py @@ -1,9 +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_SERVER_PORT=os.environ['PORT'] -INVITE=os.environ['INVITE'] PUNISH_ROLES=(1279588925257683014,) REDIS_URL=os.environ['REDIS_URL'] REDIS_USER=os.environ['REDIS_USER'] diff --git a/install.py b/install.py deleted file mode 100644 index ca9dcdc..0000000 --- a/install.py +++ /dev/null @@ -1,16 +0,0 @@ -from os import system as cmd, name - -if name != 'nt': - print('initializing environment') - cmd('python3 -m venv .venv') - print('installing discord.py') - cmd('./.venv/bin/pip3 install discord.py') - cmd('./.venv/bin/pip3 install Flask') - # token = input('Bot Token>') - # invite = input('Permanent Invite Link>') - # with open('config.py', 'w') as f: - # f.write(f"BOT_TOKEN='{token}'\nINVITE='{invite}'") - with open('aura.json', 'w') as f1: - f1.write('{}') -else: - print('installer currently does not support windows') \ No newline at end of file diff --git a/invite_sys.py b/invite_sys.py deleted file mode 100644 index 2efe081..0000000 --- a/invite_sys.py +++ /dev/null @@ -1,20 +0,0 @@ -from aura import * -from config import * -from flask import Flask, redirect - -aura = Aura() -app = Flask(__name__) - -@app.route('/') -def root(): - return "ok" - -@app.route('/') -def invite(id): - user = aura.get(str(id)) - if user: - user.balance+=120 - aura.update(user) - return redirect(INVITE, code=302) - -app.run('0.0.0.0', INVITE_SERVER_PORT) \ No newline at end of file diff --git a/main.py b/main.py index 61c28b6..5692dba 100644 --- a/main.py +++ b/main.py @@ -1,16 +1,85 @@ -import os -env = os.environ.copy() +from aura import * from config import * -from subprocess import run as run_start -from threading import Thread -import time +import discord +from discord import app_commands +from discord.ext import commands -run = lambda a: run_start(a, env=env) -t1 = Thread(target=run, args=(['gunicorn', 'invite_sys:app'],)) -t2 = Thread(target=run, args=(['python3', 'bot.py'],)) -t1.daemon = True -t2.daemon = True -if USE_INVITE_SERVER:t1.start() -t2.start() -while 1: - time.sleep(.5) \ No newline at end of file +aura = Aura() +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)) + print(await tree.sync()) + +@client.event +async def on_message(msg: discord.Message): + user = aura.get(str(msg.author.id)) + user.balance += 3 + aura.update(user) + +@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): + 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 = ""): + 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) + 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) + aura.update(user) + aura.update(user_to) + 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.update(user) + aura.update(user_to) + 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/requirements.txt b/requirements.txt index 4b1039c..93ecd77 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,2 @@ -Flask discord.py -redis -gunicorn \ No newline at end of file +redis \ No newline at end of file