Advertisement
PikalaxALT

Untitled

Mar 22nd, 2016
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.77 KB | None | 0 0
  1. async def voice_cb(message):
  2.     global player, ytqueue
  3.     if ytqueue:
  4.         return
  5.     if player:
  6.         if player.is_playing():
  7.             return
  8.     to_say = codecs.encode(message.clean_content[len(prefix + "speak "):], 'ascii', 'replace')
  9.     # await client.send_message(message.channel, to_say)
  10.     if client.is_voice_connected():
  11.         # await client.send_message(message.channel, "Now saying: " + to_say)
  12.         cur_params = []
  13.         for k, v in tts_params.items():
  14.             cur_params += ["-" + k, v]
  15.         O = subprocess.run(['espeak', '-k', '20'] + cur_params + [to_say, '-w', 'temp.wav'])
  16.         player = VC.create_ffmpeg_player("temp.wav")
  17.         player.start()
  18.     else:
  19.         await client.send_message(message.channel, "Voice client is not connected.")
  20.  
  21. async def next_video_cb(message):
  22.     global ytqueue
  23.     if len(ytqueue) == 0:
  24.         await client.send_message(message.channel, "Nothing to skip.")
  25.         return
  26.     next_video()
  27.     if len(ytqueue) == 0:
  28.         await client.send_message(message.channel, "Skipped video. Reached end of queue")
  29.     else:
  30.         await client.send_message(message.channel, "Skipped video. Now playing: " + ytqueue[0].title)
  31.  
  32. def next_video():
  33.     global ytqueue
  34.     if len(ytqueue) > 0:
  35.         ytplayer = ytqueue.pop(0)
  36.         try_stop_player(ytplayer)
  37.         if len(ytqueue) > 0:
  38.             ytqueue[0].start()
  39.  
  40. async def youtube_cb(message):
  41.     global player, ytqueue
  42.     if player:
  43.         if player.is_playing():
  44.             return
  45.  
  46.     if client.is_voice_connected():
  47.         vidhash = message.content.split()[1]
  48.         url = "http://youtu.be/" + vidhash
  49.         for attempt in range(3):
  50.             try:
  51.                 ytplayer = await VC.create_ytdl_player(url, after = next_video)
  52.             except:
  53.                 pass
  54.             else:
  55.                 break
  56.         else:
  57.             await client.send_message(message.channel, "Whoops! I couldn't get that video for you.  Try another?")
  58.             return
  59.         if len(ytqueue) == 0:
  60.             await client.send_message(message.channel, "Now playing: " + ytplayer.title)
  61.             ytplayer.start()
  62.         else:
  63.             await client.send_message(message.channel, "Queued: " + ytplayer.title)
  64.         ytplayer.message = message
  65.         ytqueue.append(ytplayer)
  66.     else:
  67.         await client.send_message(message.channel, "Voice client is not connected.")
  68.  
  69. def try_stop_player(player_ob):
  70.     if not player_ob:
  71.         return
  72.     while player_ob.is_playing():
  73.         try:
  74.             player_ob.stop()
  75.         except:
  76.             pass
  77.  
  78. async def stop_player_cb(message):
  79.     global player, ytqueue
  80.     try_stop_player(player)
  81.     if len(ytqueue) > 0:
  82.         try_stop_player(ytqueue[0])
  83.         ytqueue = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement