fix
This commit is contained in:
@@ -0,0 +1,253 @@
|
||||
import discord
|
||||
import random
|
||||
import json
|
||||
import time
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
class Server_Management(commands.Cog):
|
||||
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_join(self, guild):
|
||||
# adding prefix
|
||||
with open("saves/prefixes", "r") as f:
|
||||
prefixes = json.load(f)
|
||||
|
||||
try:
|
||||
prefixes[str(guild.id)]
|
||||
except:
|
||||
prefixes[str(guild.id)] = "&"
|
||||
|
||||
with open("saves/prefixes", "w") as f:
|
||||
json.dump(prefixes, f, indent=4)
|
||||
|
||||
# adding to setup.json
|
||||
|
||||
with open("saves/setup.json", "r") as f:
|
||||
setupX = json.load(f)
|
||||
|
||||
try:
|
||||
setupX[str(guild.id)]
|
||||
except:
|
||||
setupX[str(guild.id)] = {"save": False,
|
||||
"guild_name": guild.name,
|
||||
"debug": False}
|
||||
|
||||
with open("saves/setup.json", "w") as f:
|
||||
json.dump(setupX, f, indent=4)
|
||||
|
||||
# adding accounts
|
||||
|
||||
with open("saves/accounts.json", "r") as f:
|
||||
accounts = json.load(f)
|
||||
|
||||
try:
|
||||
accounts[str(guild.id)]
|
||||
except:
|
||||
accounts[str(guild.id)] = {}
|
||||
|
||||
with open("saves/accounts.json", "w") as f:
|
||||
json.dump(accounts, f, indent=4)
|
||||
|
||||
# adding channel
|
||||
|
||||
with open("saves/channels.json", "r") as f:
|
||||
channels = json.load(f)
|
||||
|
||||
try:
|
||||
channels[str(guild.id)]
|
||||
except:
|
||||
channels[str(guild.id)] = guild.text_channels[len(guild.text_channels)-1].name
|
||||
|
||||
await guild.text_channels[len(guild.text_channels)-1].send("This channel has been chosen by Edu-Kun by default "
|
||||
"as channel where bot sends messages(notifications)\n"
|
||||
"U can change this with command &set_channel "
|
||||
"<channel_name>\n "
|
||||
"\n\t\tuse &help to get more information")
|
||||
|
||||
with open("saves/channels.json", "w") as f:
|
||||
json.dump(channels, f, indent=4)
|
||||
|
||||
# adding to old messages file
|
||||
|
||||
with open("saves/old.json", "r") as f:
|
||||
old = json.load(f)
|
||||
|
||||
try:
|
||||
old[str(guild.id)]
|
||||
except:
|
||||
old[str(guild.id)] = {
|
||||
"homework": {},
|
||||
"messages": {}
|
||||
}
|
||||
|
||||
with open("saves/old.json", "w") as f:
|
||||
json.dump(old, f, indent=4)
|
||||
|
||||
@commands.command(hidden=True)
|
||||
async def secretxxx(self, ctx):
|
||||
for guild in self.client.guilds:
|
||||
await self.on_guild_join(guild)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_remove(self, guild):
|
||||
gi = str(guild.id)
|
||||
|
||||
# checking if we want to delete or save the data
|
||||
with open("saves/setup.json", "r") as f:
|
||||
setupX = json.load(f)
|
||||
|
||||
if setupX[str(guild.id)]["save"] is False:
|
||||
# removing prefix
|
||||
with open("saves/prefixes", "r") as f:
|
||||
prefixes = json.load(f)
|
||||
|
||||
prefixes.pop(gi)
|
||||
|
||||
with open("saves/prefixes", "w") as f:
|
||||
json.dump(prefixes, f, indent=4)
|
||||
|
||||
# removing accounts
|
||||
with open("saves/accounts.json", "r") as f:
|
||||
accounts = json.load(f)
|
||||
|
||||
accounts.pop(gi)
|
||||
|
||||
with open("saves/accounts.json", "w") as f:
|
||||
json.dump(accounts, f, indent=4)
|
||||
|
||||
# removing channel
|
||||
with open("saves/channels.json", "r") as f:
|
||||
channels = json.load(f)
|
||||
|
||||
channels.pop(gi)
|
||||
|
||||
with open("saves/channels.json", "w") as f:
|
||||
json.dump(channels, f, indent=4)
|
||||
|
||||
# removing list of old messages
|
||||
with open("saves/old.json", "r") as f:
|
||||
old = json.load(f)
|
||||
|
||||
old.pop(gi)
|
||||
|
||||
with open("saves/old.json", "w") as f:
|
||||
json.dump(old, f, indent=4)
|
||||
|
||||
try:
|
||||
# removing accounts
|
||||
with open("saves/edu.json", "r") as f:
|
||||
save = json.load(f)
|
||||
|
||||
save.pop(gi)
|
||||
|
||||
with open("saves/edu.json", "w") as f:
|
||||
json.dump(save, f, indent=4)
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
# removing accounts
|
||||
with open("saves/edu0.json", "r") as f:
|
||||
save = json.load(f)
|
||||
|
||||
save.pop(gi)
|
||||
|
||||
with open("saves/edu0.json", "w") as f:
|
||||
json.dump(save, f, indent=4)
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
# removing accounts
|
||||
with open("saves/edu1.json", "r") as f:
|
||||
save = json.load(f)
|
||||
|
||||
save.pop(gi)
|
||||
|
||||
with open("saves/edu1.json", "w") as f:
|
||||
json.dump(save, f, indent=4)
|
||||
except:
|
||||
pass
|
||||
|
||||
with open("saves/setup.json", "r") as f:
|
||||
setupX = json.load(f)
|
||||
|
||||
setupX.pop(gi)
|
||||
|
||||
with open("saves/setup.json", "w") as f:
|
||||
json.dump(setupX, f, indent=4)
|
||||
|
||||
with open("saves/names.json", "r") as f:
|
||||
names = json.load(f)
|
||||
|
||||
try:
|
||||
names.pop(gi)
|
||||
except:
|
||||
pass
|
||||
|
||||
with open("saves/names.json", "w") as f:
|
||||
json.dump(names, f, indent=4)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message):
|
||||
if message.author == self.client.user:
|
||||
return
|
||||
|
||||
# server management commands
|
||||
@commands.command()
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def change_prefix(self, ctx, *, prefix):
|
||||
with open("saves/prefixes", "r") as f:
|
||||
prefixes = json.load(f)
|
||||
|
||||
prefixes[str(ctx.guild.id)] = prefix
|
||||
|
||||
with open("saves/prefixes", "w") as f:
|
||||
json.dump(prefixes, f, indent=4)
|
||||
|
||||
await ctx.send(f"Prefix changed to '{prefix}'.")
|
||||
|
||||
@commands.command()
|
||||
@commands.has_permissions(administrator=True)
|
||||
async def save_on_quit(self, ctx, *, bool_):
|
||||
if bool_ in ["False", "false", "no", "No"]:
|
||||
|
||||
with open("saves/setup.json", "r") as f:
|
||||
store = json.load(f)
|
||||
|
||||
store[str(ctx.guild.id)]["save"] = False
|
||||
|
||||
with open("saves/setup.json", "w") as f:
|
||||
json.dump(store, f, indent=4)
|
||||
|
||||
await ctx.send("Saving on quit is turned off.")
|
||||
|
||||
elif bool_ in ["True", "true", "yes", "Yes"]:
|
||||
|
||||
with open("saves/setup.json", "r") as f:
|
||||
store = json.load(f)
|
||||
|
||||
store[str(ctx.guild.id)]["save"] = True
|
||||
|
||||
with open("saves/setup.json", "w") as f:
|
||||
json.dump(store, f, indent=4)
|
||||
|
||||
await ctx.send("Saving on quit is turned on.")
|
||||
|
||||
@commands.command()
|
||||
@commands.has_permissions(manage_messages=True)
|
||||
async def clear(self, ctx, amount=5):
|
||||
amount = int(amount)
|
||||
if amount > 1000:
|
||||
amount = 1000
|
||||
amount += 1
|
||||
await ctx.channel.purge(limit=amount)
|
||||
await ctx.send(f"Cleared {amount - 1} messages.")
|
||||
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(Server_Management(client))
|
||||
Reference in New Issue
Block a user