Added now playing command for ToukuFM

dev
pocketjawa 2017-05-24 20:13:36 -04:00
parent 56fc002d07
commit 67a1b2cc0f
3 changed files with 45 additions and 2 deletions

View File

@ -15,4 +15,8 @@ owner_id:
#Reddit Stuff
reddit_client_id:
reddit_client_secret:
reddit_client_secret:
#Icecast Stuff
metadataurl:
iceurl:

View File

@ -18,4 +18,5 @@
**!joke**: Posts a random joke from /r/Jokes
**!8ball**: You ask a question, it answeres. Simple!
**!conch** or **!magicconch**: Same as the 8ball command but waaaaay cooler
**!giveaway prize**: Do a giveaway based on users reacting with the emoji you react with secretly. Use in private and replace prize with an actual prize!
**!giveaway prize**: Do a giveaway based on users reacting with the emoji you react with secretly. Use in private and replace prize with an actual prize!
**!np**: Posts currently playing info for ToukuFM

View File

@ -7,6 +7,8 @@ import random
import xkcd
import praw
import os
import requests
import json
#Get script location
cwd = os.path.dirname(os.path.realpath(__file__))
@ -26,6 +28,10 @@ reddit_client_secret = config.get("configuration", "reddit_client_secret")
reddit_user_agent = 'linux:com.pocketjawa.discord-pocketbot:v0.1 (by /u/pocketjava)'
reddit = praw.Reddit(client_id=reddit_client_id,client_secret=reddit_client_secret,user_agent=reddit_user_agent)
#Icecast stream info setup
metadataurl = config.get("configuration", "metadataurl")
iceurl = config.get("configuration", "iceurl")
client = discord.Client()
#Subroutine to get UPS Status
@ -207,6 +213,38 @@ def on_message(message):
#Congratulate and ,essage the winner
yield from client.send_message(public_channel_id, 'Congrats to {0.user}!'.format(res))
yield from client.send_message(res.user, args)
#Get currently playing stats from toukufm.com
elif message.content.lower().startswith('!np'):
#Load JSON from stream APIs
nprequest = requests.get(metadataurl)
npobject = json.loads(nprequest.text)
icerequest = requests.get(iceurl)
iceobject = json.loads(icerequest.text)
#Add up listeners
listenersum = int(0)
for stream in iceobject['icestats']['source']:
listenersum += stream["listeners"]
#Put together the message
output = ""
if 'comment' in npobject:
output += "[{}]".format(npobject['comment'])
if 'artist' in npobject:
output += "\n{} - ".format(npobject['artist'])
if 'title' in npobject:
if 'artist' in npobject:
output += "{} ".format(npobject['title'])
else:
output += "\n{} ".format(npobject['title'])
if 'WOAR' in npobject:
output += "\nDownload/Buy: {}".format(npobject['WOAR'])
output += "\nListeners: {} ".format(listenersum)
#Set embed and send the message
npem = discord.Embed(title="Now Playing on ToukuFM", description=output, url="https://toukufm.com/")
yield from client.send_message(message.channel, embed=npem)
client.loop.create_task(ups_check())