コード例 #1
0
    async def retire_members(self):
        member_dto = MemberDto()
        inactive_members = member_dto.get_inactive_members()

        for member in inactive_members:
            guild_member = self.bot.guild.get_member(int(member.member_id))
            if guild_member is None or guild_member.bot:
                continue
            inactive_role = self.bot.guild.get_role(RETIRE_ROLE)
            await guild_member.add_roles(inactive_role)

        members = self.bot.guild.members
        for member in members:
            role_ids = []
            for role in member.roles:
                if role.id in ROLES:
                    role_ids.append(role.id)
            if len(role_ids) > 0 or member.bot:
                continue
            guild_member = self.bot.guild.get_member(int(member.id))
            if guild_member is None or guild_member.bot:
                continue
            inactive_role = self.bot.guild.get_role(RETIRE_ROLE)
            await guild_member.add_roles(inactive_role)
            return True
コード例 #2
0
    async def process_commands(self, message):
        ctx = await self.get_context(message, cls=Context)

        if ctx.command is not None and ctx.guild is not None:
            if int(message.channel.id) != int(self.channel):
                await message.channel.send(f'{message.author.mention}, I can only talk to you here: '
                                           f'{self.get_channel(int(self.channel)).mention}!')
                return

            if message.author.id in self.banlist:
                await ctx.send("You are banned from using commands.")

            elif not self.ready:
                await ctx.send("I'm not ready to receive commands. Please wait a few seconds.")

            else:
                await self.invoke(ctx)

        try:
            if ctx.guild is not None:
                content = message.content
                if len(content) > 1:
                    if content[0] != '!' or content[0] == content[1]:
                        member_dto = MemberDto()
                        member_dto.get_member(message.author.id)
                        member_dto.messages_xp += 1
                        member_dto.xp          += 1
                        await member_dto.save(self)
        except Exception as e:
            print(f'Timestamp: {datetime.now()}')
            print(f'Exception type: {type(e)}')
            print(f'Message: {message.content}')
            print(f'Exception: {e}\n')
コード例 #3
0
ファイル: events.py プロジェクト: OracleLOG/RoleManagerBot
    async def on_voice_state_update(self, member, before, after):
        if member.bot:
            return
        channel = self.bot.get_channel(int(self.bot.channel))
        member_dto = MemberDto()
        member_dto.get_member(member.id)
        config_dto = ConfigDto()
        config_dto.name = config_dto.first_to_connect
        config_dto.get_config(config_dto)
        try:
            if (before.channel is None or (before.channel is not None and before.channel.id in IGNORE_VOICE_CHANNELS)) \
                    and (after.channel is not None and after.channel.id not in IGNORE_VOICE_CHANNELS):
                member_dto.joined_voice = datetime.datetime.now()
                member_dto = await self.check_first_to_connect(
                    channel, config_dto, member, member_dto)
                await member_dto.save(self.bot)

            if (before.channel is not None and before.channel.id not in IGNORE_VOICE_CHANNELS) \
                    and (after.channel is None or after.channel.id in IGNORE_VOICE_CHANNELS):
                await self.calculate_voice_time(member_dto)
                hit_and_runner = await self.check_hit_and_runner(
                    member_dto.member_id)
                if hit_and_runner:
                    await channel.send(
                        f'{member.mention} tried to hit and run. Award is still available!'
                    )
        except Exception as e:
            print(f'Timestamp: {datetime.datetime.now()}')
            print(f'Exception type: {type(e)}')
            print(f'Arguments: {e.args}')
            print(f'Exception: {e}')
            print(f'Member id: {member.id}')
コード例 #4
0
ファイル: xp.py プロジェクト: OracleLOG/RoleManagerBot
    async def steal(self, ctx):
        member_dto = MemberDto()
        member_dto.get_member(ctx.author.id)

        if member_dto.steal_flag != 1:
            await ctx.send(
                f'{ctx.author.mention}, You were not prepared to steal any xp!'
            )
            return

        time = datetime.datetime.now() - member_dto.steal_time
        if time.seconds > 15:
            member_dto.steal_flag = 0
            await member_dto.save(self.bot)
            await ctx.send(
                f'{ctx.author.mention}, You were caught stealing xp and lost 2 xp!'
            )
            return

        xp_stolen = randrange(50)
        member_dto.steal_flag = 0
        await member_dto.save(self.bot)

        leader = MemberDto()
        leader.get_leader()
        await member_dto.save(self.bot)
        await ctx.send(
            f'{ctx.author.mention} stole {xp_stolen} xp from {self.bot.get_user(leader.member_id).mention}!'
        )
