Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b1af0232d | ||
|
|
893adebdf9 | ||
|
|
18a3727fa5 | ||
|
|
3cd1741d3f | ||
|
|
beb454392b | ||
|
|
86e46b8338 | ||
|
|
35249d9ea5 | ||
|
|
2bad2f50d6 | ||
|
|
4e976daef7 | ||
|
|
c275d8ceaf |
@@ -4,9 +4,11 @@ from config import REDIS_URL, REDIS_USER, REDIS_PSW
|
||||
|
||||
class User:
|
||||
user_id: str
|
||||
def __init__(self, user_id: str, balance: int) -> None:
|
||||
last_earned: float = 0.0
|
||||
def __init__(self, user_id: str, balance: int, last_earned: float = 0.0) -> None:
|
||||
self.balance = balance
|
||||
self.user_id = str(user_id)
|
||||
self.last_earned = float(last_earned)
|
||||
|
||||
def set_balance(self, balance) -> int:
|
||||
self.balance = balance
|
||||
@@ -23,14 +25,17 @@ class User:
|
||||
return f"**- balance: {self.balance}**"
|
||||
|
||||
class Aura:
|
||||
data: dict[str, User] = {}
|
||||
last_earns: dict[str, float] = {}
|
||||
def __init__(self) -> None:
|
||||
redis_host = REDIS_URL.split(':')
|
||||
self.r = redis.Redis(host=redis_host[0], port=int(redis_host[1]), username=REDIS_USER, password=REDIS_PSW, decode_responses=True)
|
||||
|
||||
def get(self, user_id) -> User | None:
|
||||
user_id = str(user_id)
|
||||
try:
|
||||
return User(user_id, int(self.r.get(str(user_id))))
|
||||
if not user_id in self.last_earns:
|
||||
self.last_earns[user_id] = 0.0
|
||||
return User(user_id, int(self.r.get(user_id)), self.last_earns[user_id])
|
||||
except:
|
||||
return None
|
||||
|
||||
@@ -41,3 +46,4 @@ class Aura:
|
||||
|
||||
def update(self, u: User):
|
||||
self.r.set(u.user_id, u.balance)
|
||||
self.last_earns[str(u.user_id)] = u.last_earned
|
||||
@@ -1,9 +1,9 @@
|
||||
import os
|
||||
BOT_TOKEN=os.environ['BOT_TOKEN']
|
||||
USE_INVITE=True
|
||||
INVITE=os.environ['INVITE']
|
||||
if not INVITE.endswith('/'):INVITE+='/'
|
||||
PUNISH_ROLES=[x.strip() for x in os.environ['PUNISH_ROLES'].split(',')]
|
||||
REDIS_URL=os.environ['REDIS_URL']
|
||||
REDIS_USER=os.environ['REDIS_USER']
|
||||
REDIS_PSW=os.environ['REDIS_PSW']
|
||||
COOLDOWN_PERIOD = 5
|
||||
@@ -3,10 +3,10 @@ from config import *
|
||||
import discord
|
||||
from discord import app_commands
|
||||
from discord.ext import commands
|
||||
import time
|
||||
|
||||
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
|
||||
@@ -21,17 +21,22 @@ async def on_ready():
|
||||
|
||||
@client.event
|
||||
async def on_message(msg: discord.Message):
|
||||
if msg.author.bot:
|
||||
return
|
||||
user = aura.get(str(msg.author.id))
|
||||
user.balance += 3
|
||||
aura.update(user)
|
||||
if user==None:
|
||||
return
|
||||
if int(time.time() - user.last_earned) >= COOLDOWN_PERIOD:
|
||||
user.balance += 3
|
||||
user.last_earned = time.time()
|
||||
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:
|
||||
member.send(embed=discord.Embed(color=member.color, title='✨ Welcome to ORUS! ✨', description=f'**Aura: {user.balance}\nInvite URL: {INVITE+member.id}\nShare this Invite URL to get 120+ aura per person**'))
|
||||
await member.send(embed=discord.Embed(color=member.color, title='✨ Welcome to ORUS! ✨', description=f'**Aura: {user.balance}\nInvite URL: ```{INVITE+str(member.id)}```\nShare this Invite URL for +120 aura per join!**'))
|
||||
|
||||
@tree.command(name='aura', description='Check the amount of aura a member has')
|
||||
async def get_aura(interaction: discord.Interaction, member: discord.Member = None):
|
||||
@@ -48,7 +53,7 @@ async def send(interaction: discord.Interaction, to: discord.Member, amount: int
|
||||
if amount < 0:
|
||||
amount = -amount
|
||||
for r in interaction.user.roles:
|
||||
if r.id in PUNISH_ROLES:
|
||||
if str(r.id) in PUNISH_ROLES:
|
||||
if user_to.balance >= amount:
|
||||
user_to.balance -= amount
|
||||
user.balance += 10
|
||||
@@ -82,4 +87,8 @@ async def send(interaction: discord.Interaction, to: discord.Member, amount: int
|
||||
else:
|
||||
await interaction.response.send_message(f'Cannot send. You only have {user.balance} aura!', ephemeral=True)
|
||||
|
||||
@tree.command(name='invite', description='Get the invite link and get aura')
|
||||
async def send(interaction: discord.Interaction):
|
||||
await interaction.response.send_message(f'```{INVITE+str(interaction.user.id)}```')
|
||||
|
||||
client.run(BOT_TOKEN)
|
||||
Reference in New Issue
Block a user