Skip to content

Commit

Permalink
Added guild level messages
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinTrinh1227 committed Nov 13, 2023
1 parent 3d45943 commit a432005
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
2 changes: 1 addition & 1 deletion commands/guild_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def guildinfo(self, ctx):
guild_tag = "No Tag Available"

guild_id = guild_data['_id']
guild_level, current_exp, exp_needed, exp_remaining, total_exp = guild.get_guild_exp_data(total_guild_exp)
guild_level, current_exp, exp_needed, exp_remaining, total_exp = guild.get_guild_level_data(total_guild_exp)

total_members = len(guild_data['members'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ async def on_message_delete(self, message):
async for entry in message.guild.audit_logs(limit=1, action=discord.AuditLogAction.message_delete):
deleter = entry.user

#print(entry)
#print(message)
print(entry)
print(message)

channel = self.client.get_channel(logs_channel_id)

Expand Down
71 changes: 71 additions & 0 deletions listeners/guild_level_up.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import discord
from discord.ext import tasks, commands
import json
import discord
import discord.ui
import os
from dotenv import load_dotenv
import utils.guild_data as guild
import math

# Open the JSON file and read in the data
with open('config.json') as json_file:
data = json.load(json_file)
logs_channel_id = int(data["text_channel_ids"]["guild_news"]) # logs the bot logs in this channel
embed_color = int(data["general"]["embed_color"].strip("#"), 16) #convert hex color to hexadecimal format
guild_id = int(data["general"]["discord_server_guild_id"])

# Open the JSON file and read in the data
with open('guild_cache.json') as json_file:
guild_data = json.load(json_file)["guild_data"]
total_guild_exp = guild_data["guild"]["exp"]
current_guild_level, _, _, _, _ = guild.get_guild_level_data(total_guild_exp)
current_guild_level = math.floor(current_guild_level)

class dailyguildlevelup(commands.Cog):

def __init__(self, client):
self.client = client
self.guild_id = guild_id
self.dailyguildlevelup.start()

@tasks.loop(seconds=10) # Run every 60 seconds
async def dailyguildlevelup(self):

discord_guild = self.client.get_guild(guild_id)
channel = self.client.get_channel(logs_channel_id)

# Open the JSON file and read in the data
with open('guild_cache.json') as json_file:
guild_data = json.load(json_file)["guild_data"]["guild"]

guild_name = guild_data['name']
total_guild_exp = guild_data["exp"]
guild_level, current_exp, exp_needed, exp_remaining, total_exp = guild.get_guild_level_data(total_guild_exp)

new_guild_level = math.floor(guild_level)

global current_guild_level

if new_guild_level > current_guild_level:
# print(f"{new_guild_level} > {current_guild_level}")
# print(f"Guild Level Up! Level is: {new_guild_level}! Before Level: {current_guild_level}")

embed = discord.Embed(
title=(f"🎉 | {guild_name} Level Up! - [Lvl. {current_guild_level} ➜ Lvl. {new_guild_level}]"),
description=f"The guild has just ranked up to level **{new_guild_level}**. Thank you to everyone who has contributed guild points! Total GEXP: `{'{:,}'.format(total_guild_exp)}`.",
colour= embed_color
)
# embed.timestamp = datetime.datetime.now()
embed.set_thumbnail(url = discord_guild.icon.url)
# embed.set_footer(text=f"©️ {guild.name}", icon_url = guild.icon.url)

await channel.send(embed=embed)
current_guild_level = new_guild_level # Update the current_guild_level
else:
#print(f"NO level up. Same lvl.")
pass


async def setup(client):
await client.add_cog(dailyguildlevelup(client))
6 changes: 3 additions & 3 deletions utils/guild_data.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import json

def get_guild_exp_data(exp):
def get_guild_level_data(exp):
"""
The function `get_guild_exp_data` calculates the guild level, remaining experience, and total
The function `get_guild_level_data` calculates the guild level, remaining experience, and total
experience based on the given experience points.
@param exp The "exp" parameter represents the amount of experience points that a guild has.
@return The function `get_guild_exp_data` returns a tuple containing the following values:
@return The function `get_guild_level_data` returns a tuple containing the following values:
"""
EXP_NEEDED = [
100000,
Expand Down

0 comments on commit a432005

Please sign in to comment.