From 56fc002d07b8c4ad8dbf438181437d954547b55b Mon Sep 17 00:00:00 2001 From: pocketjawa Date: Mon, 20 Mar 2017 19:01:04 -0400 Subject: [PATCH] Made the script location agnostic --- pocketbot.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pocketbot.py b/pocketbot.py index 6313a14..a974ee3 100644 --- a/pocketbot.py +++ b/pocketbot.py @@ -6,10 +6,14 @@ import datetime import random import xkcd import praw +import os + +#Get script location +cwd = os.path.dirname(os.path.realpath(__file__)) #Import config file config = configparser.ConfigParser() -config.read("/srv/discord-pocketbot/config.cfg") +config.read(cwd + "/config.cfg") token = config.get("configuration", "token") bot_channel_id = discord.Object(id=config.get("configuration", "bot_channel_id")) @@ -28,7 +32,7 @@ client = discord.Client() @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.create_subprocess_exec("/bin/bash", cwd + "/ups_status.sh") yield from asyncio.sleep(60) @@ -56,7 +60,7 @@ def on_message(message): #Posts help info 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()) #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 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() yield from client.send_message(message.channel, random.choice(tohru_pics)) @@ -163,7 +167,7 @@ def on_message(message): #Magic 8-ball simulator 2017 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') args = message.content.partition(' ')[2] if (args is ''): @@ -173,7 +177,7 @@ def on_message(message): #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'): - 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') args = message.content.partition(' ')[2] if (args is ''):