예제 #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}')
예제 #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)
예제 #3
0
    async def on_member_update(self, before, after):
        dota2 = ["dota 2"]
        bot_channel = self.bot.get_channel(int(self.bot.channel))
        gaming_1_channel = self.bot.get_channel(GAMING_1_VOICE_CHANNEL)
        is_move_dota_enable = ConfigDto()
        is_move_dota_enable.get_config_by_id(
            int(os.getenv('move_dota_enable_id')))

        if is_move_dota_enable.value is None or not is_move_dota_enable.value:
            return
        if before.activity == after.activity \
                or before.voice is None \
                or after.voice is None:
            return
        if before.voice.channel is gaming_1_channel:
            return
        if after.activity and after.activity.name.lower() in dota2:
            await bot_channel.send(
                f'{after.mention}, you are being move to {gaming_1_channel.mention}!'
            )
            await after.edit(voice_channel=gaming_1_channel)
예제 #4
0
    async def get_config(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
        config_dto = ConfigDto()
        configs = config_dto.get_configs()
        fields = []

        table = ("\n".join(f"***{config.name}*** *(Value: {config.value})*"
                           for idx, config in enumerate(configs)))
        fields.append((":black_small_square:", table))

        embed = Embed(title="Configs", colour=ctx.author.colour)
        embed.set_thumbnail(url=self.bot.guild.me.avatar_url)
        for name, value in fields:
            embed.add_field(name=name, value=value, inline=False)

        await ctx.send(embed=embed)
예제 #5
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)
예제 #6
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')
예제 #7
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
예제 #8
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}'
        )