async def send_reply(self, reply, message: discord.Message, where) -> discord.Message: if reply: for r in reply: r = random_choose(r) if isinstance(r, list) else r r = Variable(message).apply_variable(r) if where == 'group': self.Botreply = await message.channel.send(r) elif where == 'private': self.Botreply = DMchannel = await message.author.create_dm() await DMchannel.send(r) write_log(hora_atual()+f' Enviando a resposta "{r}" há mensagem "{emoji.demojize(message.content)}" do author {message.author}.', path.log)
async def send_reaction(self, reaction, message:discord.Message, where): if reaction: for r in reaction: code_reaction = r r = random_choose(r) if isinstance(r, list) else r r = emoji.emojize(r, use_aliases = True) try: if where == 'author': await message.add_reaction(r) elif where == 'bot' and self.Botreply: await self.Botreply.add_reaction(r) write_log(hora_atual()+f' Adicionando a reação "{code_reaction}" a mensagem "{emoji.demojize(message.content)}" do autor {message.author}.', path.log) except discord.HTTPException: print(r)
def make_single_inversion(args, plt_show=False, inversion_id=1): """ Function to simulate and make the inversion for a single strong lensing system Input: - lens_file struct : arguments from the parser - plt_show bool : flag to show the critical curves and caustics - inversion_id int : id for the inversion Output: - NONE """ str_log = "" if args.substructure: #create a par file with the main lens + substructures all_systems = add_subs_parfile(lens_file=args.lens_file, n_subs=3) else: #create a par file with the main lens only all_systems = add_subs_parfile(lens_file=args.lens_file, n_subs=0) # if args.lens_position_error: # for i in all_systems: # lens_err_x = np.random.randn() \ # * float(args.lens_position_error_value) # lens_err_y = np.random.randn() \ # * float(args.lens_position_error_value) # str_log = str_log + "lens_xy_real " + str(i['x_centre']) + " " + \ # str(i['y_centre']) + "\n" # i['x_centre'] = i['x_centre'] + lens_err_x # i['y_centre'] = i['y_centre'] + lens_err_y # str_log = str_log + "lens_xy_final " + str(i['x_centre']) + \ # " " + str(i['y_centre']) + "\n" str_log = str_log + "lens_xy_final " + \ str(all_systems[len(all_systems) - 1]["x_centre"]) + " " + \ str(all_systems[len(all_systems) - 1]["y_centre"]) + "\n" if args.lens_position_error: lens_err_x = np.random.randn() \ * float(args.lens_position_error_value) lens_err_y = np.random.randn() \ * float(args.lens_position_error_value) all_systems[len(all_systems) - 1]["x_centre"] = lens_err_x + \ all_systems[len(all_systems) - 1]["x_centre"] all_systems[len(all_systems) - 1]["y_centre"] = lens_err_y + \ all_systems[len(all_systems) - 1]["y_centre"] str_log = str_log + "lens_xy_final " + \ str(all_systems[len(all_systems) - 1]["x_centre"]) + " " + \ str(all_systems[len(all_systems) - 1]["y_centre"]) + "\n" #Adding error on the lens red-shift if args.lens_z_error: for i in all_systems: lens_err_z = np.random.randn() * float(args.lens_z_error_value) i['z_lens'] = i['z_lens'] + lens_err_z #Adding error on the source red-shift if args.source_z_error: source_err_z = np.random.randn() * float(args.source_z_error_value) args.source_final_z = args.source_real_z + source_err_z #z_source can be < z_lens after adding the z_source error, this while #avoid this while args.source_final_z < args.lens_real_z: source_err_z = np.random.randn() * float(args.source_z_error_value) args.source_final_z = args.source_real_z + source_err_z else: args.source_final_z = args.source_real_z #print all_systems lt.generate_par_images(all_systems, file_par='im_' + args.lens_file) lt.generate_par_curves(all_systems, args, file_par='cc_' + args.lens_file) #run lenstool to generate de caustics and critical curves str_run_lt = 'lenstool ' + 'cc_' + args.lens_file + ' -n' os.system(str_run_lt) #read the caustics and define the radius within the sources will be sorted courves_file = 'ce.dat' xy_ca = np.loadtxt(courves_file, usecols=(3, 4), unpack=True) ca_radial_max = np.sqrt(max(xy_ca[0]**2 + xy_ca[1]**2)) lenstool_img_pos = [] count = 0 #n_inter_max = 200 #sort the sources until find multiplicitie > 3 while len(lenstool_img_pos) < 4: #and count < n_inter_max: source = fc.generate_sources(n_src=1, radius=ca_radial_max) lt.write_src_multfile( src_coords = source, args = args, \ file_name = 'source.mul' ) str_run_lt = 'lenstool ' + 'im_' + args.lens_file + ' -n > lenstool.out' os.system(str_run_lt) lenstool_img_pos = list(lt.read_images_lenstool(\ image_file = 'image.all')) count = count + 1 #removing the image with lower magnification (usualy < 1) to disconsider #the central image if len(lenstool_img_pos) > 4: print "Found more than 4 multiple images" lenstool_img_mag = lt.read_amplification() min_index = lenstool_img_mag[0].index(min(lenstool_img_mag[0])) lenstool_img_mag[0].pop(min_index) lenstool_img_pos.pop(min_index) #saving multiple image positions for i in lenstool_img_pos: str_log = str_log + "im_xy_real " + str(i[0]) + " " + str( i[1]) + "\n" #adding error to the image positions if args.position_error: #lenstool_img_pos_shape = np.shape(lenstool_img_pos) im_err = float(args.position_error_value) * \ np.random.randn(np.shape(lenstool_img_pos)[0], \ np.shape(lenstool_img_pos)[1]) lenstool_img_pos = lenstool_img_pos + im_err for i in lenstool_img_pos: str_log = str_log + "im_xy_final " + str(i[0]) + " " + str(i[1]) + \ "\n" fc.write_log(str(inversion_id), "test.txt") fc.write_log(str_log, str(inversion_id) + "extra.txt") #FIXME find a way to plot cc from real and optimized system if plt_show: pc.main_plot_curves_py(plot_show=False) lt.plot_points(images=lenstool_img_pos, plt_show=True) opt_result = lt.make_inversion_lenstool(lenstool_img_pos, \ args.source_final_z, inversion_par_file = args.inv_file) #Saving files: file_dic = { 'file_generate_arcs' : 'im_' + args.lens_file, \ 'file_source' : 'source.mul', \ 'file_make_inversion' : args.inv_file, \ 'file_best_fit' : 'best.par', \ 'file_chires' : 'chires.dat', \ } lt.copy_inversion_files(inversion_id, file_dic) return opt_result
num = 0 for index in range(len(person)): # 调用信息推送接口的入参请写成如下的形式 data = { "touser": person[index], # 工号 "msgtype": "news", # news表示图文消息 "news": { "articles": [ { "title": "<h4>保费快报</h4><p> >请点击图片查看详细信息</p>", # 标题,支持html标签表达的形式 "description": information, # 内容 "picurl": img, # 上方的图片 "url": return_url(), # 点击跳转使用的链接 } ] }, "copy": 1, # 是否可复制,1表示不能,0表示可以 "share": 1,# 是否可转发,1表示不能,0表示可以 "reply": 1,# 是否可回复,1表示不能,0表示可以 "watermark": 0# 是否有水印,1表示无,0表示有 } response = requests.post(url, json=data) res = json.loads(response.text) if res['errcode'] == 0: write_log(1, person[index], "tuwen") # 这里是写log else: write_log(0, person[index], "tuwen") print("message sent yet") else: print("no message to send.")
async def on_ready(): write_log(hora_atual() + ' Bot inicializado.', paths.log)
] to_insert = dict() for each in to_read: to_insert[each] = None if each in actual: to_insert[each] = actual[each] await Interpreter.message_and_reply( self, message=message, conditions=to_insert['conditions'], expected_message=to_insert['expected message'], reply=to_insert['reply'], reaction=to_insert['reaction'], delete=to_insert['delete'], pin=to_insert['pin'], delay=to_insert['delay'], kick=to_insert['kick'], ban=to_insert['ban'], where_reply=to_insert['where reply'], where_reaction=to_insert['where reaction']) client.run(token) try: Bot() except discord.errors.LoginFailure: write_log(hora_atual() + ' Falha no login.', paths.log)
async def ban_member(self, ban, message: discord.Message): if ban and isinstance(message.channel, discord.GroupChannel): await message.author.ban() write_log(hora_atual()+f' Banindo jogador "{message.author.name}"."')
async def kick_member(self, kick, message: discord.Message): if kick and isinstance(message.channel, discord.GroupChannel): await message.author.kick() write_log(hora_atual()+f' Expulsando jogador "{message.author.name}".')
async def pin_message(self, pin, message: discord.Message): if pin: await message.pin() write_log(hora_atual()+f' Fixando mensagem "{emoji.demojize(message.content)}" do autor {message.author}.',path.log)
async def remove_message(self, delete, message: discord.Message): if delete and isinstance(message.channel, discord.GroupChannel): await message.delete() write_log(hora_atual()+f' Removendo mensagem "{emoji.demojize(message.content)}" do autor {message.author}.',path.log)
import os from config import private_token, repoUrlType from functions import write_log, load_projects write_log('Operation starting...') write_log('*' * 30, False) write_log('Getting the project list you can access from GitLab.') projects = load_projects(private_token) write_log('Your projects fetched.') write_log('*' * 30, False) for project in projects: if repoUrlType == 'ssh': projectUri = project['ssh_url_to_repo'] else: projectUri = project['http_url_to_repo'] write_log(projectUri + ' cloning...') targetDirectory = 'repositories/' + project['path'] + '.git' if os.path.exists(targetDirectory): write_log(targetDirectory + ' deleting...') os.system('rm -rf ' + targetDirectory) os.system('git clone --mirror --progress ' + projectUri + ' ' + targetDirectory) write_log(targetDirectory + ' clone completed!') write_log('*' * 30, False)