<commit_before>import asyncio
import discord
import random
import datetime
from   discord.ext import commands
from   Cogs import Settings
from   Cogs import Xp
from   Cogs import DisplayName
from   Cogs import Nullify

# This is the feed module.  It allows the bot to be fed,
# get hungry, die, be resurrected, etc.

class Feed:

	# Init with the bot reference, and a reference to the settings var and xp var
	def __init__(self, bot, settings, xp, prefix):
		self.bot = bot
		self.settings = settings
		self.xp = xp
		self.bot.loop.create_task(self.getHungry())
		self.prefix = prefix
		
	async def message(self, message):
		# Check the message and see if we should allow it.
		ignore = False
		delete = False
		hunger = int(self.settings.getServerStat(message.guild, "Hunger"))
		hungerLock = self.settings.getServerStat(message.guild, "HungerLock")
		isKill = self.settings.getServerStat(message.guild, "Killed")
		if isKill.lower() == "yes":
			ignore = True
			if message.content.startswith('{}iskill'.format(self.prefix)) or message.content.startswith('{}resurrect'.format(self.prefix)) or message.content.startswith('{}hunger'.format(self.prefix)) or message.content.startswith('{}feed'.format(self.prefix)):
				ignore = False
				
		if hunger >= 100 and hungerLock.lower() == "yes":
			ignore = True
			if message.content.startswith('{}iskill'.format(self.prefix)) or message.content.startswith('{}resurrect'.format(self.prefix)) or message.content.startswith('{}hunger'.format(self.prefix)) or message.content.startswith('{}feed'.format(self.prefix)):
				ignore = False
				
		# Check if admin and override
		isAdmin = message.author.permissions_in(message.channel).administrator
		if not isAdmin:
			checkAdmin = self.settings.getServerStat(message.guild, "AdminArray")
			for role in message.author.roles:
				for aRole in checkAdmin:
					# Get the role that corresponds to the id
					if str(aRole['ID']) == str(role.id):
						isAdmin = True
		if isAdmin:
			ignore = False
			delete = False
		
		return { 'Ignore' : ignore, 'Delete' : delete}
		
	async def getHungry(self):
		await self.bot.wait_until_ready()
		while not self.bot.is_closed():
			# Add The Hunger
			await asyncio.sleep(900) # runs every 15 minutes
			for server in self.bot.guilds:
				# Iterate through the servers and add them
				isKill = self.settings.getServerStat(server, "Killed")
				
				if isKill.lower() == "no":
					hunger = int(self.settings.getServerStat(server, "Hunger"))
					# Check if hunger is 100% and increase by 1 if not
					hunger += 1
				
					if hunger > 100:
						hunger = 100
					
					self.settings.setServerStat(server, "Hunger", hunger)
		
	@commands.command(pass_context=True)
	async def hunger(self, ctx):
		"""How hungry is the bot?"""
		
		channel = ctx.message.channel
		author  = ctx.message.author
		server  = ctx.message.guild
		
		hunger = int(self.settings.getServerStat(server, "Hunger"))
		isKill = self.settings.getServerStat(server, "Killed")
		overweight = hunger * -1
		if hunger < 0:
			
			if hunger <= -1:
				msg = 'I\'m stuffed ({:,}% overweight)... maybe I should take a break from eating...'.format(overweight)
			if hunger <= -10:
				msg = 'I\'m pudgy ({:,}% overweight)... I may get fat if I keeps going.'.format(overweight)
			if hunger <= -25:
				msg = 'I am, well fat ({:,}% overweight)... Diet time?'.format(overweight)
			if hunger <= -50:
				msg = 'I\'m obese ({:,}% overweight)... Eating is my enemy right now.'.format(overweight)
			if hunger <= -75:
				msg = 'I look fat to an extremely unhealthy degree ({:,}% overweight)... maybe you should think about *my* health?'.format(overweight)
			if hunger <= -100:
				msg = 'I am essentially dead from over-eating ({:,}% overweight).  I hope you\'re happy.'.format(overweight)
			if hunger <= -150:
				msg = 'I *AM* dead from over-eating ({:,}% overweight).  You will have to `{}resurrect` me to get me back.'.format(overweight, ctx.prefix)
				
		elif hunger == 0:
			msg = 'I\'m full ({:,}%).  You are safe.  *For now.*'.format(hunger)
		elif hunger <= 15:
			msg = 'I feel mostly full ({:,}%).  I am appeased.'.format(hunger)
		elif hunger <= 25:
			msg = 'I feel a bit peckish ({:,}%).  A snack is in order.'.format(hunger)
		elif hunger <= 50:
			msg = 'I\'m hungry ({:,}%).  Present your offerings.'.format(hunger)
		elif hunger <= 75:
			msg = 'I\'m *starving* ({:,}%)!  Do you want me to starve to death?'.format(hunger)
		else:
			msg = 'I\'m ***hangry*** ({:,}%)!  Feed me or feel my *wrath!*'.format(hunger)
			
		if isKill.lower() == "yes" and hunger > -150:
			msg = 'I *AM* dead.  Likely from *lack* of care.  You will have to `{}resurrect` me to get me back.'.format(overweight, self.prefix)
			
		await channel.send(msg)
		
	@commands.command(pass_context=True)
	async def feed(self, ctx, food : int = None):
		"""Feed the bot some xp!"""
		# feed the bot, and maybe you'll get something in return!
		msg = 'Usage: `{}feed [xp reserve feeding]`'.format(ctx.prefix)
		
		channel = ctx.message.channel
		author  = ctx.message.author
		server  = ctx.message.guild
		
		if food == None:
			await channel.send(msg)
			return
			
		if not type(food) == int:
			await channel.send(msg)
			return

		isAdmin    = author.permissions_in(channel).administrator
		adminUnlim = self.settings.getServerStat(server, "AdminUnlimited")
		reserveXP  = self.settings.getUserStat(author, server, "XPReserve")
		minRole    = self.settings.getServerStat(server, "MinimumXPRole")
		requiredXP = self.settings.getServerStat(server, "RequiredXPRole")
		isKill = self.settings.getServerStat(server, "Killed")
		hunger = int(self.settings.getServerStat(server, "Hunger"))

		approve = True
		decrement = True

		# Check Food

		if food > int(reserveXP):
			approve = False
			msg = 'You can\'t feed me *{:,}*, you only have *{:,}* xp reserve!'.format(food, reserveXP)
			
		if food < 0:
			msg = 'You can\'t feed me less than nothing! You think this is funny?!'
			approve = False
			
		if food == 0:
			msg = 'You can\'t feed me *nothing!*'
			approve = False
			
		#if author.top_role.position < int(minRole):
			#approve = False
			#msg = 'You don\'t have the permissions to feed me.'
		
		# RequiredXPRole
		if requiredXP:
			foundRole = False
			for checkRole in author.roles:
				if str(checkRole.id) == str(requiredXP):
					foundRole = True
			if not foundRole:
				approve = False
				msg = 'You don\'t have the permissions to feed me.'

		# Check admin last - so it overrides anything else
		if isAdmin and adminUnlim.lower() == "yes":
			# No limit - approve
			approve = True
			decrement = False
			
		if approve:
			# Feed was approved - let's take the XPReserve right away
			# Apply food - then check health
			hunger -= food
			
			self.settings.setServerStat(server, "Hunger", hunger)
			takeReserve = -1*food
			if decrement:
				self.settings.incrementStat(author, server, "XPReserve", takeReserve)

			if isKill.lower() == "yes":
				# Bot's dead...
				msg = '*{}* carelessly shoves *{:,} xp* into the carcass of *{}*... maybe resurrect them first next time?'.format(DisplayName.name(author), food, DisplayName.serverNick(self.bot.user, server))<commit_msg>Bot admin as admin updates<commit_after>import asyncio
