Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set bot to announce "Now playing:" when in auto playlist. #1248

Closed
Herobrice opened this issue Jul 13, 2017 · 47 comments
Closed

How to set bot to announce "Now playing:" when in auto playlist. #1248

Herobrice opened this issue Jul 13, 2017 · 47 comments

Comments

@Herobrice
Copy link

I am using the bot to play an auto playlist of NCS music as I am helping a streamer and every now and them someone asks what was queued and i would have to /queue to show them, I was wondering if there was a way to announce what is being played currently and delete that message when the next song is queued just like as if you queued the music yourself. The only difference is that the bot is on an auto playlist.

@MeepCastana
Copy link

async def cmd_np(self, player, channel, server, message):
"""
Usage:
{command_prefix}np

Displays the current song in chat.
"""

if player.current_entry:
    if self.server_specific_data[server]['last_np_msg']:
        await self.safe_delete_message(self.server_specific_data[server]['last_np_msg'])
        self.server_specific_data[server]['last_np_msg'] = None

    # TODO: Fix timedelta garbage with util function
    song_progress = ftimedelta(timedelta(seconds=player.progress))
    song_total = ftimedelta(timedelta(seconds=player.current_entry.duration))

    streaming = isinstance(player.current_entry, StreamPlaylistEntry)
    prog_str = ('`[{progress}]`' if streaming else '`[{progress}/{total}]`').format(
        progress=song_progress, total=song_total
    )
    prog_bar_str = ''

    # percentage shows how much of the current song has already been played
    percentage = 0.0
    if player.current_entry.duration > 0:
        percentage = player.progress / player.current_entry.duration
    """
    This for loop adds  empty or full squares to prog_bar_str (it could look like
    [■■■■■■■■■■□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□]
    if for example the song has already played 25% of the songs duration
    """
    progress_bar_length = 37
    for i in range(progress_bar_length):
        if (percentage < 1 / progress_bar_length * i):
            prog_bar_str += '▁'
        else:
            prog_bar_str += '▂'

    action_text = 'Streaming' if streaming else 'Playing'

    if player.current_entry.meta.get('channel', False) and player.current_entry.meta.get('author', False):
        np_text = "**Song:** [ <{url}> ] queued by **{author}** \n```{progress} Song: {title}  \n {progress_bar}```".format(

            action=action_text,
            title=player.current_entry.title,
            author=player.current_entry.meta['author'].name,
            progress_bar=prog_bar_str,
            progress=prog_str,
            url=player.current_entry.url
        )
    else:
        np_text = "**Song:** [ <{url}> ] \n```{progress} Song: {title}  \n {progress_bar}```".format(
            action=action_text,
            title=player.current_entry.title,
            progress_bar=prog_bar_str,
            progress=prog_str,
            url=player.current_entry.url
        )

    self.server_specific_data[server]['last_np_msg'] = await self.safe_send_message(channel, np_text)
    await self._manual_delete_check(message)
else:
    return Response(
        'There are no songs queued! Queue something with {}play.'.format(self.config.command_prefix),
        delete_after=30
    )

@MeepCastana
Copy link

from #674.

@Herobrice
Copy link
Author

Where do i put this?

@MeepCastana
Copy link

in bot.py

@Herobrice
Copy link
Author

ik but anywhere in there particular

@Herobrice
Copy link
Author

ive attempted this multiple times and it doesn't change the bot in anyway, and there seems to be a lot of extra files missing, do i need to download something extra for this to work?

@MeepCastana
Copy link

in bot.py put it between commands

@MeepCastana
Copy link

you don't need to download anything/add anything other than the code i sent you

@MeepCastana
Copy link

also im using Review branch

@Herobrice
Copy link
Author

ya i did put it in between commands but when i run it, it keeps saying there are multiple errors in the coding, i keep trying to fix it but once i fix one issue anotherone comes up :/

@MeepCastana
Copy link

Send me the errors

@Herobrice
Copy link
Author

