def add(user, color, value, socket): if not modCheck(user): refuse(socket) else: if not helpInts(value): sendMessage(socket, "Please format the add command properly.") else: incrementcolor(color, value)
def deduct(user, value, socket): if not modCheck(user): refuse(socket) else: try: push = int(value) deductPush(socket, push) except ValueError: sendMessage(socket, "Please use a valid value.")
def addQuote(user, words, socket): if not modCheck(user): refuse(socket) else: quote = "" for word in words[1:]: quote = quote + word.strip() + " " quote = quote[:-1] addQuote(quote) sendMessage(socket, quote + " was added.")
def joinRoom(s): readbuffer = "" Loading = True while Loading: readbuffer = readbuffer + s.recv(1024).decode('utf-8') temp = readbuffer.split("\n") readbuffer = temp.pop() for line in temp: Loading = loadingComplete(line) sendMessage(s, "Successfully joined Chat")
def wr(words, socket): game, id = getGame() if game: if len(words) > 1: category = "" for word in words[1:]: category = category + word.strip() + " " category = category[:-1] sendMessage(socket, recordLookUp(game, id, category)) else: print(printCategories(game, id)) # sendMessage(socket, printCategories(game, id))
def check(user, socket): userCheck = ConfigParser() userCheck.read('times.ini') section = str(user) if userCheck.has_section(section): time = userCheck.getint(section, 'time_val') hours, minutes = convert(time) sendMessage( socket, section + " has spent " + str(hours) + " hours and " + str(minutes) + " minutes here since Feb. 22, 2017.") else: print("problem with userCheck")
def deletecommand(user, words, socket, config): if not modCheck(user): refuse(socket) else: if not len(words) == 2: sendMessage(socket, "Please use format: !delcom [command]") else: command = words[1] if not config.has_section(command): print("sigh") else: config.remove_section(command) with open('commands.ini', 'w') as configfile: config.write(configfile) sendMessage(socket, "Command Deleted")
def deductPush(s, push): file = Path("bits.txt") if file.is_file: check = open(file, 'r+') save = current = check.read() if not current: current = 0 else: check.seek(0) check.truncate() current = int(current) - (int(push) * 10) if current < 0: sendMessage( s, "That's more than he owed, guess he did extra but we're at 0 now." ) current = 0 else: sendMessage( s, "Sheppy now has " + str(math.floor(current / 10)) + " pushups to do.") check.write(str(current)) check.close()
def doChat(): s = openSocket() joinRoom(s) readbuffer = "" while True: readbuffer = readbuffer + s.recv(1024).decode('utf-8') temp = readbuffer.split("\n") readbuffer = temp.pop() for line in temp: print(line) ##Wipe time_in on PART to prevent weirdness if PART comes before JOIN## if "JOIN" in line and not ("PRIVMSG" in line): user, rest = line.split('!', maxsplit=1) user = user[1:] startTracking(user) if "PART" in line and not ("PRIVMSG" in line): user, rest = line.split('!', maxsplit=1) user = user[1:] endTracking(user) if "PING :tmi.twitch.tv" in line: sendServerMessage(s, line.replace("PING", "PONG")) print(line) print(line.replace("PING", "PONG")) if "PRIVMSG" in line: junk, msg = line.split('PRIVMSG', maxsplit=1) if 'bits=' in junk: bits = getBits(junk) pushups = addBits(bits) sendMessage( s, "Sheppy now owes " + str(pushups) + " pushups to the stream. Check https://goo.gl/IVhdnK for an incentive to put your bits towards." ) user = getUser(junk) message = getMessage(msg) print(user + ": " + message) if message[0] == '!': commandCheck(user, message, s)
def addcom(user, words, s): config = ConfigParser() config.read('commands.ini', encoding='utf-8') if not modCheck(user): refuse(s) else: if len(words) < 3: sendMessage(s, "Please use format: !addcom [command] [message]") else: command = words[1] output = words[2] if not command[0] == '!': command = '!' + command if config.has_section(command): sendMessage( s, "Command Already Exists: Use !editcom to alter commands.") else: config.add_section(command) config.set(str(command), 'output_val', str(output)) config.write(codecs.open('commands.ini', 'wb+', 'utf-8')) sendMessage(s, "Command Added")
def donate(user, words, s): if not modCheck(user): refuse(s) else: if len(words) < 3: sendMessage( s, "Make sure to format the command as !donate [amount] [category" ) else: amount = words[1] category = words[2].strip(' \t\n\r') incentiveCheck = ConfigParser() incentiveCheck.read('incentives.ini') if incentiveCheck.has_section(category): doDonate(amount, category) sendMessage( s, "The money has been moved to an offshore account. Don't call us, we won't call you." ) else: sendMessage( s, "That's not a real incentive, guess again Pinocchio.")
def refuse(socket): sendMessage(socket, "Only mods can use this command.")