async def on_ready(): """Preliminary activity Checks all guilds for all users and initializes them in memory. """ print('We have logged in as {0.user}.'.format(client)) print('I will be speaking "{0}" as default.'.format(language)) print("Looking for new members/guilds while I was away...") # We search all guilds and users Milton can see and initialize them. i = 0 for guild in client.guilds: # Add new guilds if str(guild.id) not in G.GLD.keys(): default_dict = {"language": language} G.GLD[str(guild.id)] = mun.DefaultMunch().fromDict(default_dict, 0) tools.save(G.OPT.guilds_path, G.GLD) # Add new members for member in guild.members: if str(member.id) not in G.USR.keys(): i += 1 G.USR[str(member.id)] = mun.DefaultMunch(0) G.USR[str(member.id)].name = member.name tools.save_users() print(f"Found {i} new members") game = ds.Game("with myself.") # Update "playing" message, for fun. print("Ready!") await client.change_presence(status=ds.Status.online, activity=game)
async def on_guild_join(guild): """Handles when Milton joins a guild""" if str(guild.id) not in G.GLD.keys(): default_dict = {"language": language} G.GLD[str(guild.id)] = mun.DefaultMunch().fromDict(default_dict, 0) tools.save(G.OPT.guilds_path, G.GLD) # Add new members for member in guild.members: if str(member.id) not in G.USR.keys(): G.USR[str(member.id)] = mun.DefaultMunch(0) G.USR[str(member.id)].name = member.name tools.save_users()
def hardware_attach(self, line): args = parse_argstring(self.hardware_attach, line) hardware_yaml = args.path hardware = { 'machines': pytest_automation_infra.get_local_config(hardware_yaml) } base = munch.DefaultMunch(munch.Munch) base.hosts = munch.Munch() pytest_automation_infra.init_hosts(hardware, base) self.shell.user_ns['base'] = base self._reconnect()
async def on_member_join(member): """Handles when new members join guilds""" # Update locale for current guild G.update_loc(G.GLD[str(member.guild.id)].language) if member.bot is True: # We don't do anything with bot accounts return for channel in member.server.channels: if str(channel.name).lower() in ['casa', 'general']: line = tools.get_random_line(G.LOC.hello_path) await channel.send(line.format(member.name)) if member.id not in G.USR.keys(): G.USR[str(member.id)] = mun.DefaultMunch(0) G.USR[str(member.id)].name = member.name tools.save_users()
import munch class AttrDict(): def __init__(self, init_dict=None): if init_dict == None: init_dict = {} super().__init__() for k, v in init_dict.items(): self.__setattr__(k, v) def __setattr__(self, name, value): print(name, value) if isinstance(value, dict): att = AttrDict(init_dict=value) self.__setattr__(name, att) with open('./tree.yml') as f: # use safe_load instead load dataMap0 = yaml.safe_load(f) print(dataMap0) # att = AttrDict(init_dict=dataMap0) undefined = object() att = munch.DefaultMunch(undefined, dataMap0) # print(att.fromDict(dataMap0, undefined)) print(att.treeroot) print(att.treeroot.branch1)