Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
53 changes: 53 additions & 0 deletions framework/isobot/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""The isobot module to configure internal user/server settings."""

# Imports
import json
from typing import Union, Literal

# Classes and Functions
class Colors:
"""Contains general stdout colors."""
cyan = '\033[96m'
red = '\033[91m'
green = '\033[92m'
end = '\033[0m'

# Functions
class Configurator(Colors):
"""The class used to initialize the settings module."""
def __init__(self):
print(f"[framework/Configurator] {Colors.green}Module initialized.{Colors.end}")

def generate(self, user_id: int) -> Literal[0, 1]:
"""Generates a new settings configuration for the specified user.
Does not do anything if a configuration already exists.\n
Returns 0 if the request was successful, returns 1 if the configuration already exists."""
with open("config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f)
if str(user_id) in db.keys(): return 1
template = {
"levelup_messages": True
}
db[str(user_id)] = template
with open("config/settings.json", 'w+', encoding="utf-8") as f: json.dump(db, f, indent=4)
return 0

def fetch_setting(self, user_id: int, setting: str) -> Union[int, str, bool]:
"""Fetches the current value of a user setting."""
with open("config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f)
return db[str(user_id)][setting]

def edit_setting(self, user_id: int, setting: str, value) -> Literal[0]:
"""Modifies the value of a user setting."""
with open("config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f)
db[str(user_id)][setting] = value
return 0
def reset(self, user_id: int):
"""Completely resets the specified user's configuration."""
with open("config/settings.json", 'r', encoding="utf-8") as f: db = json.load(f)
template = {
"levelup_messages": True
}
db[str(user_id)] = template
with open("config/settings.json", 'w+', encoding="utf-8") as f: json.dump(db, f, indent=4)
return 0

23 changes: 21 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from utils import logger, ping
from math import floor
from random import randint
from framework.isobot import currency, colors, embedengine
from framework.isobot import currency, colors, embedengine, settings
from framework.isobank import authorize, manager
from discord import ApplicationContext, option
from discord.ext import commands
Expand Down Expand Up @@ -57,6 +57,7 @@ def save():
#Framework Module Loader
colors = colors.Colors()
currency = currency.CurrencyAPI("database/currency.json", "logs/currency.log")
settings = settings.Configurator()

# Theme Loader
themes = False # True: enables themes; False: disables themes;
Expand Down Expand Up @@ -95,6 +96,7 @@ async def on_message(ctx):
currency.new_bank(ctx.author.id)
create_isocoin_key(ctx.author.id)
new_userdat(ctx.author.id)
settings.generate(ctx.author.id)
if str(ctx.author.id) not in items: items[str(ctx.author.id)] = {}
if str(ctx.author.id) not in levels: levels[str(ctx.author.id)] = {"xp": 0, "level": 0}
if str(ctx.guild.id) not in automod_config:
Expand Down Expand Up @@ -135,7 +137,8 @@ async def on_message(ctx):
if levels[str(ctx.author.id)]["xp"] >= xpreq:
levels[str(ctx.author.id)]["xp"] = 0
levels[str(ctx.author.id)]["level"] += 1
await ctx.author.send(f"{ctx.author.mention}, you just ranked up to **level {levels[str(ctx.author.id)]['level']}**. Nice!")
if settings.fetch_setting(ctx.author.id, "levelup_messages") == True:
await ctx.author.send(f"{ctx.author.mention}, you just ranked up to **level {levels[str(ctx.author.id)]['level']}**. Nice!")
save()
if automod_config[str(ctx.guild.id)]["swear_filter"]["enabled"] == True:
if automod_config[str(ctx.guild.id)]["swear_filter"]["keywords"]["use_default"] and any(x in ctx.content.lower() for x in automod_config[str(ctx.guild.id)]["swear_filter"]["keywords"]["default"]):
Expand Down Expand Up @@ -267,6 +270,22 @@ async def reload(ctx: ApplicationContext, cog: str):
)
)

# Settings commands
config = client.create_group("settings", "Commands used to change bot settings.")

@config.command(
name="levelup_messages",
description="Configure whether you want to be notified for level ups or not."
)
@option(name="enabled", description="Do you want this setting enabled?", type=bool)
async def levelup_messages(ctx: ApplicationContext, enabled: bool):
if settings.fetch_setting(ctx.author.id, "levelup_messages") == enabled: return await ctx.respond("This is already done.", ephemeral=True)
settings.edit_setting(ctx.author.id, "levelup_messages", enabled)
localembed = discord.Embed(
description="Setting successfully updated.",
color=discord.Color.green()
)
await ctx.respond(embed=localembed)

# Initialization
active_cogs = [
Expand Down