Exemplo n.º 1
0
async def admin_moderate(query: types.CallbackQuery, ether: Ether, status: kb.STATUS):
    user = utils.get_user_from_entity(query.message)
    moder = query.from_user
    admin_text = await _gen_order_caption(ether, user, status=status, moder=moder)
    track = PlaylistItem.from_tg(query.message.audio).add_track_info(user.id, user.first_name, query.message.message_id)

    try:
        await query.message.edit_caption(admin_text, reply_markup=kb.admin_unmoderate(ether, status))
    except exceptions.MessageNotModified:
        return  # если не отредачилось значит кнопка уже отработалась

    stats.add(query.message.message_id, moder.id, user.id, str(track), status, DateTime.now())

    if status == kb.STATUS.REJECT:  # кнопка отмена
        return communication.cache_add(
            await BOT.send_message(user.id, texts.ORDER_DENIED.format(track, ether.name)), query.message)

    await query.message.chat.do('record_audio')
    msg_to_user: Optional[str]
    try:
        if status != kb.STATUS.NOW:
            await _can_approve_order(ether, query.message.audio)
        ether_ = None if status == kb.STATUS.NOW else ether
        new_track = await Broadcast(ether_).add_track(track, audio=query.message.audio)

    except DuplicateException:
        when_playing = 'Такой же трек уже принят на этот эфир'
        msg_to_user = texts.ORDER_ACCEPTED.format(track, ether.name)
    except NotEnoughSpaceException:
        when_playing = 'не успел :('
        msg_to_user = None
        communication.cache_add(await BOT.send_audio(
            user.id, query.message.audio.file_id, reply_markup=await kb.order_choose_day(),
            caption=texts.ORDER_ACCEPTED_TOOLATE.format(track, ether.name)), query.message
        )
    else:
        if status == kb.STATUS.NOW:
            when_playing = 'прямо сейчас!'
            msg_to_user = texts.ORDER_ACCEPTED_UPNEXT.format(track, when_playing)
        elif ether.is_now():
            minutes_left = round((new_track.start_time - DateTime.now()).seconds / 60)
            when_playing = f'через {minutes_left} ' + utils.case_by_num(minutes_left, 'минуту', 'минуты', 'минут')
            msg_to_user = texts.ORDER_ACCEPTED_UPNEXT.format(track, when_playing)
        else:
            when_playing = 'Заиграет когда надо'
            msg_to_user = texts.ORDER_ACCEPTED.format(track, ether.name)

    if msg_to_user:
        communication.cache_add(await BOT.send_message(user.id, msg_to_user), query.message)
    with suppress(exceptions.MessageNotModified):
        await query.message.edit_caption(admin_text + '\n🕑 ' + when_playing, reply_markup=kb.admin_unmoderate(ether, status))
Exemplo n.º 2
0
    async def watch(self):
        now = DateTime.now().strftime('%H:%M')

        if (now != self.__class__.beginTime):
            return

        self.logger.info('started notify at %s.' % (now))

        for guild in self.guilds:
            self.logger.debug('guild: %s.' % (guild.name))

            channel_name = self.__class__.channel_name
            channel = self.find_channel(guild, channel_name)

            if (channel is None):
                self.logger.error('channel not found by name (%s)' %
                                  (channel_name))
                break

            role_name = self.__class__.role_name
            role = self.find_role(guild, role_name)

            if (role is None):
                self.logger.error('role not found by name (%s)' % (role_name))
                break

            await self.notify(channel, 'ワイが神絵師や!', role)

        self.logger.info('finished notify at %s.' % (now))
Exemplo n.º 3
0
    async def _get_start_time(self):
        if not self.ether:
            return DateTime.now()

        if self.ether.is_now():
            from player import Broadcast
            return await Broadcast.player.current_track_stop_time()
        return self.ether.start_time
Exemplo n.º 4
0
    async def watch(self):
        now = DateTime.now()
        self.logger.debug('started execution disconnect at %s.' % (now))

        await self.check_awake(self.guilds, now)

        for guild in self.guilds:
            self.logger.debug('guild: %s.' % (guild.name))

            if (not await self.is_executable(guild, now)):
                continue

            for voice_channel in guild.voice_channels:
                self.logger.debug('voice_channel: %s.' % (voice_channel.name))
                await self.disconnect(guild, voice_channel, now)

        self.logger.debug('finished execution disconnect at %s.' % (now))
Exemplo n.º 5
0
    async def do_sleep(self, minutes, guild, channel):
        if (minutes < 1):
            await channel.send('minutes must be greater than or equal 1.')
            return

        if (self.sleeping_list_per_guild.get(guild.id) is not None):
            del self.sleeping_list_per_guild[guild.id]

        if (minutes > 120):
            await channel.send('minutes must be less than 120.')
            return

        awake_time = DateTime.now().replace(microsecond=0) + timedelta(
            minutes=minutes)
        text = 'start sleeping %s minutes. until %s.' % (
            minutes, awake_time.isoformat())
        await channel.send(text)
        await self.change_presence(status=Status.idle)  # fix me.
        self.sleeping_list_per_guild[guild.id] = awake_time
Exemplo n.º 6
0
 def duration(self, from_now: bool = False):
     s = DateTime.now() if from_now and self.is_now() else self.start_time
     return int((self.stop_time - s).total_seconds())
Exemplo n.º 7
0
 def is_already_play_today(self) -> bool:
     return self.is_today() and self.stop_time < DateTime.now()
Exemplo n.º 8
0
 def is_will_be_play_today(self) -> bool:
     return self.is_today() and self.start_time > DateTime.now()
Exemplo n.º 9
0
 def is_now(self) -> bool:
     return self.is_today(
     ) and self.start_time < DateTime.now() < self.stop_time
Exemplo n.º 10
0
    async def command(self, message):
        now = DateTime.now()
        commands = message.content.split(' ')
        guild = message.guild
        channel = message.channel

        if (commands is None or len(commands) < 2):
            return

        if (commands[1] == 'run'):
            for voice_channel in guild.voice_channels:
                await self.disconnect(guild, voice_channel, now)
            return

        if (commands[1] == 'add'):
            if (len(commands) < 3):
                await channel.send('time is required.')
                return

            await self.do_add(commands[2], guild, channel)
            return

        if (commands[1] == 'remove'):
            if (len(commands) < 3):
                await channel.send('time is required.')
                return

            await self.do_remove(commands[2], guild, channel)
            return

        if (commands[1] == 'exclude'):
            if (len(commands) < 3):
                await channel.send('weekday is required.')
                return

            if (len(commands) < 4):
                await channel.send('time is required.')
                return

            await self.do_exclude(commands[2], commands[3], guild, channel)
            return

        if (commands[1] == 'include'):
            if (len(commands) < 3):
                await channel.send('weekday is required.')
                return

            if (len(commands) < 4):
                await channel.send('time is required.')
                return

            await self.do_include(commands[2], commands[3], guild, channel)
            return

        if (commands[1] == 'list'):
            await self.do_list(guild, channel)
            return

        if (commands[1] == 'sleep'):
            if (len(commands) < 3):
                await channel.send('minutes is required.')
                return

            await self.do_sleep(int(commands[2]), guild, channel)
            return

        if (commands[1] == 'awake'):
            await self.do_awake(guild, channel)
            return

        if (commands[1] == 'status'):
            await self.do_status(guild, channel)
            return

        await self.do_help(channel)