Made the script location agnostic

dev
pocketjawa 2017-03-20 19:01:04 -04:00
parent 189a091d67
commit 56fc002d07
1 changed files with 10 additions and 6 deletions

View File

@ -6,10 +6,14 @@ import datetime
import random import random
import xkcd import xkcd
import praw import praw
import os
#Get script location
cwd = os.path.dirname(os.path.realpath(__file__))
#Import config file #Import config file
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read("/srv/discord-pocketbot/config.cfg") config.read(cwd + "/config.cfg")
token = config.get("configuration", "token") token = config.get("configuration", "token")
bot_channel_id = discord.Object(id=config.get("configuration", "bot_channel_id")) bot_channel_id = discord.Object(id=config.get("configuration", "bot_channel_id"))
@ -28,7 +32,7 @@ client = discord.Client()
@asyncio.coroutine @asyncio.coroutine
def ups_check(): def ups_check():
while not client.is_closed: while not client.is_closed:
yield from asyncio.create_subprocess_exec("/bin/bash", "/srv/discord-pocketbot/ups_status.sh") yield from asyncio.create_subprocess_exec("/bin/bash", cwd + "/ups_status.sh")
yield from asyncio.sleep(60) yield from asyncio.sleep(60)
@ -56,7 +60,7 @@ def on_message(message):
#Posts help info #Posts help info
elif message.content.lower().startswith('!help'): elif message.content.lower().startswith('!help'):
helpfile = open("/srv/discord-pocketbot/helpcommand.txt","r") helpfile = open(cwd + "/helpcommand.txt","r")
yield from client.send_message(message.channel, helpfile.read()) yield from client.send_message(message.channel, helpfile.read())
#Sleeps for 5 seconds. Don't know why I still have this tbh #Sleeps for 5 seconds. Don't know why I still have this tbh
@ -96,7 +100,7 @@ def on_message(message):
#Posts random picture of Tohru #Posts random picture of Tohru
elif message.content.lower().startswith('!tohru'): elif message.content.lower().startswith('!tohru'):
tohru_list_file = open("/srv/discord-pocketbot/lists/tohru_images.txt", "r") tohru_list_file = open(cwd + "/lists/tohru_images.txt", "r")
tohru_pics = tohru_list_file.read().split() tohru_pics = tohru_list_file.read().split()
yield from client.send_message(message.channel, random.choice(tohru_pics)) yield from client.send_message(message.channel, random.choice(tohru_pics))
@ -163,7 +167,7 @@ def on_message(message):
#Magic 8-ball simulator 2017 #Magic 8-ball simulator 2017
elif message.content.lower().startswith('!8ball'): elif message.content.lower().startswith('!8ball'):
ball_response_file = open("/srv/discord-pocketbot/lists/8ball_responses.txt", "r") ball_response_file = open(cwd + "/lists/8ball_responses.txt", "r")
ball_responses = ball_response_file.read().split('\n') ball_responses = ball_response_file.read().split('\n')
args = message.content.partition(' ')[2] args = message.content.partition(' ')[2]
if (args is ''): if (args is ''):
@ -173,7 +177,7 @@ def on_message(message):
#Magic Conch Shell simulator 2002 (way cooler than that lame "Magic" 8-ball) #Magic Conch Shell simulator 2002 (way cooler than that lame "Magic" 8-ball)
elif message.content.lower().startswith('!conch') or message.content.lower().startswith('!magicconch'): elif message.content.lower().startswith('!conch') or message.content.lower().startswith('!magicconch'):
ball_response_file = open("/srv/discord-pocketbot/lists/8ball_responses.txt", "r") ball_response_file = open(cwd + "/lists/8ball_responses.txt", "r")
ball_responses = ball_response_file.read().split('\n') ball_responses = ball_response_file.read().split('\n')
args = message.content.partition(' ')[2] args = message.content.partition(' ')[2]
if (args is ''): if (args is ''):