Own Settings for every Server the Bot joined
This commit is contained in:
parent
e24e5e55c8
commit
750e021833
40
akuma.py
40
akuma.py
@ -4,13 +4,17 @@ from discord.ext import commands
|
|||||||
|
|
||||||
#config file
|
#config file
|
||||||
c = json.load(open("settings.json", "r"))
|
c = json.load(open("settings.json", "r"))
|
||||||
|
s = json.load(open("server.json", "r"))
|
||||||
|
|
||||||
#The Bot itself
|
#The Bot itself
|
||||||
bot = commands.Bot(description=c["description"], command_prefix=c["prefix"])
|
bot = commands.Bot(description=c["description"], command_prefix=c["prefix"])
|
||||||
|
|
||||||
#Function to write changed config to JSON file
|
#Function to write changed config to JSON file
|
||||||
def writeJSON(data):
|
def writeConfig(data):
|
||||||
with open("settings.json", "w") as file:
|
json.dump(data, open("settings.json", "w"), indent=4)
|
||||||
json.dump(data, file, indent=4)
|
|
||||||
|
def writeServer(data):
|
||||||
|
json.dump(data, open("server.json", "w"), indent=4)
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
@ -18,13 +22,27 @@ async def on_ready():
|
|||||||
game = (c["prefix"] + "help" if (c["game"] == "") else c["prefix"] + "help | " + c["game"])
|
game = (c["prefix"] + "help" if (c["game"] == "") else c["prefix"] + "help | " + c["game"])
|
||||||
return await bot.change_presence(status=discord.Status.online,activity=discord.Game(name=game))
|
return await bot.change_presence(status=discord.Status.online,activity=discord.Game(name=game))
|
||||||
|
|
||||||
|
@bot.event
|
||||||
|
async def on_guild_join(guild):
|
||||||
|
s[str(guild.id)] = {"adminRole": "", "modRole": "", "joinMessage" : "", "suggestionChannel": 0, "modChannel": 0}
|
||||||
|
writeServer(s)
|
||||||
|
|
||||||
|
@bot.event
|
||||||
|
async def on_guild_remove(guild):
|
||||||
|
del s[str(guild.id)]
|
||||||
|
writeServer(s)
|
||||||
|
|
||||||
|
@bot.command()
|
||||||
|
async def invite(ctx):
|
||||||
|
await ctx.send("https://discordapp.com/oauth2/authorize?client_id={}&scope=bot&permissions=8".format(bot.user.id))
|
||||||
|
|
||||||
@bot.command(hidden=True)
|
@bot.command(hidden=True)
|
||||||
async def printExt(ctx):
|
async def printExt(ctx):
|
||||||
"""Prints out every loaded extension"""
|
"""Prints out every loaded extension"""
|
||||||
s = []
|
string = []
|
||||||
for ext in bot.extensions:
|
for ext in bot.extensions:
|
||||||
s.append(ext.split(".")[1])
|
string.append(ext.split(".")[1])
|
||||||
await ctx.send("Loaded extensions: " + ", ".join(s))
|
await ctx.send("Loaded extensions: " + ", ".join(string))
|
||||||
|
|
||||||
@bot.command(hidden=True)
|
@bot.command(hidden=True)
|
||||||
async def load(ctx, ext : str = None, json : bool = False):
|
async def load(ctx, ext : str = None, json : bool = False):
|
||||||
@ -32,7 +50,7 @@ async def load(ctx, ext : str = None, json : bool = False):
|
|||||||
|
|
||||||
First argument is the name of python file without .py extension.
|
First argument is the name of python file without .py extension.
|
||||||
(Optional) If second argument is True, it will be autoloaded"""
|
(Optional) If second argument is True, it will be autoloaded"""
|
||||||
if(ctx.author.id != c["owner"]):
|
if(ctx.author.id != ctx.guild.owner.id):
|
||||||
return
|
return
|
||||||
if(ext == None):
|
if(ext == None):
|
||||||
return await ctx.send("No extension specified")
|
return await ctx.send("No extension specified")
|
||||||
@ -41,14 +59,14 @@ async def load(ctx, ext : str = None, json : bool = False):
|
|||||||
await ctx.send("Loaded " + ext)
|
await ctx.send("Loaded " + ext)
|
||||||
if(json):
|
if(json):
|
||||||
c["extensions"].append(ext)
|
c["extensions"].append(ext)
|
||||||
writeJSON(c)
|
writeConfig(c)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await ctx.send("Failed to load extension \"{}\": {}".format(ext, "{} ({})".format(type(e).__name__, e)))
|
await ctx.send("Failed to load extension \"{}\": {}".format(ext, "{} ({})".format(type(e).__name__, e)))
|
||||||
|
|
||||||
@bot.command(hidden=True)
|
@bot.command(hidden=True)
|
||||||
async def reload(ctx, ext : str = None):
|
async def reload(ctx, ext : str = None):
|
||||||
"""Reloads an extension"""
|
"""Reloads an extension"""
|
||||||
if(ctx.author.id != c["owner"]):
|
if(ctx.author.id != ctx.guild.owner.id):
|
||||||
return
|
return
|
||||||
if(ext == None):
|
if(ext == None):
|
||||||
return await ctx.send("No extension specified")
|
return await ctx.send("No extension specified")
|
||||||
@ -69,7 +87,7 @@ async def unload(ctx, ext : str = None, json : bool = False):
|
|||||||
|
|
||||||
First argument is the name of the extension.
|
First argument is the name of the extension.
|
||||||
(Optional) If second argument is True, it will be removed from autoload"""
|
(Optional) If second argument is True, it will be removed from autoload"""
|
||||||
if(ctx.author.id != c["owner"]):
|
if(ctx.author.id != ctx.guild.owner.id):
|
||||||
return
|
return
|
||||||
if(ext == None):
|
if(ext == None):
|
||||||
return await ctx.send("No extension specified")
|
return await ctx.send("No extension specified")
|
||||||
@ -78,7 +96,7 @@ async def unload(ctx, ext : str = None, json : bool = False):
|
|||||||
await ctx.send("Unloaded " + ext)
|
await ctx.send("Unloaded " + ext)
|
||||||
if(json):
|
if(json):
|
||||||
c["extensions"].remove(ext)
|
c["extensions"].remove(ext)
|
||||||
writeJSON(c)
|
writeConfig(c)
|
||||||
else:
|
else:
|
||||||
await ctx.send("Extension " + ext + " not loaded")
|
await ctx.send("Extension " + ext + " not loaded")
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import discord, json
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from akuma import c, writeJSON
|
from akuma import s, c, writeServer
|
||||||
|
|
||||||
modCommands = """```Possible Commands:
|
modCommands = """```Possible Commands:
|
||||||
mod setJoinMessage <msg>
|
mod setJoinMessage <msg>
|
||||||
@ -24,7 +24,7 @@ class Moderation():
|
|||||||
@commands.group()
|
@commands.group()
|
||||||
async def mod(self, ctx):
|
async def mod(self, ctx):
|
||||||
"""Commands usable a Mod"""
|
"""Commands usable a Mod"""
|
||||||
if (ctx.author.id not in c["mods"]):
|
if (s[str(ctx.guild.id)]["modRole"] not in [r.name for r in ctx.author.roles]):
|
||||||
return
|
return
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
||||||
await ctx.send(modCommands)
|
await ctx.send(modCommands)
|
||||||
@ -32,7 +32,7 @@ class Moderation():
|
|||||||
@commands.group()
|
@commands.group()
|
||||||
async def admin(self, ctx):
|
async def admin(self, ctx):
|
||||||
"""Commands usable by an Admin"""
|
"""Commands usable by an Admin"""
|
||||||
if(ctx.author.id not in c["admins"]):
|
if(s[str(ctx.guild.id)]["adminRole"] not in [r.name for r in ctx.author.roles]):
|
||||||
return
|
return
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
||||||
await ctx.send(adminCommands)
|
await ctx.send(adminCommands)
|
||||||
@ -48,8 +48,8 @@ class Moderation():
|
|||||||
### Mod Commands ###
|
### Mod Commands ###
|
||||||
@mod.command()
|
@mod.command()
|
||||||
async def setJoinMessage(self, ctx, *, msg : str):
|
async def setJoinMessage(self, ctx, *, msg : str):
|
||||||
c["joinMessage"] = msg
|
s[str(ctx.guild.id)]["joinMessage"] = msg
|
||||||
writeJSON(c)
|
writeServer(s)
|
||||||
await ctx.send("Join Message sucessfully changed to: " + msg)
|
await ctx.send("Join Message sucessfully changed to: " + msg)
|
||||||
|
|
||||||
### Admin Commands ###
|
### Admin Commands ###
|
||||||
@ -61,11 +61,11 @@ class Moderation():
|
|||||||
if user is None:
|
if user is None:
|
||||||
return await ctx.send("User not Found")
|
return await ctx.send("User not Found")
|
||||||
#Add Mod Role to User
|
#Add Mod Role to User
|
||||||
if(c["modRole"] not in [r.name for r in user.roles]):
|
if(s[str(ctx.guild.id)]["modRole"] not in [r.name for r in user.roles]):
|
||||||
await user.add_roles(discord.utils.get(ctx.guild.roles, name=c["modRole"]))
|
await user.add_roles(discord.utils.get(ctx.guild.roles, name=s[str(ctx.guild.id)]["modRole"]))
|
||||||
await ctx.send("User " + user.name + " was added to " + c["modRole"])
|
await ctx.send("User " + user.name + " was added to " + s[str(ctx.guild.id)]["modRole"])
|
||||||
else:
|
else:
|
||||||
return await ctx.send("User " + user.name + " is already in " + c["modRole"])
|
return await ctx.send("User " + user.name + " is already in " + s[str(ctx.guild.id)]["modRole"])
|
||||||
|
|
||||||
@admin.command()
|
@admin.command()
|
||||||
async def rmMod(self, ctx, id : int = None):
|
async def rmMod(self, ctx, id : int = None):
|
||||||
@ -76,29 +76,29 @@ class Moderation():
|
|||||||
return await ctx.send("User not Found")
|
return await ctx.send("User not Found")
|
||||||
if (user.id == ctx.author.id):
|
if (user.id == ctx.author.id):
|
||||||
return await ctx.send("You can't remove yourself from Mods")
|
return await ctx.send("You can't remove yourself from Mods")
|
||||||
if(c["adminRole"] in [r.name for r in user.roles] and ctx.author.id != ctx.guild.owner.id):
|
if(s[str(ctx.guild.id)]["adminRole"] in [r.name for r in user.roles] and ctx.author.id != ctx.guild.owner.id):
|
||||||
return await ctx.send("You can't remove this ID")
|
return await ctx.send("You can't remove this ID")
|
||||||
if(c["modRole"] in [r.name for r in user.roles]):
|
if(s[str(ctx.guild.id)]["modRole"] in [r.name for r in user.roles]):
|
||||||
await user.remove_roles(discord.utils.get(ctx.guild.roles, name=c["modRole"]))
|
await user.remove_roles(discord.utils.get(ctx.guild.roles, name=s[str(ctx.guild.id)]["modRole"]))
|
||||||
await ctx.send("User " + user.name + " was removed from " + c["modRole"])
|
await ctx.send("User " + user.name + " was removed from " + s[str(ctx.guild.id)]["modRole"])
|
||||||
else:
|
else:
|
||||||
return await ctx.send("User " + user.name + " wasn't in " + c["modRole"])
|
return await ctx.send("User " + user.name + " wasn't in " + s[str(ctx.guild.id)]["modRole"])
|
||||||
|
|
||||||
### Owner Commands ###
|
### Owner Commands ###
|
||||||
@owner.command()
|
@owner.command()
|
||||||
async def setModRole(self, ctx, msg : str):
|
async def setModRole(self, ctx, msg : str):
|
||||||
if(msg not in [r.name for r in ctx.guild.roles]):
|
if(msg not in [r.name for r in ctx.guild.roles]):
|
||||||
return await ctx.send("Role " + msg + " does not exist")
|
return await ctx.send("Role " + msg + " does not exist")
|
||||||
c["modRole"] = msg
|
s[str(ctx.guild.id)]["modRole"] = msg
|
||||||
writeJSON(c)
|
writeServer(s)
|
||||||
await ctx.send("Mod role set")
|
await ctx.send("Mod role set")
|
||||||
|
|
||||||
@owner.command()
|
@owner.command()
|
||||||
async def setAdminRole(self, ctx, msg : str):
|
async def setAdminRole(self, ctx, msg : str):
|
||||||
if(msg not in [r.name for r in ctx.guild.roles]):
|
if(msg not in [r.name for r in ctx.guild.roles]):
|
||||||
return await ctx.send("Role " + msg + " does not exist")
|
return await ctx.send("Role " + msg + " does not exist")
|
||||||
c["adminRole"] = msg
|
s[str(ctx.guild.id)]["adminRole"] = msg
|
||||||
writeJSON(c)
|
writeServer(s)
|
||||||
await ctx.send("Admin role set")
|
await ctx.send("Admin role set")
|
||||||
|
|
||||||
@owner.command()
|
@owner.command()
|
||||||
@ -109,17 +109,17 @@ class Moderation():
|
|||||||
if user is None:
|
if user is None:
|
||||||
return await ctx.send("User not Found")
|
return await ctx.send("User not Found")
|
||||||
#Add Admin Role to User
|
#Add Admin Role to User
|
||||||
if(c["adminRole"] not in [r.name for r in user.roles]):
|
if(s[str(ctx.guild.id)]["adminRole"] not in [r.name for r in user.roles]):
|
||||||
await user.add_roles(discord.utils.get(ctx.guild.roles, name=c["adminRole"]))
|
await user.add_roles(discord.utils.get(ctx.guild.roles, name=s[str(ctx.guild.id)]["adminRole"]))
|
||||||
await ctx.send("User " + user.name + " was added to " + c["adminRole"])
|
await ctx.send("User " + user.name + " was added to " + s[str(ctx.guild.id)]["adminRole"])
|
||||||
else:
|
else:
|
||||||
return await ctx.send("User " + user.name + " is already in " + c["adminRole"])
|
return await ctx.send("User " + user.name + " is already in " + s[str(ctx.guild.id)]["adminRole"])
|
||||||
#Add Mod Role to User
|
#Add Mod Role to User
|
||||||
if(c["modRole"] not in [r.name for r in user.roles]):
|
if(s[str(ctx.guild.id)]["modRole"] not in [r.name for r in user.roles]):
|
||||||
await user.add_roles(discord.utils.get(ctx.guild.roles, name=c["modRole"]))
|
await user.add_roles(discord.utils.get(ctx.guild.roles, name=s[str(ctx.guild.id)]["modRole"]))
|
||||||
await ctx.send("User " + user.name + " was added to " + c["modRole"])
|
await ctx.send("User " + user.name + " was added to " + s[str(ctx.guild.id)]["modRole"])
|
||||||
else:
|
else:
|
||||||
return await ctx.send("User " + user.name + " is already in " + c["modRole"])
|
return await ctx.send("User " + user.name + " is already in " + s[str(ctx.guild.id)]["modRole"])
|
||||||
|
|
||||||
@owner.command()
|
@owner.command()
|
||||||
async def rmAdmin(self, ctx, id : int = None):
|
async def rmAdmin(self, ctx, id : int = None):
|
||||||
@ -130,11 +130,11 @@ class Moderation():
|
|||||||
return await ctx.send("User not Found")
|
return await ctx.send("User not Found")
|
||||||
if (user.id == ctx.author.id):
|
if (user.id == ctx.author.id):
|
||||||
return await ctx.send("You can't remove yourself from Admins")
|
return await ctx.send("You can't remove yourself from Admins")
|
||||||
if(c["adminRole"] in [r.name for r in user.roles]):
|
if(s[str(ctx.guild.id)]["adminRole"] in [r.name for r in user.roles]):
|
||||||
await user.remove_roles(discord.utils.get(ctx.guild.roles, name=c["adminRole"]))
|
await user.remove_roles(discord.utils.get(ctx.guild.roles, name=s[str(ctx.guild.id)]["adminRole"]))
|
||||||
await ctx.send("User " + user.name + " was removed from " + c["adminRole"])
|
await ctx.send("User " + user.name + " was removed from " + s[str(ctx.guild.id)]["adminRole"])
|
||||||
else:
|
else:
|
||||||
return await ctx.send("User " + user.name + " wasn't in " + c["adminRole"])
|
return await ctx.send("User " + user.name + " wasn't in " + s[str(ctx.guild.id)]["adminRole"])
|
||||||
|
|
||||||
#Setup
|
#Setup
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from akuma import c
|
from akuma import s
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
class User():
|
class User():
|
||||||
@ -9,7 +9,7 @@ class User():
|
|||||||
@commands.command()
|
@commands.command()
|
||||||
async def greetMe(self, ctx):
|
async def greetMe(self, ctx):
|
||||||
"""Prints the greeting text a user receives by joining the server"""
|
"""Prints the greeting text a user receives by joining the server"""
|
||||||
await ctx.send(c["joinMessage"])
|
await ctx.send(s[str(ctx.guild.id)]["joinMessage"])
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def suggest(self, ctx, *, msg : str):
|
async def suggest(self, ctx, *, msg : str):
|
||||||
@ -20,8 +20,8 @@ class User():
|
|||||||
e = discord.Embed(color=0x6428c8)
|
e = discord.Embed(color=0x6428c8)
|
||||||
e.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
|
e.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
|
||||||
e.add_field(name="Suggestion", value=msg)
|
e.add_field(name="Suggestion", value=msg)
|
||||||
if(c["suggestionChannel"] != 0):
|
if(s[str(ctx.guild.id)]["suggestionChannel"] != 0):
|
||||||
chan = self.bot.get_channel(c["suggestionChannel"])
|
chan = self.bot.get_channel(s[str(ctx.guild.id)]["suggestionChannel"])
|
||||||
await chan.send(embed=e)
|
await chan.send(embed=e)
|
||||||
else:
|
else:
|
||||||
await ctx.send(e)
|
await ctx.send(e)
|
||||||
|
2
server.json
Normal file
2
server.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
@ -3,13 +3,9 @@
|
|||||||
"prefix": "~",
|
"prefix": "~",
|
||||||
"description": "A Discord Bot written by Akuma#7346",
|
"description": "A Discord Bot written by Akuma#7346",
|
||||||
"game": "",
|
"game": "",
|
||||||
"adminRole": "",
|
|
||||||
"modRole": "",
|
|
||||||
"extensions": [
|
"extensions": [
|
||||||
"fun",
|
"fun",
|
||||||
"moderation",
|
"moderation",
|
||||||
"user"
|
"user"
|
||||||
],
|
]
|
||||||
"joinMessage": "",
|
|
||||||
"suggestionChannel": 0
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user