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
18 changes: 17 additions & 1 deletion cogs/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,26 @@

with open(f"{wdir}/database/warnings.json", 'r', encoding="utf-8") as f: warnings = json.load(f)

# Functions
def save():
with open(f"{wdir}/database/warnings.json", 'w+', encoding="utf-8") as f: json.dump(warnings, f)

# Functions
def new_warnings_guild(guild_id: int) -> int:
"""Makes a new key for guild warnings in the warnings database.\n\nReturns `0` if successful, returns `1` if key already exists."""
if str(guild_id) not in warnings:
warnings[str(guild_id)] = {}
save()
return 0
else: return 1

def new_warnings_user(guild_id: int, user_id: int) -> int:
"""Makes a new key for user warnings for the specified guild in the warnings database.\n\nReturns `0` if successful, returns `1` if key already exists."""
if str(user_id) not in warnings[str(guild_id)].keys():
warnings[str(guild_id)][str(user_id)] = []
save()
return 0
else: return 1

# Commands
class Moderation(commands.Cog):
def __init__(self, bot):
Expand Down
8 changes: 3 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from discord.ext.commands import *
from cogs.economy import new_bank, new_wallet
from cogs.isocoin import create_isocoin_key
from cogs.moderation import new_warnings_guild, new_warnings_user

# Slash option types:
# Just use variable types to define option types.
Expand All @@ -34,7 +35,6 @@
color = discord.Color.random()
wdir = os.getcwd()
reddit = praw.Reddit(client_id='_pazwWZHi9JldA', client_secret='1tq1HM7UMEGIro6LlwtlmQYJ1jB4vQ', user_agent='idk', check_for_async=False)
with open('database/warnings.json', 'r', encoding="utf-8") as f: warnings = json.load(f)
with open('database/items.json', 'r', encoding="utf-8") as f: items = json.load(f)
with open('config/shop.json', 'r', encoding="utf-8") as f: shopitem = json.load(f)
with open('database/presence.json', 'r', encoding="utf-8") as f: presence = json.load(f)
Expand All @@ -44,7 +44,6 @@

#Pre-Initialization Commands
def save():
with open('database/warnings.json', 'w+', encoding="utf-8") as f: json.dump(warnings, f, indent=4)
with open('database/items.json', 'w+', encoding="utf-8") as f: json.dump(items, f, indent=4)
with open('database/presence.json', 'w+', encoding="utf-8") as f: json.dump(presence, f, indent=4)
with open('database/levels.json', 'w+', encoding="utf-8") as f: json.dump(levels, f, indent=4)
Expand Down Expand Up @@ -108,9 +107,9 @@ async def on_ready():
async def on_message(ctx):
new_wallet(ctx.author.id)
new_bank(ctx.author.id)
new_warnings_guild(ctx.guild.id)
new_warnings_user(ctx.guild.id, ctx.author.id)
create_isocoin_key(ctx.author.id)
if str(ctx.guild.id) not in warnings: warnings[str(ctx.guild.id)] = {}
if str(ctx.author.id) not in warnings[str(ctx.guild.id)]: warnings[str(ctx.guild.id)][str(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: automod_config[str(ctx.guild.id)] = \
Expand Down Expand Up @@ -219,7 +218,6 @@ async def help(ctx: ApplicationContext, command:str=None):
async def sync(ctx: ApplicationContext):
if ctx.author.id != 738290097170153472: return await ctx.respond('Sorry, this command is only for my developer\'s use.')
try:
with open('database/warnings.json', 'r') as f: warnings = json.load(f)
with open('database/items.json', 'r') as f: items = json.load(f)
with open('config/shop.json', 'r') as f: shopitem = json.load(f)
await ctx.respond('Databases resynced.', ephemeral=True)
Expand Down