async def event_filter(ctx): if ctx.guild != None: openVars = open( pathlib.Path(f'Vars/{ctx.guild.id}/{ctx.guild.id}.json'), 'rt') load = json.loads(openVars.read()) openVars.close() admin = bot.get_user((load.get('DiscordBackend').get('adminUserId'))) bannedWordsList = load.get('BannedWords') else: return # bannedwordregex = re.compile print("Running filter") if (ctx.author == bot.user): print( "The message was sent by the bot, and thus was ignored by the filter." ) return else: msgToList = ctx.content.split(" ") for item in msgToList: itemFinal = ExtFuncs.puncStrip(item) if (str(itemFinal).lower() in bannedWordsList): await ctx.delete() await ctx.channel.send( ctx.author.mention + " Please refrain from using that language.") await admin.send(ctx.author.name + ' said: ' + ctx.content) else: continue
async def event_filter(ctx): # A function to read every message and moderate based off of a predetermined list of words bannedWordsList = ExtFuncs.filePath(gid).bannedWords for listObj in bannedWordsList: listObjIndex = bannedWordsList.index(listObj) listObj = listObj.rstrip("\n") bannedWordsList[listObjIndex] = listObj userName = ctx.author.name print("Running filter") if (ctx.author.name.lower() == os.environ['BOT_NICK'].lower() or ctx.author.is_mod == True): print( "The message was sent by the channel owner, a moderator, or the bot, and thus was ignored by the filter." ) return else: msgToList = ctx.content.split(" ") # print(msgToList) for item in msgToList: itemFinal = ExtFuncs.puncStrip(item) if (str(itemFinal).lower() in bannedWordsList): await ctx.channel.send( "@" + userName + " Please refrain from using that language.") await ctx.channel.timeout(userName, 30, "Poor choice of words...") else: continue