Add restart method for admin

This commit is contained in:
Klaus-Uwe Mitterer 2017-03-23 13:05:48 +01:00
parent 929138f3c8
commit 6e12ba4a44
4 changed files with 33 additions and 12 deletions

View file

@ -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)

View file

@ -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.'''

View file

@ -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)):

View file

@ -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))