async def unblock_guild(self, ctx, *guilds): for guild in guilds: u.block['guild_ids'].remove(guild) u.dump(u.block, 'cogs/block.json', json=True) await ctx.send('\N{WHITE HEAVY CHECK MARK} **Unblocked guilds**')
async def unblock_user(self, ctx, *users: d.User): for user in users: u.block['user_ids'].remove(user.id) u.dump(u.block, 'cogs/block.json', json=True) await ctx.send('\N{WHITE HEAVY CHECK MARK} **Unblocked users**')
async def queue_for_deletion(self, channel): def check(msg): if 'stop d' in msg.content.lower() and msg.channel is channel and msg.author.guild_permissions.administrator: raise exc.Abort elif msg.channel is channel and not msg.pinned: return True return False try: async for message in channel.history(limit=None): if 'stop d' in message.content.lower() and message.author.guild_permissions.administrator: raise exc.Abort if not message.pinned: await self.queue.put(message) while not self.bot.is_closed(): message = await self.bot.wait_for('message', check=check) await self.queue.put(message) except exc.Abort: u.tasks['auto_del'].remove(channel.id) u.dump(u.tasks, 'cogs/tasks.pkl') if not u.tasks['auto_del']: self.deleting = False print('STOPPED : deleting #{}'.format(channel.name)) await channel.send('**Stopped queueing messages for deletion in** {}'.format(channel.mention))
async def _settings_deleteresponses(self, ctx): if ctx.guild.id not in u.settings['del_resp']: u.settings['del_resp'].append(ctx.guild.id) else: u.settings['del_resp'].remove(ctx.guild.id) u.dump(u.settings, 'settings.pkl') await ctx.send(f'**Delete command responses:** `{ctx.guild.id in u.settings["del_resp"]}`')
async def _settings_deletecommands(self, ctx): if ctx.guild.id not in u.settings['del_ctx']: u.settings['del_ctx'].append(ctx.guild.id) else: u.settings['del_ctx'].remove(ctx.guild.id) u.dump(u.settings, 'settings.pkl') await ctx.send('**Delete command invocations:** `{}`'.format(ctx.guild.id in u.settings['del_ctx']))
async def on_ready(): if not checks.ready: from cogs import booru, info, management, owner, tools for cog in (tools.Utils(bot), owner.Bot(bot), management.Admin(bot), info.Info(bot), booru.MsG(bot)): bot.add_cog(cog) u.cogs[type(cog).__name__] = cog print(f'COG : {type(cog).__name__}') if u.config['playing'] != '': await bot.change_presence(activity=d.Game(u.config['playing'])) print('\n> > > > > > > > >' f'\nC O N N E C T E D : {bot.user.name}' '\n> > > > > > > > >\n') try: if u.temp['startup']: with suppress(err.NotFound): if u.temp['startup'][0] == 'guild': ctx = bot.get_channel(u.temp['startup'][1]) else: ctx = bot.get_user(u.temp['startup'][1]) message = await ctx.fetch_message(u.temp['startup'][2]) await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') u.temp['startup'] = () u.dump(u.temp, 'temp/temp.pkl') checks.ready = True except KeyError: u.dump({'startup': ()}, 'temp/temp.pkl') except AttributeError: pass else: print( '\n- - - -\nI N F O : reconnected, reinitializing tasks\n- - - -\n' ) reconnect = await bot.get_user(u.config['owner_id'] ).send('**RECONNECTING**') await reconnect.add_reaction('\N{SLEEPING SYMBOL}') if u.tasks['auto_del']: for channel in u.tasks['auto_del']: temp = bot.get_channel(channel) bot.loop.create_task(u.cogs['Admin'].queue_for_deletion(temp)) print(f'RESTARTED : auto-deleting in #{temp.name}') u.cogs['Admin'].deleting = True bot.loop.create_task(u.cogs['Admin'].delete()) if u.config['playing'] != '': await bot.change_presence(activity=d.Game(u.config['playing'])) await reconnect.add_reaction('\N{WHITE HEAVY CHECK MARK}') print('\nS U C C E S S\n')
async def on_guild_remove(guild): print(f'LEFT : {guild.name}') for task, idents in u.tasks.items(): for channel in guild.channels: if channel.id in idents: idents.remove(channel.id) print(f'STOPPED : {task} in #{channel.id}') u.dump(u.tasks, 'cogs/tasks.pkl')
async def change_status(self, ctx, *, game=None): if game: await self.bot.change_presence(game=d.Game(name=game)) u.config['playing'] = game u.dump(u.config, 'config.json', json=True) await ctx.send(f'**Game changed to** `{game}`') else: await self.bot.change_presence(game=None) u.config['playing'] = '' u.dump(u.config, 'config.json', json=True) await ctx.send('**Game changed to** ` `')
async def on_error(error, *args, **kwargs): print(f'\n! ! ! ! !\nE R R O R : {sys.exc_info()[1].text}\n! ! ! ! !\n', file=sys.stderr) tb.print_exc() await bot.get_user(u.config['owner_id'] ).send(f'**ERROR** \N{WARNING SIGN}\n```\n{error}```') if u.temp['startup']: u.temp.clear() u.dump(u.temp, 'temp/temp.pkl') await bot.logout()
async def die(self, ctx): await u.add_reaction(ctx.message, '\N{CRESCENT MOON}') chantype = 'guild' if isinstance(ctx.channel, d.TextChannel) else 'private' u.temp['startup'] = (chantype, ctx.channel.id if chantype == 'guild' else ctx.author.id, ctx.message.id) u.dump(u.temp, 'temp/temp.pkl') # loop = self.bot.loop.all_tasks() # for task in loop: # task.cancel() print( '\n< < < < < < < < < < < <\nD I S C O N N E C T E D\n< < < < < < < < < < < <\n' ) await self.bot.logout()
async def auto_delete(self, ctx): try: if ctx.channel.id not in u.tasks['auto_del']: u.tasks['auto_del'].append(ctx.channel.id) u.dump(u.tasks, 'cogs/tasks.pkl') self.bot.loop.create_task(self.queue_for_deletion(ctx.channel)) if not self.deleting: self.bot.loop.create_task(self.delete()) self.deleting = True print('STARTED : auto-deleting in #{}'.format(ctx.channel.name)) await ctx.send('**Auto-deleting all messages in {}**'.format(ctx.channel.mention)) else: raise exc.Exists except exc.Exists: await ctx.send('**Already auto-deleting in {}.** Type `stop d(eleting)` to stop.'.format(ctx.channel.mention)) await u.add_reaction(ctx.message, '\N{CROSS MARK}')
async def restart(self, ctx): await u.add_reaction(ctx.message, '\N{SLEEPING SYMBOL}') print( '\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^\nR E S T A R T I N G\n^ ^ ^ ^ ^ ^ ^ ^ ^ ^\n' ) chantype = 'guild' if isinstance(ctx.channel, d.TextChannel) else 'private' u.temp['startup'] = (chantype, ctx.channel.id if chantype == 'guild' else ctx.author.id, ctx.message.id) u.dump(u.temp, 'temp/temp.pkl') # loop = self.bot.loop.all_tasks() # for task in loop: # task.cancel() await self.bot.logout() os.execl(sys.executable, 'python3', 'run.py')
visualizeWords = [ "great", "cool", "brilliant", "wonderful", "well", "amazing", "worth", "sweet", "enjoyable", "boring", "bad", "dumb", "annoying", "female", "male", "queen", "king", "man", "woman", "rain", "snow", "hail", "coffee", "tea"] # dimensionality reduction visualizeIdx = [tokens[word] for word in visualizeWords] visualizeVecs = wordVectors[visualizeIdx, :] # save word vectors for evaluation sampleVectors = {word: list(vec) for word, vec in zip(visualizeWords, visualizeVecs)} #sampleVectorsPath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "sampleVectors.json") #dump(sampleVectors, sampleVectorsPath) dump(sampleVectors, r'C:\Users\msingleton\Documents\XCS224N-A2\sampleVectors.json') temp = (visualizeVecs - np.mean(visualizeVecs, axis=0)) covariance = 1.0 / len(visualizeIdx) * temp.T.dot(temp) U, S, V = np.linalg.svd(covariance) coord = temp.dot(U[:, 0:2]) for i in range(len(visualizeWords)): plt.text(coord[i, 0], coord[i, 1], visualizeWords[i], bbox=dict(facecolor='green', alpha=0.1)) plt.xlim((np.min(coord[:, 0]), np.max(coord[:, 0]))) plt.ylim((np.min(coord[:, 1]), np.max(coord[:, 1]))) plt.savefig(r'C:\Users\msingleton\Documents\XCS224N-A2\word_vectors.png')
axis=0) visualizeWords = [ "great", "cool", "brilliant", "wonderful", "well", "amazing", "worth", "sweet", "enjoyable", "boring", "bad", "dumb", "annoying", "female", "male", "queen", "king", "man", "woman", "rain", "snow", "hail", "coffee", "tea"] # dimensionality reduction visualizeIdx = [tokens[word] for word in visualizeWords] visualizeVecs = wordVectors[visualizeIdx, :] # save word vectors for evaluation sampleVectors = {word: list(vec) for word, vec in zip(visualizeWords, visualizeVecs)} sampleVectorsPath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "sampleVectors.json") dump(sampleVectors, sampleVectorsPath) temp = (visualizeVecs - np.mean(visualizeVecs, axis=0)) covariance = 1.0 / len(visualizeIdx) * temp.T.dot(temp) U, S, V = np.linalg.svd(covariance) coord = temp.dot(U[:, 0:2]) for i in range(len(visualizeWords)): plt.text(coord[i, 0], coord[i, 1], visualizeWords[i], bbox=dict(facecolor='green', alpha=0.1)) plt.xlim((np.min(coord[:, 0]), np.max(coord[:, 0]))) plt.ylim((np.min(coord[:, 1]), np.max(coord[:, 1]))) plt.savefig('word_vectors.png')
"male", "queen", "king", "man", "woman", "rain", "snow", "hail", "coffee", "tea" ] # dimensionality reduction visualize_idx = [tokens[word] for word in visualize_words] visualize_vecs = word_vectors[visualize_idx, :] # save word vectors for evaluation sample_vectors = { word: list(vec) for word, vec in zip(visualize_words, visualize_vecs) } sample_vectors_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "sample_vectors.json") dump(sample_vectors, sample_vectors_path) temp = (visualize_vecs - np.mean(visualize_vecs, axis=0)) covariance = 1.0 / len(visualize_idx) * temp.T.dot(temp) U, S, V = np.linalg.svd(covariance) coord = temp.dot(U[:, 0:2]) for i in range(len(visualize_words)): plt.text(coord[i, 0], coord[i, 1], visualize_words[i], bbox=dict(facecolor='green', alpha=0.1)) plt.xlim((np.min(coord[:, 0]), np.max(coord[:, 0]))) plt.ylim((np.min(coord[:, 1]), np.max(coord[:, 1])))
async def block_guild(self, ctx, *guilds): for guild in guilds: u.block['guild_ids'].append(guild) u.dump(u.block, 'cogs/block.json', json=True)
async def block_user(self, ctx, *users: d.User): for user in users: u.block['user_ids'].append(user.id) u.dump(u.block, 'cogs/block.json', json=True)