From 1af33fb13c2709ea59bcd20edac2c5a19d9c418d Mon Sep 17 00:00:00 2001 From: Zac Herd Date: Thu, 1 Dec 2016 23:31:18 +0000 Subject: [PATCH] v0.18.0 added reload feature for auto-updating --- bootstrap.sh | 32 ++++++++++++++++++++++++++++++++ bot.py | 7 ++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 bootstrap.sh diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..d203bbd --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# user to effectively run bot as (so we can safely run as root for pip) +puser="admin" + +while : +do + date + + echo Updating repository... + runuser -m $puser -c 'git pull' + + # if root we can update discord.py + if [ "$EUID" -eq 0 ] + then + echo Updating discord.py... + python3 -m pip install -U https://github.com/Rapptz/discord.py/archive/master.zip#egg=discord.py[voice] + fi + + echo Starting Maki... + runuser -m $puser -c 'rm -f ./reload' + runuser -m $puser -c 'python3 bot.py' + + # okay to quit if rval was not 0 + if [ ! -f ./reload ] + then + echo no reload file, stopping for realsies... + exit + fi +done + +exit diff --git a/bot.py b/bot.py index 4200b49..97dbdfd 100644 --- a/bot.py +++ b/bot.py @@ -31,7 +31,7 @@ from secret import token, lfmkey # CONFIGURATION # bot version -version = "v0.17.5" +version = "v0.18.0" # text shown by .help command helptext = """I am a Discord bot written in Python @@ -177,6 +177,11 @@ def on_message(message): run = False yield from client.send_message(message.channel, 'But will I dream? ;_;') yield from client.logout() + + if message.content[5:] == 'reload': + # touch a file called 'reload' which signals we should restart + with open('reload', 'a'): + os.utime('reload', None) else: # user not admin, refuse response = 'Don\'t be so rude! >:('