Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async def voice_cb(message):
- global player, ytqueue
- if ytqueue:
- return
- if player:
- if player.is_playing():
- return
- to_say = codecs.encode(message.clean_content[len(prefix + "speak "):], 'ascii', 'replace')
- # await client.send_message(message.channel, to_say)
- if client.is_voice_connected():
- # await client.send_message(message.channel, "Now saying: " + to_say)
- cur_params = []
- for k, v in tts_params.items():
- cur_params += ["-" + k, v]
- O = subprocess.run(['espeak', '-k', '20'] + cur_params + [to_say, '-w', 'temp.wav'])
- player = VC.create_ffmpeg_player("temp.wav")
- player.start()
- else:
- await client.send_message(message.channel, "Voice client is not connected.")
- async def next_video_cb(message):
- global ytqueue
- if len(ytqueue) == 0:
- await client.send_message(message.channel, "Nothing to skip.")
- return
- next_video()
- if len(ytqueue) == 0:
- await client.send_message(message.channel, "Skipped video. Reached end of queue")
- else:
- await client.send_message(message.channel, "Skipped video. Now playing: " + ytqueue[0].title)
- def next_video():
- global ytqueue
- if len(ytqueue) > 0:
- ytplayer = ytqueue.pop(0)
- try_stop_player(ytplayer)
- if len(ytqueue) > 0:
- ytqueue[0].start()
- async def youtube_cb(message):
- global player, ytqueue
- if player:
- if player.is_playing():
- return
- if client.is_voice_connected():
- vidhash = message.content.split()[1]
- url = "http://youtu.be/" + vidhash
- for attempt in range(3):
- try:
- ytplayer = await VC.create_ytdl_player(url, after = next_video)
- except:
- pass
- else:
- break
- else:
- await client.send_message(message.channel, "Whoops! I couldn't get that video for you. Try another?")
- return
- if len(ytqueue) == 0:
- await client.send_message(message.channel, "Now playing: " + ytplayer.title)
- ytplayer.start()
- else:
- await client.send_message(message.channel, "Queued: " + ytplayer.title)
- ytplayer.message = message
- ytqueue.append(ytplayer)
- else:
- await client.send_message(message.channel, "Voice client is not connected.")
- def try_stop_player(player_ob):
- if not player_ob:
- return
- while player_ob.is_playing():
- try:
- player_ob.stop()
- except:
- pass
- async def stop_player_cb(message):
- global player, ytqueue
- try_stop_player(player)
- if len(ytqueue) > 0:
- try_stop_player(ytqueue[0])
- ytqueue = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement