Compare commits
8 commits
main
...
circleci-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f299b19bab | ||
|
|
5cab8f6fa7 | ||
|
|
2245bcdef9 | ||
|
|
5e9e3bc7c2 | ||
|
|
feb9080a3e | ||
|
|
8009936a64 | ||
|
|
09af134de2 | ||
|
|
f9087bc36c |
8 changed files with 70 additions and 71 deletions
43
.circleci/config.yml
Normal file
43
.circleci/config.yml
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# Use the latest 2.1 version of CircleCI pipeline process engine.
|
||||
# See: https://circleci.com/docs/2.0/configuration-reference
|
||||
version: 2.1
|
||||
|
||||
workflows:
|
||||
clone-and-run:
|
||||
jobs:
|
||||
- clone
|
||||
#filters:
|
||||
# branches:
|
||||
# only: main
|
||||
- deploy
|
||||
#requires:
|
||||
# - clone
|
||||
#filters:
|
||||
# branches:
|
||||
# only: main
|
||||
|
||||
jobs:
|
||||
clone:
|
||||
machine:
|
||||
image: "ubuntu-2004:current"
|
||||
steps:
|
||||
- add_ssh_keys:
|
||||
fingerprints:
|
||||
- "b7:39:6c:c8:a1:24:72:26:e6:a8:d1:c6:0d:24:82:a6"
|
||||
- run:
|
||||
name: Clone
|
||||
command: |
|
||||
echo $SSH_KEY > pkey
|
||||
ssh -i pkey $SSH_USER@$SSH_HOST "cd /etc/BotYam && gh repo sync"
|
||||
deploy:
|
||||
machine:
|
||||
image: "ubuntu-2004:current"
|
||||
steps:
|
||||
- add_ssh_keys:
|
||||
fingerprints:
|
||||
- "b7:39:6c:c8:a1:24:72:26:e6:a8:d1:c6:0d:24:82:a6"
|
||||
- run:
|
||||
name: Deploy Over SSH
|
||||
command: |
|
||||
echo $SSH_KEY > pkey
|
||||
ssh -i pkey $SSH_USER@$SSH_HOST "cd /etc/BotYam && docker-compose up -d --build"
|
||||
19
.github/workflows/main.yml
vendored
19
.github/workflows/main.yml
vendored
|
|
@ -1,19 +0,0 @@
|
|||
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,10 +1,5 @@
|
|||
# BotYam
|
||||
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.
|
||||
A bot that is proudly from Bat Yam, under the twitter handle **@FromBatYam**.
|
||||
|
||||
## 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™™.
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ The API tokens are stored in the API hash, used to communicate with Twitter API.
|
|||
!!! warning "Twitter API License Changes"
|
||||
Currently, the bot is operating under the Twitter API Elevated Access.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
|
||||
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"
|
||||
Currently, the bot is operating under the Twitter API Elevated Access.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
|
||||
Please follow `@FromBotYam` for updates.
|
||||
|
|
|
|||
|
|
@ -1,22 +1,11 @@
|
|||
import tweepy
|
||||
import random
|
||||
import re
|
||||
import requests
|
||||
import time
|
||||
from connector import Connector
|
||||
from connector import printlog
|
||||
|
||||
def init_streamobject(conn):
|
||||
printlog("Loading Stream object...")
|
||||
print("Loading Stream object...")
|
||||
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):
|
||||
# Search for word in word bank
|
||||
if any(word in tweet.data['text'] for word in words):
|
||||
|
|
@ -25,33 +14,31 @@ def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
|
|||
try:
|
||||
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
|
||||
res = conn.api.create_tweet(
|
||||
text=reply_text,
|
||||
in_reply_to_tweet_id=tweet["id"]
|
||||
)
|
||||
response_data = f"RESPONDING: {res.data['text']}"
|
||||
printlog(response_data)
|
||||
except tweepy.errors.TwitterServerError as e:
|
||||
printlog("ERROR: An error occured, we'll try again in a few minutes. The error: " + str(e))
|
||||
time.sleep(5)
|
||||
try:
|
||||
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
|
||||
res = conn.api.create_tweet(
|
||||
text=reply_text,
|
||||
in_reply_to_tweet_id=tweet["id"]
|
||||
)
|
||||
except tweepy.errors.TwitterServerError as e:
|
||||
print("ERROR: An error occured, we'll try again in a few minutes. The error: " + str(e))
|
||||
try:
|
||||
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
|
||||
res = conn.api.create_tweet(
|
||||
text=reply_text,
|
||||
in_reply_to_tweet_id=tweet["id"]
|
||||
)
|
||||
|
||||
response_data = f"RESPONDING: {res.data['text']}"
|
||||
printlog(response_data)
|
||||
print(response_data)
|
||||
except Exception as e:
|
||||
printlog("ERROR: An exception occured. The error: " + str(e))
|
||||
print("ERROR: An exception occured. The error: " + str(e))
|
||||
except Exception as e:
|
||||
printlog("ERROR: An exception occured. The error: " + str(e))
|
||||
print("ERROR: An exception occured. The error: " + str(e))
|
||||
postcounter = postcounter + 1
|
||||
return postcounter
|
||||
|
||||
class BotYamPoster(tweepy.StreamingClient):
|
||||
|
||||
# Define a callback function to handle tweets
|
||||
def on_tweet(self, tweet):
|
||||
# Make it easy on Yashar
|
||||
|
|
@ -70,11 +57,11 @@ class BotYamPoster(tweepy.StreamingClient):
|
|||
|
||||
# Debug
|
||||
tweet_data = f"NEW TWEET from @{conn.api.get_user(id=tweet.data['author_id']).data['username']}: {tweet.data['text']}"
|
||||
printlog(tweet_data)
|
||||
print(tweet_data)
|
||||
|
||||
# Spare me if starts with RT
|
||||
if tweet.data['text'][:2] == "RT":
|
||||
printlog("Skipping retweet...")
|
||||
print("Skipping retweet...")
|
||||
return
|
||||
|
||||
# Run on all gags
|
||||
|
|
@ -100,7 +87,7 @@ class BotYamPoster(tweepy.StreamingClient):
|
|||
postcounter)
|
||||
|
||||
if (postcounter == 0 and "@FromBotYam" in tweet.data['text']):
|
||||
printlog("Post counter for this tweet: 0! Posting tilt.")
|
||||
print("Post counter for this tweet: 0! Posting tilt.")
|
||||
|
||||
if any(tilter in tweet.data['text'] for tilter in reply_bank['special_gags']['tilt']['keywords']):
|
||||
postcounter = post_reply(
|
||||
|
|
@ -123,4 +110,4 @@ class BotYamPoster(tweepy.StreamingClient):
|
|||
# Define a callback function to handle errors
|
||||
def on_error(self, status_code):
|
||||
# Print the error code
|
||||
printlog("ERROR: " + status_code)
|
||||
print("ERROR: " + status_code)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,10 @@
|
|||
import os
|
||||
import redis
|
||||
import time
|
||||
import tweepy
|
||||
from datetime import datetime
|
||||
|
||||
def printlog(text):
|
||||
print((datetime.fromtimestamp(time.time())).strftime("%d-%m-%Y, %H:%M:%S") + ": " + text)
|
||||
|
||||
class Connector():
|
||||
def __init__(self):
|
||||
printlog("Loading Redis connector...")
|
||||
print("Loading Redis connector...")
|
||||
# TODO: Add token
|
||||
self.dbconn = redis.Redis(
|
||||
host=os.getenv("REDIS_HOST"),
|
||||
|
|
@ -18,11 +13,11 @@ class Connector():
|
|||
)
|
||||
|
||||
self.api = Connector.init_api(self.dbconn)
|
||||
printlog("Success loading connectors!")
|
||||
print("Success loading connectors!")
|
||||
|
||||
def init_api(dbconn):
|
||||
# Syslog report
|
||||
printlog("Loading Twitter API connector...")
|
||||
print("Loading Twitter API connector...")
|
||||
|
||||
return tweepy.Client(
|
||||
bearer_token=dbconn.hget("api", "bearer").decode("utf-8"),
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
import sys
|
||||
import tweepy
|
||||
import time
|
||||
from BotYamPoster import BotYamPoster
|
||||
from BotYamPoster import init_streamobject
|
||||
from connector import Connector
|
||||
from connector import printlog
|
||||
|
||||
def main():
|
||||
printlog("BOT-YAM - VERSION 3.0.2 >>>>")
|
||||
print("BOT-YAM - VERSION 3.0.2 >>>>")
|
||||
conn = Connector()
|
||||
stream = init_streamobject(conn)
|
||||
printlog("Adding stream rules...")
|
||||
print("Adding stream rules...")
|
||||
stream.add_rules(tweepy.StreamRule(conn.get_victims()['stream_filter']))
|
||||
stream.add_rules(tweepy.StreamRule("@FromBotYam"))
|
||||
# Start listening for tweets
|
||||
printlog("Starting Twitter stream!")
|
||||
print("Starting Twitter stream!")
|
||||
stream.filter(expansions="author_id")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in a new issue