Пример #1
0
 async def restart(self, ctx: commands.Context):
     '''
     Restart the Secret Santa after pause
     '''
     currAuthor = ctx.author
     is_paused = True
     if ((currAuthor.top_role == ctx.guild.roles[-1]) and is_paused):
         # ensure all users have all info submitted
         all_fields_complete = True
         for user in self.usr_list:
             if (user.wishlisturl_is_set() and user.pref_is_set()):
                 pass
             else:
                 all_fields_complete = False
                 try:
                     await currAuthor.send(
                         BOT_ERROR.HAS_NOT_SUBMITTED(user.name))
                     await ctx.send(
                         "`Partner assignment cancelled: participant info incomplete.`"
                     )
                 except Exception as e:
                     BOT_ERROR.output_exception(e, self.logger)
                     await ctx.send(currAuthor.mention +
                                    BOT_ERROR.DM_FAILED)
                     BOT_ERROR.output_error(
                         currAuthor.mention + BOT_ERROR.DM_FAILED,
                         self.logger)
         list_changed = self.SecretSantaHelper.usr_list_changed_during_pause(
             self.usr_list, self.user_left_during_pause)
         if (list_changed):
             ctx.send(
                 f"User list changed during the pause. Partners must be picked again with `{CONFIG.prefix}start`."
             )
         else:
             self.exchange_started = True
             is_paused = False
             self.config['programData']['exchange_started'] = True
             self.config.write()
             await ctx.send(
                 "No change was made during the pause. Secret Santa resumed with the same partners."
             )
     elif (currAuthor.top_role != ctx.guild.roles[-1]):
         await ctx.send(BOT_ERROR.NO_PERMISSION(ctx.guild.roles[-1]))
     elif (not is_paused):
         await ctx.send(BOT_ERROR.NOT_PAUSED)
     else:
         await ctx.send(BOT_ERROR.UNREACHABLE)
     return
Пример #2
0
    async def start(self, ctx: commands.Context):
        '''
        Begin the Secret Santa
        '''
        currAuthor = ctx.author
        if (currAuthor.top_role == ctx.guild.roles[-1]):
            # first ensure all users have all info submitted
            all_fields_complete = True
            for user in self.usr_list:
                if (user.wishlisturl_is_set() and user.pref_is_set()):
                    pass
                else:
                    all_fields_complete = False
                    try:
                        await currAuthor.send(
                            BOT_ERROR.HAS_NOT_SUBMITTED(user.name))
                        await ctx.send(
                            "`Partner assignment cancelled: participant info incomplete.`"
                        )
                    except Exception as e:
                        BOT_ERROR.output_exception(e, self.logger)
                        await ctx.send(currAuthor.mention +
                                       BOT_ERROR.DM_FAILED)
                        BOT_ERROR.output_error(
                            currAuthor.mention + BOT_ERROR.DM_FAILED,
                            self.logger)

            # select a random partner for each participant if all information is complete and there are enough people to do it
            if (all_fields_complete and (len(self.usr_list) > 1)):
                BOT_ERROR.output_info("Proposing a partner list", self.logger)
                potential_list = self.SecretSantaHelper.propose_partner_list(
                    self.usr_list)
                while (not self.SecretSantaHelper.partners_are_valid(
                        potential_list)):
                    BOT_ERROR.output_info("Proposing a partner list",
                                          self.logger)
                    potential_list = self.SecretSantaHelper.propose_partner_list(
                        self.usr_list)
                # save to config file
                BOT_ERROR.output_info("Partner assignment successful",
                                      self.logger)
                for user in potential_list:
                    (temp_index, temp_user
                     ) = self.SecretSantaHelper.get_participant_object(
                         int(user.idstr),
                         self.usr_list)  # get the user's object in usr_list
                    (index,
                     partner) = self.SecretSantaHelper.get_participant_object(
                         int(user.partnerid),
                         self.usr_list)  # get their partner
                    temp_user.partnerid = user.partnerid
                    self.config['members'][str(user.usrnum)][
                        SecretSantaConstants.PARTNERID] = user.partnerid
                    self.config.write()
                    # tell participants who their partner is
                    this_user = ctx.guild.get_member(int(user.idstr))
                    message_pt1 = f"{str(partner.name)}#{str(partner.discriminator)} is your Secret Santa partner! Mosey on over to their wishlist URL(s) and pick out a gift! Remember to keep it in the ${CONFIG.min_budget}-{CONFIG.max_budget} range.\n"
                    message_pt2 = f"Their wishlist(s) can be found here: {partner.wishlisturl}\n"
                    message_pt3 = f"And their gift preferences can be found here: {partner.preferences}\n"
                    message_pt4 = f"If you have trouble accessing your partner's wishlist, try `{CONFIG.prefix}dmpartner` or contact an admin to get in touch with them. This is a *secret* santa, after all!"
                    santa_message = message_pt1 + message_pt2 + message_pt3 + message_pt4
                    try:
                        await this_user.send(santa_message)
                    except Exception as e:
                        BOT_ERROR.output_exception(e, self.logger)
                        await currAuthor.send(
                            f"Failed to send message to {this_user.name}#{this_user.discriminator} about their partner. Ask them to turn on server DMs for Secret Santa stuff."
                        )

                # mark the exchange as in-progress
                self.exchange_started = True
                self.is_paused = False
                self.config['programData']['exchange_started'] = True
                self.config.write()
                usr_list = copy.deepcopy(potential_list)
                await ctx.send(
                    "Secret Santa pairs have been picked! Check your PMs and remember not to let your partner know. Have fun!"
                )
            elif not all_fields_complete:
                await ctx.send(currAuthor.mention +
                               BOT_ERROR.SIGNUPS_INCOMPLETE)
            elif not (len(self.usr_list) > 1):
                await ctx.send(BOT_ERROR.NOT_ENOUGH_SIGNUPS)
            else:
                await ctx.send(BOT_ERROR.UNREACHABLE)
        else:
            await ctx.send(BOT_ERROR.NO_PERMISSION(ctx.guild.roles[-1]))
        return