discord-pocketbot/pocketbot.py

154 lines
8.6 KiB
Python
Raw Normal View History

2017-02-21 04:27:12 +00:00
#!/usr/bin/env python3.4
import discord
import asyncio
import configparser
2017-02-22 02:47:03 +00:00
import datetime
import random
2017-02-27 02:00:09 +00:00
import xkcd
2017-03-01 04:08:35 +00:00
import praw
2017-02-21 04:27:12 +00:00
#Import config file
config = configparser.ConfigParser()
config.read("/srv/discord-pocketbot/config.cfg")
token = config.get("configuration", "token")
2017-02-21 05:21:00 +00:00
bot_channel_id = discord.Object(id=config.get("configuration", "bot_channel_id"))
2017-03-02 00:18:02 +00:00
owner_id = discord.User(id=config.get("configuration", "owner_id"))
2017-02-21 04:27:12 +00:00
2017-03-01 04:08:35 +00:00
#Reddit Setup
reddit_client_id = config.get("configuration", "reddit_client_id")
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)
2017-02-21 04:27:12 +00:00
client = discord.Client()
2017-02-25 01:22:55 +00:00
#Subroutine to get UPS Status
@asyncio.coroutine
def ups_check():
while not client.is_closed:
yield from asyncio.create_subprocess_exec("/bin/bash", "/srv/discord-pocketbot/ups_status.sh")
yield from asyncio.sleep(60)
2017-02-21 04:27:12 +00:00
@client.event
@asyncio.coroutine
def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
2017-02-21 05:21:00 +00:00
yield from client.send_message(bot_channel_id, "This isn't Tatooine...")
2017-02-22 04:23:25 +00:00
yield from client.change_presence(game=discord.Game(name='with some droids'))
2017-02-21 04:27:12 +00:00
@client.event
@asyncio.coroutine
def on_message(message):
2017-02-27 02:31:15 +00:00
#Maki Monday praise command
2017-02-27 02:24:40 +00:00
if (message.content.lower().startswith('!maki')) or (message.content.lower().startswith('!monday')):
2017-02-21 04:27:12 +00:00
yield from client.send_message(message.channel, 'http://maki.pocketjawa.com/monday.png')
2017-02-27 02:31:15 +00:00
#Posts help info
2017-02-22 04:15:15 +00:00
elif message.content.lower().startswith('!help'):
helpfile = open("/srv/discord-pocketbot/helpcommand.txt","r")
yield from client.send_message(message.channel, helpfile.read())
2017-02-27 02:31:15 +00:00
#Sleeps for 5 seconds. Don't know why I still have this tbh
elif message.content.lower().startswith('!sleep'):
2017-02-21 04:27:12 +00:00
yield from asyncio.sleep(5)
yield from client.send_message(message.channel, 'Done sleeping')
2017-02-27 02:31:15 +00:00
#Posts link to my mix archive
elif message.content.lower().startswith('!mixes'):
2017-02-21 05:31:02 +00:00
yield from client.send_message(message.channel, 'You can download mp3s of any of my mixes at http://maki.pocketjawa.com/mixes/')
2017-02-27 02:31:15 +00:00
#Pokes the person who said the command
elif message.content.lower().startswith('!pokeme'):
yield from client.send_message(message.channel, "_pokes <@"+message.author.id+">_")
2017-02-27 02:31:15 +00:00
#Dump the navy seal copypasta
elif message.content.lower().startswith('!wtf'):
yield from client.send_typing(message.channel)
yield from asyncio.sleep(3)
yield from client.send_message(message.channel, 'What the fuck did you just fucking say about me, you little bitch? Ill have you know I graduated top of my class in the Navy Seals, and Ive been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and Im the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. Youre fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and thats just with my bare hands. Not only am I extensively trained in unarmed combat, but I have access to the entire arsenal of the United States Marine Corps and I will use it to its full extent to wipe your miserable ass off the face of the continent, you little shit. If only you could have known what unholy retribution your little “clever” comment was about to bring down upon you, maybe you would have held your fucking tongue. But you couldnt, you didnt, and now youre paying the price, you goddamn idiot. I will shit fury all over you and you will drown in it. Youre fucking dead, kiddo.')
2017-02-27 02:31:15 +00:00
#Countdown until the Switch comes out!
2017-02-22 02:47:03 +00:00
elif message.content.lower().startswith('!switch'):
now = datetime.datetime.now()
switchdate = datetime.datetime(2017, 3, 3)
switchdelta = switchdate - now
if (switchdelta.total_seconds() > 0):
switchmsg = "<:switchl:283809380137435139>Only **%s** until the Switch comes out!<:switchr:283809391835349004>" % (switchdelta)
else:
switchmsg = "The <:switchl:283809380137435139>Switch<:switchr:283809391835349004> is already out!!! <:pjchamp:231619017599746048>"
2017-02-22 02:47:03 +00:00
yield from client.send_message(message.channel, switchmsg)
2017-02-27 02:31:15 +00:00
#Posts status of the UPS
2017-02-25 01:22:55 +00:00
elif message.content.lower().startswith('!ups'):
ups_status = open("/tmp/ups_status.txt","r")
yield from client.send_message(message.channel, ups_status.read())
2017-02-27 02:31:15 +00:00
#Posts random picture of Tohru
elif message.content.lower().startswith('!tohru'):
tohru_list_file = open("/srv/discord-pocketbot/lists/tohru_images.txt", "r")
tohru_pics = tohru_list_file.read().split()
yield from client.send_message(message.channel, random.choice(tohru_pics))
2017-02-27 02:31:15 +00:00
#Sets the bot's Now Playing status
elif message.content.lower().startswith('!setplaying'):
yield from client.change_presence(game=discord.Game(name=message.content.partition(' ')[2]))
2017-02-27 02:00:09 +00:00
#xkcd comic fetcher
elif message.content.lower().startswith('!xkcd'):
args = message.content.partition(' ')[2]
if (args is ''):
comic = xkcd.getRandomComic()
comicnum = str (comic.number)
xkmessage = 'xkcd #' + comicnum + ': ' + comic.getTitle() + '\n' + comic.getImageLink() + '\n' + 'Alt Text: '+comic.getAltText()
yield from client.send_message(message.channel, xkmessage)
else:
if ('latest' in args):
comic = xkcd.getLatestComic()
comicnum = str (comic.number)
xkmessage = 'The most recent xkcd is #' + comicnum + ': ' + comic.getTitle() + '\n' + comic.getImageLink() + '\n' + 'Alt Text: '+comic.getAltText()
yield from client.send_message(message.channel, xkmessage)
elif (args.isdigit()):
comic = xkcd.getComic(args)
if (comic.number == -1):
yield from client.send_message(message.channel, 'There is no xkcd comic #' + args + '. Please try again.')
else:
comicnum = str (comic.number)
xkmessage = 'xkcd is #' + comicnum + ': ' + comic.getTitle() + '\n' + comic.getImageLink() + '\n' + 'Alt Text: '+comic.getAltText()
yield from client.send_message(message.channel, xkmessage)
else:
yield from client.send_message(message.channel, '`'+args+'`' + 'is not a valid option. Please leave blank for a random comic, say "latest" for the latest comic or put the number of the comic you want.' )
#Post random submisison from /r/EarthPorn's top this week
elif (message.content.lower().startswith('!earth')) or (message.content.lower().startswith('!earthporn')):
earthporn = reddit.subreddit('earthporn').top('week')
earthpornr = list(earthporn)
yield from client.send_message(message.channel, random.choice(earthpornr).url)
2017-03-01 05:01:46 +00:00
#Link some porn! (actually SFW)
elif message.content.lower().startswith('!porn'):
earthporn = reddit.subreddit('earthporn').hot(limit=5)
serverporn = reddit.subreddit('ServerPorn').hot(limit=5)
cableporn = reddit.subreddit('cableporn').hot(limit=5)
foodporn = reddit.subreddit('FoodPorn').hot(limit=5)
shittyfoodporn = reddit.subreddit('shittyfoodporn').hot(limit=5)
porn_multi_r = list(earthporn) + list(serverporn) + list(cableporn) + list(foodporn) + list(shittyfoodporn)
yield from client.send_message(message.channel, random.choice(porn_multi_r).url)
2017-03-02 00:26:29 +00:00
#Kill the bot so it can be reloaded
elif (message.content.lower().startswith('!kill')) or (message.content.lower().startswith('!restart')):
author_id = message.author
if author_id == owner_id:
yield from client.send_message(message.channel, 'Goodbye Onii-chan!!!')
yield from client.close()
else:
yield from client.send_message(message.channel, 'Booooo you\'re not Onii-chan. You\'re not allowed to use this command!')
2017-02-21 04:27:12 +00:00
2017-02-25 01:22:55 +00:00
client.loop.create_task(ups_check())
2017-02-21 04:27:12 +00:00
client.run(token)