async def set_greeting_text(self, ctx, args):
        title = ""
        description = ""
        is_title = True

        for i in args:
            if i.startswith("-") and i.endswith("-") and is_title:
                title += i[1:-1]
                is_title = False

            elif i.startswith('-') and title == "":
                title += i[1:] + " "

            elif i.endswith('-') and description == "":
                title += i[:-1]
                is_title = False

            elif is_title:
                title += i + " "

            elif not is_title:
                description += i + " "

            description = description[:-1]

            self.db_proc().set_greeting(ctx.guild.id, title + "; " + description)

            await ctx.message.delete(delay=3)

            emb = BASIC_EMB.copy()
            emb.title = "Done"
            await ctx.send(embed=emb, delete_after=5)
    async def send_invite(self, ctx):
        emb = BASIC_EMB.copy()
        emb.title = "Welcome, {}!".format(ctx.author.display_name)
        emb.url = PUB_LINK

        await ctx.message.delete(delay=2)

        await ctx.send(embed=emb)
    async def send_avatar(self, ctx):
        user = ctx.message.mentions[0] if ctx.message.mentions else None
        emb = BASIC_EMB.copy()

        if user is None:
            raise NoUserSpec()

        emb.title = "Avatar of {0}".format(user.display_name)
        emb.set_image(url=user.avatar_url)
        await ctx.send(embed=emb)
    async def pause_resume(self, ctx):
        player = self.bot.wavelink.get_player(guild_id=ctx.guild.id,
                                              cls=CustomPlayer)

        if not player.is_connected:
            return

        await ctx.message.delete(delay=2)

        if not player.is_paused:
            emb = BASIC_EMB.copy()
            emb.title = "Pausing..."
            await ctx.send(embed=emb, delete_after=2)
            await player.set_pause(True)

        else:
            emb = BASIC_EMB.copy()
            emb.title = "Starting..."
            await ctx.send(embed=emb, delete_after=2)
            await player.set_pause(False)
    async def skip(self, ctx):
        player = self.bot.wavelink.get_player(guild_id=ctx.guild.id,
                                              cls=CustomPlayer)

        if not player.is_connected:
            return

        await ctx.message.delete(delay=2)

        emb = BASIC_EMB.copy()
        emb.title = "Skipping..."
        await ctx.send(embed=emb, delete_after=2)
        await player.stop()
    async def send_random_cat(self, ctx):
        async with aiohttp.ClientSession() as session:
            async with session.get("http://aws.random.cat//meow") as resp:
                json_resp = await resp.json()
                cat_file_url = json_resp['file']

                del json_resp

        emb = BASIC_EMB.copy()
        emb.title = ":smiley_cat: Here's your cat :smiley_cat:"
        emb.set_image(url=cat_file_url)

        await ctx.send(embed=emb)
Beispiel #7
0
    async def send_donate_link(self, ctx):
        emb = BASIC_EMB.copy()

        emb.title = "Your links"
        emb.description = "[Boosty]({}) or [Patreon]({})\n" \
                          "Donate features while available **only** on Boosty! " \
                          "In other case go to pub and ask there the administrator".format(*DONATE_LINKS)

        try:
            await ctx.send(embed=emb)

        except Forbidden:
            await ctx.author.send("I couldn't send the mesaage to channel",
                                  embed=emb)
    async def set_volume(self, ctx, value):
        player = self.bot.wavelink.get_player(guild_id=ctx.guild.id,
                                              cls=CustomPlayer)

        value = int(value)

        await ctx.message.delete(delay=2)

        if not 0 < value < 101:
            raise IncorrectVolume()

        emb = BASIC_EMB.copy()
        emb.title = "Volume is {}".format(value)
        await ctx.send(embed=emb, delete_after=2)

        await player.set_volume(value)
    async def send_member_info(self, ctx):
        user = ctx.message.mentions[0] if ctx.message.mentions else None
        emb = BASIC_EMB.copy()

        if user is None:
            raise NoUserSpec()

        emb.title = "Info about {}".format(user.display_name)
        emb.add_field(name="Joined at", value=str(user.joined_at)[:10])
        emb.add_field(name="Status", value=user.status)
        emb.add_field(name="Roles", value=to_column_string(user.roles[::-1]))
        emb.add_field(name="Activity",
                      value=to_column_string(user.activities)
                      if user.activities else "User has no activity right now")

        await ctx.send(embed=emb)
