Move strings to bottools.strings
This commit is contained in:
parent
699ad8b32b
commit
ef958366b9
0
bottools/__init__.py
Normal file
0
bottools/__init__.py
Normal file
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import ast, dbtools, html, io, logging, moviepy.editor, PIL.Image, random, setuptools, string, strings, telegram.ext, twitools, urllib.request, tweepy
|
import ast, dbtools, html, io, logging, moviepy.editor, PIL.Image, random, setuptools, string, bottools.strings, telegram.ext, twitools, urllib.request, tweepy
|
||||||
|
|
||||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -10,42 +10,39 @@ def log(bot, update, error):
|
||||||
|
|
||||||
def twoExceptions(e, message):
|
def twoExceptions(e, message):
|
||||||
text = {
|
text = {
|
||||||
32: strings.badToken,
|
32: bottools.strings.badToken,
|
||||||
36: strings.selfSpam,
|
36: bottools.strings.selfSpam,
|
||||||
64: strings.accountSuspended,
|
64: bottools.strings.accountSuspended,
|
||||||
88: strings.rateLimit,
|
88: bottools.strings.rateLimit,
|
||||||
89: strings.badToken,
|
89: bottools.strings.badToken,
|
||||||
99: strings.badToken,
|
99: bottools.strings.badToken,
|
||||||
130: strings.overload,
|
130: bottools.strings.overload,
|
||||||
131: strings.twitterError,
|
131: bottools.strings.twitterError,
|
||||||
161: strings.followLimit,
|
161: bottools.strings.followLimit,
|
||||||
185: strings.tweetLimit,
|
185: bottools.strings.tweetLimit,
|
||||||
186: strings.tweetLimit,
|
186: bottools.strings.tweetLimit,
|
||||||
187: strings.dupTweet,
|
187: bottools.strings.dupTweet,
|
||||||
205: strings.rateLimit,
|
205: bottools.strings.rateLimit,
|
||||||
226: strings.automatedTweet,
|
226: bottools.strings.automatedTweet,
|
||||||
271: strings.selfMute,
|
271: bottools.strings.selfMute,
|
||||||
272: strings.notMuted,
|
272: bottools.strings.notMuted,
|
||||||
323: strings.multipleGIFs,
|
323: bottools.strings.multipleGIFs,
|
||||||
326: strings.accountLocked,
|
326: bottools.strings.accountLocked,
|
||||||
354: strings.longTweet
|
354: bottools.strings.longTweet
|
||||||
}.get(e.api_code)
|
}.get(e.api_code)
|
||||||
|
|
||||||
message.reply_text(text or strings.twoFail)
|
message.reply_text(text or bottools.strings.twoFail)
|
||||||
|
|
||||||
def getTwo(message):
|
def getTwo(message):
|
||||||
try:
|
try:
|
||||||
return twitools.twoBotHelper(message.chat_id)
|
return twitools.twoBotHelper(message.chat_id)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
noauth(message)
|
message.reply_text(bottools.strings.noauth)
|
||||||
except tweepy.error.TweepError as e:
|
except tweepy.error.TweepError as e:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def noauth(message):
|
|
||||||
message.reply_text(strings.noauth)
|
|
||||||
|
|
||||||
def start(bot, update):
|
def start(bot, update):
|
||||||
update.message.reply_text(strings.start % (setuptools.botname(), setuptools.botname()))
|
update.message.reply_text(bottools.strings.start % (setuptools.botname(), setuptools.botname()))
|
||||||
|
|
||||||
def auth(bot, update):
|
def auth(bot, update):
|
||||||
db = dbtools.dbHelper()
|
db = dbtools.dbHelper()
|
||||||
|
@ -53,11 +50,11 @@ def auth(bot, update):
|
||||||
|
|
||||||
if not (db.ato(cid) or db.ase(cid)):
|
if not (db.ato(cid) or db.ase(cid)):
|
||||||
auth = tweepy.OAuthHandler(setuptools.cke(), setuptools.cse())
|
auth = tweepy.OAuthHandler(setuptools.cke(), setuptools.cse())
|
||||||
update.message.reply_text(strings.auth % auth.get_authorization_url())
|
update.message.reply_text(bottools.strings.auth % auth.get_authorization_url())
|
||||||
dbtools.dbHelper().storeToken(cid, auth.request_token)
|
dbtools.dbHelper().storeToken(cid, auth.request_token)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
update.message.reply_text(strings.authimp)
|
update.message.reply_text(bottools.strings.authimp)
|
||||||
|
|
||||||
def verify(bot, update, args):
|
def verify(bot, update, args):
|
||||||
db = dbtools.dbHelper()
|
db = dbtools.dbHelper()
|
||||||
|
@ -70,22 +67,22 @@ def verify(bot, update, args):
|
||||||
try:
|
try:
|
||||||
auth.get_access_token(args[0])
|
auth.get_access_token(args[0])
|
||||||
dbtools.dbHelper().storeUser(cid, auth.access_token, auth.access_token_secret)
|
dbtools.dbHelper().storeUser(cid, auth.access_token, auth.access_token_secret)
|
||||||
update.message.reply_text(strings.verify)
|
update.message.reply_text(bottools.strings.verify)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
dbtools.dbHelper().deleteUser(update.message.chat_id)
|
dbtools.dbHelper().deleteUser(update.message.chat_id)
|
||||||
update.message.reply_text(strings.verifyfail)
|
update.message.reply_text(bottools.strings.verifyfail)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
update.message.reply_text(strings.verifyimp)
|
update.message.reply_text(bottools.strings.verifyimp)
|
||||||
|
|
||||||
def unauth(bot, update):
|
def unauth(bot, update):
|
||||||
dbtools.dbHelper().deleteUser(update.message.chat_id)
|
dbtools.dbHelper().deleteUser(update.message.chat_id)
|
||||||
update.message.reply_text(strings.unauth % setuptools.url())
|
update.message.reply_text(bottools.strings.unauth % setuptools.url())
|
||||||
|
|
||||||
def fish(bot, update):
|
def fish(bot, update):
|
||||||
dbtools.dbHelper().addFish(update.message.chat_id)
|
dbtools.dbHelper().addFish(update.message.chat_id)
|
||||||
update.message.reply_text(strings.fishThanks)
|
update.message.reply_text(bottools.strings.fishThanks)
|
||||||
|
|
||||||
def follow(bot, update, args):
|
def follow(bot, update, args):
|
||||||
try:
|
try:
|
||||||
|
@ -149,17 +146,13 @@ def explicitTweet(bot, update, args, reply = None):
|
||||||
two.tweet(' '.join(args), reply)
|
two.tweet(' '.join(args), reply)
|
||||||
|
|
||||||
except tweepy.error.TweepError as e:
|
except tweepy.error.TweepError as e:
|
||||||
logging.exception("Meh.")
|
|
||||||
twoExceptions(e, update.message)
|
twoExceptions(e, update.message)
|
||||||
|
|
||||||
except:
|
|
||||||
logging.exception("Meh.")
|
|
||||||
|
|
||||||
def reply(bot, update, args):
|
def reply(bot, update, args):
|
||||||
try:
|
try:
|
||||||
reply = getTweetID(args[0], update.message.chat_id)
|
reply = getTweetID(args[0], update.message.chat_id)
|
||||||
except:
|
except:
|
||||||
update.message.reply_text(strings.cantfind % args[0])
|
update.message.reply_text(bottools.strings.cantfind % args[0])
|
||||||
|
|
||||||
explicitTweet(bot, update, args[1:], reply)
|
explicitTweet(bot, update, args[1:], reply)
|
||||||
|
|
||||||
|
@ -169,7 +162,7 @@ def retweet(bot, update, args):
|
||||||
tid = getTweetID(tweet, update.message.chat_id)
|
tid = getTweetID(tweet, update.message.chat_id)
|
||||||
getTwo(update.message).api.retweet(tid)
|
getTwo(update.message).api.retweet(tid)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
update.message.reply_text(strings.cantfind % tweet)
|
update.message.reply_text(bottools.strings.cantfind % tweet)
|
||||||
except tweepy.error.TweepError as e:
|
except tweepy.error.TweepError as e:
|
||||||
twoExceptions(e, update.message)
|
twoExceptions(e, update.message)
|
||||||
|
|
||||||
|
@ -179,7 +172,7 @@ def like(bot, update, args):
|
||||||
tid = getTweetID(tweet, update.message.chat_id)
|
tid = getTweetID(tweet, update.message.chat_id)
|
||||||
getTwo(update.message).api.create_favorite(tid)
|
getTwo(update.message).api.create_favorite(tid)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
update.message.reply_text(strings.cantfind % tweet)
|
update.message.reply_text(bottools.strings.cantfind % tweet)
|
||||||
except tweepy.error.TweepError as e:
|
except tweepy.error.TweepError as e:
|
||||||
twoExceptions(e, update.message)
|
twoExceptions(e, update.message)
|
||||||
|
|
||||||
|
@ -187,8 +180,8 @@ def tweet(bot, update):
|
||||||
try:
|
try:
|
||||||
if dbtools.dbHelper().getTStatus(update.message.chat_id):
|
if dbtools.dbHelper().getTStatus(update.message.chat_id):
|
||||||
explicitTweet(bot, update, [update.message.text])
|
explicitTweet(bot, update, [update.message.text])
|
||||||
except:
|
except twepy.error.TweepError as e:
|
||||||
noauth(update.message)
|
twoExceptions(e, update.message)
|
||||||
|
|
||||||
def timeline(bot, update, args = [10]):
|
def timeline(bot, update, args = [10]):
|
||||||
try:
|
try:
|
||||||
|
@ -215,12 +208,12 @@ def timeline(bot, update, args = [10]):
|
||||||
|
|
||||||
def toggleTweet(bot, update):
|
def toggleTweet(bot, update):
|
||||||
try:
|
try:
|
||||||
update.message.reply_text(strings.toggleTweet % (strings.toggleTweetOn if dbtools.dbHelper().toggleTweet(update.message.chat_id) else strings.toggleTweetOff))
|
update.message.reply_text(bottools.strings.toggleTweet % (bottools.strings.toggleTweetOn if dbtools.dbHelper().toggleTweet(update.message.chat_id) else bottools.strings.toggleTweetOff))
|
||||||
except:
|
except tweepy.error.TweepError as e:
|
||||||
noauth(update.message)
|
twoExceptions(e, update.message)
|
||||||
|
|
||||||
def unknown(bot, update):
|
def unknown(bot, update):
|
||||||
update.message.reply_text(strings.unknownCommand)
|
update.message.reply_text(bottools.strings.unknownCommand)
|
||||||
|
|
||||||
def test(bot, update, args):
|
def test(bot, update, args):
|
||||||
print(args)
|
print(args)
|
||||||
|
|
Loading…
Reference in a new issue