Beispiel #1
0
 async def on_ready(self):
     log('Вошёл под', self.user)
     self.vk_to_discord_channel = self.get_channel(
         config.vk_to_discord_channel_id)
     self.discord_to_discord_channel = self.get_channel(
         config.discord_to_discord_channel_id)
     await self.set_game()
Beispiel #2
0
 async def vk_task(self):
     await self.wait_until_ready()
     await asyncio.sleep(5)
     while not self.is_closed():
         try:
             await self.get_vk_data(self.send_embed_from_vk)
         except Exception as e:
             log(e)
         await asyncio.sleep(config.vk_to_discord_timeout)
Beispiel #3
0
    async def on_ready(self):
        log('Вошёл под', self.user)
        await self.set_game()
        await self.load_entities()
        await self.reload_color_roles()
        await self.prepare_messages()

        await self.referral_patrol.refresh(self.main_guild)
        log('Загрузка завершена!')
Beispiel #4
0
 async def get_vk_data(send_method):
     with Storage(config.vk_group_ids) as s:
         for _ in config.vk_group_ids:
             oldest_group, after = s.get_next()
             v_cli = VKClient(config.vk_access_token)
             post = v_cli.get_mostly_liked_post(oldest_group, after=after)
             if post:
                 group_profile = v_cli.get_group_profile(oldest_group)
                 await send_method(post, group_profile)
                 s.set_after(oldest_group, post['date'])
                 return
             else:
                 s.set_after(oldest_group,
                             datetime.datetime.now().timestamp())
                 log('Отсутствуют новые подходящие посты:', oldest_group)
Beispiel #5
0
    async def on_raw_reaction_add(self, payload):
        if self.user.id == payload.user_id:
            return

        if payload.message_id in self.command_messages:
            member = self.main_guild.get_member(payload.user_id)

            if payload.message_id == self.color_change_message.id:
                await self.swap_color_role(
                    member,
                    self.color_roles[self.fix_emoji(str(payload.emoji))])

            if payload.message_id == self.shuffle_roles_message.id and not self.sorter.busy:
                await self.shuffle_roles_message.clear_reactions()
                await self.shuffle_roles_message.add_reaction(config.wait_emoji
                                                              )
                if str(payload.emoji) == config.shuffle_emoji:
                    await self.sorter.sort(self, original=False)
                elif str(payload.emoji) == config.back_emoji:
                    await self.sorter.sort(self, original=True)
                await self.shuffle_roles_message.clear_reactions()
                await self.prepare_shuffle_roles_message()

            if payload.message_id == self.invite_create_message.id:
                invite_text = await self.inviter.generate_invite(
                    member, self.main_channel, self)
                if invite_text:
                    try:
                        await member.send(invite_text)
                    except Exception as e:
                        log(e)
                        invite_text = config.error_template.replace(
                            '<mention>', member.mention) + invite_text
                        try:
                            await self.main_channel.send(invite_text)
                        except Exception as e:
                            log(e)

            await self.command_messages[payload.message_id].remove_reaction(
                payload.emoji, member)
Beispiel #6
0
    async def handle(self, member, before, after, client):

        if after.channel == client.create_voice_channel:
            await client.create_voice_channel.set_permissions(member,
                                                              connect=False)
            new_channel = await client.main_guild.create_voice_channel(
                name=
                f'{self.fix_emoji(random.choice(list(client.color_roles.keys())))} {random.choice(config.lore_channel_names)}',
                position=self.get_max_position() if self.created_channels else
                client.create_voice_channel.position,
                category=client.create_voice_channel.category)
            self.created_channels.append(new_channel)
            await member.edit(voice_channel=new_channel)
            await asyncio.sleep(60)
            await client.create_voice_channel.set_permissions(member,
                                                              overwrite=None)

        for channel in list(self.created_channels):
            if len(channel.members) == 0:
                try:
                    await channel.delete()
                except Exception as e:
                    log(e)
                self.created_channels.remove(channel)