コード例 #5
0
ファイル: xp.py プロジェクト: OracleLOG/RoleManagerBot
 async def leaderboard(self, ctx):
     member_dto = MemberDto()
     results = member_dto.get_leaderboard()
     menu = MenuPages(source=HelpMenu(ctx, results),
                      clear_reactions_after=True,
                      timeout=60.0)
     await menu.start(ctx)
コード例 #6
0
ファイル: events.py プロジェクト: OracleLOG/RoleManagerBot
 async def on_raw_reaction_remove(self, payload):
     user = self.bot.get_user(payload.user_id)
     if not user.bot:
         member_dto = MemberDto()
         member_dto.get_member(payload.user_id)
         if member_dto.emojis_xp < 1:
             return
         member_dto.emojis_xp += -1
         await member_dto.save(self.bot)
コード例 #7
0
ファイル: events.py プロジェクト: OracleLOG/RoleManagerBot
 async def on_member_join(self, member):
     if not member.bot:
         member_dto = MemberDto()
         member_dto.member_id = member.id
         guild_member = self.bot.guild.get_member(int(member_dto.member_id))
         role_nomad = self.bot.guild.get_role(int(ROLE_NOMAD))
         channel = self.bot.get_channel(int(self.bot.channel))
         await channel.send(f'{guild_member.mention}, bun venit in Romania!'
                            )
         await guild_member.add_roles(role_nomad)
         await member_dto.save(self.bot)
コード例 #8
0
    async def exchange_xp(self, ctx, member: Optional[Member]):
        if ctx.author.id not in admins_ids:
            await ctx.send(f'Only designated admins can run this command')
            return

        member_dto = MemberDto()

        if member is not None:
            member_dto.get_member(int(member.id))
            member_dto.xp += member_dto.messages_xp
            await member_dto.save(self.bot)
            await ctx.send(
                f'{member.mention} message xp was converted into currency')
コード例 #9
0
 async def xp(self, ctx):
     member_dto = MemberDto()
     member_dto.set_member(ctx.author.id)
     member_level = member_dto.get_member_level()
     level_name = member_level.name
     next_level = LevelDto()
     next_level = next_level.get_next_level(member_dto.total_xp)
     xp_needed = int(next_level.xp_amount - member_dto.total_xp)
     embed = Embed(
         title=f'{ctx.message.author.display_name}',
         description=
         f'Your level is: {level_name} and you have {member_dto.total_xp} XP. \n'
         f' XP needed until next level: {xp_needed}')
     await ctx.send(embed=embed)
コード例 #10
0
async def execute_reset_day(bot: Bot):
    config_dto = ConfigDto()
    config_dto.name = config_dto.first_to_connect
    config_dto.get_config(config_dto)
    config_dto.value = 0
    config_dto.save()

    member_dto = MemberDto()
    filters = [('first_to_voice_channel', 1)]
    member_dto.get_member_by_filters(filters)
    member_dto.first_to_voice_channel = 0
    await member_dto.save(bot)
    member = bot.guild.get_member(member_dto.member_id)
    role = bot.guild.get_role(int(FIRST_TO_CONNECT_ROLE))
    await member.remove_roles(role)
コード例 #11
0
 async def check_web_status(self):
     voice_channels = self.bot.guild.voice_channels
     members = []
     for voice_channel in voice_channels:
         if len(voice_channel.members) < 2:
             return
         members_found = voice_channel.members
         for member_found in members_found:
             members.append(member_found)
     for member in members:
         if member.voice.self_video:
             member_dto = MemberDto()
             member_dto.get_member(member.id)
             member_dto.web_xp += 1
             await member_dto.save(self.bot)
コード例 #12
0
ファイル: events.py プロジェクト: OracleLOG/RoleManagerBot
    async def on_raw_reaction_add(self, payload):
        if not payload.member.bot:
            member_dto = MemberDto()
            member_dto.get_member(payload.member.id)
            member_extend_dto = member_dto.get_reaction_extend()

            if member_extend_dto.name is None:
                member_dto.emojis_xp += 1
                await member_dto.save(self.bot)

                member_dto.set_reaction_extend()

            if member_extend_dto.name is not None:
                time_elapsed = datetime.datetime.now(
                ) - member_extend_dto.modified
                if time_elapsed.seconds > REACTION_COOLDOWN:
                    member_dto.emojis_xp += 1
                    await member_dto.save(self.bot)
                    member_extend_dto.update_extend()

            channel = self.bot.guild.get_channel(payload.channel_id)
            message = await channel.fetch_message(payload.message_id)

            now = int((datetime.datetime.now()).strftime('%S'))
            message_send = int(message.created_at.strftime('%S'))

            if now - message_send > REACTION_COOLDOWN:
                await message.clear_reactions()
                return
コード例 #13
0
async def games_rewarding(bot: Bot, winner: int, loser: int, stake: int):
    member_winner = MemberDto()
    member_loser = MemberDto()

    member_winner.get_member(winner)
    member_winner.xp += stake
    await member_winner.save(bot)

    member_loser.get_member(loser)
    member_loser.xp += -stake
    await member_loser.save(bot)
    return
コード例 #14
0
    async def about(self, ctx, message: Optional[str] = None):
        about_dto = AboutDto()
        results = about_dto.get_abouts(message)

        if results is None or not results:
            await ctx.send(f"I know nothing about {message}")
            return
        member_dto = MemberDto()
        member_dto.get_member(ctx.author.id)
        about_dto = random.choice(results)

        embed = Embed(title=f'{about_dto.name}',
                      description=f"{about_dto.description}",
                      colour=ctx.author.color)
        embed.set_footer(
            text=
            f'Author - {self.bot.get_user(about_dto.member_id).display_name}',
            icon_url=self.bot.get_user(about_dto.member_id).avatar_url)
        await ctx.send(embed=embed)
コード例 #15
0
ファイル: events.py プロジェクト: OracleLOG/RoleManagerBot
    async def check_hit_and_runner(self, member_id: int):
        config_dto = ConfigDto()
        config_dto.name = config_dto.first_to_connect
        config_dto.get_config(config_dto)

        member_dto = MemberDto()
        member_dto.get_member(member_id)

        last_modified = datetime.datetime.timestamp(config_dto.modified)
        member_left = datetime.datetime.timestamp(member_dto.left_voice)

        if member_left - last_modified < TIME_TO_VALIDATE_FLAG:
            member_dto.first_to_voice_channel = 0
            member_dto.xp += -10
            config_dto.value = 0
            config_dto.save()
            role = self.bot.guild.get_role(int(FIRST_TO_CONNECT_ROLE))
            member = self.bot.guild.get_member(int(member_dto.member_id))
            await member.remove_roles(role)
            await member_dto.save(self.bot)
            return True
        return False
コード例 #16
0
ファイル: xp.py プロジェクト: OracleLOG/RoleManagerBot
    async def get_xp(self, ctx, member: Optional[Member] = None):
        member_dto = MemberDto()

        if member is None:
            member_dto.get_member(ctx.author.id)
            message = f'You have {member_dto.xp} amount of xp (currency) and a total of {member_dto.total_xp} xp'
        else:
            member_dto.get_member(member.id)
            message = f'{member.mention} has {member_dto.xp} amount of xp  (currency) ' \
                      f'and a total of {member_dto.total_xp} xp'
        await ctx.send(message)
コード例 #17
0
    async def steal_xp(self):
        member_dto = MemberDto()
        member_dto.reset_heist()
        leader_member_dto = member_dto.get_leader()
        thieves = member_dto.get_thieves(leader_member_dto)
        member_dto = random.choice(thieves)
        member_dto.steal_flag = 1
        await member_dto.save(self.bot)

        channel = self.bot.get_channel(int(self.bot.channel))
        await channel.send(
            f'{self.bot.get_user(member_dto.member_id).mention} '
            f'you have 15 seconds to steal from the leader! Use !steal')
        await channel.send(
            f'{self.bot.get_user(leader_member_dto.member_id).mention} '
            f'you have 10 seconds to defend your xp! Use !stop_the_heist')
