Rework of Bot
This commit is contained in:
parent
6f0e6737fd
commit
86b53caba6
198
akuma.py
198
akuma.py
@ -1,154 +1,58 @@
|
|||||||
import json, discord, io
|
import json, discord, os, io
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ext.commands import CommandNotFound
|
|
||||||
|
|
||||||
#config files
|
class Akuma(commands.Bot):
|
||||||
cFile = "settings.json"
|
def __init__(self):
|
||||||
sFile = "server.json"
|
#storing configuration path
|
||||||
|
self.cfgPath = os.path.join(
|
||||||
|
os.environ.get("APPDATA") or
|
||||||
|
os.environ.get("XDG_CONFIG_HOME") or
|
||||||
|
os.path.join(os.environ["HOME"], ".config"),
|
||||||
|
"Akumatic", "Akuma-Matata")
|
||||||
|
|
||||||
|
#creating config directory if not available
|
||||||
|
if not os.path.exists(self.cfgPath):
|
||||||
|
os.makedirs(self.cfgPath)
|
||||||
|
|
||||||
|
#configuration objects for internal use
|
||||||
|
self.cfg = self.loadJSON("settings.json", {"token": "", "prefix": ">>", "description": "A Discord Bot written b"
|
||||||
|
"y Akuma#7346", "game": "", "extensions": ["core", "server", "fun", "user"]})
|
||||||
|
if self.cfg["token"] == "":
|
||||||
|
self.cfg["token"] = input("Please insert the Bot Token: ")
|
||||||
|
self.writeJSON("settings.json", self.cfg)
|
||||||
|
|
||||||
c = json.load(open(cFile, "r"))
|
self.serverCfg = self.loadJSON("server.json")
|
||||||
s = json.load(open(sFile, "r"))
|
|
||||||
|
#initializing the bot
|
||||||
#Function to write changed config to JSON file
|
super().__init__(description=self.cfg["description"], command_prefix=self.cfg["prefix"],
|
||||||
def writeConfig(data):
|
case_insensitive=True)
|
||||||
json.dump(data, open(cFile, "w"), indent=4)
|
|
||||||
|
#loading extensions given in cfg
|
||||||
def writeServer(data):
|
for ext in self.cfg["extensions"]:
|
||||||
json.dump(data, open(sFile, "w"), indent=4)
|
try:
|
||||||
|
self.load_extension("extensions." + ext)
|
||||||
#The Bot itself
|
except Exception as e:
|
||||||
bot = commands.Bot(description=c["description"], command_prefix=c["prefix"])
|
print("Failed to load extension \"{}\": {}".format(ext,
|
||||||
|
"{} ({})".format(type(e).__name__, e)))
|
||||||
@bot.event
|
|
||||||
async def on_ready():
|
def run(self):
|
||||||
print("Bot is running!")
|
super().run(self.cfg["token"])
|
||||||
game = (c["prefix"] + "help" if (c["game"] == "") else c["prefix"] + "help | " + c["game"])
|
print("Bot running")
|
||||||
return await bot.change_presence(status=discord.Status.online,activity=discord.Game(name=game))
|
|
||||||
|
def loadJSON(self, s : str, default : dict = None):
|
||||||
@bot.event
|
if not os.path.isfile(os.path.join(self.cfgPath, s)):
|
||||||
async def on_guild_join(guild):
|
with open(os.path.join(self.cfgPath, s), "w+") as f:
|
||||||
s[str(guild.id)] = {"adminRole": "", "modRole": "", "joinMessage": "", "suggestionChannel": 0, "modChannel": 0, "announcementChannel": 0, "announcements": 0, "logEditAndDelete": True, "logEditAndDeleteChannel": 0, "logJoinAndLeave": True, "logJoinAndLeaveChannel" : 0}
|
if default == None:
|
||||||
writeServer(s)
|
json.dump({}, f, indent=4)
|
||||||
|
|
||||||
@bot.event
|
|
||||||
async def on_guild_remove(guild):
|
|
||||||
del s[str(guild.id)]
|
|
||||||
writeServer(s)
|
|
||||||
|
|
||||||
@bot.event
|
|
||||||
async def on_command_error(ctx, error):
|
|
||||||
if isinstance(error, CommandNotFound):
|
|
||||||
return
|
|
||||||
raise error
|
|
||||||
|
|
||||||
@bot.event
|
|
||||||
async def on_message(message):
|
|
||||||
if message.guild == None and message.author.bot == False and message.content[:len(bot.command_prefix)] != bot.command_prefix:
|
|
||||||
user = bot.get_user(c["maintainer"])
|
|
||||||
if user is not None:
|
|
||||||
e = discord.Embed(color=0xc83232)
|
|
||||||
e.set_author(name = str(message.author) + " sent a DM.", icon_url=message.author.avatar_url)
|
|
||||||
e.add_field(name="Profile", value=message.author.mention, inline=False)
|
|
||||||
if message.content:
|
|
||||||
e.add_field(name="Content", value=message.content, inline=False)
|
|
||||||
numAtch = len(message.attachments)
|
|
||||||
if numAtch == 0:
|
|
||||||
await user.send(embed=e)
|
|
||||||
elif numAtch == 1:
|
|
||||||
x = io.BytesIO()
|
|
||||||
await message.attachments[0].save(x)
|
|
||||||
name = message.attachments[0].filename
|
|
||||||
f = discord.File(x, filename = name)
|
|
||||||
extention = name.split(".")[-1]
|
|
||||||
if extention in ["jpg", "jpeg", "png", "webp", "gif"]:
|
|
||||||
e.set_image(url = "attachment://"+name)
|
|
||||||
await user.send(embed=e, file=f)
|
|
||||||
else:
|
else:
|
||||||
e.add_field(name="Attachment",value=name, inline=False)
|
json.dump(default, f, indent=4)
|
||||||
await user.send(embed=e)
|
with open(os.path.join(self.cfgPath, s), "r") as f:
|
||||||
await user.send(file=f)
|
return json.load(f)
|
||||||
else:
|
|
||||||
e.add_field(name="Attachments",value=str(numAtch)+" Attachments sent", inline=False)
|
|
||||||
await user.send(embed=e)
|
|
||||||
for a in message.attachments:
|
|
||||||
x = io.BytesIO()
|
|
||||||
await a.save(x)
|
|
||||||
await user.send(file=discord.File(x, filename=a.filename))
|
|
||||||
await bot.process_commands(message)
|
|
||||||
|
|
||||||
@bot.command(hidden=True)
|
def writeJSON(self, s : str, data):
|
||||||
async def printExt(ctx):
|
with open(os.path.join(self.cfgPath, s), "w") as f:
|
||||||
"""Prints out every loaded extension"""
|
json.dump(data, f, indent=4)
|
||||||
string = []
|
|
||||||
for ext in bot.extensions:
|
|
||||||
string.append(ext.split(".")[1])
|
|
||||||
await ctx.send("Loaded extensions: " + ", ".join(string))
|
|
||||||
|
|
||||||
@bot.command(hidden=True)
|
|
||||||
async def load(ctx, ext : str = None, json : bool = False):
|
|
||||||
"""Loads a new python file from \"extension\" folder.
|
|
||||||
|
|
||||||
First argument is the name of python file without .py extension.
|
|
||||||
(Optional) If second argument is True, it will be autoloaded"""
|
|
||||||
if(ctx.author.id != c["maintainer"]):
|
|
||||||
return
|
|
||||||
if(ext == None):
|
|
||||||
return await ctx.send("No extension specified")
|
|
||||||
try:
|
|
||||||
bot.load_extension("extensions." + ext)
|
|
||||||
await ctx.send("Loaded " + ext)
|
|
||||||
if(json):
|
|
||||||
c["extensions"].append(ext)
|
|
||||||
writeConfig(c)
|
|
||||||
except Exception as e:
|
|
||||||
await ctx.send("Failed to load extension \"{}\": {}".format(ext, "{} ({})".format(type(e).__name__, e)))
|
|
||||||
|
|
||||||
@bot.command(hidden=True)
|
|
||||||
async def reload(ctx, ext : str = None):
|
|
||||||
"""Reloads an extension"""
|
|
||||||
if(ctx.author.id != c["maintainer"]):
|
|
||||||
return
|
|
||||||
if(ext == None):
|
|
||||||
return await ctx.send("No extension specified")
|
|
||||||
if(("extensions." + ext) in bot.extensions):
|
|
||||||
bot.unload_extension("extensions." + ext)
|
|
||||||
await ctx.send("Unloaded " + ext)
|
|
||||||
try:
|
|
||||||
bot.load_extension("extensions." + ext)
|
|
||||||
await ctx.send("Loaded " + ext)
|
|
||||||
except Exception as e:
|
|
||||||
await ctx.send("Failed to load extension \"{}\": {}".format(ext, "{} ({})".format(type(e).__name__, e)))
|
|
||||||
else:
|
|
||||||
await ctx.send("Extension " + ext + " not loaded")
|
|
||||||
|
|
||||||
@bot.command(hidden=True)
|
|
||||||
async def unload(ctx, ext : str = None, json : bool = False):
|
|
||||||
"""Unloads an extension.
|
|
||||||
|
|
||||||
First argument is the name of the extension.
|
|
||||||
(Optional) If second argument is True, it will be removed from autoload"""
|
|
||||||
if(ctx.author.id != c["maintainer"]):
|
|
||||||
return
|
|
||||||
if(ext == None):
|
|
||||||
return await ctx.send("No extension specified")
|
|
||||||
if(("extensions." + ext) in bot.extensions):
|
|
||||||
bot.unload_extension("extensions." + ext)
|
|
||||||
await ctx.send("Unloaded " + ext)
|
|
||||||
if(json):
|
|
||||||
c["extensions"].remove(ext)
|
|
||||||
writeConfig(c)
|
|
||||||
else:
|
|
||||||
await ctx.send("Extension " + ext + " not loaded")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
#loads all extensions mentioned in settings.json
|
bot = Akuma()
|
||||||
if(c["token"] == ""):
|
bot.run()
|
||||||
print("Please insert a Bot Token into settings.json first")
|
|
||||||
exit()
|
|
||||||
for ext in c["extensions"]:
|
|
||||||
try:
|
|
||||||
bot.load_extension("extensions." + ext)
|
|
||||||
except Exception as e:
|
|
||||||
print("Failed to load extension \"{}\": {}".format(ext, "{} ({})".format(type(e).__name__, e)))
|
|
||||||
|
|
||||||
bot.run(c["token"])
|
|
123
extensions/core.py
Normal file
123
extensions/core.py
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
from discord.ext import commands
|
||||||
|
import discord, io
|
||||||
|
|
||||||
|
class Core(commands.Cog):
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
#Listener
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_ready(self):
|
||||||
|
print("Bot is running!")
|
||||||
|
game = self.bot.cfg["prefix"] + "help" + (" | " + self.bot.cfg["game"] if self.bot.cfg["game"] != "" else "")
|
||||||
|
await self.bot.change_presence(status=discord.Status.online, activity=discord.Game(name=game))
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_guild_join(self, guild):
|
||||||
|
self.bot.serverCfg[str(guild.id)] = {}
|
||||||
|
self.bot.writeJSON("server.json", self.bot.serverCfg)
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_guild_remove(self, guild):
|
||||||
|
del self.bot.serverCfg[str(guild.id)]
|
||||||
|
self.bot.writeJSON("server.json", self.bot.serverCfg)
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_command_error(self, ctx, error):
|
||||||
|
if isinstance(error, commands.CommandNotFound):
|
||||||
|
return await ctx.author.send("The command you tried to use does not exist.")
|
||||||
|
if isinstance(error, commands.NotOwner):
|
||||||
|
return await ctx.send("Only the owner of this bot can use this command.")
|
||||||
|
if isinstance(error, commands.MissingPermissions):
|
||||||
|
return await ctx.send("You don't have the necessary permissions to use this command.")
|
||||||
|
if isinstance(error, commands.NoPrivateMessage):
|
||||||
|
return await ctx.send("This command is only usable in a server.")
|
||||||
|
info = await self.bot.application_info()
|
||||||
|
user = info.owner
|
||||||
|
if user is not None:
|
||||||
|
e = discord.Embed(color=0xc83232)
|
||||||
|
e.set_author(name="Error Log")
|
||||||
|
e.add_field(name="Source", value=ctx.message.channel, inline=False)
|
||||||
|
e.add_field(name="Trigger", value=ctx.message.content,inline=False)
|
||||||
|
e.add_field(name="Trace", value=error, inline=False)
|
||||||
|
await user.send(embed=e)
|
||||||
|
|
||||||
|
#Commands
|
||||||
|
@commands.command()
|
||||||
|
@commands.is_owner()
|
||||||
|
async def stop(self, ctx):
|
||||||
|
await self.bot.close()
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.is_owner()
|
||||||
|
async def changeGame(self, ctx, *, msg : str = None):
|
||||||
|
self.bot.cfg["game"] = "" if msg == None else msg
|
||||||
|
game = self.bot.cfg["prefix"] + "help" + (" | " + self.bot.cfg["game"] if self.bot.cfg["game"] != "" else "")
|
||||||
|
await self.bot.change_presence(status=discord.Status.online, activity=discord.Game(name=game))
|
||||||
|
|
||||||
|
@commands.command(hidden=True)
|
||||||
|
@commands.is_owner()
|
||||||
|
async def load(self, ctx, ext : str = None, json : bool = False):
|
||||||
|
"""Loads a new python file from \"extension\" folder.
|
||||||
|
|
||||||
|
First argument is the name of python file without .py extension.
|
||||||
|
(Optional) If second argument is True, it will be autoloaded"""
|
||||||
|
if ext == None:
|
||||||
|
return await ctx.send("No extension specified")
|
||||||
|
try:
|
||||||
|
self.bot.load_extension("extensions." + ext)
|
||||||
|
await ctx.send("Loaded " + ext)
|
||||||
|
if json:
|
||||||
|
self.bot.cfg["extensions"].append(ext)
|
||||||
|
self.bot.writeJSON("settings.json", self.bot.cfg)
|
||||||
|
except Exception as e:
|
||||||
|
await ctx.send("Failed to load extension \"{}\": {}".format(ext, "{} ({})".format(type(e).__name__, e)))
|
||||||
|
|
||||||
|
@commands.command(hidden=True)
|
||||||
|
@commands.is_owner()
|
||||||
|
async def unload(self, ctx, ext : str = None, json : bool = False):
|
||||||
|
"""Unloads an extension.
|
||||||
|
|
||||||
|
First argument is the name of the extension.
|
||||||
|
(Optional) If second argument is True, it will be removed from autoload"""
|
||||||
|
if ext == None:
|
||||||
|
return await ctx.send("No extension specified")
|
||||||
|
if ("extensions." + ext) in self.bot.extensions:
|
||||||
|
self.bot.unload_extension("extensions." + ext)
|
||||||
|
await ctx.send("Unloaded " + ext)
|
||||||
|
if json:
|
||||||
|
self.bot.cfg["extensions"].remove(ext)
|
||||||
|
self.bot.writeJSON("settings.json", self.bot.cfg)
|
||||||
|
else:
|
||||||
|
await ctx.send("Extension {} not loaded".format(ext))
|
||||||
|
|
||||||
|
@commands.command(hidden=True)
|
||||||
|
@commands.is_owner()
|
||||||
|
async def reload(self, ctx, ext : str = None):
|
||||||
|
"""Reloads an extension"""
|
||||||
|
if ext == None:
|
||||||
|
return await ctx.send("No extension specified")
|
||||||
|
if ("extensions." + ext) in self.bot.extensions:
|
||||||
|
self.bot.unload_extension("extensions." + ext)
|
||||||
|
await ctx.send("Unloaded " + ext)
|
||||||
|
try:
|
||||||
|
self.bot.load_extension("extensions." + ext)
|
||||||
|
await ctx.send("Loaded " + ext)
|
||||||
|
except Exception as e:
|
||||||
|
await ctx.send("Failed to load extension \"{}\": {}".format(ext, "{} ({})".format(type(e).__name__, e)))
|
||||||
|
else:
|
||||||
|
await ctx.send("Extension {} not loaded".format(ext))
|
||||||
|
|
||||||
|
@commands.command(hidden=True)
|
||||||
|
@commands.is_owner()
|
||||||
|
async def printExt(self, ctx):
|
||||||
|
"""Prints out every loaded extension"""
|
||||||
|
string = []
|
||||||
|
temp = None
|
||||||
|
for ext in self.bot.extensions:
|
||||||
|
temp = ext.split(".")
|
||||||
|
string.append(temp[1] if len(temp) > 1 else temp[0])
|
||||||
|
await ctx.send("Loaded extensions: {}".format(", ".join(string)))
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(Core(bot))
|
@ -8,98 +8,102 @@ class Fun(commands.Cog):
|
|||||||
@commands.command()
|
@commands.command()
|
||||||
async def ping(self, ctx):
|
async def ping(self, ctx):
|
||||||
"""Ping, Pong"""
|
"""Ping, Pong"""
|
||||||
await ctx.send(ctx.author.mention + " Pong!")
|
await ctx.send("{} Pong!".format(ctx.author.mention))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def d4(self, ctx):
|
async def d4(self, ctx, *, msg : str = None):
|
||||||
"""Throws a four-sided dice."""
|
"""Throws a four-sided dice."""
|
||||||
await ctx.send(ctx.author.mention + " You rolled a D4: " + str(random.randint(1,4)))
|
await ctx.send("{} You rolled a D4{}: {}".format(ctx.author.mention,
|
||||||
|
"" if msg is None else " for \"{}\"".format(msg), random.randint(1, 4)))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def d6(self, ctx):
|
async def d6(self, ctx, *, msg : str = None):
|
||||||
"""Throws a six-sided dice."""
|
"""Throws a six-sided dice."""
|
||||||
await ctx.send(ctx.author.mention + " You rolled a D6: " + str(random.randint(1,6)))
|
await ctx.send("{} You rolled a D6{}: {}".format(ctx.author.mention,
|
||||||
|
"" if msg is None else " for \"{}\"".format(msg), random.randint(1, 6)))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def d8(self, ctx):
|
async def d8(self, ctx, *, msg : str = None):
|
||||||
"""Throws a eight-sided dice."""
|
"""Throws a eight-sided dice."""
|
||||||
await ctx.send(ctx.author.mention + " You rolled a D8: " + str(random.randint(1,8)))
|
await ctx.send("{} You rolled a D8{}: {}".format(ctx.author.mention,
|
||||||
|
"" if msg is None else " for \"{}\"".format(msg), random.randint(1, 8)))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def d10(self, ctx):
|
async def d10(self, ctx, *, msg : str = None):
|
||||||
"""Throws a eight-sided dice."""
|
"""Throws a eight-sided dice."""
|
||||||
await ctx.send(ctx.author.mention + " You rolled a D10: " + str(random.randint(1,10)))
|
await ctx.send("{} You rolled a D10{}: {}".format(ctx.author.mention,
|
||||||
|
"" if msg is None else " for \"{}\"".format(msg), random.randint(1, 10)))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def d12(self, ctx):
|
async def d12(self, ctx, *, msg : str = None):
|
||||||
"""Throws a twelve-sided dice."""
|
"""Throws a twelve-sided dice."""
|
||||||
await ctx.send(ctx.author.mention + " You rolled a D12: " + str(random.randint(1,12)))
|
await ctx.send("{} You rolled a D12{}: {}".format(ctx.author.mention,
|
||||||
|
"" if msg is None else " for \"{}\"".format(msg), random.randint(1, 12)))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def d20(self, ctx):
|
async def d20(self, ctx, *, msg : str = None):
|
||||||
"""Throws a twenty-sided dice."""
|
"""Throws a twenty-sided dice."""
|
||||||
await ctx.send(ctx.author.mention + " You rolled a D20: " + str(random.randint(1,20)))
|
await ctx.send("{} You rolled a D20{}: {}".format(ctx.author.mention,
|
||||||
|
"" if msg is None else " for \"{}\"".format(msg), random.randint(1, 20)))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def d100(self, ctx):
|
async def d100(self, ctx, *, msg : str = None):
|
||||||
"""Throws a hundred-sided dice."""
|
"""Throws a hundred-sided dice."""
|
||||||
await ctx.send(ctx.author.mention + " You rolled a D100: " + str(random.randint(1,100)))
|
await ctx.send("{} You rolled a D100{}: {}".format(ctx.author.mention,
|
||||||
|
"" if msg is None else " for \"{}\"".format(msg), random.randint(1, 100)))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command(name="8ball")
|
||||||
async def magic8ball(self,ctx, *, msg : str = None):
|
async def magic8ball(self,ctx, *, msg : str = None):
|
||||||
if msg is None:
|
if msg is None:
|
||||||
await ctx.send(":8ball: You need a question")
|
await ctx.send(":8ball: You need to specify a question.")
|
||||||
else:
|
else:
|
||||||
answers = ["Yes.", "As I see it, yes.", "Outlook good.", "For sure",
|
|
||||||
"Without a doubt.", "It is decidedly so.", "Without a doubt.",
|
|
||||||
"Maybe", "Perhaps","It is uncertain", "Dont even think about it.",
|
|
||||||
"Nope.", "Don't count on it.", "My sources say no.",
|
|
||||||
"Outlook not so good.", "Very doubtful.", "Definitely no."]
|
|
||||||
e = discord.Embed(color=0x3296ff)
|
e = discord.Embed(color=0x3296ff)
|
||||||
e.set_author(name = str(ctx.author), icon_url=ctx.author.avatar_url)
|
e.set_author(name = str(ctx.author), icon_url=ctx.author.avatar_url)
|
||||||
e.add_field(name=":grey_question: Question", value=msg, inline=False)
|
e.add_field(name=":grey_question: Question", value=msg, inline=False)
|
||||||
e.add_field(name=":8ball: Answer", value=random.choice(answers), inline=False)
|
e.add_field(name=":8ball: Answer", value=random.choice(
|
||||||
|
["Yes.", "As I see it, yes.", "Outlook good.", "For sure", "Without a doubt.", "It is decidedly so.",
|
||||||
|
"Without a doubt.", "Maybe", "Perhaps","It is uncertain", "Dont even think about it.", "Nope.", "Don't "
|
||||||
|
"count on it.", "My sources say no.", "Outlook not so good.", "Very doubtful.", "Definitely no."]
|
||||||
|
), inline=False)
|
||||||
await ctx.send(embed=e)
|
await ctx.send(embed=e)
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def coin(self, ctx):
|
async def coin(self, ctx):
|
||||||
"""Throws a coin."""
|
"""Throws a coin."""
|
||||||
await ctx.send(ctx.author.mention + " Your coin flip is " + ("Head" if (random.random() < 0.5) else "Tail"))
|
await ctx.send("{} Your coin flip is {}".format(ctx.author.mention, random.choice(["Head", "Tail"])))
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def rps(self, ctx, userChoice : str=""):
|
async def rps(self, ctx, userChoice : str = None):
|
||||||
"""Play Rock, Paper, Scissors with the Bot
|
"""Play Rock, Paper, Scissors with the Bot
|
||||||
Input \"r\" for Rock, \"p\" for Paper and \"s\" for Scissors"""
|
Input \"r\" for Rock, \"p\" for Paper and \"s\" for Scissors"""
|
||||||
vals = ["r", "p", "s"]
|
if userChoice == None or str.lower(userChoice) not in ["r", "p", "s"]:
|
||||||
userChoice = str.lower(userChoice)
|
return await ctx.send("{} Invalid input. Please enter \"r\", \"p\" or \"s\"".format(ctx.author.mention))
|
||||||
if userChoice == "" or userChoice not in vals:
|
|
||||||
await ctx.send(ctx.author.mention + " Invalid input. Please enter \"r\", \"p\", or \"s\"")
|
botChoice = ["r", "p", "s"][random.randint(0,2)]
|
||||||
|
if userChoice == "r" and botChoice == "p":
|
||||||
|
await ctx.send("{} You lose".format(ctx.author.mention))
|
||||||
|
elif userChoice == "p" and botChoice == "s":
|
||||||
|
await ctx.send("{} You lose".format(ctx.author.mention))
|
||||||
|
elif userChoice == "s" and botChoice == "r":
|
||||||
|
await ctx.send("{} You lose".format(ctx.author.mention))
|
||||||
|
elif userChoice == "r" and botChoice == "s":
|
||||||
|
await ctx.send("{} You win".format(ctx.author.mention))
|
||||||
|
elif userChoice == "p" and botChoice == "r":
|
||||||
|
await ctx.send("{} You win".format(ctx.author.mention))
|
||||||
|
elif userChoice == "s" and botChoice == "p":
|
||||||
|
await ctx.send("{} You win".format(ctx.author.mention))
|
||||||
else:
|
else:
|
||||||
botChoice = vals[random.randint(0,2)]
|
await ctx.send("{} It's a tie".format(ctx.author.mention))
|
||||||
if(userChoice == "r" and botChoice == "p"):
|
|
||||||
await ctx.send(ctx.author.mention + " You lose")
|
|
||||||
elif(userChoice == "r" and botChoice == "s"):
|
|
||||||
await ctx.send(ctx.author.mention + " You win")
|
|
||||||
elif(userChoice == "p" and botChoice == "r"):
|
|
||||||
await ctx.send(ctx.author.mention + " You win")
|
|
||||||
elif(userChoice == "p" and botChoice == "s"):
|
|
||||||
await ctx.send(ctx.author.mention + " You lose")
|
|
||||||
elif(userChoice == "s" and botChoice == "r"):
|
|
||||||
await ctx.send(ctx.author.mention + " You lose")
|
|
||||||
elif(userChoice == "s" and botChoice == "p"):
|
|
||||||
await ctx.send(ctx.author.mention + " You win")
|
|
||||||
else:
|
|
||||||
await ctx.send(ctx.author.mention + " It's a tie")
|
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def roll(self, ctx, a : int = 0, b : int= 100):
|
async def roll(self, ctx, a : int = 0, b : int= 100):
|
||||||
"""Rolls a random number between min and max.
|
"""Rolls a random number between min and max.
|
||||||
Default values are 0 and 100"""
|
Default values are 0 and 100"""
|
||||||
if(a > b):
|
if a > b:
|
||||||
temp = a
|
temp = a
|
||||||
a = b
|
a = b
|
||||||
b = temp
|
b = temp
|
||||||
await ctx.send(ctx.author.mention + " Random roll between " + str(a) + " and " + str(b) + ": " + str(random.randint(a,b)))
|
await ctx.send("{} Random roll between {} and {}: {}".format(ctx.author.mention, a, b, random.randint(a, b)))
|
||||||
|
|
||||||
#Setup
|
#Setup
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
|
@ -1,310 +0,0 @@
|
|||||||
import discord, io
|
|
||||||
from discord.ext import commands
|
|
||||||
from datetime import datetime
|
|
||||||
from akuma import s, c, writeServer
|
|
||||||
|
|
||||||
modCommands = """```Possible Commands:
|
|
||||||
mod setJoinMessage <msg>
|
|
||||||
```"""
|
|
||||||
|
|
||||||
adminCommands = """```Possible Commands:
|
|
||||||
admin addMod <id>
|
|
||||||
admin rmMod <id>
|
|
||||||
```"""
|
|
||||||
|
|
||||||
ownerCommands = """```Possible Commands:
|
|
||||||
owner addAdmin <id>
|
|
||||||
owner rmAdmin <id>
|
|
||||||
```"""
|
|
||||||
|
|
||||||
class Moderation(commands.Cog):
|
|
||||||
def __init__(self, bot):
|
|
||||||
self.bot = bot
|
|
||||||
|
|
||||||
#Logs
|
|
||||||
@commands.Cog.listener()
|
|
||||||
async def on_member_join(self, member):
|
|
||||||
if s[str(member.guild.id)]["logJoinAndLeave"] == True:
|
|
||||||
if s[str(member.guild.id)]["joinMessage"] != "":
|
|
||||||
await member.send(s[str(member.guild.id)]["joinMessage"])
|
|
||||||
if s[str(member.guild.id)]["logJoinAndLeaveChannel"] != 0:
|
|
||||||
e = discord.Embed(color=0x32c832)
|
|
||||||
e.set_author(name = str(member) + " has joined the server.", icon_url=member.avatar_url)
|
|
||||||
e.add_field(name="ID", value=str(member.id), inline=False)
|
|
||||||
e.add_field(name="Mention", value=member.mention, inline=False)
|
|
||||||
chan = self.bot.get_channel(s[str(member.guild.id)]["logJoinAndLeaveChannel"])
|
|
||||||
await chan.send(embed=e)
|
|
||||||
|
|
||||||
@commands.Cog.listener()
|
|
||||||
async def on_member_remove(self, member):
|
|
||||||
if s[str(member.guild.id)]["logJoinAndLeave"] == True:
|
|
||||||
if s[str(member.guild.id)]["logJoinAndLeaveChannel"] != 0:
|
|
||||||
e = discord.Embed(color=0xc83232)
|
|
||||||
e.set_author(name = str(member) + " has left the server.", icon_url=member.avatar_url)
|
|
||||||
e.add_field(name="ID", value=str(member.id), inline=False)
|
|
||||||
e.add_field(name="Mention", value=member.mention, inline=False)
|
|
||||||
chan = self.bot.get_channel(s[str(member.guild.id)]["logJoinAndLeaveChannel"])
|
|
||||||
await chan.send(embed=e)
|
|
||||||
|
|
||||||
@commands.Cog.listener()
|
|
||||||
async def on_message_edit(self, before, after):
|
|
||||||
if before.guild is not None and before.author.bot == False and s[str(before.guild.id)]["logEditAndDelete"] == True:
|
|
||||||
if s[str(before.guild.id)]["logEditAndDeleteChannel"] != 0 and before.content != after.content:
|
|
||||||
e = discord.Embed(color=0x32c8c8)
|
|
||||||
e.set_author(name = str(before.author) + " edited a message.", icon_url=before.author.avatar_url)
|
|
||||||
e.add_field(name="Profile", value=before.author.mention, inline=False)
|
|
||||||
e.add_field(name="Channel", value=str(before.channel.name), inline=False)
|
|
||||||
e.add_field(name="Message before", value=before.content,inline=False)
|
|
||||||
e.add_field(name="Message after", value=after.content,inline=False)
|
|
||||||
chan = self.bot.get_channel(s[str(before.guild.id)]["logEditAndDeleteChannel"])
|
|
||||||
await chan.send(embed=e)
|
|
||||||
|
|
||||||
@commands.Cog.listener()
|
|
||||||
async def on_message_delete(self, message):
|
|
||||||
if message.guild is not None and message.author.bot == False and s[str(message.guild.id)]["logEditAndDelete"] == True:
|
|
||||||
if s[str(message.guild.id)]["logEditAndDeleteChannel"] != 0:
|
|
||||||
e = discord.Embed(color=0xc83232)
|
|
||||||
e.set_author(name = str(message.author) + "'s message got deleted.", icon_url=message.author.avatar_url)
|
|
||||||
e.add_field(name="Profile", value=message.author.mention, inline=False)
|
|
||||||
e.add_field(name="Channel", value=str(message.channel.name), inline=False)
|
|
||||||
if message.content:
|
|
||||||
e.add_field(name="Message", value=message.content,inline=False)
|
|
||||||
numAtch = len(message.attachments)
|
|
||||||
if numAtch == 1:
|
|
||||||
e.add_field(name="Attachments", value="The message had " + str(numAtch) + " attachment",inline=False)
|
|
||||||
e.add_field(name="File Name", value=message.attachments[0].filename, inline=False)
|
|
||||||
elif numAtch > 1:
|
|
||||||
e.add_field(name="Attachments", value="The message had " + str(numAtch) + " attachments",inline=False)
|
|
||||||
for a in message.attachments:
|
|
||||||
e.add_field(name="File Name", value=a.filename, inline=False)
|
|
||||||
chan = self.bot.get_channel(s[str(message.guild.id)]["logEditAndDeleteChannel"])
|
|
||||||
await chan.send(embed=e)
|
|
||||||
|
|
||||||
#Groups
|
|
||||||
@commands.group()
|
|
||||||
async def mod(self, ctx):
|
|
||||||
"""Commands usable a Mod"""
|
|
||||||
if s[str(ctx.guild.id)]["modRole"] not in [r.name for r in ctx.author.roles]:
|
|
||||||
return
|
|
||||||
if ctx.invoked_subcommand is None:
|
|
||||||
await ctx.send(modCommands)
|
|
||||||
|
|
||||||
@commands.group()
|
|
||||||
async def admin(self, ctx):
|
|
||||||
"""Commands usable by an Admin"""
|
|
||||||
if s[str(ctx.guild.id)]["adminRole"] not in [r.name for r in ctx.author.roles]:
|
|
||||||
return
|
|
||||||
if ctx.invoked_subcommand is None:
|
|
||||||
await ctx.send(adminCommands)
|
|
||||||
|
|
||||||
@commands.group()
|
|
||||||
async def owner(self, ctx):
|
|
||||||
"""Commands usable by the Owner"""
|
|
||||||
if ctx.author.id != ctx.guild.owner.id:
|
|
||||||
return
|
|
||||||
if ctx.invoked_subcommand is None:
|
|
||||||
await ctx.send(ownerCommands)
|
|
||||||
|
|
||||||
### Mod Commands ###
|
|
||||||
@mod.command()
|
|
||||||
async def setJoinMessage(self, ctx, *, msg : str):
|
|
||||||
s[str(ctx.guild.id)]["joinMessage"] = msg
|
|
||||||
writeServer(s)
|
|
||||||
await ctx.send("Join Message sucessfully changed to: " + msg)
|
|
||||||
|
|
||||||
@mod.command()
|
|
||||||
async def setAnnouncementChannel(self, ctx, cid : int = None):
|
|
||||||
if cid is None:
|
|
||||||
return await ctx.send("Please specify a channel")
|
|
||||||
if cid not in [c.id for c in ctx.guild.channels]:
|
|
||||||
return await ctx.send("Channel " + cid + " does not exist")
|
|
||||||
s[str(ctx.guild.id)]["announcementChannel"] = cid
|
|
||||||
writeServer(s)
|
|
||||||
await ctx.send("Announcement channel set")
|
|
||||||
|
|
||||||
@mod.command()
|
|
||||||
async def setModChannel(self, ctx, cid : int = None):
|
|
||||||
if cid is None:
|
|
||||||
return await ctx.send("Please specify a channel")
|
|
||||||
if cid not in [c.id for c in ctx.guild.channels]:
|
|
||||||
return await ctx.send("Channel " + cid + " does not exist")
|
|
||||||
s[str(ctx.guild.id)]["modChannel"] = cid
|
|
||||||
writeServer(s)
|
|
||||||
await ctx.send("Mod channel set")
|
|
||||||
|
|
||||||
@mod.command()
|
|
||||||
async def setMemberLogChannel(self, ctx, cid : int = None):
|
|
||||||
if cid is None:
|
|
||||||
return await ctx.send("Please specify a channel")
|
|
||||||
if cid not in [c.id for c in ctx.guild.channels]:
|
|
||||||
return await ctx.send("Channel " + cid + " does not exist")
|
|
||||||
s[str(ctx.guild.id)]["logJoinAndLeaveChannel"] = cid
|
|
||||||
writeServer(s)
|
|
||||||
await ctx.send("Member log channel set")
|
|
||||||
|
|
||||||
@mod.command()
|
|
||||||
async def setMessageChannel(self, ctx, cid : int = None):
|
|
||||||
if cid is None:
|
|
||||||
return await ctx.send("Please specify a channel")
|
|
||||||
if cid not in [c.id for c in ctx.guild.channels]:
|
|
||||||
return await ctx.send("Channel " + cid + " does not exist")
|
|
||||||
s[str(ctx.guild.id)]["logEditAndDeleteChannel"] = cid
|
|
||||||
writeServer(s)
|
|
||||||
await ctx.send("Message log channel set")
|
|
||||||
|
|
||||||
@mod.command()
|
|
||||||
async def changeMemberLogging(self, ctx):
|
|
||||||
if s[str(ctx.guild.id)]["logJoinAndLeave"] == True:
|
|
||||||
s[str(ctx.guild.id)]["logJoinAndLeave"] = False
|
|
||||||
else:
|
|
||||||
s[str(ctx.guild.id)]["logJoinAndLeave"] = True
|
|
||||||
writeServer(s)
|
|
||||||
await ctx.send("Member logging set to " + str(s[str(ctx.guild.id)]["logJoinAndLeave"]))
|
|
||||||
|
|
||||||
@mod.command()
|
|
||||||
async def changeMessageLogging(self, ctx):
|
|
||||||
if s[str(ctx.guild.id)]["logEditAndDelete"] == True:
|
|
||||||
s[str(ctx.guild.id)]["logEditAndDelete"] = False
|
|
||||||
else:
|
|
||||||
s[str(ctx.guild.id)]["logEditAndDelete"] = True
|
|
||||||
writeServer(s)
|
|
||||||
await ctx.send("Message logging set to " + str(s[str(ctx.guild.id)]["logEditAndDelete"]))
|
|
||||||
|
|
||||||
@mod.command()
|
|
||||||
async def kick(self, ctx, id : int = None, *, msg : str = None):
|
|
||||||
if id == None:
|
|
||||||
return await ctx.send("Missing id")
|
|
||||||
if msg == None:
|
|
||||||
return await ctx.send("Please specify a reason for kicking this user")
|
|
||||||
user = ctx.guild.get_member(id)
|
|
||||||
if user is None:
|
|
||||||
return await ctx.send("User not Found")
|
|
||||||
if s[str(ctx.guild.id)]["modRole"] in [r.name for r in user.roles]:
|
|
||||||
return await ctx.send("You can't kick this user")
|
|
||||||
await ctx.guild.kick(user)
|
|
||||||
if s[str(ctx.guild.id)]["modChannel"] != 0:
|
|
||||||
e = discord.Embed(color=0x6428c8)
|
|
||||||
e.set_author(name = ctx.author.name, icon_url=ctx.author.avatar_url)
|
|
||||||
e.add_field(name="Kicked:", value=str(user), inline=False)
|
|
||||||
e.add_field(name="Reason:", value=msg, inline=False)
|
|
||||||
chan = self.bot.get_channel(s[str(ctx.guild.id)]["modChannel"])
|
|
||||||
await chan.send(embed=e)
|
|
||||||
|
|
||||||
@mod.command()
|
|
||||||
async def announce(self, ctx, *, msg):
|
|
||||||
if s[str(ctx.guild.id)]["announcementChannel"] == 0:
|
|
||||||
return await ctx.send("No Channel for Announcements specified. Please set it up first with \"setAnnouncementChannel\"")
|
|
||||||
else:
|
|
||||||
e = discord.Embed(color=0x6428c8)
|
|
||||||
num = s[str(ctx.guild.id)]["announcements"]
|
|
||||||
num += 1
|
|
||||||
s[str(ctx.guild.id)]["announcements"] = num
|
|
||||||
writeServer(s)
|
|
||||||
e.add_field(name="#" + str(s[str(ctx.guild.id)]["announcements"]) + " - " + datetime.now().strftime("%d.%m.%Y"), value=msg, inline=False)
|
|
||||||
chan = self.bot.get_channel(s[str(ctx.guild.id)]["announcementChannel"])
|
|
||||||
await chan.send(embed=e)
|
|
||||||
|
|
||||||
@mod.command()
|
|
||||||
async def printServerSettings(self, ctx):
|
|
||||||
e = discord.Embed(color=0x6428c8)
|
|
||||||
for i in s[str(ctx.guild.id)].items():
|
|
||||||
n = i[0]
|
|
||||||
if i[1] == "":
|
|
||||||
v = "not set"
|
|
||||||
elif i[1] == 0:
|
|
||||||
if i[0] == "announcements":
|
|
||||||
v = 0
|
|
||||||
else:
|
|
||||||
v = "not set"
|
|
||||||
else:
|
|
||||||
v = i[1]
|
|
||||||
e.add_field(name=n, value=v, inline=False)
|
|
||||||
await ctx.send(embed=e)
|
|
||||||
|
|
||||||
### Admin Commands ###
|
|
||||||
@admin.command()
|
|
||||||
async def addMod(self, ctx, id : int = None):
|
|
||||||
if id == None:
|
|
||||||
return await ctx.send("Missing id")
|
|
||||||
user = ctx.guild.get_member(id)
|
|
||||||
if user is None:
|
|
||||||
return await ctx.send("User not Found")
|
|
||||||
#Add Mod Role to User
|
|
||||||
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=s[str(ctx.guild.id)]["modRole"]))
|
|
||||||
await ctx.send("User " + user.name + " was added to " + s[str(ctx.guild.id)]["modRole"])
|
|
||||||
else:
|
|
||||||
return await ctx.send("User " + user.name + " is already in " + s[str(ctx.guild.id)]["modRole"])
|
|
||||||
|
|
||||||
@admin.command()
|
|
||||||
async def rmMod(self, ctx, id : int = None):
|
|
||||||
if id == None:
|
|
||||||
return await ctx.send("Missing id")
|
|
||||||
user = ctx.guild.get_member(id)
|
|
||||||
if user is None:
|
|
||||||
return await ctx.send("User not Found")
|
|
||||||
if user.id == ctx.author.id:
|
|
||||||
return await ctx.send("You can't remove yourself from Mods")
|
|
||||||
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")
|
|
||||||
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=s[str(ctx.guild.id)]["modRole"]))
|
|
||||||
await ctx.send("User " + user.name + " was removed from " + s[str(ctx.guild.id)]["modRole"])
|
|
||||||
else:
|
|
||||||
return await ctx.send("User " + user.name + " wasn't in " + s[str(ctx.guild.id)]["modRole"])
|
|
||||||
|
|
||||||
### Owner Commands ###
|
|
||||||
@owner.command()
|
|
||||||
async def setModRole(self, ctx, msg : str):
|
|
||||||
if msg not in [r.name for r in ctx.guild.roles]:
|
|
||||||
return await ctx.send("Role " + msg + " does not exist")
|
|
||||||
s[str(ctx.guild.id)]["modRole"] = msg
|
|
||||||
writeServer(s)
|
|
||||||
await ctx.send("Mod role set")
|
|
||||||
|
|
||||||
@owner.command()
|
|
||||||
async def setAdminRole(self, ctx, msg : str):
|
|
||||||
if msg not in [r.name for r in ctx.guild.roles]:
|
|
||||||
return await ctx.send("Role " + msg + " does not exist")
|
|
||||||
s[str(ctx.guild.id)]["adminRole"] = msg
|
|
||||||
writeServer(s)
|
|
||||||
await ctx.send("Admin role set")
|
|
||||||
|
|
||||||
@owner.command()
|
|
||||||
async def addAdmin(self, ctx, id : int = None):
|
|
||||||
if id == None:
|
|
||||||
return await ctx.send("Missing id")
|
|
||||||
user = ctx.guild.get_member(id)
|
|
||||||
if user is None:
|
|
||||||
return await ctx.send("User not Found")
|
|
||||||
#Add Admin Role to User
|
|
||||||
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=s[str(ctx.guild.id)]["adminRole"]))
|
|
||||||
await ctx.send("User " + user.name + " was added to " + s[str(ctx.guild.id)]["adminRole"])
|
|
||||||
else:
|
|
||||||
return await ctx.send("User " + user.name + " is already in " + s[str(ctx.guild.id)]["adminRole"])
|
|
||||||
#Add Mod Role to User
|
|
||||||
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=s[str(ctx.guild.id)]["modRole"]))
|
|
||||||
await ctx.send("User " + user.name + " was added to " + s[str(ctx.guild.id)]["modRole"])
|
|
||||||
else:
|
|
||||||
return await ctx.send("User " + user.name + " is already in " + s[str(ctx.guild.id)]["modRole"])
|
|
||||||
|
|
||||||
@owner.command()
|
|
||||||
async def rmAdmin(self, ctx, id : int = None):
|
|
||||||
if id == None:
|
|
||||||
return await ctx.send("Missing id")
|
|
||||||
user = ctx.guild.get_member(id)
|
|
||||||
if user is None:
|
|
||||||
return await ctx.send("User not Found")
|
|
||||||
if user.id == ctx.author.id:
|
|
||||||
return await ctx.send("You can't remove yourself from Admins")
|
|
||||||
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=s[str(ctx.guild.id)]["adminRole"]))
|
|
||||||
await ctx.send("User " + user.name + " was removed from " + s[str(ctx.guild.id)]["adminRole"])
|
|
||||||
else:
|
|
||||||
return await ctx.send("User " + user.name + " wasn't in " + s[str(ctx.guild.id)]["adminRole"])
|
|
||||||
|
|
||||||
#Setup
|
|
||||||
def setup(bot):
|
|
||||||
bot.add_cog(Moderation(bot))
|
|
258
extensions/server.py
Normal file
258
extensions/server.py
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
import discord, random
|
||||||
|
from discord.ext import commands
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
class Server(commands.Cog):
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
def serverCfgCheck(self, id : int, key : str, default):
|
||||||
|
if str(id) not in self.bot.serverCfg:
|
||||||
|
self.bot.serverCfg[str(id)] = {}
|
||||||
|
if "server" not in self.bot.serverCfg[str(id)]:
|
||||||
|
self.bot.serverCfg[str(id)]["server"] = {}
|
||||||
|
if key not in self.bot.serverCfg[str(id)]["server"]:
|
||||||
|
self.bot.serverCfg[str(id)]["server"][key] = default
|
||||||
|
self.bot.writeJSON("server.json", self.bot.serverCfg)
|
||||||
|
|
||||||
|
#Listener
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_member_join(self, member):
|
||||||
|
self.serverCfgCheck(member.guild.id, "logMemberEvent", False)
|
||||||
|
self.serverCfgCheck(member.guild.id, "joinMessage", "")
|
||||||
|
self.serverCfgCheck(member.guild.id, "memberEventChannel", 0)
|
||||||
|
self.serverCfgCheck(member.guild.id, "modChannel", 0)
|
||||||
|
|
||||||
|
if self.bot.serverCfg[str(member.guild.id)]["server"]["logMemberEvent"]:
|
||||||
|
if self.bot.serverCfg[str(member.guild.id)]["server"]["joinMessage"] != "":
|
||||||
|
await member.send(self.bot.serverCfg[str(member.guild.id)]["server"]["joinMessage"])
|
||||||
|
if self.bot.serverCfg[str(member.guild.id)]["server"]["memberEventChannel"] != 0:
|
||||||
|
e = discord.Embed(color=0x32c832)
|
||||||
|
e.set_author(name = str(member) + " joined the server.", icon_url=member.avatar_url)
|
||||||
|
e.add_field(name="ID", value=str(member.id), inline=False)
|
||||||
|
e.add_field(name="Mention", value=member.mention, inline=False)
|
||||||
|
chan = self.bot.get_channel(self.bot.serverCfg[str(member.guild.id)]["server"]["memberEventChannel"])
|
||||||
|
await chan.send(embed=e)
|
||||||
|
else:
|
||||||
|
if self.bot.serverCfg[str(member.guild.id)]["server"]["modChannel"] != 0:
|
||||||
|
chan = self.bot.get_channel(self.bot.serverCfg[str(member.guild.id)]["server"]["modChannel"])
|
||||||
|
await chan.send("The ***logMemberEvent*** flag is set, but no ***memberEventChannel*** was specifie"
|
||||||
|
"d. You can set it with `{0}setMemberEventChannel <id>` or disable ***logMemberEvent*** with `{0}to"
|
||||||
|
"ggleMemberEvent`".format(self.bot.command_prefix))
|
||||||
|
else:
|
||||||
|
user = member.guild.owner
|
||||||
|
await user.send("The ***logMemberEvent*** flag in your server \"{0}\" is set, but no ***memberEvent"
|
||||||
|
"Channel*** was specified. You can set it with `{1}setMemberEventChannel <id>` or disable ***logMem"
|
||||||
|
"berEvent*** with `{1}toggleMemberEvent`.\nYou received this message directly because no ***modChan"
|
||||||
|
"nel*** was specified. You can set it with `{1}setModChannel <id>`".format(member.guild.name,
|
||||||
|
self.bot.command_prefix))
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_member_remove(self, member):
|
||||||
|
self.serverCfgCheck(member.guild.id, "logMemberEvent", False)
|
||||||
|
self.serverCfgCheck(member.guild.id, "memberEventChannel", 0)
|
||||||
|
self.serverCfgCheck(member.guild.id, "modChannel", 0)
|
||||||
|
|
||||||
|
if self.bot.serverCfg[str(member.guild.id)]["server"]["logMemberEvent"]:
|
||||||
|
if self.bot.serverCfg[str(member.guild.id)]["server"]["memberEventChannel"] != 0:
|
||||||
|
e = discord.Embed(color=0xc83232)
|
||||||
|
e.set_author(name = str(member) + " left the server.", icon_url=member.avatar_url)
|
||||||
|
e.add_field(name="ID", value=str(member.id), inline=False)
|
||||||
|
e.add_field(name="Mention", value=member.mention, inline=False)
|
||||||
|
chan = self.bot.get_channel(self.bot.serverCfg[str(member.guild.id)]["server"]["memberEventChannel"])
|
||||||
|
await chan.send(embed=e)
|
||||||
|
else:
|
||||||
|
if self.bot.serverCfg[str(member.guild.id)]["server"]["modChannel"] != 0:
|
||||||
|
chan = self.bot.get_channel(self.bot.serverCfg[str(member.guild.id)]["server"]["modChannel"])
|
||||||
|
await chan.send("The ***logMemberEvent*** flag is set, but no ***memberEventChannel*** was specifie"
|
||||||
|
"d. You can set it with `{0}setMemberEventChannel <id>` or disable ***logMemberEvent*** with `{0}to"
|
||||||
|
"ggleMemberEvent`".format(self.bot.command_prefix))
|
||||||
|
else:
|
||||||
|
user = member.guild.owner
|
||||||
|
await user.send("The ***logMemberEvent*** flag in your server \"{0}\" is set, but no ***memberEvent"
|
||||||
|
"Channel*** was specified. You can set it with `{1}setMemberEventChannel <id>` or disable ***logMem"
|
||||||
|
"berEvent*** with `{1}toggleMemberEvent`.\nYou received this message directly because no ***modChan"
|
||||||
|
"nel*** was specified. You can set it with `{1}setModChannel <id>`".format(member.guild.name,
|
||||||
|
self.bot.command_prefix))
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_message_edit(self, before, after):
|
||||||
|
if before.guild is None or before.author.bot:
|
||||||
|
return
|
||||||
|
self.serverCfgCheck(before.guild.id, "logMessageEvent", False)
|
||||||
|
self.serverCfgCheck(before.guild.id, "messageEventChannel", 0)
|
||||||
|
self.serverCfgCheck(before.guild.id, "modChannel", 0)
|
||||||
|
|
||||||
|
if self.bot.serverCfg[str(before.guild.id)]["server"]["logMessageEvent"] and before.content != after.content:
|
||||||
|
if self.bot.serverCfg[str(before.guild.id)]["server"]["messageEventChannel"] != 0:
|
||||||
|
e = discord.Embed(color=0x32c8c8)
|
||||||
|
e.set_author(name = str(before.author) + " edited a message.", icon_url=before.author.avatar_url)
|
||||||
|
e.add_field(name="Profile", value=before.author.mention, inline=False)
|
||||||
|
e.add_field(name="Channel", value=str(before.channel.name), inline=False)
|
||||||
|
e.add_field(name="Message before", value=before.content,inline=False)
|
||||||
|
e.add_field(name="Message after", value=after.content,inline=False)
|
||||||
|
chan = self.bot.get_channel(self.bot.serverCfg[str(before.guild.id)]["server"]["messageEventChannel"])
|
||||||
|
await chan.send(embed=e)
|
||||||
|
else:
|
||||||
|
if self.bot.serverCfg[str(before.guild.id)]["server"]["modChannel"] != 0:
|
||||||
|
chan = self.bot.get_channel(self.bot.serverCfg[str(before.guild.id)]["server"]["modChannel"])
|
||||||
|
await chan.send("The ***logMessageEvent*** flag is set, but no ***messageEventChannel*** was specif"
|
||||||
|
"ied. You can set it with `{0}setMessageEventChannel <id>` or disable ***logMessageEvent*** with `"
|
||||||
|
"{0}toggleMessageEvent`".format(self.bot.command_prefix))
|
||||||
|
else:
|
||||||
|
user = before.guild.owner
|
||||||
|
await user.send("The ***logMessageEvent*** flag in your server \"{0}\" is set, but no ***messageEve"
|
||||||
|
"ntChannel*** was specified. You can set it with `{1}setMessageEventChannel <id>` or disable ***log"
|
||||||
|
"MessageEvent*** with `{1}toggleMessageEvent`.\nYou received this message directly because no ***mo"
|
||||||
|
"dChannel*** was specified. You can set it with `{1}setModChannel <id>`".format(before.guild.name,
|
||||||
|
self.bot.command_prefix))
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_message_delete(self, message):
|
||||||
|
if message.guild is None or message.author.bot:
|
||||||
|
return
|
||||||
|
self.serverCfgCheck(message.guild.id, "logMessageEvent", False)
|
||||||
|
self.serverCfgCheck(message.guild.id, "messageEventChannel", 0)
|
||||||
|
self.serverCfgCheck(message.guild.id, "modChannel", 0)
|
||||||
|
|
||||||
|
if self.bot.serverCfg[str(message.guild.id)]["server"]["logMessageEvent"]:
|
||||||
|
if self.bot.serverCfg[str(message.guild.id)]["server"]["messageEventChannel"] != 0:
|
||||||
|
e = discord.Embed(color=0xc83232)
|
||||||
|
e.set_author(name = str(message.author) + "'s message got deleted.", icon_url=message.author.avatar_url)
|
||||||
|
e.add_field(name="Profile", value=message.author.mention, inline=False)
|
||||||
|
e.add_field(name="Channel", value=str(message.channel.name), inline=False)
|
||||||
|
if message.content:
|
||||||
|
e.add_field(name="Message", value=message.content,inline=False)
|
||||||
|
num = len(message.attachments)
|
||||||
|
if num > 0:
|
||||||
|
e.add_field(name="Attachments", value="The message had {} attachment(s)".format(num),inline=False)
|
||||||
|
for a in message.attachments:
|
||||||
|
e.add_field(name="File Name", value=a.filename, inline=False)
|
||||||
|
chan = self.bot.get_channel(self.bot.serverCfg[str(message.guild.id)]["server"]["messageEventChannel"])
|
||||||
|
await chan.send(embed=e)
|
||||||
|
else:
|
||||||
|
if self.bot.serverCfg[str(message.guild.id)]["server"]["modChannel"] != 0:
|
||||||
|
chan = self.bot.get_channel(self.bot.serverCfg[str(message.guild.id)]["server"]["modChannel"])
|
||||||
|
await chan.send("The ***logMessageEvent*** flag is set, but no ***messageEventChannel*** was specif"
|
||||||
|
"ied. You can set it with `{0}setMessageEventChannel <id>` or disable ***logMessageEvent*** with `"
|
||||||
|
"{0}toggleMessageEvent`".format(self.bot.command_prefix))
|
||||||
|
else:
|
||||||
|
user = message.guild.owner
|
||||||
|
await user.send("The ***logMessageEvent*** flag in your server \"{0}\" is set, but no ***messageEve"
|
||||||
|
"ntChannel*** was specified. You can set it with `{1}setMessageEventChannel <id>` or disable ***log"
|
||||||
|
"MessageEvent*** with `{1}toggleMessageEvent`.\nYou received this message directly because no ***mo"
|
||||||
|
"dChannel*** was specified. You can set it with `{1}setModChannel <id>`".format(message.guild.name,
|
||||||
|
self.bot.command_prefix))
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
async def greetMe(self, ctx):
|
||||||
|
"""Prints the greeting text a user receives by joining the server"""
|
||||||
|
self.serverCfgCheck(ctx.guild.id, "joinMessage", "")
|
||||||
|
temp = self.bot.serverCfg[str(ctx.guild.id)]["server"].get("joinMessage")
|
||||||
|
await ctx.send("No welcome message specified for this server." if temp == "" else temp)
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
@commands.has_permissions(manage_channels=True)
|
||||||
|
async def setJoinMessage(self, ctx, *, msg : str):
|
||||||
|
self.serverCfgCheck(ctx.guild.id, "joinMessage", "")
|
||||||
|
self.bot.serverCfg[str(ctx.guild.id)]["server"]["joinMessage"] = msg
|
||||||
|
self.bot.writeJSON("server.json", self.bot.serverCfg)
|
||||||
|
await ctx.send("joinMessage successfully changed to:\n{}".format(msg))
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
@commands.has_permissions(manage_channels=True)
|
||||||
|
async def toggleMessageEvent(self, ctx):
|
||||||
|
self.serverCfgCheck(ctx.guild.id, "logMessageEvent", False)
|
||||||
|
temp = not self.bot.serverCfg[str(ctx.guild.id)]["server"]["logMessageEvent"]
|
||||||
|
self.bot.serverCfg[str(ctx.guild.id)]["server"]["logMessageEvent"] = temp
|
||||||
|
self.bot.writeJSON("server.json", self.bot.serverCfg)
|
||||||
|
await ctx.send("logMessageEvent set to {}".format(temp))
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
@commands.has_permissions(manage_channels=True)
|
||||||
|
async def setMessageEventChannel(self, ctx, id : int = None):
|
||||||
|
if id is None:
|
||||||
|
return await ctx.send("Please specify a channel")
|
||||||
|
if id not in [c.id for c in ctx.guild.channels]:
|
||||||
|
return await ctx.send("Channel {} does not exist on this server.".format(id))
|
||||||
|
self.serverCfgCheck(ctx.guild.id, "messageEventChannel", 0)
|
||||||
|
self.bot.serverCfg[str(ctx.guild.id)]["server"]["messageEventChannel"] = id
|
||||||
|
self.bot.writeJSON("server.json", self.bot.serverCfg)
|
||||||
|
await ctx.send("messageEventChannel successfully set.")
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
@commands.has_permissions(manage_channels=True)
|
||||||
|
async def toggleMemberEvent(self, ctx):
|
||||||
|
self.serverCfgCheck(ctx.guild.id, "logMemberEvent", False)
|
||||||
|
temp = not self.bot.serverCfg[str(ctx.guild.id)]["server"]["logMemberEvent"]
|
||||||
|
self.bot.serverCfg[str(ctx.guild.id)]["server"]["logMemberEvent"] = temp
|
||||||
|
self.bot.writeJSON("server.json", self.bot.serverCfg)
|
||||||
|
await ctx.send("logMemberEvent set to {}".format(temp))
|
||||||
|
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
@commands.has_permissions(manage_channels=True)
|
||||||
|
async def setMemberEventChannel(self, ctx, id : int = None):
|
||||||
|
if id is None:
|
||||||
|
return await ctx.send("Please specify a channel")
|
||||||
|
if id not in [c.id for c in ctx.guild.channels]:
|
||||||
|
return await ctx.send("Channel {} does not exist on this server.".format(id))
|
||||||
|
self.serverCfgCheck(ctx.guild.id, "memberEventChannel", 0)
|
||||||
|
self.bot.serverCfg[str(ctx.guild.id)]["server"]["memberEventChannel"] = id
|
||||||
|
self.bot.writeJSON("server.json", self.bot.serverCfg)
|
||||||
|
await ctx.send("memberEventChannel successfully set.")
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
@commands.has_permissions(manage_channels=True)
|
||||||
|
async def setModChannel(self, ctx, id : int = None):
|
||||||
|
if id is None:
|
||||||
|
return await ctx.send("Please specify a channel")
|
||||||
|
if id not in [c.id for c in ctx.guild.channels]:
|
||||||
|
return await ctx.send("Channel {} does not exist on this server.".format(id))
|
||||||
|
self.serverCfgCheck(ctx.guild.id, "modChannel", 0)
|
||||||
|
self.bot.serverCfg[str(ctx.guild.id)]["server"]["modChannel"] = id
|
||||||
|
self.bot.writeJSON("server.json", self.bot.serverCfg)
|
||||||
|
await ctx.send("modChannel successfully set.")
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
@commands.has_permissions(manage_channels=True)
|
||||||
|
async def setAnnouncementChannel(self, ctx, id : int = None):
|
||||||
|
if id is None:
|
||||||
|
return await ctx.send("Please specify a channel")
|
||||||
|
if id not in [c.id for c in ctx.guild.channels]:
|
||||||
|
return await ctx.send("Channel {} does not exist on this server.".format(id))
|
||||||
|
self.serverCfgCheck(ctx.guild.id, "announcementChannel", 0)
|
||||||
|
self.bot.serverCfg[str(ctx.guild.id)]["server"]["announcementChannel"] = id
|
||||||
|
self.bot.writeJSON("server.json", self.bot.serverCfg)
|
||||||
|
await ctx.send("announcementChannel successfully set.")
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.guild_only()
|
||||||
|
@commands.has_permissions(manage_channels=True)
|
||||||
|
async def announce(self, ctx, *, msg : str = None):
|
||||||
|
self.serverCfgCheck(ctx.guild.id, "announcementChannel", 0)
|
||||||
|
self.serverCfgCheck(ctx.guild.id, "announcements", 0)
|
||||||
|
if self.bot.serverCfg[str(ctx.guild.id)]["server"]["announcementChannel"] == 0:
|
||||||
|
return await ctx.send("***announcementChannel*** is not set up yet. You can set it with `{0}setAnnouncement"
|
||||||
|
"Channel <id>`".format(self.bot.command_prefix))
|
||||||
|
if msg is None:
|
||||||
|
return await ctx.send("Please specify a message to announce")
|
||||||
|
e = discord.Embed(color=0x6428c8)
|
||||||
|
num = self.bot.serverCfg[str(ctx.guild.id)]["server"]["announcements"] + 1
|
||||||
|
self.bot.serverCfg[str(ctx.guild.id)]["server"]["announcements"] = num
|
||||||
|
self.bot.writeJSON("server.json", self.bot.serverCfg)
|
||||||
|
e.add_field(name="#{} - {} (UTC)".format(num, datetime.utcnow().strftime("%d.%m.%Y")), value=msg, inline=False)
|
||||||
|
chan = self.bot.get_channel(self.bot.serverCfg[str(ctx.guild.id)]["server"]["announcementChannel"])
|
||||||
|
await chan.send(embed=e)
|
||||||
|
|
||||||
|
#Setup
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(Server(bot))
|
@ -1,44 +1,55 @@
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from akuma import s
|
import discord, io
|
||||||
import discord
|
|
||||||
|
|
||||||
class User(commands.Cog):
|
class User(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command()
|
@commands.Cog.listener()
|
||||||
async def greetMe(self, ctx):
|
async def on_message(self, message):
|
||||||
"""Prints the greeting text a user receives by joining the server"""
|
if message.author.bot or message.guild != None:
|
||||||
await ctx.send(s[str(ctx.guild.id)]["joinMessage"])
|
return
|
||||||
|
if message.content[:len(self.bot.command_prefix)] != self.bot.command_prefix:
|
||||||
|
info = await self.bot.application_info()
|
||||||
|
user = info.owner
|
||||||
|
if user is not None:
|
||||||
|
e = discord.Embed(color=0x802080)
|
||||||
|
e.set_author(name = str(message.author) + " sent a DM.",
|
||||||
|
icon_url=message.author.avatar_url)
|
||||||
|
e.add_field(name="Profile", value=message.author.mention, inline=False)
|
||||||
|
if message.content:
|
||||||
|
e.add_field(name="Content", value=message.content, inline=False)
|
||||||
|
numAtch = len(message.attachments)
|
||||||
|
if numAtch == 0:
|
||||||
|
await user.send(embed=e)
|
||||||
|
elif numAtch == 1:
|
||||||
|
x = io.BytesIO()
|
||||||
|
await message.attachments[0].save(x)
|
||||||
|
name = message.attachments[0].filename
|
||||||
|
f = discord.File(x, filename = name)
|
||||||
|
extention = name.split(".")[-1]
|
||||||
|
if extention in ["jpg", "jpeg", "png", "webp", "gif"]:
|
||||||
|
e.set_image(url = "attachment://"+name)
|
||||||
|
await user.send(embed=e, file=f)
|
||||||
|
else:
|
||||||
|
e.add_field(name="Attachment",value=name, inline=False)
|
||||||
|
await user.send(embed=e)
|
||||||
|
await user.send(file=f)
|
||||||
|
else:
|
||||||
|
e.add_field(name="Attachments",value=str(numAtch)+" Attachments sent",
|
||||||
|
inline=False)
|
||||||
|
await user.send(embed=e)
|
||||||
|
for a in message.attachments:
|
||||||
|
x = io.BytesIO()
|
||||||
|
await a.save(x)
|
||||||
|
await user.send(file=discord.File(x, filename=a.filename))
|
||||||
|
|
||||||
@commands.command(hidden=True)
|
@commands.command(hidden=True)
|
||||||
async def botinvite(self, ctx):
|
async def botinvite(self, ctx):
|
||||||
await ctx.send("""Invite Link: <https://discordapp.com/oauth2/authorize?client_id={}&scope=bot&permissions=8>
|
await ctx.send("Invite this bot to your server: <https://discordapp.com/oauth2/authorize?client_id={}&scope=bot"
|
||||||
\nPlease read <https://github.com/Akumatic/Akuma-Matata/blob/master/README.md> for informations""".format(self.bot.user.id))
|
"&permissions=8>\nPlease read <https://github.com/Akumatic/Akuma-Matata/blob/master/README.md> for informat"
|
||||||
|
"ions".format(self.bot.user.id))
|
||||||
|
|
||||||
@commands.command()
|
|
||||||
async def suggest(self, ctx, *, msg : str = None):
|
|
||||||
"""Makes a suggestion to the moderation team.
|
|
||||||
|
|
||||||
Only callable from a server
|
|
||||||
|
|
||||||
Your original message gets deleted and sent to a private suggestion channel.
|
|
||||||
If no suggestion channel is specified, it will be sent to the owner instead."""
|
|
||||||
if(ctx.guild == None):
|
|
||||||
return await ctx.send("This command can only be used within a server")
|
|
||||||
if(msg == None):
|
|
||||||
return await ctx.send("Your suggestion can't be empty")
|
|
||||||
await ctx.message.delete()
|
|
||||||
e = discord.Embed(description="Server: " + ctx.guild.name, color=0x6428c8)
|
|
||||||
e.set_author(name=ctx.author, icon_url=ctx.author.avatar_url)
|
|
||||||
e.add_field(name="Suggestion", value=msg)
|
|
||||||
if(s[str(ctx.guild.id)]["suggestionChannel"] != 0):
|
|
||||||
chan = self.bot.get_channel(s[str(ctx.guild.id)]["suggestionChannel"])
|
|
||||||
await chan.send(embed=e)
|
|
||||||
else:
|
|
||||||
await ctx.guild.get_member(ctx.guild.owner.id).send(embed=e)
|
|
||||||
|
|
||||||
|
|
||||||
#Setup
|
#Setup
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(User(bot))
|
bot.add_cog(User(bot))
|
@ -1,2 +0,0 @@
|
|||||||
{
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"token": "",
|
|
||||||
"prefix": "~",
|
|
||||||
"description": "A Discord Bot written by Akuma#7346",
|
|
||||||
"game": "",
|
|
||||||
"extensions": [
|
|
||||||
"fun",
|
|
||||||
"moderation",
|
|
||||||
"user"
|
|
||||||
],
|
|
||||||
"maintainer": 0
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user