Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. # -*- coding:Utf-8 -*-
  2.  
  3. from __future__ import with_statement
  4.  
  5. import es
  6. import os
  7. import re
  8.  
  9. regex = re.compile(r"""\b(?:http|telnet|gopher|file|wais|ftp):[\w/#~:.?+=&%@!\-.:?\-]+?(?=[.:?\-]*(?:[^\w/#~:.?+=&%@!\-.:?\-]|$))""", re.VERBOSE | re.MULTILINE | re.IGNORECASE)
  10.  
  11. es.ServerVar('ucf_version', 1.0, 'Version of the URLChatFilter\'s script by FMIS | Menace.').makepublic()
  12.  
  13. def getURLWhiteList(path):
  14.     with open(path, 'r') as file:
  15.         return [n for n in file.read().splitlines() if not n.startswith('#')]
  16.    
  17. def removeURLFromString(string):
  18.     for url in regex.findall(string):
  19.         if url not in URLWhiteList:
  20.             if ucf_method == 'hidden':
  21.                 string = string.replace(url, re.sub('[^\.:/]', '*', url))
  22.             elif ucf_method == 'deleted':
  23.                 string = string.replace(url, '')
  24.             elif ucf_method == 'changed':
  25.                 string = string.replace(url, ucf_urltoreplace)
  26.     return string
  27.  
  28. def sayFilter(userid, text, teamonly):
  29.     return(userid, removeURLFromString(text.strip('"')), teamonly)
  30.    
  31. def es_map_start(ev):
  32.     global IPWhiteList
  33.     IPWhiteList = getIpWhiteList(os.path.join(es.getAddonPath('urlchatfilter'), 'urlwhitelist.txt'))
  34.    
  35. def load():  es.addons.registerSayFilter(sayFilter)
  36. def unload():  es.addons.unregisterSayFilter(sayFilter)
  37.  
  38. URLWhiteList = getURLWhiteList(os.path.join(es.getAddonPath('urlchatfilter'), 'urlwhitelist.txt'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement