Dict is fun!™
This commit is contained in:
parent
2c3aa46107
commit
a6f3773048
3 changed files with 18 additions and 18 deletions
|
|
@ -12,10 +12,10 @@ def init_streamobject(conn):
|
||||||
def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
|
def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
|
||||||
# Search for word in word bank
|
# Search for word in word bank
|
||||||
if any(word in tweet.data['text'] for word in words):
|
if any(word in tweet.data['text'] for word in words):
|
||||||
reply_text = reply_text_bank[random.randint(0, (reply_text_bank.len()-1))]
|
reply_text = reply_text_bank[random.randint(0, (len(reply_text_bank)-1))]
|
||||||
# Post reply
|
# Post reply
|
||||||
if tweet.data['author_id'] in victim_bank.author_id:
|
if tweet.data['author_id'] in victim_bank.author_id:
|
||||||
reply_text = victim_bank.text[random.randint(0,2)] + "\n" + reply_text
|
reply_text = victim_bank['reply'][random.randint(0,2)] + "\n" + reply_text
|
||||||
res = conn.api.create_tweet(
|
res = conn.api.create_tweet(
|
||||||
text=reply_text,
|
text=reply_text,
|
||||||
in_reply_to_tweet_id=tweet["id"]
|
in_reply_to_tweet_id=tweet["id"]
|
||||||
|
|
@ -52,33 +52,33 @@ class BotYamPoster(tweepy.StreamingClient):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Run on all gags
|
# Run on all gags
|
||||||
for gag in reply_bank.gags:
|
for gag in reply_bank['gags']:
|
||||||
postcounter = post_reply(conn, reply_bank.victims, tweet, gag.keywords, gag.reply, postcounter)
|
postcounter = post_reply(conn, reply_bank['victims'], tweet, gag['keywords'], gag['reply'], postcounter)
|
||||||
|
|
||||||
# Special gags
|
# Special gags
|
||||||
if reply_bank.special_gags['haikar_misadot'].keywords[0] in tweet.data["text"]:
|
if reply_bank['special_gags']['haikar_misadot']['keywords'][0] in tweet.data["text"]:
|
||||||
postcounter = post_reply(
|
postcounter = post_reply(
|
||||||
conn,
|
conn,
|
||||||
reply_bank.victims,
|
reply_bank['victims'],
|
||||||
tweet,
|
tweet,
|
||||||
reply_bank.special_gags['haikar_misadot'].keywords,
|
reply_bank['special_gags']['haikar_misadot']['keywords'],
|
||||||
reply_bank.special_gags['haikar_misadot'].reply,
|
reply_bank['special_gags']['haikar_misadot']['reply'],
|
||||||
postcounter)
|
postcounter)
|
||||||
elif not any(gebol in tweet.data['text'] for gebol in reply_bank.gags[1].keywords) and any(misada in tweet.data['text'] for misada in reply_bank.special_gags['misadot'].keywords):
|
elif not any(gebol in tweet.data['text'] for gebol in reply_bank['gags'][1]['keywords']) and any(misada in tweet.data['text'] for misada in reply_bank['special_gags']['misadot']['keywords']):
|
||||||
postcounter = post_reply(
|
postcounter = post_reply(
|
||||||
conn,
|
conn,
|
||||||
reply_bank.victims,
|
reply_bank['victims'],
|
||||||
tweet,
|
tweet,
|
||||||
reply_bank.special_gags['misadot'].keywords,
|
reply_bank['special_gags']['misadot']['keywords'],
|
||||||
reply_bank.special_gags['misadot'].reply,
|
reply_bank['special_gags']['misadot']['reply'],
|
||||||
postcounter)
|
postcounter)
|
||||||
|
|
||||||
if any(tilter in tweet.data['text'] for tilter in reply_bank.special_gags['tilt'].keywords) or (postcounter == 0 and "@FromBotYam" in tweet.data['text']):
|
if any(tilter in tweet.data['text'] for tilter in reply_bank['special_gags']['tilt']['keywords']) or (postcounter == 0 and "@FromBotYam" in tweet.data['text']):
|
||||||
postcounter = post_reply(
|
postcounter = post_reply(
|
||||||
conn,
|
conn,
|
||||||
reply_bank.victims,
|
reply_bank['victims'],
|
||||||
tweet, reply_bank.special_gags['tilt'].keywords,
|
tweet, reply_bank['special_gags']['tilt']['keywords'],
|
||||||
reply_bank.special_gags['tilt'].reply,
|
reply_bank['special_gags']['tilt']['reply'],
|
||||||
postcounter)
|
postcounter)
|
||||||
|
|
||||||
# Define a callback function to handle errors
|
# Define a callback function to handle errors
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class Connector():
|
||||||
return self.dbconn.json().get('reply_bank')
|
return self.dbconn.json().get('reply_bank')
|
||||||
|
|
||||||
def get_victims(self):
|
def get_victims(self):
|
||||||
return self.dbconn.json().get('reply_bank').victims
|
return self.dbconn.json().get('reply_bank')['victims']
|
||||||
|
|
||||||
def get_bearer(self):
|
def get_bearer(self):
|
||||||
return self.dbconn.hget("api", "bearer").decode("utf-8")
|
return self.dbconn.hget("api", "bearer").decode("utf-8")
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ def main():
|
||||||
conn = Connector()
|
conn = Connector()
|
||||||
stream = init_streamobject(conn)
|
stream = init_streamobject(conn)
|
||||||
syslog.syslog(syslog.LOG_INFO, "Adding stream rules...")
|
syslog.syslog(syslog.LOG_INFO, "Adding stream rules...")
|
||||||
stream.add_rules(tweepy.StreamRule(conn.get_victims().stream_filter))
|
stream.add_rules(tweepy.StreamRule(conn.get_victims()['stream_filter']))
|
||||||
stream.add_rules(tweepy.StreamRule("@FromBotYam"))
|
stream.add_rules(tweepy.StreamRule("@FromBotYam"))
|
||||||
# Start listening for tweets
|
# Start listening for tweets
|
||||||
syslog.syslog(syslog.LOG_INFO, "Starting Twitter stream!")
|
syslog.syslog(syslog.LOG_INFO, "Starting Twitter stream!")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue