invite system
This commit is contained in:
@@ -5,4 +5,4 @@ AruaBot is a economy discord bot!
|
|||||||
# Installation
|
# Installation
|
||||||
run `python3 install.py` (Windows not supported yet)
|
run `python3 install.py` (Windows not supported yet)
|
||||||
|
|
||||||
then run `./.venv/bin/python3 main.py`
|
then run `python3 run.py`
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
from json import dump, load
|
||||||
|
|
||||||
|
class User:
|
||||||
|
def __init__(self, balance: int) -> None:
|
||||||
|
self.balance = balance
|
||||||
|
|
||||||
|
def set_balance(self, balance) -> int:
|
||||||
|
self.balance = balance
|
||||||
|
return self.balance
|
||||||
|
|
||||||
|
def add_balance(self, balance) -> int:
|
||||||
|
self.balance += balance
|
||||||
|
return self.balance
|
||||||
|
|
||||||
|
def to_dict(self) -> dict:
|
||||||
|
return {'balance': self.balance}
|
||||||
|
|
||||||
|
def to_md(self) -> str:
|
||||||
|
return f"**- balance: {self.balance}**"
|
||||||
|
|
||||||
|
class Aura:
|
||||||
|
data: dict[str, User] = {}
|
||||||
|
file = ''
|
||||||
|
def __init__(self, file: str) -> None:
|
||||||
|
with open(file, 'r')as f:
|
||||||
|
self.file = file
|
||||||
|
data = load(f)
|
||||||
|
for k in data:
|
||||||
|
self.data[k] = User(data[k]['balance'])
|
||||||
|
|
||||||
|
def load(self) -> None:
|
||||||
|
with open(self.file, 'r')as f:
|
||||||
|
data = load(f)
|
||||||
|
for k in data:
|
||||||
|
self.data[k] = User(data[k]['balance'])
|
||||||
|
|
||||||
|
def get(self, user_id) -> User | None:
|
||||||
|
if user_id in self.data:
|
||||||
|
return self.data[user_id]
|
||||||
|
|
||||||
|
def add(self, user_id) -> User:
|
||||||
|
self.data[user_id] = User(10)
|
||||||
|
return self.data[user_id]
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
data = {}
|
||||||
|
for k in self.data:
|
||||||
|
data[k] = self.data[k].to_dict()
|
||||||
|
with open(self.file, 'w')as f:
|
||||||
|
dump(data, f, indent=2)
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
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')
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
from aura import *
|
||||||
|
from config import *
|
||||||
|
from flask import Flask, redirect
|
||||||
|
from os import environ
|
||||||
|
|
||||||
|
aura = Aura('aura.json')
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@app.route('/<id>')
|
||||||
|
def root(id):
|
||||||
|
aura.load()
|
||||||
|
user = aura.get(str(id))
|
||||||
|
if user:
|
||||||
|
user.balance+=120
|
||||||
|
aura.save()
|
||||||
|
return redirect(INVITE, code=302)
|
||||||
|
|
||||||
|
app.run('127.0.0.1', environ['PORT'])
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
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))
|
||||||
|
member.send(embed=discord.Embed(color=member.color, title='✨ Welcome to ORUS! ✨', description=f'**Aura: {user.balance}**'))
|
||||||
|
|
||||||
|
@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):
|
||||||
|
aura.load()
|
||||||
|
user = aura.get(str(interaction.user.id))
|
||||||
|
user_to = aura.get(str(to.id))
|
||||||
|
if user.balance >= amount:
|
||||||
|
user.balance -= amount
|
||||||
|
user_to.balance += amount
|
||||||
|
embed = discord.Embed(
|
||||||
|
color=interaction.user.color,
|
||||||
|
description=f'**From: {interaction.user.name}\nAmount: {amount}**'
|
||||||
|
)
|
||||||
|
await to.send(embed=embed)
|
||||||
|
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)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
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
|
||||||
|
t1.start()
|
||||||
|
t2.start()
|
||||||
|
while 1:
|
||||||
|
if input() == 'q':
|
||||||
|
t1.join(0)
|
||||||
|
t2.join(0)
|
||||||
Reference in New Issue
Block a user