async def pinit(self, ctx, name, pid): """ `!pinit` _ `course name` _ _ `piazza id` _ **Usage:** !pinit <course name> <piazza id> **Examples:** `!pinit CPSC221 ke1ukp9g4xx6oi` creates a CPSC221 Piazza instance for the server *Only usable by TAs and Profs """ self.bot.d_handler.piazza_handler = PiazzaHandler( name, pid, PIAZZA_EMAIL, PIAZZA_PASSWORD, ctx.guild) # dict.get defaults to None so KeyError is never thrown for channel in self.piazza_dict.get("channels"): self.bot.d_handler.piazza_handler.add_channel(channel) self.piazza_dict["course_name"] = name self.piazza_dict["piazza_id"] = pid self.piazza_dict["guild_id"] = ctx.guild.id writeJSON(self.piazza_dict, "data/piazza.json") response = f"Piazza instance created!\nName: {name}\nPiazza ID: {pid}\n" response += "If the above doesn't look right, please use `!pinit` again with the correct arguments" await ctx.send(response)
def piazza_start(self): if all(field in self.piazza_dict for field in ("course_name", "piazza_id", "guild_id")): self.bot.d_handler.piazza_handler = PiazzaHandler( self.piazza_dict["course_name"], self.piazza_dict["piazza_id"], PIAZZA_EMAIL, PIAZZA_PASSWORD, self.piazza_dict["guild_id"]) # dict.get will default to an empty tuple so a key error is never raised # We need to have the empty tuple because if the default value is None, an error is raised (NoneType object # is not iterable). for ch in self.piazza_dict.get("channels", tuple()): self.bot.d_handler.piazza_handler.add_channel(int(ch))