# Path: utils/checks.py
# class No_Owner(commands.CommandError): pass
# class No_Perms(commands.CommandError): pass
# class No_Role(commands.CommandError): pass
# class No_Admin(commands.CommandError): pass
# class No_Mod(commands.CommandError): pass
# class No_Sup(commands.CommandError): pass
# class No_ServerandPerm(commands.CommandError): pass
# class Nsfw(commands.CommandError): pass
# def is_owner_check(message):
# def is_owner():
# def check_permissions(ctx, perms):
# def role_or_perm(t, ctx, check, **perms):
# def mod_or_perm(**perms):
# 	def predicate(ctx):
# def admin_or_perm(**perms):
# 	def predicate(ctx):
# def is_in_servers(*server_ids):
# 	def predicate(ctx):
# def server_and_perm(ctx, *server_ids, **perms):
# def sup(ctx):
# def nsfw():
# 	def predicate(ctx):
# 
# Path: mods/cog.py
# class Cog(metaclass=CogMeta):
# 	def __init__(self, bot:NotSoBot):
# 		self._bot = bot
# 
# 	@property
# 	def bot(self):
# 		return self._bot
# 
# 	@classmethod
# 	def setup(cls, bot:NotSoBot):
# 		bot.add_cog(cls(bot))


import discord
import asyncio
import mods.Tags
from discord.ext import commands
from utils import checks
from mods.cog import Cog

	@commands.group(pass_context=True, aliases=['welcomemessage', 'join'], invoke_without_command=True, no_pm=True)
	@checks.admin_or_perm(manage_server=True)
	async def welcome(self, ctx, *, message:str=None):
		channel = ctx.message.channel
		for c in ctx.message.channel_mentions:
			channel = c
			message = message.replace(c.mention, '').replace('#'+c.name, '')
		sql = 'SELECT server FROM `welcome` WHERE server={0}'
		sql = sql.format(ctx.message.server.id)
		result = self.cursor.execute(sql).fetchall()
		if len(result) == 0:
			if message is None:
				msg = ':white_check_mark: Enabled welcome messages for {0}.'.format(channel.mention)
			else:
				msg = ':white_check_mark: Added welcome message for {0}.'.format(channel.mention)
			sql = 'INSERT INTO `welcome` (`server`, `channel`, `message`, `user`) VALUES (%s, %s, %s, %s)'
			self.cursor.execute(sql, (ctx.message.server.id, channel.id, message, ctx.message.author.id))
		else:
			if message is None:
				await self.bot.say(':warning: Please input something to edit the welcome message to.\n`welcome clear` to disable welcome messages.')
				return
			msg = ':white_check_mark: Edited welcome message.'
			sql = "UPDATE `welcome` SET message={0} WHERE server={1}"
			sql = sql.format(self.escape(message), ctx.message.server.id)
			self.cursor.execute(sql)
		self.cursor.commit()
		await self.bot.say(msg)

	@welcome.command(name='remove', pass_context=True, aliases=['delete', 'clear', 'disable'], invoke_without_command=True)

# Path: utils/checks.py
# class No_Owner(commands.CommandError): pass
# class No_Perms(commands.CommandError): pass
# class No_Role(commands.CommandError): pass
# class No_Admin(commands.CommandError): pass
# class No_Mod(commands.CommandError): pass
# class No_Sup(commands.CommandError): pass
# class No_ServerandPerm(commands.CommandError): pass
# class Nsfw(commands.CommandError): pass
# def is_owner_check(message):
# def is_owner():
# def check_permissions(ctx, perms):
# def role_or_perm(t, ctx, check, **perms):
# def mod_or_perm(**perms):
# 	def predicate(ctx):
# def admin_or_perm(**perms):
# 	def predicate(ctx):
# def is_in_servers(*server_ids):
# 	def predicate(ctx):
# def server_and_perm(ctx, *server_ids, **perms):
# def sup(ctx):
# def nsfw():
# 	def predicate(ctx):
# 
# Path: mods/cog.py
# class Cog(metaclass=CogMeta):
# 	def __init__(self, bot:NotSoBot):
# 		self._bot = bot
# 
# 	@property
# 	def bot(self):
# 		return self._bot
# 
# 	@classmethod
# 	def setup(cls, bot:NotSoBot):
# 		bot.add_cog(cls(bot))


# Path: mods/JoinLeave.py
import discord
import asyncio
import mods.Tags
from discord.ext import commands
from utils import checks
from mods.cog import Cog


	@commands.group(pass_context=True, aliases=['welcomemessage', 'join'], invoke_without_command=True, no_pm=True)
	@checks.admin_or_perm(manage_server=True)
	async def welcome(self, ctx, *, message:str=None):
		channel = ctx.message.channel
		for c in ctx.message.channel_mentions:
			channel = c
			message = message.replace(c.mention, '').replace('#'+c.name, '')
		sql = 'SELECT server FROM `welcome` WHERE server={0}'
		sql = sql.format(ctx.message.server.id)
		result = self.cursor.execute(sql).fetchall()
		if len(result) == 0:
			if message is None:
				msg = ':white_check_mark: Enabled welcome messages for {0}.'.format(channel.mention)
			else:
				msg = ':white_check_mark: Added welcome message for {0}.'.format(channel.mention)
			sql = 'INSERT INTO `welcome` (`server`, `channel`, `message`, `user`) VALUES (%s, %s, %s, %s)'
			self.cursor.execute(sql, (ctx.message.server.id, channel.id, message, ctx.message.author.id))
		else:
			if message is None:
				await self.bot.say(':warning: Please input something to edit the welcome message to.\n`welcome clear` to disable welcome messages.')
				return
			msg = ':white_check_mark: Edited welcome message.'
			sql = "UPDATE `welcome` SET message={0} WHERE server={1}"
			sql = sql.format(self.escape(message), ctx.message.server.id)
			self.cursor.execute(sql)
		self.cursor.commit()
		await self.bot.say(msg)

	@welcome.command(name='remove', pass_context=True, aliases=['delete', 'clear', 'disable'], invoke_without_command=True)

	@checks.admin_or_perm(manage_server=True)