actually is there a way u can just send me a completed file, i didnt personalise it that much i can fix it myself after.

@MeepCastana
Copy link

Why don't you send me errors u get when u try to launch the bot? I edited my bot so many times i'll have to send you a zip folder. Make it simple.. send me errors u get and i will tell you what to fix.

@Herobrice
Copy link
Author

error 1
This is the first error that starts the chain when i try to fix it. I may have fixed it wrong. But i just reset it and freshly copied and pasted it so u can tell me :)

@MeepCastana
Copy link

you need to respect indentations

@MeepCastana
Copy link

MeepCastana commented Jul 17, 2017

send me ur bot.py file
and i will edit it for you...

@Herobrice
Copy link
Author

bot.zip
Here it is.

@Herobrice
Copy link
Author

i probs put the coding in the wrong place in the first place xD

@MeepCastana
Copy link

New WinRAR ZIP archive.zip
should work

@Kyrandix
Copy link

@TimmyTheRat i have the same problem too, could you pls tell me what should i add in my bot.py?

@MeepCastana
Copy link

async def cmd_np(self, player, channel, server, message):
"""
Usage:
{command_prefix}np

Displays the current song in chat.
"""

if player.current_entry:
if self.server_specific_data[server]['last_np_msg']:
await self.safe_delete_message(self.server_specific_data[server]['last_np_msg'])
self.server_specific_data[server]['last_np_msg'] = None

# TODO: Fix timedelta garbage with util function
song_progress = ftimedelta(timedelta(seconds=player.progress))
song_total = ftimedelta(timedelta(seconds=player.current_entry.duration))

streaming = isinstance(player.current_entry, StreamPlaylistEntry)
prog_str = ('`[{progress}]`' if streaming else '`[{progress}/{total}]`').format(
    progress=song_progress, total=song_total
)
prog_bar_str = ''

# percentage shows how much of the current song has already been played
percentage = 0.0
if player.current_entry.duration > 0:
    percentage = player.progress / player.current_entry.duration
"""
This for loop adds  empty or full squares to prog_bar_str (it could look like
[■■■■■■■■■■□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□]
if for example the song has already played 25% of the songs duration
"""
progress_bar_length = 37
for i in range(progress_bar_length):
    if (percentage < 1 / progress_bar_length * i):
        prog_bar_str += '▁'
    else:
        prog_bar_str += '▂'

action_text = 'Streaming' if streaming else 'Playing'

if player.current_entry.meta.get('channel', False) and player.current_entry.meta.get('author', False):
    np_text = "**Song:** [ <{url}> ] queued by **{author}** \n```{progress} Song: {title}  \n {progress_bar}```".format(

        action=action_text,
        title=player.current_entry.title,
        author=player.current_entry.meta['author'].name,
        progress_bar=prog_bar_str,
        progress=prog_str,
        url=player.current_entry.url
    )
else:
    np_text = "**Song:** [ <{url}> ] \n```{progress} Song: {title}  \n {progress_bar}```".format(
        action=action_text,
        title=player.current_entry.title,
        progress_bar=prog_bar_str,
        progress=prog_str,
        url=player.current_entry.url
    )

self.server_specific_data[server]['last_np_msg'] = await self.safe_send_message(channel, np_text)
await self._manual_delete_check(message)

else:
return Response(
'There are no songs queued! Queue something with {}play.'.format(self.config.command_prefix),
delete_after=30
)

@Kyrandix
Copy link

ok.. but i copied this before put it in my bot.py and i get that identation error

@MeepCastana
Copy link

download the zip file i sent and look how i made the np command. The spaces are VERY important

@Kyrandix
Copy link

still get the error, but i noticed in the file i downloaded ■■■■■■■■■■□□□□□□□□□□□□□□□□□□□□□□□□□□□□□□ these squares of the progress bar display. meanwhile in my bot.py these squares are all "???????????????????" idk if you understand what i said

@Kyrandix
Copy link

notepad _18-07-2017_00-17-33
i see this in the file i downloaded

@Kyrandix
Copy link

notepad _18-07-2017_00-17-49
this is what i see in my file

@MeepCastana
Copy link

send me ur bot.py file

@Kyrandix
Copy link

bot.zip

@MeepCastana
Copy link

does it work ?

@Kyrandix
Copy link

Kyrandix commented Jul 17, 2017

you are a faggot. really i had to say this after you banned me because i used 1 of your server emojis

@Herobrice
Copy link
Author

uh, whatever happened here.. ok then.. anywayy..... Timmy, the file u gave me it says IndentationError: unident does not match any outer indentation level

@MeepCastana
Copy link

send me the whole error

@Pesoen
Copy link

Pesoen commented Jul 21, 2017

just tried getting it to work, but i get this error now.
[Command] 167062581658255361/Pesoen (!!np) Traceback (most recent call last): File "E:\GIT\MusicBot\musicbot\bot.py", line 1968, in on_message response = await handler(**handler_kwargs) File "E:\GIT\MusicBot\musicbot\bot.py", line 1698, in cmd_np song_progress = ftimedelta(timedelta(seconds=player.progress)) NameError: name 'ftimedelta' is not defined

any ideas? want to get this function working as well :)

@Pesoen
Copy link

Pesoen commented Jul 21, 2017

also Herobrice. the line numer is very important, had the same error, took me two seconds after finding the line to fix it. here is my bot.py file, no errors, unless np is called.
https://www.dropbox.com/s/3ckje27270w7xzk/bot.zip?dl=0

if you want to fix it yourself, go to line 1684 and remove a single space. that will fix it :)

@MeepCastana
Copy link

It doesn't work because you're using the default branch. Switch to review if u want the command to work properly

@Pesoen
Copy link

Pesoen commented Jul 22, 2017

got the review version. still not showing now playing unless called. but hey no errors at least.

other than this one, after skip is used, but its at random, not always showing.
[ERROR:bot] Exception in on_message Traceback (most recent call last): File "V:\MusicBot\musicbot\bot.py", line 2464, in on_message response = await handler(**handler_kwargs) File "V:\MusicBot\musicbot\bot.py", line 1866, in cmd_skip or author == player.current_entry.meta.get('author', None): AttributeError: 'NoneType' object has no attribute 'meta'

@AMNYST
Copy link

AMNYST commented Aug 24, 2017

Hey , could you guys PLEASE , post a working one ?

This is what i'am having right now tried to paste it myself and tried the file giveen by @TimmyTheRat

Without sucess

http://i.imgur.com/ZzhXLQF.png

@MeepCastana
Copy link

MeepCastana commented Aug 25, 2017

Its working. You have spacing errors.
Since so many people have issues with indentation click here https://hastebin.com/pijetetuji.py

@AMNYST
Copy link

AMNYST commented Aug 25, 2017

Guess i should say thanks , buuuut no :>

http://i.imgur.com/kd8LUgT.png

@MeepCastana
Copy link

Because you don't have "Review" branch. The command will not work on the normal version

@AMNYST
Copy link

AMNYST commented Aug 25, 2017

Mh , i tried i swear.

File are identical and still

http://i.imgur.com/pilFgoe.png

@MeepCastana
Copy link

Send me a ss. I wanna see the start of the command

@AMNYST
Copy link

AMNYST commented Aug 25, 2017

Alright , well nevermind i got some progress.

http://i.imgur.com/Sv6oVLr.png

I can slove it alone , though when a new song start from the playlist the bot doesn't say anything :/

@MeepCastana
Copy link

Its a command. It doesn't show the message unless you call it

@MeepCastana
Copy link

If you are using notepad++ make sure this is enabled http://imgur.com/a/ViiIy

@AMNYST
Copy link

AMNYST commented Aug 25, 2017

That was it thank you!

http://i.imgur.com/uCuNePF.png

@LunaChann
Copy link

I dont understand a thing o-o

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants