Skip to content

Commit

Permalink
If order to prevent Companion's %AnagramSolver, %yttags, and %http fr…
Browse files Browse the repository at this point in the history
…om becoming

weapons in server raids, an Allow setting has been added for each.

In the whitelists, @username has been replaced by @ROLE for increased security.

Changes to be committed:
	modified:   Companion
  • Loading branch information
rapmd73 committed Dec 24, 2024
1 parent 77e46b8 commit 0183d63
Showing 1 changed file with 63 additions and 35 deletions.
98 changes: 63 additions & 35 deletions Companion
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ from googleapiclient.discovery import build

# Active version

Version="0.0.0.0.1235"
Version="0.0.0.0.1250"

# The running name of the program. Must be global and NEVER changing.

Expand Down Expand Up @@ -2617,24 +2617,37 @@ async def ImposterAmoungUs(guild, member):

# Check wwhitelist

def CheckWhitelist(bot,whitelist,message):
def CheckWhitelist(bot,whitelist,message=None,user=None):
if message==None and author==None:
return False

if user==None:
author=message.author
else:
author=user

# Check whitelist
if whitelist in bot:
wList=bot[whitelist].split(',')
for uc in wList:
uc=uc.lower().strip()
# Is this a whitelisted user ID
if uc[0]=='!':
if uc[1:]==str(message.author.id):
return True
# Is this a whitelisted user
if uc[0]=='@':
if uc[1:]==message.author.name.lower().strip():
return True
# Is this a white listed channel
if uc[0]=='#':
if uc[1:]==message.channel.name.lower().strip():
if whitelist not in bot:
return False

wList=bot[whitelist].split(',')
for uc in wList:
uc=uc.lower().strip()
# Is this a whitelisted user ID
if uc[0]=='!':
if uc[1:]==str(author.id):
return True
# Is this a whitelisted user role.
if uc[0]=='@':
for role in author.roles:
if role.name==uc[1:]:
return True
return False
# Is this a white listed channel
if uc[0]=='#' and message!=None:
if uc[1:]==message.channel.name.lower().strip():
return True

return False

# The `IsPIIDetected` function is an asynchronous handler that checks for
Expand Down Expand Up @@ -3595,32 +3608,47 @@ async def on_message(message):
# Anagram solver... how the hell did I end up don the rabbit hole? Really?

if os.path.exists(AnagramWordList) and input_text.lower().strip().startswith('%anagramsolver'):
letters=input_text[14:].strip().lower()
input_text=AnagramSolver(letters)
await send_response(bot,message,input_text)
return
if CheckWhitelist(bot,'AllowAnagramSolver',message):
letters=input_text[14:].strip().lower()
input_text=AnagramSolver(letters)
await send_response(bot,message,input_text)
return
else:
# Write response for "That action is not allowed here... Self deleting
await message.delete()
return

# Read tags from YouTune video
if os.path.exists(bot['YTtags']) and os.path.exists(bot['noYTtags']) \
and input_text.lower().strip().startswith('%yttags'):
# Web/URL reference
url=input_text[7:].strip()
input_text=yttags2text(url)
if input_text==None:
await send_response(bot,message,PickRandomResponse(bot['noYTtags']))
elif input_text=='{[(*VNF*)]}':
await send_response(bot,message,PickRandomResponse(bot['URLBroken']))
if CheckWhitelist(bot,'AllowYTTags',message):
# Web/URL reference
url=input_text[7:].strip()
input_text=yttags2text(url)
if input_text==None:
await send_response(bot,message,PickRandomResponse(bot['noYTtags']))
elif input_text=='{[(*VNF*)]}':
await send_response(bot,message,PickRandomResponse(bot['URLBroken']))
else:
await send_response(bot,message,f"{PickRandomResponse(bot['YTtags'])}\n\n{input_text}")
return
else:
await send_response(bot,message,f"{PickRandomResponse(bot['YTtags'])}\n\n{input_text}")
return
# Write response for "That action is not allowed here... Self deleting
await message.delete()
return

# if the input text starts with "%http", replace it with the actual URL text
if os.path.exists(bot['TooMuchInformation']) and input_text.lower().strip().startswith('%http'):
# Web/URL reference
url=input_text.replace(' ','')[1:]
input_text=html2text(message.guild.id,url)
if input_text==None:
await send_response(bot,message,PickRandomResponse(bot['URLBroken']))
if CheckWhitelist(bot,'AllowYTTags',message):
# Web/URL reference
url=input_text.replace(' ','')[1:]
input_text=html2text(message.guild.id,url)
if input_text==None:
await send_response(bot,message,PickRandomResponse(bot['URLBroken']))
return
else:
# Write response for "That action is not allowed here... Self deleting
await message.delete()
return

# Give the AI the message
Expand Down

0 comments on commit 0183d63

Please sign in to comment.