Compare commits
20 commits
circleci-p
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5025040cb9 | ||
|
|
c9b12f3ea9 | ||
|
|
8b728793ce | ||
|
|
2351f608ae | ||
|
|
158881ab9d | ||
|
|
ec1b9360e0 | ||
|
|
e9b62a5782 | ||
|
|
7a2290158b | ||
|
|
0fcede8acf | ||
|
|
984148f633 | ||
|
|
c50b4e3f68 | ||
|
|
4660178f37 | ||
|
|
9653dbb123 | ||
|
|
cdbe3a27d6 | ||
|
|
46e279111f | ||
|
|
11958835ee | ||
|
|
2ba8e2be24 | ||
|
|
04e0b70511 | ||
|
|
2ba379280a | ||
|
|
acc7c91bfb |
7 changed files with 71 additions and 27 deletions
19
.github/workflows/main.yml
vendored
Normal file
19
.github/workflows/main.yml
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: executing remote ssh commands using password
|
||||||
|
uses: appleboy/ssh-action@v0.1.7
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.SSH_HOST }}
|
||||||
|
username: ${{ secrets.SSH_USER }}
|
||||||
|
password: ${{ secrets.SSH_PASSWORD }}
|
||||||
|
port: 22
|
||||||
|
script: "cd /etc/BotYam && git pull && docker-compose up -d --build"
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
# BotYam
|
# BotYam
|
||||||
A bot that is proudly from Bat Yam, under the twitter handle **@FromBatYam**.
|
A bot that is proudly from Bat Yam, under the twitter handle **@FromBotYam**.
|
||||||
|
|
||||||
|
## Twitter API Changes Notice
|
||||||
|
On April 19th, new changes for the API access that has been announced will come into effect. The bot will act as a videons archive until integrations into a suitable, affordable platform will apply.
|
||||||
|
|
||||||
|
Updates will be posted on the **@FromBotYam** handle on Twitter.
|
||||||
|
|
||||||
## What's going on?
|
## What's going on?
|
||||||
The bot was originally intended to annoy Aviv Yashar, but now it developed into a massive shitposting machine that is the only hope for both the left™ and Hapoel™™.
|
The bot was originally intended to annoy Aviv Yashar, but now it developed into a massive shitposting machine that is the only hope for both the left™ and Hapoel™™.
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ The API tokens are stored in the API hash, used to communicate with Twitter API.
|
||||||
!!! warning "Twitter API License Changes"
|
!!! warning "Twitter API License Changes"
|
||||||
Currently, the bot is operating under the Twitter API Elevated Access.
|
Currently, the bot is operating under the Twitter API Elevated Access.
|
||||||
|
|
||||||
On February 9th, new changes for the API access that has been announced will come into effect, and currently there isn't a guarantee that the bot will be up after the changes will be applied.
|
On April 19th, new changes for the API access that has been announced will come into effect. The bot will act as a videons archive until integrations into a suitable, affordable platform will apply.
|
||||||
|
|
||||||
|
|
||||||
Please follow `@FromBotYam` for updates.
|
Please follow `@FromBotYam` for updates.
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ Welcome to the Bot Yam documentation, to ultimate source of knowledge when it co
|
||||||
!!! warning "Twitter API License Changes"
|
!!! warning "Twitter API License Changes"
|
||||||
Currently, the bot is operating under the Twitter API Elevated Access.
|
Currently, the bot is operating under the Twitter API Elevated Access.
|
||||||
|
|
||||||
On February 9th, new changes for the API access that has been announced will come into effect, and currently there isn't a guarantee that the bot will be up after the changes will be applied.
|
On April 19th, new changes for the API access that has been announced will come into effect. The bot will act as a videons archive until integrations into a suitable, affordable platform will apply.
|
||||||
|
|
||||||
|
|
||||||
Please follow `@FromBotYam` for updates.
|
Please follow `@FromBotYam` for updates.
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,22 @@
|
||||||
import tweepy
|
import tweepy
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
from connector import Connector
|
from connector import Connector
|
||||||
|
from connector import printlog
|
||||||
|
|
||||||
def init_streamobject(conn):
|
def init_streamobject(conn):
|
||||||
print("Loading Stream object...")
|
printlog("Loading Stream object...")
|
||||||
return BotYamPoster(conn.get_bearer())
|
return BotYamPoster(conn.get_bearer())
|
||||||
|
|
||||||
|
def expand_tco_url(url):
|
||||||
|
response = requests.head(url, allow_redirects=False)
|
||||||
|
if 'location' in response.headers:
|
||||||
|
return response.headers['location']
|
||||||
|
else:
|
||||||
|
return url
|
||||||
|
|
||||||
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):
|
||||||
|
|
@ -18,8 +29,11 @@ def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
|
||||||
text=reply_text,
|
text=reply_text,
|
||||||
in_reply_to_tweet_id=tweet["id"]
|
in_reply_to_tweet_id=tweet["id"]
|
||||||
)
|
)
|
||||||
|
response_data = f"RESPONDING: {res.data['text']}"
|
||||||
|
printlog(response_data)
|
||||||
except tweepy.errors.TwitterServerError as e:
|
except tweepy.errors.TwitterServerError as e:
|
||||||
print("ERROR: An error occured, we'll try again in a few minutes. The error: " + str(e))
|
printlog("ERROR: An error occured, we'll try again in a few minutes. The error: " + str(e))
|
||||||
|
time.sleep(5)
|
||||||
try:
|
try:
|
||||||
if tweet.data['author_id'] in victim_bank['author_id'] and not "@FromBotYam" in tweet.data['text']:
|
if tweet.data['author_id'] in victim_bank['author_id'] and not "@FromBotYam" in tweet.data['text']:
|
||||||
reply_text = victim_bank['reply'][random.randint(0,2)] + "\nו" + reply_text
|
reply_text = victim_bank['reply'][random.randint(0,2)] + "\nו" + reply_text
|
||||||
|
|
@ -29,16 +43,15 @@ def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
|
||||||
)
|
)
|
||||||
|
|
||||||
response_data = f"RESPONDING: {res.data['text']}"
|
response_data = f"RESPONDING: {res.data['text']}"
|
||||||
print(response_data)
|
printlog(response_data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("ERROR: An exception occured. The error: " + str(e))
|
printlog("ERROR: An exception occured. The error: " + str(e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("ERROR: An exception occured. The error: " + str(e))
|
printlog("ERROR: An exception occured. The error: " + str(e))
|
||||||
postcounter = postcounter + 1
|
postcounter = postcounter + 1
|
||||||
return postcounter
|
return postcounter
|
||||||
|
|
||||||
class BotYamPoster(tweepy.StreamingClient):
|
class BotYamPoster(tweepy.StreamingClient):
|
||||||
|
|
||||||
# Define a callback function to handle tweets
|
# Define a callback function to handle tweets
|
||||||
def on_tweet(self, tweet):
|
def on_tweet(self, tweet):
|
||||||
# Make it easy on Yashar
|
# Make it easy on Yashar
|
||||||
|
|
@ -57,11 +70,11 @@ class BotYamPoster(tweepy.StreamingClient):
|
||||||
|
|
||||||
# Debug
|
# Debug
|
||||||
tweet_data = f"NEW TWEET from @{conn.api.get_user(id=tweet.data['author_id']).data['username']}: {tweet.data['text']}"
|
tweet_data = f"NEW TWEET from @{conn.api.get_user(id=tweet.data['author_id']).data['username']}: {tweet.data['text']}"
|
||||||
print(tweet_data)
|
printlog(tweet_data)
|
||||||
|
|
||||||
# Spare me if starts with RT
|
# Spare me if starts with RT
|
||||||
if tweet.data['text'][:2] == "RT":
|
if tweet.data['text'][:2] == "RT":
|
||||||
print("Skipping retweet...")
|
printlog("Skipping retweet...")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Run on all gags
|
# Run on all gags
|
||||||
|
|
@ -87,7 +100,7 @@ class BotYamPoster(tweepy.StreamingClient):
|
||||||
postcounter)
|
postcounter)
|
||||||
|
|
||||||
if (postcounter == 0 and "@FromBotYam" in tweet.data['text']):
|
if (postcounter == 0 and "@FromBotYam" in tweet.data['text']):
|
||||||
print("Post counter for this tweet: 0! Posting tilt.")
|
printlog("Post counter for this tweet: 0! Posting tilt.")
|
||||||
|
|
||||||
if any(tilter in tweet.data['text'] for tilter in reply_bank['special_gags']['tilt']['keywords']):
|
if any(tilter in tweet.data['text'] for tilter in reply_bank['special_gags']['tilt']['keywords']):
|
||||||
postcounter = post_reply(
|
postcounter = post_reply(
|
||||||
|
|
@ -110,4 +123,4 @@ class BotYamPoster(tweepy.StreamingClient):
|
||||||
# Define a callback function to handle errors
|
# Define a callback function to handle errors
|
||||||
def on_error(self, status_code):
|
def on_error(self, status_code):
|
||||||
# Print the error code
|
# Print the error code
|
||||||
print("ERROR: " + status_code)
|
printlog("ERROR: " + status_code)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,15 @@
|
||||||
import os
|
import os
|
||||||
import redis
|
import redis
|
||||||
|
import time
|
||||||
import tweepy
|
import tweepy
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def printlog(text):
|
||||||
|
print((datetime.fromtimestamp(time.time())).strftime("%d-%m-%Y, %H:%M:%S") + ": " + text)
|
||||||
|
|
||||||
class Connector():
|
class Connector():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
print("Loading Redis connector...")
|
printlog("Loading Redis connector...")
|
||||||
# TODO: Add token
|
# TODO: Add token
|
||||||
self.dbconn = redis.Redis(
|
self.dbconn = redis.Redis(
|
||||||
host=os.getenv("REDIS_HOST"),
|
host=os.getenv("REDIS_HOST"),
|
||||||
|
|
@ -13,11 +18,11 @@ class Connector():
|
||||||
)
|
)
|
||||||
|
|
||||||
self.api = Connector.init_api(self.dbconn)
|
self.api = Connector.init_api(self.dbconn)
|
||||||
print("Success loading connectors!")
|
printlog("Success loading connectors!")
|
||||||
|
|
||||||
def init_api(dbconn):
|
def init_api(dbconn):
|
||||||
# Syslog report
|
# Syslog report
|
||||||
print("Loading Twitter API connector...")
|
printlog("Loading Twitter API connector...")
|
||||||
|
|
||||||
return tweepy.Client(
|
return tweepy.Client(
|
||||||
bearer_token=dbconn.hget("api", "bearer").decode("utf-8"),
|
bearer_token=dbconn.hget("api", "bearer").decode("utf-8"),
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,20 @@
|
||||||
import sys
|
import sys
|
||||||
import tweepy
|
import tweepy
|
||||||
|
import time
|
||||||
from BotYamPoster import BotYamPoster
|
from BotYamPoster import BotYamPoster
|
||||||
from BotYamPoster import init_streamobject
|
from BotYamPoster import init_streamobject
|
||||||
from connector import Connector
|
from connector import Connector
|
||||||
|
from connector import printlog
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print("BOT-YAM - VERSION 3.0.2 >>>>")
|
printlog("BOT-YAM - VERSION 3.0.2 >>>>")
|
||||||
conn = Connector()
|
conn = Connector()
|
||||||
stream = init_streamobject(conn)
|
stream = init_streamobject(conn)
|
||||||
print("Adding stream rules...")
|
printlog("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
|
||||||
print("Starting Twitter stream!")
|
printlog("Starting Twitter stream!")
|
||||||
stream.filter(expansions="author_id")
|
stream.filter(expansions="author_id")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue