def main(): print('> Iniciando operação update_function') path = FUNC_PATH+sys.argv[2]+'\\'+sys.argv[1] if len(sys.argv) > 2: try: utils.createZipFile(path) utils.createBackup('U', path+'/file.zip') print('> Enviando arquivo') p = subprocess.Popen( ['aws', '--region', utils.getRegion(sys.argv[2]), 'lambda', 'update-function-code', '--function-name', sys.argv[1], '--zip-file', 'fileb://'+path+'/file.zip', '--revision-id', utils.getRevisionID()['RevisionId']] , stdout=subprocess.PIPE, shell=True) p.wait() text = p.stdout.read().decode() text = ast.literal_eval(text) utils.updateRevisionID(text['FunctionName'], text['LastModified'], text['RevisionId'], sys.argv[2]) os.remove(path+'/file.zip') utils.log('UPD', sys.argv[1], sys.argv[2]) except SyntaxError as err: print('> Erro:', err) if os.path.isfile(path+'/file.zip'): os.remove(path+'/file.zip') else: print('> Está faltando argumentos') print('> Operação finalizada')
def main(): print('> Iniciando operação get_function') if len(sys.argv) > 2: try: print('> Fazendo requisição da função lambda') p = subprocess.Popen([ 'aws', '--region', utils.getRegion(sys.argv[2]), 'lambda', 'get-function', '--function-name', sys.argv[1] ], stdout=subprocess.PIPE, shell=True) text = p.stdout.read().decode() text = ast.literal_eval(text) urllib.request.urlretrieve(text['Code']['Location'], 'file.zip') utils.updateRevisionID(text['Configuration']['FunctionName'], text['Configuration']['LastModified'], text['Configuration']['RevisionId'], sys.argv[2]) extractFile() print('> Função handler:', text['Configuration']['Handler']) utils.createBackup('G', 'file.zip') if utils.checkException(): utils.updateFunction() utils.checkPackages() os.remove('file.zip') utils.log('GET', sys.argv[1], sys.argv[2]) except Exception as err: print('> Erro:', err) if os.path.isfile('file.zip'): os.remove('file.zip') else: print('> Está faltando argumentos') print('> Operação finalizada')
async def background_loop(): await sleep(10) await bot.wait_until_ready() while not bot.is_closed(): u.log("Checking twitch...") await t.check(streamerChannel) await sleep(60)
async def raid(self, ctx: Context, twitchChannel: str = None): u.log(ctx) if not u.vip(ctx.author): await ctx.send(f"{ctx.author.mention}, only VIPs can use this command.") return if not twitchChannel: await ctx.send(f"{ctx.author.mention}, please specify a channel name.") return await ctx.send(f"@everyone we're raiding https://twitch.tv/{twitchChannel}")
async def stop(ctx): if not u.dev(ctx.author): await ctx.send( f"{ctx.author.mention}, only developers can use this command.") return u.log("Developer initiated logout...", u.ERR) await ctx.send(f"Goodbye...") await bot.logout() exit(1)
async def reload(ctx): u.log(ctx) if not u.dev(ctx.author): await ctx.send( f"{ctx.author.mention}, only developers can use this command.") return global config config = u.reloadConfig() await ctx.send(f"{ctx.author.mention}, reloaded config!") return
def _calculatePhoneAccuracy(self): """ Similar to _calculateHybridAccuracy, except uses phonemes only. Converts ref and hyp to phonemes and does a direct edit distance on the entire thing. phone_accuracy c [0,1] """ oovId = self.common.symbolTable['<UNK>'] hyp = self.hypothesis ref = self.reference # convert all words in ref to phonemes, excluding oov try: ref_phones = [ self.common.lexicon[self.common.symbolTableToInt[x]] for x in ref if x != oovId ] except KeyError as e: # word in ref not in lexicon, abort trying to convert it to phonemes log('Warning: couldn\'t find prompt words in lexicon or symbol table (grading with 0.0), prompt: {}' .format(self.common.intToSym(ref))) return 0.0 # convert all words in hyp to phonemes hyp_phones = [] for x in hyp: try: hyp_phones.append( self.common.lexicon[self.common.symbolTableToInt[x]]) except KeyError as e: # word in hyp not in lexicon, must be a phoneme, in which case just append it and remove the ! hyp_phones.append([self.common.symbolTableToInt[x][1:]]) ref_phones = list(itertools.chain.from_iterable(ref_phones)) hyp_phones = list(itertools.chain.from_iterable(hyp_phones)) N = len(ref_phones) ed, _ = self._levenshteinDistance(hyp_phones, ref_phones) try: ratio = 1 - min(ed / N, 1) except ZeroDivisionError as e: ratio = 0.0 return ratio
async def link(self, ctx, url: str = None): u.log(ctx) if not u.streamer(ctx.author): await ctx.send(f"{ctx.author.mention}, only streamers can use this command.") return if not url: await ctx.send(f"{ctx.author.mention}, please enter your custom stream link.") return if not url.startswith("https://") or not url.startswith("http://"): url = "https://" + url current_user = twitch_db.find_one({"discord_id": str(ctx.author.id)}) current_user["custom_stream_url"] = url param = {"discord_id": str(ctx.author.id)} param2= {"$set": current_user} twitch_db.update_one(param, param2) await ctx.send(f"{ctx.author.mention}, your custom link has been set!")
async def on_message(message: discord.Message): global suggestionChannel if message.channel == suggestionChannel: embed = discord.Embed(title="New Feature Request!", color=0x8000ff) embed.set_author( name=f"{message.author.name}#{message.author.discriminator}", icon_url=message.author.avatar_url) embed.add_field(name="Request", value=message.content, inline=True) if message.author.id not in config["devs"]: await message.author.send( "Your request has been sent to the developers. They will respond as soon as possible. The embed below is what they have recieved.", embed=embed) u.log( f"Request from {message.author.name}#{message.author.discriminator} recieved..." ) for dev in config["devs"]: developer: discord.User = bot.get_user(dev) await developer.send(embed=embed) await bot.process_commands(message)
async def streamer(self, ctx, _user: discord.Member = None, _username: str = None): u.log(ctx) if not u.vip(ctx.author): await ctx.send(f"{ctx.author.mention}, only VIPs can use this command.") return if not _user: await ctx.send(f"{ctx.author.mention}, please tag a user to make them a streamer.") return if not _username: await ctx.send(f"{ctx.author.mention}, please specify the users Twitch username.") return if u.streamer(_user) or twitch_db.find_one({"discord_id": str(_user.id)}): await ctx.send(f"{ctx.author.mention}, that user is already a streamer.") return await _user.add_roles(self.streamerRole) twitch_db.insert_one({ "twitch_username": _username, "message_id": None, "discord_id": str(_user.id), "response": {}, "custom_stream_url": None }) await ctx.send(f"{_user.mention}, {ctx.author.mention} has made you a streamer!")
if not u.dev(ctx.author): await ctx.send( f"{ctx.author.mention}, only developers can use this command.") return global config config = u.reloadConfig() await ctx.send(f"{ctx.author.mention}, reloaded config!") return @bot.command() async def stop(ctx): if not u.dev(ctx.author): await ctx.send( f"{ctx.author.mention}, only developers can use this command.") return u.log("Developer initiated logout...", u.ERR) await ctx.send(f"Goodbye...") await bot.logout() exit(1) u.log("Starting script...") bot.loop.create_task(background_loop()) if "--debug" in argv: bot.run(secrets["dev_token"]) else: bot.run(secrets["token"])
def _calculateHybridAccuracy(self) -> (float, float): """ Hybrid accuracy is some sort of metric, attempts to locate correct words. E.g. ref: the dog jumped over the fence hyp: the /c/o/d/ ran over the tent would result in an accuracy of 3/6 + 1/3*1/6 = 0.555 for getting the, over, the and a single phoneme from dog correct. Extra words are also treated as errors, e.g. ref: the dog jumped over the fence hyp: /i/n/s/e/r/t/i/o/n/ the dog jumped over the fence would divide insertion by the average phoneme count of words (if 5) and then accuracy would be 6 - 5/4 / 6 = 4.75/6 = 0.792 TODO not make this average, but use an actual phoneme 2 grapheme and locate the words Words in middle, are compared to phonemes of the words from ref, and a ratio of correct phonemes calculated from that. accuracy c [0,1] also calculates regular WER (done here since the align hyp computation is needed and has already been done here) on a word level grouping hyp phonemes into words e.g. ref: the dog jumped over the fence hyp: the /c/o/d/ ran over the tent would result in a wer of 3/6 = 0.5 (3 substitutions) return: (hybrid, wer) """ oovId = self.common.symbolTable['<UNK>'] hyp = self.hypothesis ref = self.reference # convert all words in ref to phonemes try: ref_phones = [ self.common.lexicon[self.common.symbolTableToInt[x]] for x in ref ] except KeyError as e: # word in ref not in lexicon, abort trying to convert it to phonemes log('Warning: couldn\'t find prompt words in lexicon or symbol table (grading 0.0), prompt: {}' .format(self.common.intToSym(ref)), e=e) return (0.0, 0.0) aligned = self._alignHyp(hyp, ref) ali_no_oov = [x for x in aligned if x != -2] # remove oov for part of our analysis hyp_no_oov = [x for x in hyp if x != oovId] # mark positions of recognized words, e.g. rec_words = [0, 3, 5] rec_words = [] # mark all strings of -1's (meaning we have phonemes inserted) minus_ones = [ ] # minus_ones = [(1,3), (4,5), ..], i.e. tuples of linked sequences of -1's inSequence = False seq = [] # partial sequence for i, a in enumerate(ali_no_oov): if a == -1 and not inSequence: inSequence = True seq.append(i) if a != -1 and inSequence: inSequence = False seq.append(i) minus_ones.append(seq) seq = [] # if we have -1's at the end of ali_no_oov if i == len(ali_no_oov) - 1 and a == -1 and inSequence: seq.append(len(ali_no_oov)) minus_ones.append(seq) if a >= 0: rec_words.append(a) # for each sequence of -1's calculate phoneme overlap with corresponding words. # e.g. if ref: the cat jumped # hyp: the cat j u m p # we would calc the overlap of 'j u m p e d' with 'j u m p' ratios = [ ] # len(ratios) == len(minus_ones) ratios of each sequence phoneme overlap (contribution to word error rate) wer_insertions = 0 for seq in minus_ones: # convert seq to phoneme list, grab e.g. !h from symbolTable and remove ! to match with lexicon seq_phones = [ self.common.symbolTableToInt[x][1:] for x in hyp_no_oov[seq[0]:seq[1]] ] ref_phones_range = ( ) # which indices in ref_phones do we want to compare to? (which words) # figure out which words we should compare each phoneme sequence with # find out if we are a -1 sequence in the beginning, middle or end of the hyp if seq[0] == 0: # beginning, look at all words up to the first recognized word if rec_words: ref_phones_range = (0, rec_words[0]) else: # no recognized words, compare to entire ref ref_phones_range = (0, len(ref_phones)) elif seq[-1] == len(hyp_no_oov): # end, look at words from last recognized word ref_phones_range = (rec_words[-1] + 1, len(ref_phones)) else: # middle, look at words between recognized words to the left&right of this sequence # since this is neither beginning or end, we know we have recognized words on both sides # e.g. aligned: [0, 1, -1, -1, -1, 4] # we want to look at words ref[2:4] ref_phones_range = (ali_no_oov[seq[0] - 1] + 1, ali_no_oov[seq[1]]) hybridPenalty = 1.5 if ref_phones_range[1] - ref_phones_range[0] > 0: # use formulaAccura more (e.g. our aligner inserted more phonemes than are in # the reference), we can get a penalty for at most (1-hybridPenalty)*ref word count # for the entire sequence. N = sum([ len(ref_phones[i]) for i in range(ref_phones_range[0], ref_phones_range[1]) ]) ed, _ = self._levenshteinDistance( seq_phones, list( itertools.chain.from_iterable( ref_phones[ref_phones_range[0]:ref_phones_range[1]] ))) ratio = 1 - min(ed / N, hybridPenalty) normalized_ratio = ratio * (ref_phones_range[1] - ref_phones_range[0]) ratios.append(normalized_ratio) else: # no words to compare to (empty interval this seq compares to) # attempt to attempt to give some sort of minus penalty # in similar ratio to the one above (if hybridPenalty=1.5 then at most -1/2*wc) # use average phoneme count from lexicon, and give at most # an error of 1/2 that. For example if avg=5 and our seq has # 11 phonemes we give an error of -1/2 * floor(11/5) = -1 ratios.append((1 - hybridPenalty) * int( (seq[1] - seq[0]) / self.common.avgPhonemeCount)) wer_insertions += 1 hybrid = max((len(rec_words) + sum(ratios)) / len(ref), 0) # WAcc = (H - I)/N # https://en.wikipedia.org/wiki/Word_error_rate wer = (len([x for x in aligned if x >= 0]) - wer_insertions) / len(ref) return (hybrid, wer)
async def on_ready(): u.log("Bot ready...") u.log("Running version: " + __version__) global guild global secrets global vipRole global beansRole global streamerRole global welcomeChannel global streamerChannel global changelogChannel global suggestionChannel guild = bot.get_guild(601701439995117568) # roles vipRole = guild.get_role(601711869668884484) streamerRole = guild.get_role(601710639068610578) beansRole = guild.get_role(601711999939903489) # channels changelogChannel = bot.get_channel(603279565439369236) welcomeChannel = bot.get_channel(603284631151706112) streamerChannel = bot.get_channel(604088400819126361) suggestionChannel = bot.get_channel(608371806549704800) embed = discord.Embed(title=f"BeanBot v{__version__}", color=0xff6000) embed.set_author(name=f"BeanBot Devs", icon_url=bot.user.avatar_url) embed.add_field(name="Changelog", value=f"\t- {newline.join(config['meta']['changelog'])}") embed.set_footer(text=f"Build #{config['meta']['build_number']}") if __version__ != secrets["CACHED_VERSION"] and "--debug" not in argv: secrets["CACHED_VERSION"] = __version__ secrets["CACHED_BUILD"] = config["meta"]["build_number"] u.editConfig("secrets.json", secrets) secrets = u.reloadConfig("secrets.json") msg = await changelogChannel.send(embed=embed) secrets["CHANGELOG_MESSAGE_ID"] = msg.id elif config["meta"]["build_number"] != secrets["CACHED_BUILD"]: msg = await changelogChannel.fetch_message( secrets["CHANGELOG_MESSAGE_ID"]) if msg.author != bot.user: u.log(f"Can\'t update build number... Not my message.") else: await msg.edit(embed=embed) elif "--debug" in argv: u.log("Debugging", u.WRN) u.log("BeanBot logged in...") for extension in initial_extensions: bot.load_extension(extension) u.log(f"Loaded {extension}")
def notify(usernames: Dict[str, str], a: Presence, boot: bool): thestring = "" theicon = "robloxnotif.ico" thecolor = Fore.WHITE thesound = "robloxnotif" if usernames[str(a.userId)].startswith("!") or usernames[str( a.userId)].startswith("[!]"): thesound = "fav" if str(a.userPresenceType) == str(PresenceType.Playing.value): thestring = "playing: " + a.lastLocation if a.lastLocation == "": thestring = "playing something" theicon = "playing" thecolor = Fore.LIGHTGREEN_EX # better for powershell elif str(a.userPresenceType) == str(PresenceType.Online.value): thestring = "online" theicon = "online" thecolor = Fore.LIGHTCYAN_EX # better for powershell elif str(a.userPresenceType) == str(PresenceType.InStudio.value): thestring = "in studio: " + a.lastLocation if a.lastLocation == "": thestring = "in studio making something" theicon = "studio" thecolor = Fore.LIGHTYELLOW_EX # better for powershell elif (str(a.userPresenceType) == str( PresenceType.Offline.value)) and (not boot): thestring = "now offline" thecolor = Fore.LIGHTBLACK_EX # better for powershell theicon = "offline" if thestring != "": log(usernames[str(a.userId)] + " is " + thestring, thecolor) if thePlatform == "Linux" or thePlatform == "Darwin": from notifypy import Notify notif = Notify() notif.title = usernames[str(a.userId)] + " is" notif.message = thestring notif.icon = f"./icons/png/{theicon}.png" notif.audio = path.realpath(f"./sounds/{thesound}.wav") notif.application_name = "robloxnotif" notif.send(block=True) elif thePlatform == "Windows": import win10toast from playsound import playsound toast = win10toast.ToastNotifier() toast.show_toast( usernames[str(a.userId)] + " is", thestring, duration=3, icon_path="./icons/" + theicon + ".ico", threaded=True, sound=False, ) try: playsound(path.realpath(f"./sounds/{thesound}.wav")) except UnicodeDecodeError: pass while toast.notification_active(): sleep(0.1)
def main(): ns = parse_arguments() outFile = ns.outFile utils.log(config.DESCRIPTION + '\n', outFile) profile = utils.read_profile(ns.inputFile, ns.aaOrder, config.AA_ORDER) fr = utils.read_single_fasta(ns.fasta) if not profile.shape[0] == len(fr): raise BetawareError("Error: FASTA sequence length doesn't match profile dimension.") pred = detect_TMBB(profile) utils.log('Sequence id : %s\n' % (fr.id,), outFile) utils.log('Sequence length : %d\n' % (len(fr.seqdata),), outFile) sens = 1.0 - ns.sens th = config.TH_RNG_MIN + ((sens - config.SENS_MIN) * (config.TH_RNG_MAX - config.TH_RNG_MIN) / (config.SENS_MAX - config.SENS_MIN)) if pred >= th: utils.log('Predicted TMBB : Yes\n', outFile) topology, probs = predict_topology(profile) utils.log('Topology : %s\n' % (utils.get_TM_segments(topology),), outFile) utils.log(utils.get_SS_string(topology, fr.seqdata, probs, l = config.SS_LINE_LEN), outFile) else: utils.log('Predicted TMBB : No\n', outFile) if ns.report_topology: topology, probs = predict_topology(profile) utils.log('TMB Strands : %s\n' % (utils.get_TM_segments(topology, l = 60, o = 18),), outFile) utils.log(utils.get_SS_string(topology, fr.seqdata, probs, l = config.SS_LINE_LEN), outFile) utils.log('//\n\n', outFile) sys.exit(0)
async def check(self, streamerChannel: discord.TextChannel): for streamer in self.twitch.find(): username = streamer["twitch_username"] headers = { "User-Agent": "Your user agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36 OPR/63.0.3368.51 (Edition beta)", "Client-ID": self.secrets["twitchToken"] } u.log(f"\tChecking if {username} is live...") try: r = requests.get( f"https://api.twitch.tv/helix/streams?user_login={username}", headers=headers) streamData = r.json() r.close() except requests.ConnectionError as e: u.log("You\'re not connected to the Internet:tm:... Aborting", u.ERR) self.twitch.update_one({"twitch_username": username}, {"$set": streamer}) return if streamData["data"]: try: try: streamData = r.json()["data"][0] except: streamData = r.json()["data"] continue r = requests.get( f"https://api.twitch.tv/helix/users?id={streamData['user_id']}", headers=headers) try: userData = r.json()["data"][0] except: userData = r.json()["data"] continue r.close() r = requests.get( f"https://api.twitch.tv/helix/games?id={streamData['game_id']}", headers=headers) try: gameData = r.json()["data"][0] except: gameData = r.json()["data"] continue r.close() except requests.ConnectionError as e: u.log( "You\'re not connected to the Internet:tm:... Aborting", u.ERR) self.twitch.update_one({"twitch_username": username}, {"$set": streamer}) return user: discord.User = await self.bot.fetch_user( int(streamer["discord_id"])) embed: discord.Embed if (streamer["custom_stream_url"]): embed = discord.Embed(title=streamData["title"], url=streamer["custom_stream_url"], color=0x8000ff) else: embed = discord.Embed(title=streamData["title"], url=f"https://twitch.tv/{username}", color=0x8000ff) embed.set_author(name=user.name, icon_url=user.avatar_url) embed.set_thumbnail( url=gameData["box_art_url"].format(width=390, height=519)) embed.set_image(url=streamData["thumbnail_url"].format( width=1280, height=720)) embed.add_field(name="Game", value=gameData["name"], inline=True) embed.add_field(name="Viewers", value=streamData["viewer_count"], inline=True) if not streamer["message_id"]: u.log(f"\t\t{username} is now live, announcing stream...") msg = await streamerChannel.send( f"@everyone {user.mention} is live!", embed=embed) streamer["message_id"] = msg.id elif streamer["response"] != streamData: msg = await streamerChannel.fetch_message( streamer["message_id"]) if msg.author != self.bot.user: u.log( f"\t\tCan\'t update {username}\'s live message... Not my message." ) return u.log(f"\t\tUpdating {username}\'s live message...") await msg.edit( content=f"@everyone {user.mention} is live!", embed=embed) streamer["response"] = streamData else: if streamer["message_id"]: u.log( f"\t\t{username} is no longer live, deleting message..." ) msg = await streamerChannel.fetch_message( streamer["message_id"]) await msg.delete() streamer["response"] = {} streamer["message_id"] = None self.twitch.update_one({"twitch_username": username}, {"$set": streamer})
import deployconfig from modules import utils from modules import argparser from modules import versioning args = argparser.args if args.use_colors: utils.USE_COLORS = True user_data = None try: with open(".user.json", "r", encoding="UTF-8") as f: user_data = json.load(f) utils.log("Loaded .user.json", level=utils.INFO) except: utils.log("Failed to load .user.json", level=utils.INFO) if args.path == None: args.app_env = args.app_name + "-" + args.app_env if user_data == None: utils.log("No path and no .user.json, exiting", level=utils.FATAL) elif args.app_name not in user_data["targets"]: utils.log("No such profile {}".format(args.app_name), level=utils.FATAL) elif args.app_env not in user_data["targets"][ args.app_name]["envs"] or args.app_env not in user_data["envs"]: