Exemplo n.º 1
0
    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}')
Exemplo n.º 2
0
    async def reset_day(self):
        config_dto = ConfigDto()
        config_dto.name = config_dto.daily_reset
        config_dto.get_config(config_dto)
        this_hour = datetime.datetime.now().hour
        if config_dto.value != this_hour:
            return

        await execute_reset_day(self.bot)
Exemplo n.º 3
0
    async def add_config(self, ctx, name, value):
        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
        config_dto = ConfigDto()
        config_dto.name = name
        config_dto.value = value
        config_dto.add_config()

        await ctx.send(f'{config_dto.name} config was added')
Exemplo n.º 4
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)
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    async def edit_config(self, ctx, name, value):
        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

        config_dto = ConfigDto()
        config_dto.name = name
        config_dto.get_config(config_dto)

        if config_dto.value is None:
            await ctx.send(f'No config found with name {name}')
            return

        config_dto.value = value
        config_dto.save()
        await ctx.send(
            f'{config_dto.name} config has been saved. New value {config_dto.value}'
        )