Compare commits

...

20 commits

Author SHA1 Message Date
Lucy Joshua
5025040cb9 Updates on README and docs about API 2023-04-05 02:46:36 +03:00
Lucy Joshua
c9b12f3ea9
bugfix of timestamps 2023-03-22 14:44:54 +02:00
Lucy Joshua
8b728793ce
Time stamps 2023-03-22 14:35:11 +02:00
Lucy Joshua
2351f608ae
Timestamps 2023-03-22 14:34:34 +02:00
Lucy Joshua
158881ab9d
Bugfix + timestamp 2023-03-22 14:33:43 +02:00
Lucy Joshua
ec1b9360e0
it's deprecated 2023-03-22 14:15:17 +02:00
Lucy Joshua
e9b62a5782 Debug 2023-03-10 21:16:45 +02:00
Lucy Joshua
7a2290158b Merge branch 'main' of https://github.com/notBscalE/BotYam into main 2023-03-10 21:11:10 +02:00
Lucy Joshua
0fcede8acf New one? 2023-03-10 21:10:49 +02:00
Lucy Joshua
984148f633
The maybe factor? 2023-02-25 03:30:02 +02:00
Lucy Joshua
c50b4e3f68
plis 2023-02-25 03:23:58 +02:00
Lucy Joshua
4660178f37
AH 2023-02-25 03:22:55 +02:00
Lucy Joshua
9653dbb123
h 2023-02-25 03:19:56 +02:00
Lucy Joshua
cdbe3a27d6
Give me a reason to be happy 2023-02-25 03:16:17 +02:00
Lucy Joshua
46e279111f
well 2023-02-25 03:05:44 +02:00
Lucy Joshua
11958835ee
? 2023-02-25 02:48:18 +02:00
Lucy Joshua
2ba8e2be24
Committing 2023-02-25 02:29:33 +02:00
Lucy Joshua
04e0b70511
Maybe now an answer? 2023-02-25 02:21:36 +02:00
Lucy Joshua
2ba379280a
Hm? 2023-02-25 02:17:08 +02:00
Lucy Joshua
acc7c91bfb
CI? 2023-02-25 02:14:30 +02:00
7 changed files with 71 additions and 27 deletions

19
.github/workflows/main.yml vendored Normal file
View 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"

View file

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

View file

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

View file

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

View file

@ -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):
@ -14,31 +25,33 @@ def post_reply(conn, victim_bank, tweet, words, reply_text_bank, postcounter):
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
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( 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"]
) )
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']}" 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)

View file

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

View file

@ -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__":