diff --git a/bottools/methods.py b/bottools/methods.py index b6c2fec..e7284b9 100644 --- a/bottools/methods.py +++ b/bottools/methods.py @@ -1,4 +1,4 @@ -import ast, dbtools, html, io, logging, moviepy.editor, PIL.Image, random, setuptools, string, bottools.strings, telegram.ext, twitools, urllib.request, tweepy +import ast, dbtools, html, io, logging, moviepy.editor, os, PIL.Image, random, setuptools, string, bottools.strings, sys, telegram.ext, telegram, time, twitools, urllib.request, tweepy def getTwo(message): try: @@ -218,3 +218,16 @@ def timeline(bot, update, args = [10]): db.commit() +# Administrator + +def isadmin(message): + two = bottools.methods.getTwo(message) + if two.whoami().strip("@") == setuptools.admin().strip("@"): + return True + return False + +def restart(bot, update): + if bottools.methods.isadmin(update.message): + update.message.reply_text(bottools.strings.restart) + time.sleep(0.5) + os.execl(sys.executable, sys.executable, *sys.argv) diff --git a/bottools/strings.py b/bottools/strings.py index 2de9aa0..7c7e369 100644 --- a/bottools/strings.py +++ b/bottools/strings.py @@ -27,19 +27,19 @@ After authentication, you will be able to tweet from your account. Just drop me Additionally, you will be able to use the following commands: -* User functions: -** /follow USER - Follow a user. -** /unfollow USER - Unfollow a user. +*User functions* +* /follow USER - Follow a user. +* /unfollow USER - Unfollow a user. -* Tweet functions: -** /like TWEET - Like a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline. -** /reply TWEET TEXT - Reply TEXT to a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline. -** /retweet TWEET - Retweet a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline. -** /toggletweet - Turn automatic tweeting of messages on/off. Useful in groups. -** /tweet TEXT - Explicitly tweet TEXT even if automatic tweeting is off (/toggletweet). +*Tweet functions* +* /like TWEET - Like a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline. +* /reply TWEET TEXT - Reply TEXT to a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline. +* /retweet TWEET - Retweet a tweet. You will need to pass a tweet ID (TWEET) as returned by /timeline. +* /toggletweet - Turn automatic tweeting of messages on/off. Useful in groups. +* /tweet TEXT - Explicitly tweet TEXT even if automatic tweeting is off (/toggletweet). -* Timeline functions: -** /timeline - Shows you the latest tweets in your timeline. Returns 10 tweets by default, but you may also use it like /timeline 20, which would return 20 tweets. +*Timeline functions* +* /timeline - Shows you the latest tweets in your timeline. Returns 10 tweets by default, but you may also use it like /timeline 20, which would return 20 tweets. If you have any further questions about these commands, I'll try to help you. Just use /help COMMAND for that. For instance, "/help timeline" will show you further details about the /timeline command. @@ -116,3 +116,5 @@ accountLocked = '''Your account was locked by Twitter for security reasons. Plea longTweet = '''Sorry, but this tweet is too long.''' cantfind = '''Sorry, I can't find a tweet with ID %s. Please check your timeline and try again.''' + +restart = '''Restarting. Be right back. Hopefully.''' diff --git a/setuptools/__init__.py b/setuptools/__init__.py index a290c80..c7ddc54 100644 --- a/setuptools/__init__.py +++ b/setuptools/__init__.py @@ -106,6 +106,11 @@ def url(): except: return SetupExecption() +def admin(): + try: + return getSetting("Bot", "admin") + except: + return SetupException() def dbCheck(db, create = False): if (not create and dbInitialized(db)) or (create and not dbInitialized(db)): diff --git a/telegrambot.py b/telegrambot.py index 62f9ed1..b68c1a6 100755 --- a/telegrambot.py +++ b/telegrambot.py @@ -19,6 +19,7 @@ if __name__ == "__main__": updater.dispatcher.add_handler(telegram.ext.CommandHandler("login", bottools.methods.auth)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("logout", bottools.methods.unauth)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("reply", bottools.methods.reply, pass_args=True)) + updater.dispatcher.add_handler(telegram.ext.CommandHandler("restart", bottools.methods.restart)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("retweet", bottools.methods.retweet, pass_args=True)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("start", bottools.methods.start)) updater.dispatcher.add_handler(telegram.ext.CommandHandler("timeline", bottools.methods.timeline, pass_args=True))