def rmuser(self, jenni, input, line): if not input.admin: return if len(line) < 9: jenni.reply("No input provided.") return line = line[8:].split() channel = uc.encode((input.sender).lower()) nick = uc.encode(line[0]).lower() def check(nick, channel): nick = nick.lower() channel = channel.lower() if channel in self.scores_dict: if nick in self.scores_dict[channel]: del self.scores_dict[channel][nick] return self.STRINGS["rmuser"].format(nick, channel) else: return self.STRINGS["nouser"].format(nick, channel) else: return self.STRINGS["nochan"].format(channel) if len(line) == 1: ## .rmuser <nick> result = check(nick, (input.sender).lower()) self.save() elif len(line) == 2: ## .rumser <channel> <nick> result = check(line[1], nick) self.save() jenni.say(result)
def setpoint(self, jenni, input, line): if not input.admin: return line = line[10:].split() if len(line) != 4: return channel = uc.encode(line[0]).lower() nick = uc.encode(line[1]).lower() try: add = int(line[2]) sub = int(line[3]) except: jenni.say(self.STRINGS["invalid"]) return if add < 0 or sub < 0: jenni.reply("You are doing it wrong.") return if channel not in self.scores_dict: self.scores_dict[channel] = dict() self.scores_dict[channel][nick] = [int(add), int(sub)] self.save() jenni.say(self.str_score(nick, channel))
def given_user(nick, channel): nick = uc.encode(nick.lower()) channel = channel.lower() if channel in self.scores_dict: if nick in self.scores_dict[channel]: return self.str_score(nick, channel) else: return self.STRINGS["nouser"].format(nick, channel) else: return self.STRINGS["nochan"].format(channel)
def get_results(text, manual=False): if not text: return False, list() a = re.findall(url_finder, text) k = len(a) i = 0 display = list() passs = False channel = str() if hasattr(text, 'sender'): channel = text.sender while i < k: url = uc.encode(a[i][0]) url = uc.decode(url) url = uc.iriToUri(url) url = remove_nonprint(url) domain = getTLD(url) if '//' in domain: domain = domain.split('//')[1] if 'i.imgur.com' in url and url.startswith('http://'): url = url.replace('http:', 'https:') bitly = url if not url.startswith(EXCLUSION_CHAR): passs, page_title = find_title(url) if not manual: if bitly_loaded: if channel and channel not in simple_channels: bitly = short(url) if bitly: bitly = bitly[0][1] display.append([page_title, url, bitly, passs]) else: ## has exclusion character if manual: ## only process excluded URLs if .title is used url = url[1:] passs, page_title = find_title(url) display.append([page_title, url, bitly, passs]) i += 1 ## check to make sure at least 1 URL worked correctly overall_pass = False for x in display: if x[-1] == True: overall_pass = True return overall_pass, display
def ep(m): entity = m.group() if entity.startswith('&#x'): cp = int(entity[3:-1], 16) meep = chr(cp) elif entity.startswith('&#'): cp = int(entity[2:-1]) meep = chr(cp) else: entity_stripped = entity[1:-1] try: char = name2codepoint[entity_stripped] meep = chr(char) except: if entity_stripped in HTML_ENTITIES: meep = HTML_ENTITIES[entity_stripped] else: meep = str() try: return uc.decode(meep) except: return uc.decode(uc.encode(meep))
def editpoints(self, jenni, input, nick, points): if not nick: return nick = uc.encode(nick.lower()) if not nick: jenni.reply(self.STRINGS["cantadd"]) elif (not input.admin) and (input.nick).lower() == nick: jenni.reply(self.STRINGS["denied"]) else: nick = nick.lower() chan = (input.sender).lower() if chan not in self.scores_dict: self.scores_dict[chan] = {} if not nick in self.scores_dict[chan]: self.scores_dict[chan][nick] = [0, 0] # Add a point if points is TRUE, remove if FALSE if points: self.scores_dict[chan][nick][0] += 1 else: self.scores_dict[chan][nick][1] += 1 self.save() jenni.say(self.str_score(nick, chan))
def write_addquote(text): fn = open('quotes.txt', 'a') output = uc.encode(text) fn.write(output) fn.write('\n') fn.close()
def find_title(url): """ This finds the title when provided with a string of a URL. """ for item in IGNORE: if item in url: return False, 'ignored' if not re.search('^((https?)|(ftp))://', url): url = 'http://' + url if '/#!' in url: url = url.replace('/#!', '/?_escaped_fragment_=') if 'i.imgur' in url: a = url.split('.') url = a[0][:-1] + '.'.join(a[1:-1]) if 'zerobin.net' in url: return True, 'ZeroBin' url = uc.decode(url) msg = str() k = 0 status = False while not status: k += 1 if k > 3: break msg = dict() try: status, msg = proxy.get_more(url) except: try: status, msg = get_page_backup(url) except: continue if type(msg) == type(dict()) and 'code' in msg: status = msg['code'] else: continue time.sleep(0.5) if not status: return False, msg useful = msg info = useful['headers'] page = useful['read'] try: mtype = info['content-type'] except: print('failed mtype:', str(info)) return False, 'mtype failed' if not (('/html' in mtype) or ('/xhtml' in mtype)): return False, str(mtype) content = page regex = re.compile('<(/?)title( [^>]+)?>', re.IGNORECASE) content = regex.sub(r'<\1title>', content) regex = re.compile('[\'"]<title>[\'"]', re.IGNORECASE) content = regex.sub('', content) start = content.find('<title>') if start == -1: return False, 'NO <title> found' end = content.find('</title>', start) if end == -1: return False, 'NO </title> found' content = content[start + 7:end] content = content.strip('\n').rstrip().lstrip() title = content if len(title) > 200: title = title[:200] + '[...]' def e(m): entity = m.group() if entity.startswith('&#x'): cp = int(entity[3:-1], 16) meep = chr(cp) elif entity.startswith('&#'): cp = int(entity[2:-1]) meep = chr(cp) else: entity_stripped = entity[1:-1] try: char = name2codepoint[entity_stripped] meep = chr(char) except: if entity_stripped in HTML_ENTITIES: meep = HTML_ENTITIES[entity_stripped] else: meep = str() try: return uc.decode(meep) except: return uc.decode(uc.encode(meep)) title = r_entity.sub(e, title) title = title.replace('\n', '') title = title.replace('\r', '') def remove_spaces(x): if ' ' in x: x = x.replace(' ', ' ') return remove_spaces(x) else: return x title = remove_spaces(title) new_title = str() for char in title: unichar = uc.encode(char) if len(list(uc.encode(char))) <= 3: new_title += uc.encode(char) title = new_title title = re.sub(r'(?i)dcc\ssend', '', title) title += '\x0F' if title: return True, title else: return False, 'No Title'