Compare commits

..
10 Commits
Author SHA1 Message Date
selimaj-dev 7b1af0232d invite await fix 2024-09-07 11:04:55 -04:00
Leo 893adebdf9 invite command 2024-09-07 11:01:55 -04:00
selimaj-dev 18a3727fa5 cooldown 2024-09-05 15:58:57 +02:00
selimaj-dev 3cd1741d3f cooldown 2024-09-05 15:54:30 +02:00
selimaj-dev beb454392b cooldown 2024-09-05 15:47:16 +02:00
selimaj-dev 86e46b8338 cooldown 2024-09-05 15:40:27 +02:00
selimaj-dev 35249d9ea5 cooldown 2024-09-05 15:34:04 +02:00
selimaj-dev 2bad2f50d6 cooldown 2024-09-05 15:31:24 +02:00
selimaj-dev 4e976daef7 final 2024-09-04 01:19:28 +02:00
selimaj-dev c275d8ceaf final 2024-09-04 01:16:36 +02:00
3 changed files with 27 additions and 12 deletions
+9 -3
View File
@@ -4,9 +4,11 @@ from config import REDIS_URL, REDIS_USER, REDIS_PSW
class User: class User:
user_id: str 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.balance = balance
self.user_id = str(user_id) self.user_id = str(user_id)
self.last_earned = float(last_earned)
def set_balance(self, balance) -> int: def set_balance(self, balance) -> int:
self.balance = balance self.balance = balance
@@ -23,14 +25,17 @@ class User:
return f"**- balance: {self.balance}**" return f"**- balance: {self.balance}**"
class Aura: class Aura:
data: dict[str, User] = {} last_earns: dict[str, float] = {}
def __init__(self) -> None: def __init__(self) -> None:
redis_host = REDIS_URL.split(':') 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) 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: def get(self, user_id) -> User | None:
user_id = str(user_id)
try: 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: except:
return None return None
@@ -41,3 +46,4 @@ class Aura:
def update(self, u: User): def update(self, u: User):
self.r.set(u.user_id, u.balance) self.r.set(u.user_id, u.balance)
self.last_earns[str(u.user_id)] = u.last_earned
+1 -1
View File
@@ -1,9 +1,9 @@
import os import os
BOT_TOKEN=os.environ['BOT_TOKEN'] BOT_TOKEN=os.environ['BOT_TOKEN']
USE_INVITE=True
INVITE=os.environ['INVITE'] INVITE=os.environ['INVITE']
if not INVITE.endswith('/'):INVITE+='/' if not INVITE.endswith('/'):INVITE+='/'
PUNISH_ROLES=[x.strip() for x in os.environ['PUNISH_ROLES'].split(',')] PUNISH_ROLES=[x.strip() for x in os.environ['PUNISH_ROLES'].split(',')]
REDIS_URL=os.environ['REDIS_URL'] REDIS_URL=os.environ['REDIS_URL']
REDIS_USER=os.environ['REDIS_USER'] REDIS_USER=os.environ['REDIS_USER']
REDIS_PSW=os.environ['REDIS_PSW'] REDIS_PSW=os.environ['REDIS_PSW']
COOLDOWN_PERIOD = 5
+15 -6
View File
@@ -3,10 +3,10 @@ from config import *
import discord import discord
from discord import app_commands from discord import app_commands
from discord.ext import commands from discord.ext import commands
import time
aura = Aura() aura = Aura()
client = discord.Client(intents=discord.Intents.all()) client = discord.Client(intents=discord.Intents.all())
# bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
tree = app_commands.CommandTree(client) tree = app_commands.CommandTree(client)
@client.event @client.event
@@ -21,17 +21,22 @@ async def on_ready():
@client.event @client.event
async def on_message(msg: discord.Message): async def on_message(msg: discord.Message):
if msg.author.bot:
return
user = aura.get(str(msg.author.id)) user = aura.get(str(msg.author.id))
user.balance += 3 if user==None:
aura.update(user) return
if int(time.time() - user.last_earned) >= COOLDOWN_PERIOD:
user.balance += 3
user.last_earned = time.time()
aura.update(user)
@client.event @client.event
async def on_member_join(member: discord.Member): async def on_member_join(member: discord.Member):
user = aura.get(str(member.id)) user = aura.get(str(member.id))
if not user: if not user:
user = aura.add(str(member.id)) user = aura.add(str(member.id))
if USE_INVITE: 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!**'))
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**'))
@tree.command(name='aura', description='Check the amount of aura a member has') @tree.command(name='aura', description='Check the amount of aura a member has')
async def get_aura(interaction: discord.Interaction, member: discord.Member = None): 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: if amount < 0:
amount = -amount amount = -amount
for r in interaction.user.roles: for r in interaction.user.roles:
if r.id in PUNISH_ROLES: if str(r.id) in PUNISH_ROLES:
if user_to.balance >= amount: if user_to.balance >= amount:
user_to.balance -= amount user_to.balance -= amount
user.balance += 10 user.balance += 10
@@ -82,4 +87,8 @@ async def send(interaction: discord.Interaction, to: discord.Member, amount: int
else: else:
await interaction.response.send_message(f'Cannot send. You only have {user.balance} aura!', ephemeral=True) 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) client.run(BOT_TOKEN)