import discord
import random
import datetime
from   discord.ext import commands
from   Cogs import Settings
from   Cogs import Xp
from   Cogs import DisplayName
from   Cogs import Nullify

# This is the feed module.  It allows the bot to be fed,
# get hungry, die, be resurrected, etc.

class Feed:

	# Init with the bot reference, and a reference to the settings var and xp var
	def __init__(self, bot, settings, xp, prefix):
		self.bot = bot
		self.settings = settings
		self.xp = xp
		self.bot.loop.create_task(self.getHungry())
		self.prefix = prefix
		
	async def message(self, message):
		# Check the message and see if we should allow it.
		ignore = False
		delete = False
		hunger = int(self.settings.getServerStat(message.guild, "Hunger"))
		hungerLock = self.settings.getServerStat(message.guild, "HungerLock")
		isKill = self.settings.getServerStat(message.guild, "Killed")
		if isKill.lower() == "yes":
			ignore = True
			if message.content.startswith('{}iskill'.format(self.prefix)) or message.content.startswith('{}resurrect'.format(self.prefix)) or message.content.startswith('{}hunger'.format(self.prefix)) or message.content.startswith('{}feed'.format(self.prefix)):
				ignore = False
				
		if hunger >= 100 and hungerLock.lower() == "yes":
			ignore = True
			if message.content.startswith('{}iskill'.format(self.prefix)) or message.content.startswith('{}resurrect'.format(self.prefix)) or message.content.startswith('{}hunger'.format(self.prefix)) or message.content.startswith('{}feed'.format(self.prefix)):
				ignore = False
				
		# Check if admin and override
		isAdmin = message.author.permissions_in(message.channel).administrator
		if not isAdmin:
			checkAdmin = self.settings.getServerStat(message.guild, "AdminArray")
			for role in message.author.roles:
				for aRole in checkAdmin:
					# Get the role that corresponds to the id
					if str(aRole['ID']) == str(role.id):
						isAdmin = True
		if isAdmin:
			ignore = False
			delete = False
		
		return { 'Ignore' : ignore, 'Delete' : delete}
		
	async def getHungry(self):
		await self.bot.wait_until_ready()
		while not self.bot.is_closed():
			# Add The Hunger
			await asyncio.sleep(900) # runs every 15 minutes
			for server in self.bot.guilds:
				# Iterate through the servers and add them
				isKill = self.settings.getServerStat(server, "Killed")
				
				if isKill.lower() == "no":
					hunger = int(self.settings.getServerStat(server, "Hunger"))
					# Check if hunger is 100% and increase by 1 if not
					hunger += 1
				
					if hunger > 100:
						hunger = 100
					
					self.settings.setServerStat(server, "Hunger", hunger)
		
	@commands.command(pass_context=True)
	async def hunger(self, ctx):
		"""How hungry is the bot?"""
		
		channel = ctx.message.channel
		author  = ctx.message.author
		server  = ctx.message.guild
		
		hunger = int(self.settings.getServerStat(server, "Hunger"))
		isKill = self.settings.getServerStat(server, "Killed")
		overweight = hunger * -1
		if hunger < 0:
			
			if hunger <= -1:
				msg = 'I\'m stuffed ({:,}% overweight)... maybe I should take a break from eating...'.format(overweight)
			if hunger <= -10:
				msg = 'I\'m pudgy ({:,}% overweight)... I may get fat if I keeps going.'.format(overweight)
			if hunger <= -25:
				msg = 'I am, well fat ({:,}% overweight)... Diet time?'.format(overweight)
			if hunger <= -50:
				msg = 'I\'m obese ({:,}% overweight)... Eating is my enemy right now.'.format(overweight)
			if hunger <= -75:
				msg = 'I look fat to an extremely unhealthy degree ({:,}% overweight)... maybe you should think about *my* health?'.format(overweight)
			if hunger <= -100:
				msg = 'I am essentially dead from over-eating ({:,}% overweight).  I hope you\'re happy.'.format(overweight)
			if hunger <= -150:
				msg = 'I *AM* dead from over-eating ({:,}% overweight).  You will have to `{}resurrect` me to get me back.'.format(overweight, ctx.prefix)
				
		elif hunger == 0:
			msg = 'I\'m full ({:,}%).  You are safe.  *For now.*'.format(hunger)
		elif hunger <= 15:
			msg = 'I feel mostly full ({:,}%).  I am appeased.'.format(hunger)
		elif hunger <= 25:
			msg = 'I feel a bit peckish ({:,}%).  A snack is in order.'.format(hunger)
		elif hunger <= 50:
			msg = 'I\'m hungry ({:,}%).  Present your offerings.'.format(hunger)
		elif hunger <= 75:
			msg = 'I\'m *starving* ({:,}%)!  Do you want me to starve to death?'.format(hunger)
		else:
			msg = 'I\'m ***hangry*** ({:,}%)!  Feed me or feel my *wrath!*'.format(hunger)
			
		if isKill.lower() == "yes" and hunger > -150:
			msg = 'I *AM* dead.  Likely from *lack* of care.  You will have to `{}resurrect` me to get me back.'.format(overweight, self.prefix)
			
		await channel.send(msg)
		
	@commands.command(pass_context=True)
	async def feed(self, ctx, food : int = None):
		"""Feed the bot some xp!"""
		# feed the bot, and maybe you'll get something in return!
		msg = 'Usage: `{}feed [xp reserve feeding]`'.format(ctx.prefix)
		
		channel = ctx.message.channel
		author  = ctx.message.author
		server  = ctx.message.guild
		
		if food == None:
			await channel.send(msg)
			return
			
		if not type(food) == int:
			await channel.send(msg)
			return

		isAdmin    = author.permissions_in(channel).administrator
		checkAdmin = self.settings.getServerStat(ctx.message.guild, "AdminArray")
		# Check for bot admin
		isBotAdmin      = False
		for role in ctx.message.author.roles:
			for aRole in checkAdmin:
				# Get the role that corresponds to the id
				if str(aRole['ID']) == str(role.id):
					isBotAdmin = True
					break
		botAdminAsAdmin = self.settings.getServerStat(server, "BotAdminAsAdmin")
		adminUnlim = self.settings.getServerStat(server, "AdminUnlimited")
		reserveXP  = self.settings.getUserStat(author, server, "XPReserve")
		minRole    = self.settings.getServerStat(server, "MinimumXPRole")
		requiredXP = self.settings.getServerStat(server, "RequiredXPRole")
		isKill = self.settings.getServerStat(server, "Killed")
		hunger = int(self.settings.getServerStat(server, "Hunger"))

		approve = True
		decrement = True

		# Check Food

		if food > int(reserveXP):
			approve = False
			msg = 'You can\'t feed me *{:,}*, you only have *{:,}* xp reserve!'.format(food, reserveXP)
			
		if food < 0:
			msg = 'You can\'t feed me less than nothing! You think this is funny?!'
			approve = False
			
		if food == 0:
			msg = 'You can\'t feed me *nothing!*'
			approve = False
			
		#if author.top_role.position < int(minRole):
			#approve = False
			#msg = 'You don\'t have the permissions to feed me.'
		
		# RequiredXPRole
		if requiredXP:
			foundRole = False
			for checkRole in author.roles:
				if str(checkRole.id) == str(requiredXP):
					foundRole = True
			if not foundRole:
				approve = False
				msg = 'You don\'t have the permissions to feed me.'

		# Check bot admin
		if isBotAdmin and botAdminAsAdmin.lower() == "yes":
			# Approve as admin
			approve = True
			if adminUnlim.lower() == "yes":
				# No limit
				decrement = False
			
		# Check admin last - so it overrides anything else
		if isAdmin:
			# No limit - approve
			approve = True
			if adminUnlim.lower() == "yes":
				# No limit
				decrement = False
			
		if approve:
			# Feed was approved - let's take the XPReserve right away
			# Apply food - then check health
			hunger -= food
			
			self.settings.setServerStat(server, "Hunger", hunger)
			takeReserve = -1*food
			if decrement:
				self.settings.incrementStat(author, server, "XPReserve", takeReserve)

			if isKill.lower() == "yes":
				# Bot's dead...
				msg = '*{}* carelessly shoves *{:,} xp* into the carcass of *{}*... maybe resurrect them first next time?'.format(DisplayName.name(author), food, DisplayName.serverNick(self.bot.user, server))
{'fraction_non_alphanumeric': 0.13477737665463296, 'fraction_numerical': 0.00681909346169274, 'mean_word_length': 3.3778167983611356, 'pattern_counts': {'":': 12, '<': 31, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3566714', 'n_tokens_mistral': 5784, 'n_tokens_neox': 4819, 'n_words': 1477}