def create_poll(self, title, user, **kwargs): ''' Creates a poll with the parameters Title : User ''' if title in self.poll_list: return "The poll already exist, remove it before" poll = Poll(title, user) self.poll_list[title] = poll poll.question = kwargs["question"] #set basic choices poll.choices = [":+1:",":-1:"] return "The poll \""+title+"\" has been created"
def poll(self, *args): """ Start a poll """ if len(args) == 0: return "text", POLL_HELP_MSG if args[0] == "help": return "text", POLL_HELP_MSG choices = [ phrase.strip() for phrase in self._user_msg.content.split(";") ] try: expiry_str = (choices.pop(-1) if "ends in" in choices[-1].lower() else "ends in 1 hour") except (KeyError, IndexError, ValueError): return "text", POLL_HELP_MSG words = expiry_str.split(" ") try: poll = Poll( time_length=TimeLength(unit=words[3], amount_of_time=words[2])) except ValueError: return "text", POLL_HELP_MSG poll.prompt = choices.pop(0) poll.choices = choices poll.channel_id = self._channel.id poll.votes = {idx: [] for idx in range(len(poll.choices))} poll.save() return_str = f"```{poll.prompt} ({expiry_str})\n\n" for choice_num in range(len(poll.choices)): return_str += f"{choice_num+1}.\t{poll.choices[choice_num]}\n" return_str += (f'\n\nType or DM me "!vote {poll.poll_id} ' '<choice number>" to vote```') return "text", return_str