Beispiel #10
0
    async def send_guild_info(self, ctx):
        guild = ctx.guild

        emb = BASIC_EMB.copy()

        emb.title = guild.name

        emb.add_field(name="Region", value=str(guild.region).title())
        emb.add_field(name="Members", value=guild.member_count)
        emb.add_field(name="Owner", value=guild.owner.display_name)
        emb.add_field(name="Roles", value=to_column_string(guild.roles))
        emb.add_field(name="Text channels",
                      value=to_column_string(guild.text_channels))
        emb.add_field(name="Voice channels",
                      value=to_column_string(guild.voice_channels))

        await ctx.message.delete(delay=2)

        await ctx.send(embed=emb)
Beispiel #11
0
    async def now_playing(self, ctx):
        player = self.bot.wavelink.get_player(guild_id=ctx.guild.id,
                                              cls=CustomPlayer)

        if not player.is_connected:
            return

        track = player.current

        emb = BASIC_EMB.copy()
        if track is not None:
            emb.title = ":musical_note: Now playing :musical_note:"
            to_end = self._get_humanize_time(track.length - player.position)
            emb.description = "[{}]({})\nTo end {}".format(
                track.title, track.uri, to_end)

        else:
            emb.title = "Nothing playing"

        await ctx.message.delete()
        await ctx.send(embed=emb, delete_after=5)
Beispiel #12
0
    async def on_member_join(self, member):
        guild = member.guild
        channel = guild.system_channel if guild.system_channel is not None else guild.text_channels[
            0]
        text = self.db_proc.get_greeting(guild.id).split("; ")

        emb = BASIC_EMB.copy()
        emb.title = text[0].format(user=member.display_name,
                                   server=guild.name,
                                   prefix=PREFIX)
        emb.description = text[1].format(user=member.mention,
                                         server=guild.name,
                                         prefix=PREFIX)

        if guild.id == PUB_ID:
            role = guild.get_role(DEFAULT_ROLE_ID)
            await member.add_roles(role)

        try:
            if self.db_proc.is_greeting_enabled(guild.id):
                await channel.send(embed=emb)
        except (Forbidden, ClientConnectionError):
            pass
Beispiel #13
0
    async def play(self, ctx, query):
        player = self.bot.wavelink.get_player(guild_id=ctx.guild.id,
                                              cls=CustomPlayer)

        if not player.is_connected:
            await self.connect(ctx)

        info_for_music[ctx.guild.id]["channel"] = ctx.channel.id

        estimated_time = self._get_humanize_time(
            info_for_music[ctx.guild.id]["time"] - player.position)
        estimated_time = estimated_time if estimated_time != "" else "00:00:00"

        pos_in_queue = player.queue.qsize(
        ) + 1  # TODO Make it more properly. When playing - 1, when no - 0

        await ctx.message.delete(delay=2)

        if not URL_TEMPL.match(query):
            if ctx.command.name == "soundcloud":
                query = f"scsearch:{query}"
                platform = "SoundCloud"

            else:
                query = f"ytsearch:{query}"
                platform = "YouTube"

        else:
            if YOUTUBE_URL.match(query):
                platform = "YouTube"

            elif SOUNDCLOUD_URL.match(query):
                platform = "SoundCloud"

            else:
                platform = "some platform"

        tracks = await self.bot.wavelink.get_tracks(f'{query}')

        if not tracks:
            raise NoneTracksFound()

        if isinstance(tracks, wavelink.TrackPlaylist):
            for track in tracks.tracks:
                await player.queue.put(track)
                info_for_music[ctx.guild.id]["time"] += track.duration

            emb = BASIC_EMB.copy()
            emb.title = ":notes: Playlist added :notes:"
            emb.description = "[{}]({})".format(
                tracks.data["playlistInfo"]["name"],
                query if URL_TEMPL.match(query) else None)

            emb.add_field(name="Songs", value=len(tracks.tracks))

        else:
            track = tracks[0]

            if not track.is_stream:
                info_for_music[ctx.guild.id]["time"] += track.duration

            else:
                raise StreamsNotPlayable()

            await player.queue.put(track)

            emb = BASIC_EMB.copy()
            emb.title = ":musical_note: Track added :musical_note:"
            emb.description = "[{}]({})".format(track.title, track.uri)

            emb.add_field(name="Duration",
                          value=self._get_humanize_time(int(track.duration)))

        emb.add_field(name="Position in queue", value=pos_in_queue)

        emb.add_field(name="Estimated time until start", value=estimated_time)

        emb.set_footer(text="Requested by {} from {}".format(
            ctx.author, platform),
                       icon_url=ctx.author.avatar_url)

        await ctx.send(embed=emb)

        if not player.is_playing:
            await player.do_next()