def remTag(text, nick, host): if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return result = delfromDB(text.split(' ', 1)[0], text.split(' ', 1)[1]) if result is 0: return "Tag removed." return "Tag doesn't exist."
def zkb(match, nick, host): if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return global lastURL if match.group(0).lower() in lastURL: return return pullkill(match.group(0).lower())
def titlec(match, nick, host): global lastURL, header matchtext = match.group(0).lower() if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return if 'twitch.tv' in matchtext or 'zkillboard' in matchtext: return elif 'youtube.com' in matchtext or 'youtu.be' in matchtext: return elif 'twitter.com' in matchtext or 'https://t.co' in matchtext: return elif 'ebin.pw' in matchtext or 'csgoani.me' in matchtext: return elif 'xkcd.com' in matchtext: return #to discard pictures picture = matchtext.rsplit('.', 1)[-1] if 'jpg' in picture or 'png' in picture or 'gif' in picture or 'webm' in picture or 'mp4' in picture or 'webm' in picture: return if matchtext in lastURL: return lastURL = matchtext req = requests.get(match.group(0), headers=header) tree = fromstring(req.content) title = tree.findtext('.//title') title = title.replace('\n', '').replace('\r', '').lstrip(' ') return title
def setTag(text, nick, host): if text is None or text is "": return if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return if addtoDB(text) is 0: return "Tag added." return "Tag already exists."
def getTag(text, nick, host): if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return retv = getfromDB(text) if retv is 1: return "No tags found for: " + text return "Tags for " + text + ": " + retv
def agdq_donation(nick, host): if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return h_t = requests.get("https://gamesdonequick.com/tracker/19").text html = lxml.html.fromstring(h_t) donation = html.xpath("//small") return "Games Done Quick" + donation[0].text.replace('\n', ' ').replace( '\r', ' ').replace('\u2014', '-')
def tfwgrab(nick, host): if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return global tfwdb db = sqlite3.connect(tfwdb) cur = db.cursor() query = "SELECT * FROM tfw ORDER BY RANDOM() LIMIT 1;" cur.execute(query) ret = cur.fetchone()[0] db.close() return ret
def tfwadd(match, nick, host): if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return global tfwdb matchtext = match.group(0) db = sqlite3.connect(tfwdb) cur = db.cursor() query = "CREATE TABLE IF NOT EXISTS tfw (text TEXT);" cur.execute(query) print("Adding tfw:", matchtext) cur.execute("INSERT INTO tfw VALUES(?)", (matchtext,)) db.commit() db.close()
def agdq(nick, host): global oauth_token if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return url = "https://api.twitch.tv/kraken/streams/gamesdonequick?oauth_token=" + oauth_token obj = requests.get(url).json() if obj['stream'] is None: return "Stream is OFFLINE." stream = "Twitch Streamer: gamesdonequick" + " -=- Status: Online -=- Game: " + obj[ 'stream']['game'] + " -=- Title: " + obj['stream']['channel'][ 'status'] + " -=- Viewers: " + str(obj['stream']['viewers']) return stream + " Watch LIVE: http://www.twitch.tv/gamesdonequick"
def regTag(match, nick, host): if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return matchtext = match.group(0).lower() tag = matchtext.split('?', 1)[-1] if tag is None: return retv = getfromDB(tag) if retv is 1: # return "No tags found for: " + tag #silently fail instead return return "Tags for " + tag + ": " + retv
def getTagged(text, nick, host): if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return global tagName retv = "" listv = [] i = 0 for item in tagName: if text.lower() == item[1].lower(): listv.append(item[0]) for item in listv: retv += item if i + 1 is not len(listv): retv += ", " i += 1 if retv is "": return return "Tagged " + text + ": " + retv
def blacklist_check(text): retv = blacklist.bl_ret(text) if retv is True: return True else: return False
def sched(nick, host, text, notice): global oauth_token if blacklist.bl_ret(nick) or blacklist.bl_ret(host): return global schedule, current_game, epoch #update game for comparison later obj = requests.get( "https://api.twitch.tv/kraken/streams/gamesdonequick?oauth_token=" + oauth_token).json() try: current_game = obj['stream']['game'] except TypeError as e: return "Stream offline." #used to reparse the schedule in case of game overruns/short runs (15min) curtime = arrow.utcnow() if epoch is 0: #force update timediff = 900 else: timediff = (curtime - epoch).seconds if not schedule or timediff > 900: parse_agdq_schedule() epoch = curtime #if there's text following it, search in the game list and return time if text: for i, (tm, gm) in enumerate(schedule[1:]): if text.lower() in gm.lower(): gtime = schedule[i + 1][0].format('YYYY/M/D HH:mm:ss') now = arrow.utcnow() #catch if the game was already played if schedule[i + 1][0] < now: return "Event already passed." timetil = (schedule[i + 1][0] - now).total_seconds() time = timetil / 3600 hours = int(time) minutes = int((time * 60) % 60) seconds = int((time * 3600) % 60) return str(schedule[i + 1][1]) + " " + str( gtime) + " UTC. Time until: " + "%d:%02d:%02d" % ( hours, minutes, seconds) #checking this is hackish right now, not bothered fixing (yet) if i + 2 is len(schedule): notice("Game not found") return current = None game = schedule[0][1] for i, (tm, gm) in enumerate(schedule[1:]): if current_game is gm: current = gm game = schedule[i + 2][1] return 'GDQ Currently Playing: {} | Up Next: {}'.format( current, game) game = gm #game didn't match, find game via time now = arrow.utcnow() for i, (tm, gm) in enumerate(schedule[1:]): if tm > now: current = schedule[i][1] game = gm return 'GDQ Currently Playing: {} | Up Next: {}'.format( current, game)