def send_message(s, message): try: s.send(b"PRIVMSG #%s :%s\r\n" % (CHANNEL, message.encode())) print(">>BOT : " + message) logger(">>BOT", message, False, True) except Exception as errormsg: errorlog(errormsg, "Send_message", message)
def main(): #initial = (3,3) initial = None # initial probability of transmission p_transmission = 0.15 np.random.seed(1) global log log = logger() # create board board = Board(25, 25, initial, p_transmission, 0) initialise_window(board)
"accept-encoding": "gzip, deflate, br", "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7", #"content-length": "135", "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "cookie": "BAIDUID=4AF31140B675845AB1E3EAEF36CABCC4:FG=1; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; BDUSS=noxVWZqZmhUaW1YSTVNQkZGSE5MY0p5aDRKWlJwV2pXLWdqY0NTSkZDVDJiUDlkSVFBQUFBJCQAAAAAAAAAAAEAAACCWms-tO3Jz9lctLJ0d2ljZQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPbf113239ddf; BIDUPSID=4AF31140B675845AB1E3EAEF36CABCC4; PSTM=1574481182; pgv_pvi=2670401536; APPGUIDE_8_2_2=1; to_lang_often=%5B%7B%22value%22%3A%22en%22%2C%22text%22%3A%22%u82F1%u8BED%22%7D%2C%7B%22value%22%3A%22zh%22%2C%22text%22%3A%22%u4E2D%u6587%22%7D%5D; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; delPer=0; PSINO=7; BDRCVFR[tox4WRQ4-Km]=mk3SLVN4HKm; BDRCVFR[-pGxjrCMryR]=mk3SLVN4HKm; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; H_PS_PSSID=1427_21090_30788_30909_30940_30823; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1582278813,1582536761,1582634892,1583071160; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1583111614; yjs_js_security_passport=cf9f5bdb2b8c84e28ee6c535ed5c23a40ee4cef8_1583111615_js; session_name=cn.bing.com; session_id=1583129492829; from_lang_often=%5B%7B%22value%22%3A%22fra%22%2C%22text%22%3A%22%u6CD5%u8BED%22%7D%2C%7B%22value%22%3A%22dan%22%2C%22text%22%3A%22%u4E39%u9EA6%u8BED%22%7D%2C%7B%22value%22%3A%22en%22%2C%22text%22%3A%22%u82F1%u8BED%22%7D%5D", "origin": "https://fanyi.baidu.com", "referer": "https://fanyi.baidu.com/", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-origin", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36", "x-requested-with": "XMLHttpRequest"} request = urllib.request.Request(url=url, headers=headers) reponse = urllib.request.urlopen(request, data=date.encode()) #报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte import gzip from Logger import logger #print(reponse.read().decode("utf8")) #进行解压缩 或者注释注释掉压缩的请求语句 f = gzip.GzipFile(fileobj=reponse) reponse_finall = f.read().decode() #print(reponse_finall) a = logger() a.warning(reponse_finall)
def main(): global comlimits readbuffer = "" modt = False comlimits = [] modules = [] # Starting the timer in case of a disconnect keepalivetimer = threading.Timer(310, nopong) keepalivetimer.start() # Loading the basic modules load_send_message(FOLDER, CHANNEL) load_logger(FOLDER) load_errorlog(FOLDER) # Resolve user id to channel id via the Twitch API try: url = "https://api.twitch.tv/helix/users?login="******"OAuth " + OAUTH } r = requests.get(url, headers=headers).json() channel_id = r['data'][0]['id'] except Exception as errormsg: errorlog(errormsg, 'Twitch API/get Client_id', '') exit(0) # Load all the modules that were enabled in the config file if module_rules: load_rules(s, FOLDER) modules.append("Rules") if module_backseatmessage: load_bsmessage(FOLDER) modules.append("Backseatmessage") if module_deathcounter: load_deaths(FOLDER) modules.append("Deathcounter") if module_quotes: load_quotes(FOLDER) modules.append("Quotes") if module_raffles: load_raffles(FOLDER, CLIENTID, channel_id) modules.append("Raffles") if module_bonertimer: load_bonertimer(FOLDER) modules.append("Bonertimer") if module_rimworldautomessage: load_rimworldautomessage(s, FOLDER, channel_id, CLIENTID) modules.append("RimWorldMessage") if module_questions: load_questions(FOLDER) modules.append("Questions") if module_modlog: load_modlog(channel_id, headers, FOLDER) modules.append("Modlog") if module_conversion: modules.append("Conversions") if module_followergoal: load_followergoals(FOLDER) modules.append("followergoals") if module_rimmods: load_mod(STEAMAPIKEY) modules.append("rimmods") if module_SongSuggestions: load_suggestions(FOLDER) modules.append("SongSuggestions") # Infinite loop waiting for commands while True: try: # Recieving messages readbuffer = readbuffer + s.recv(1024).decode() temp = readbuffer.split("\n") readbuffer = temp.pop() for line in temp: if printraw: print(line) if lograw: logline(line) # Checks if message is PING. If so reply pong and extend the timer for a restart if "PING" in line: s.send(b"PONG\r\n") try: keepalivetimer.cancel() keepalivetimer = threading.Timer(310, nopong) keepalivetimer.start() except Exception as errormsg: errorlog(errormsg, "keepalivetimer", '') if module_unshorten: try: followergoal(s, channel_id, CHANNEL, CLIENTID) except Exception as errormsg: errorlog(errormsg, "") if module_backseatmessage: bsmcheck(channel_id, CLIENTID) else: # Splits the given string so we can work with it better if modt and "ACK" not in line: parts = line.split(" :", 2) else: parts = line.split(":", 2) if printparts: print(parts) if "QUIT" not in parts[1] and "JOIN" not in parts[ 1] and "PART" not in parts[ 1] and "ACK" not in parts[1]: issub = False ismod = False if "CLEARCHAT" in parts[1] and module_modlog: modlog(s, parts) templist = [ 'QUIT', 'JOIN', 'PART', 'ACK', 'USERSTATE', 'ROOMSTATE', 'CLEARCHAT' ] tempparts = parts[1].split(" ") if not any(s in tempparts[1] for s in templist): try: # Sets the message variable to the actual message sent message = parts[2][:len(parts[2]) - 1] except: message = "" # Sets the username variable to the actual username usernamesplit = str.split(parts[1], "!") username = usernamesplit[0] displayname = username tags = str.split(parts[0], ';') # Get index of mod and sub status dynamically because tag indexes are not fixed subindex = [ i for i, z in enumerate(tags) if 'subscriber' in z ] modindex = [ i for i, z in enumerate(tags) if 'mod' in z ] displayindex = [ i for i, z in enumerate(tags) if 'display-name' in z ] # Only works after twitch is done announcing stuff (modt = Message of the day) if modt: try: subindex = subindex[0] modindex = modindex[0] displayindex = displayindex[0] if tags[displayindex] != 'display-name=': displayname = tags[displayindex] displayname = displayname.split("=")[1] displayname = displayname.replace( "\\s", '') except: pass try: if tags[subindex] == 'subscriber=1' or 'subscriber' in tags[ 0]: issub = True else: issub = False if tags[modindex] == 'mod=1' or 'mod' in tags[ 0] or 'broadcaster' in tags[0]: ismod = True else: ismod = False except Exception: pass if printmessage: if message != "": print(displayname + ": " + message) if message != "": logger(displayname, message, issub, ismod) if module_unshorten: tempmessage = message.split(" ") for shorturl in tempmessage: if validators.url( "http://" + shorturl ) or validators.url("https://" + shorturl): unshorten(s, shorturl) # These are the actual commands if message == "": pass elif message[0] == '!': if message.lower() == "!test": send_message( s, "Test successful. Bot is online!") if module_rules: if "!rule" in message.lower( ) and ismod and '!rule' not in comlimits: threading.Timer( 5, command_limiter, ['!rule']).start() comlimits.append('!rule') rules, warnings = func_rules( s, rules, warnings, message) if module_deathcounter: if "!deaths" in message.lower( ) and "!deaths" not in comlimits: game = str( getgame(channel_id, CLIENTID)).lower() cooldown_time = func_deaths( s, message, game, ismod) threading.Timer( cooldown_time, command_limiter, ['!deaths']).start() comlimits.append('!deaths') if message.lower( ) == "!dead" and "!dead" not in comlimits and ( ismod or issub): threading.Timer(30, command_limiter, ['!dead']).start() comlimits.append('!dead') game = str(getgame(channel_id, CLIENTID)).lower() dead(s, game) if module_raffles: if "!raffle" in message.lower() and ismod: raffle(s, message) elif "!join" in message.lower(): join_raffle(s, displayname, message, issub, ismod) if module_roulette: if "!roulette" in message.lower( ) and "!roulette" not in comlimits and module_roulette: threading.Timer( 20, command_limiter, ['!roulette']).start() comlimits.append('!roulette') roulette(displayname, s) if module_paddle: if "!paddle" in message and "!paddle" not in comlimits: threading.Timer( 20, command_limiter, ['!paddle']).start() comlimits.append('!paddle') paddle(s, displayname, message) if module_quotes: if message.lower( ) == "!lastquote" and "!quote" not in comlimits: threading.Timer( 15, command_limiter, ['!quote']).start() comlimits.append('!quote') last_quote(s) elif "!addquote" in message.lower( ) and ismod: game = getgame(channel_id, CLIENTID) add_quote(s, message, game) elif "!removequote" in message.lower( ) and ismod: remove_quote(s, message) elif "!quote" in message.lower( ) and "!quote" not in comlimits: if not ismod: threading.Timer( 15, command_limiter, ['!quote']).start() comlimits.append('!quote') get_quote(s, message) if module_backseatmessage: if "!backseatmessage" in message.lower( ) or '!bsm' in message.lower() and ismod: backseatmessage(s, message) if module_bonertimer: if "!starttimer" in message.lower( ) and ismod and ismod: starttimer(s) elif "!stoptimer" in message.lower( ) and ismod: stoptimer(s) elif "!openbets" in message.lower( ) and ismod: openbets(s) elif "!closebets" in message.lower( ) and ismod: closebets(s) elif message.lower() == "!betstats": betstats(s) elif "!bet" in message.lower(): bet(s, displayname, message) elif "!mybet" in message.lower(): mybet(s, displayname) elif "!clearbets" in message.lower( ) and ismod: clearbets(s) elif "!addbet" in message.lower( ) and ismod: addbet(s, message) elif ("!rembet" or "!removebet" ) in message.lower() and ismod: removebet(s, message) elif "!currentboner" in message.lower(): currentboner(s) elif "!brokenboner" in message.lower(): brokenboner(s) elif "!setboner" in message.lower(): setboner(s, message) elif "!addending" in message.lower(): addending(s, message) elif "!timer" in message.lower(): timer(s) elif "!resettimer" in message.lower( ) and ismod: resettimer(s) elif "!fidwins" in message.lower( ) and ismod: fidwins(s) elif "!winner" in message.lower( ) and ismod: winner(s, message) if module_questions: if message == "!question" and "!question" not in comlimits: if not ismod: threading.Timer( 15, command_limiter, ['!question']).start() comlimits.append('!question') question(s, message) elif "!addquestion" in message and ismod and module_questions: add_question(s, message) elif "!removequestion" in message and ismod and module_questions: threading.Timer( 5, command_limiter, ['!removequestion']).start() comlimits.append('!removequestion') remove_question(s, message) if "!bot" in message.lower(): send_message( s, "This bot is made by Bastixx669. Feel free to message him with " "questions, idea's or cookies!") if module_conversion: if "!convert" in message.lower(): convert(s, message) if module_rimmods: if "!linkmod" in message.lower( ) and "!linkmod" not in comlimits: threading.Timer( 15, command_limiter, ['!linkmod']).start() comlimits.append('!linkmod') mod(s, message) if module_SongSuggestions: if "!suggest" in message.lower( ) and "!suggest" not in comlimits: threading.Timer( 10, command_limiter, ['!linkmod']).start() comlimits.append('!linkmod') suggest(s, message) elif "!clearsuggestions" in message.lower( ) and ismod: clearsuggestions(s) if message.lower( ) == '!restart' and username == 'bastixx669': nopong() for l in parts: if "End of /NAMES list" in l: modt = True print(">>>Bot ready in channel: %s" % CHANNEL.decode()) logger( '>>>Bot', f'Bot ready in channel {CHANNEL.decode()}', False, True) print("modules loaded: %s" % ", ".join(modules)) except Exception as errormsg: try: errorlog(errormsg, 'Main()', temp) except Exception: errorlog(errormsg, 'Main()', '')
VMAX = 120.0 VMIN = 0.0 print('env info:**********') print('env name is:', args.env_name) sample_times = args.sample_times print("sample_times:", sample_times) print('VMAX is:' + str(VMAX) + " VMIN is:" + str(VMIN)) print('**********') file_name = "%s_%s_%s" % (args.policy_name, args.env_name, str(args.seed)) print("---------------------------------------") print("Settings: %s" % (file_name)) print("---------------------------------------") log_stat = logger(args.exp_name, str(args.seed), "result/" + args.policy_name) #record the reward env = gym.make(args.env_name) # 保存网络参数的频率 save_net_freq = args.save_net # 保存过去的网络参数的总数 net_number = args.save_num # Set seeds env.seed(args.seed) torch.manual_seed(args.seed) np.random.seed(args.seed) vis = Visualizer('Distributed TPS-CI2 DDPG_' + args.exp_name + "_" + str(args.seed))