Пример #1
0
    async def attendance_inner(self) -> List[str]:
        """Get the names of all people in the event voice channels,
        then send it to the Attendees table in 90 minutes,
        and return the attendees' names"""
        PERIOD = 5400 if not common.DEV_VERSION else 300  # the total period in seconds
        STEP = PERIOD // 4  # how long to wait per scan

        # get the event channels
        with open("./Text Files/channels.txt") as f:
            channel_ids = [int(line.strip("\n")) for line in f.readlines()]

        channels = [self.bot.get_channel(id) for id in channel_ids]

        # repeat every `STEP` minutes
        attendees = set()  # ensure no duplicates
        for i in range(4):
            # add each person in each event channel to attendees
            for channel in channels:
                for name in [person.display_name for person in channel.members]:
                    attendees.add(memtils.NameParser(name).parsed)

            # sleep for 30 minutes
            # but don't wait a fourth time
            print(f"({D.datetime.now()}): {attendees} at roll call {i}")
            if i == 3:
                break
            else:
                await async_sleep(STEP)

        # record the attendance
        print(f"Recording attendees: {attendees}")
        self.db.record_att(attendees)
        return attendees
Пример #2
0
 async def get_my_attendance(self, ctx):
     """Get your attendance %"""
     name = memtils.NameParser(ctx.author.display_name).parsed
     ratio = self.db.get_member_att(name)
     if ratio is None:
         await ctx.send("You haven't attended any events, brother. Please join our future wars!")
     else:
         await ctx.send(f"{memtils.get_title(ctx.author)}, your attendance ratio is: {ratio}")
Пример #3
0
 async def remove_away(self, ctx, name: str):
     """Remove a person's away status."""
     name = memtils.NameParser(name).parsed
     # validate the person
     if not await memtils.is_member(name, [r[1] for r in self.db.get_all_members()]):
         await ctx.send("That person is not in our chapter!")
     else:
         self.db.unmark_away(name)
         await ctx.send("An old face has returned :D")
Пример #4
0
 async def is_away(self, ctx, name: str):
     """Get whether the person is away."""
     # parse the name
     name = memtils.NameParser(name).parsed
     row = self.db.get_member_by_name(name)
     if row:
         await ctx.send(f'''{name} is marked as {"not" if not row[2] else ""} away in our archives, my lord.''')
     else:
         await ctx.send(f'''Our archives don't know of this "{name}", my lord.''')
Пример #5
0
 async def joined_at(self, ctx, name: str):
     """Get the join date of a member by their name."""
     # parse the name
     name = memtils.NameParser(name).parsed
     joined_at = self.db.get_join_date_by_name(name)
     # handle no member found
     if not joined_at:
         await ctx.send(f'Our archives do not know this "{name}"')
     else:
         await ctx.send(f"He joined our chapter on {joined_at.strftime('%d.%m')}")
Пример #6
0
    async def mark_as_away(self, ctx, name: str):
        """Mark the target as away in the database."""
        # parse the name
        name = memtils.NameParser(name).parsed
        member_found = self.db.mark_away(name)

        # report whether the query was successful
        if member_found:
            await ctx.send("May he return to action soon, my lord.")
        else:
            await ctx.send(f'''Our archives don't know of this "{name}", my lord.''')
Пример #7
0
    async def remove_member(self, ctx, name: str):
        """Unregister a member by their name."""
        # parse the name
        name = memtils.NameParser(name).parsed

        # validate the name
        if not await memtils.is_member(name, [r[1] for r in self.db.get_all_members()]):
            return await ctx.send("That person is not in our chapter!")

        self.db.delete_member(name)
        await ctx.send("Another brother lost to the warp...")
Пример #8
0
    async def on_member_update(self, before: Member, after: Member):
        """Add new scouts to the Members table automatically"""
        # get the roles that were added
        new_role_names = [
            role_.name for role_ in after.roles if role_ not in before.roles]
        if "Scout" in new_role_names:
            # get their name
            name = memtils.NameParser(after.display_name).parsed

            # only register them if they're not already registered
            if not await memtils.is_member(name,
                                           [r[1] for r in self.db.get_all_members()]):
                self.db.add_member(name)
                print(f"New member detected: {name}")
Пример #9
0
    async def kick_member(self, person: Member):
        """Remove the person from the outfit, move them to Guardsman,
           and DM them about it.

           This is its own method so that get_attendance can be
           extended to auto-kick people."""
        # remove them from the DB
        self.db.delete_member(memtils.NameParser(person.display_name).parsed)

        # get the member-only roles roles
        member_role_ids = [
            588061401617268746,  # Custodes
            564827583540363264,  # Ogryn
            729040717636304948,  # Null Maiden
            702914817157234708,  # Noise Marine
            564827583540363264,  # Remembrancer
            696160922439385091,  # Arbites
            696160804940152982,  # Chrono-gladiator
            545804189180231691,  # Keeper
            545807109774770187,  # Astartes
            545804149821014036,  # Scout
            545804220763340810,  # Champion,
            545819032868356395,  # Chaplain
        ]
        guild = person.guild
        member_roles = [guild.get_role(id) for id in member_role_ids]

        # move them to Guardsman
        await person.remove_roles(*member_roles, reason="Kicked from the outfit")
        await person.add_roles(guild.get_role(545803265741291521), reason="Kicked from the outfit")

        # DM them
        try:
            await person.send("You've been kicked from the chapter because you haven't" +
                              " attended enough events this month." +
                              " You can return in 2 weeks if you have more time :)")
        # ping them in the bot channel if they can't be DMed
        except Forbidden:
            await common.bot_channel.send(f"{person.mention} You've been kicked from the chapter " +
                                          "because you haven't attended enough events this month." +
                                          " You can return in 2 weeks if you have more time :)")