コード例 #18
0
    async def xp_police(self, ctx, from_member: Member, to_member: Member,
                        amount: int):
        if ctx.author.id not in admins_ids:
            await ctx.send(f'Only designated admins can run this command')
            return

        from_member_dto = MemberDto()
        from_member_dto.get_member(int(from_member.id))
        to_member_dto = MemberDto()
        to_member_dto.get_member(int(to_member.id))

        if from_member_dto.xp < amount:
            ctx.send(
                f'There is a mistake. {from_member.mention} does not have {amount} amount of xp'
            )
            return

        await self.admin_service.transfer_xp(self.bot, from_member_dto,
                                             to_member_dto, amount)
        await ctx.send('Command executed')
コード例 #19
0
 async def add_all_members(self, ctx):
     roles = ctx.author.roles
     role_ids = []
     for role in roles:
         role_ids.append(role.id)
     if GODMODE_ROLE_ID not in role_ids:
         await ctx.send('You do not have permission to use this command')
         return
     members = ctx.guild.members
     count = 0
     for member in members:
         member_dto = MemberDto()
         check_if_exists = member_dto.get_member(member.id)
         if check_if_exists is None:
             member_dto = MemberDto()
             member_dto.save_member(member.id)
             count += 1
     await ctx.send(f'{count} members have been added to database')
コード例 #20
0
    async def slap(self,
                   ctx,
                   member: Member,
                   slab_counter: Optional[int] = 1,
                   *,
                   reason: Optional[str] = 'None'):
        await ctx.message.delete()

        member_slapped = MemberDto()
        db_member = member_slapped.get_member(member.id)
        if db_member is None:
            await ctx.send(f'Member {member.mention} not yet in bot database.')
            return

        slapping_member = MemberDto()
        slapping_member.get_member(ctx.author.id)

        await ctx.send(
            f'{ctx.author.display_name} slapped {member.mention} {slab_counter} times. Reason: {reason}'
        )
コード例 #21
0
    async def add_member(self, ctx, member: Member):
        roles = ctx.author.roles
        role_ids = []
        for role in roles:
            role_ids.append(role.id)
        if GODMODE_ROLE_ID not in role_ids:
            await ctx.send('You do not have permission to use this command')
            return
        member_dto = MemberDto()
        member_dto.save_member(member.id)
        member_dto = member_dto.get_member(member.id)
        embed = Embed(title='Member added!')
        fields = [(self.bot.get_user(member_dto.member_id), member_dto.xp,
                   member_dto.get_member_level().name, False)]

        for name, xp, level, inline in fields:
            embed.add_field(name=f'Name: {name}',
                            value=f'XP: {xp} - Level: {level}',
                            inline=inline)

        await ctx.send(embed=embed)
コード例 #22
0
ファイル: xp.py プロジェクト: OracleLOG/RoleManagerBot
    async def stop_the_heist(self, ctx):
        member_dto = MemberDto()
        member_dto.get_member(ctx.author.id)
        leader = MemberDto()
        leader.get_leader()
        thief = MemberDto()
        thief.get_thief()

        if member_dto.member_id != leader.member_id:
            await ctx.send(
                f'{ctx.author.mention}, Only the leader can defend the xp!')
            return

        time = datetime.datetime.now() - thief.steal_time
        if time.seconds > 10:
            await ctx.send(
                f'{ctx.author.mention}, You were too late to stop the thief!')
            return

        thief.steal_flag = 0
        await thief.save(self.bot)
        await ctx.send(
            f'{ctx.author.mention} got home in time to stop the heist! '
            f'{self.bot.get_user(thief.member_id).mention}, you can`t steal xp anymore!'
        )
コード例 #23
0
def check_minimum_xp(member_id: int, xp: int):
    member_dto = MemberDto()
    member_dto.get_member(member_id)
    if member_dto.xp < xp:
        return False
    return True