diff --git a/.gitignore b/.gitignore index c660c83..6fde461 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,19 @@ __pycache__/image_utils.cpython-39.pyc emoji_cache/ -*.ttf \ No newline at end of file +dry/ +*.ttf +*.pyc +__pycache__/ +rdrama_auth_token +twitter_access_token +twitter_access_token_secret +twitter_api_key +twitter_api_secret +twitter_bearer_token +twitter_client_id +twitter_client_secret +*.db +*.db-journal +log +*.json + diff --git a/automeme.py b/automeme.py index 26040fa..8661095 100644 --- a/automeme.py +++ b/automeme.py @@ -49,19 +49,36 @@ DARRELL_QUOTES = [ ":#marseyjurisdiction: \nCan we please address :marseyjurisdiction:?", ":#marseygrouns:", ":#marseygrouns:\n:marseygrouns: for the substain?", + ":#marseygrouns:\nWho would you say is the plantiff in this matter?", + ":#marseygrouns:\nWould it be fair to say that the State of Wisconsin is not a living, breathing person?", + ":#marseygrouns:\nThe defense calls the State of Wisconsin.", + ":#brooksannoyed:\nHow can you even call yourself a judge?", + ":#brooksannoyed:\n\*takes off shirt for some reason\*", + ":#brooksannoyed:\nMind boggling. Ming boggling.", + ":#brooksannoyed:\nSHE SAID SHE WAS 18!", ":#marseyrelevancy:\nuhh what's the :marseyrelevancy:?", + ":#marseyrelevancy:\n[\*talks for fifty minutes straight\*](https://rdrama.net/post/113381/marseygrounsmarseyjudge-darrel-brooks-entire-50minute-long)", + ":#marseyrelevancy:\nI see what you're doing. Trying to be slick.", ":#brooksannoyed:\nYour honor, that's a load of crap.", ":#marseytakit:\nIs that lawfully law?", ":#marseytakit:\nIs that a :marseytakit:?", ":#brooksannoyed:\nI AM A GROWN MAN WITH GROWN KIDS AINT NOBODY TELL ME WHEN TO TALK", ":#marseybiast:\nIs this a common law court or an admiralty court?", + ":#marseybiast:\nSeems to me like a lot of your answers are coached.", + ":#marseyjurisdiction:\nWe STILL have yet to discuss :#marseyjurisdiction:.", + ":#marseyjurisdiction:\nWhat da bid'ness?", + ":#marseyjurisdiction:\nI need a signed affidavit of your oath of office." ] DARRELL_KEYWORDS = [ "brooks", "darrell" ] DARRELL_DISCLAIMER = "_I am not Darrell Brooks, I am a third party intervener, here on behalf of my client_" - +LLM_KEYWORDS = [ + "llm", + "landlordmessiah", + "landlord messiah" +] TEST_MODE = False DRY_MODE = False @@ -311,7 +328,6 @@ def create_comment_message(chud: bool, pizza: bool, bird : bool, marsey : bool, message = choice(ANTISPAM_MESSAGES) +"\n" if (mention != None): message += f"@{mention}\n" - message += f"" if (chud): message += "\ntrans lives matter" @@ -490,13 +506,20 @@ def handle_comment(comment : dict, rdrama : RDramaAPIInterface, session : Sessio message = choice(DARRELL_QUOTES) message += "\n\n" message += DARRELL_DISCLAIMER - message += f"" post_id = comment['post_id'] user_id = 0 if comment['author'] == '👻' else comment['author']['id'] new_comment_id = rdrama.reply_to_comment_easy(comment['id'], post_id, message)['id'] Comment.create_new_comment(comment['id'], new_comment_id, session) Post.increment_replies(post_id, session) User.increase_number_of_comments(user_id, session) + elif comment_contains_keyword(comment_text, LLM_KEYWORDS): + message = "![](/images/1669576960061573.webp)" + post_id = comment['post_id'] + user_id = 0 if comment['author'] == '👻' else comment['author']['id'] + new_comment_id = rdrama.reply_to_comment_easy(comment['id'], post_id, message)['id'] + Comment.create_new_comment(comment['id'], new_comment_id, session) + Post.increment_replies(post_id, session) + User.increase_number_of_comments(user_id, session) else: Comment.create_new_comment(comment['id'], None, session) except BaseException as e: diff --git a/upload_best_meme_to_twitter.py b/upload_best_meme_to_twitter.py index d639ff7..4ed18b3 100644 --- a/upload_best_meme_to_twitter.py +++ b/upload_best_meme_to_twitter.py @@ -14,8 +14,6 @@ consumer_secret = load_key_from_file("twitter_api_secret") access_token = load_key_from_file("twitter_access_token") access_token_secret = load_key_from_file("twitter_access_token_secret") - - auth = tweepy.OAuth1UserHandler( consumer_key, consumer_secret, @@ -25,7 +23,10 @@ auth = tweepy.OAuth1UserHandler( api = tweepy.API(auth) rdrama = get_rdrama() -best = rdrama.get_comments(user = "automeme", sort = "top", t="day")['data'][0] +for comment in rdrama.get_comments(user = "automeme", sort = "top", t="day")['data']: + if "Darrell Brooks" not in comment['body'] and "twitter" not in comment['body']: + best = comment + break print(json.dumps(best, indent=4)) comment_text = best['body'] diff --git a/upload_top_scoring_link_to_twitter.py b/upload_top_scoring_link_to_twitter.py new file mode 100644 index 0000000..2f4180b --- /dev/null +++ b/upload_top_scoring_link_to_twitter.py @@ -0,0 +1,98 @@ +from io import BytesIO +import re +import tweepy +from automeme import TextLine, get_rdrama, strip_markdown +import utils +import json +from meme_generator import get_image_file_from_url + +def load_key_from_file(filename : str) -> str: + with open(utils.get_real_filename(filename), "r") as f: + return f.read() + +TWEET_LENGTH = 280 +URL_LENGTH = 23 +HASHTAG_REGION = 23424977 +IMAGE_URL_REGEX = r"https://rdrama\.net/images/([1234567890]*)\.webp" +TWEET_URL_REGEX = r"https://twitter\.com/([a-zA-Z]*)/status/([0-9]*)" + +consumer_key = load_key_from_file("twitter_api_key") +consumer_secret = load_key_from_file("twitter_api_secret") +access_token = load_key_from_file("twitter_access_token") +access_token_secret = load_key_from_file("twitter_access_token_secret") + +auth = tweepy.OAuth1UserHandler( + consumer_key, + consumer_secret, + access_token, + access_token_secret +) +api = tweepy.API(auth) +rdrama = get_rdrama() + +def post_rdrama_tweet(post, api): + tweet_url = post['url'] + tweet_text = get_tweet_text(post) + + return api.update_status(tweet_text, attachment_url=tweet_url) + +def post_rdrama_image(post, api): + animated_image = get_image_file_from_url(post['url']) + file = BytesIO(initial_bytes=animated_image.get_binary_gif()) + media = api.media_upload(filename = "foo.gif", file=file, chunked=True, wait_for_async_finalize = True) + media_id = media.media_id_string + tweet_text = get_tweet_text(post) + return api.update_status(tweet_text, media_ids=[media_id]) + +def post_rdrama_basic_article(post, api): + tweet_text = get_tweet_text(post) + return api.update_status(tweet_text) + +def hashtagify(string, api): + trends = api.get_place_trends(id=23424977)[0]['trends'] + trend_words = [] + for trend in trends: + name = trend['name'].lower() + if '#' in name: + trend_words.append(name[1:]) + else: + for word in name.split(' '): + trend_words.append(word) + print(trend_words) + input = string + for hashtag in trend_words: + input = re.sub(f" {hashtag} ", f" #{hashtag} ", input) + return input + +def get_tweet_text(post): + rdrama_url = post['permalink'] + title = post['title'] + + text_space = TWEET_LENGTH - URL_LENGTH - 1 + actual_title = re.sub(r":[^ ]*:", "", title) #remove marseys + actual_title = hashtagify(actual_title, api) + if (len(title) > text_space): + actual_title = actual_title[0:text_space-3] + "..." + else: + actual_title = actual_title + + return f"{actual_title} {rdrama_url}" + +def post_top_scoring_link(rdrama, api): + post = None + for current_post in rdrama.get_posts(sort='top', t='hour')['data']: + if not current_post['club']: + post = current_post + break + #post = rdrama.get_posts(sort='top', t='hour')['data'][0] #top scoring post + if re.match(TWEET_URL_REGEX, post['url']): + tweet = post_rdrama_tweet(post, api) + elif re.match(IMAGE_URL_REGEX, post['url']): + tweet = post_rdrama_image(post, api) + else: + tweet = post_rdrama_basic_article(post, api) + url = f"https://twitter.com/drama_meme/status/{tweet.id}" + rdrama.reply_to_post(post['id'], f"Nice post, bro! [I posted it to twitter]({url}).") + +if __name__ == "__main__": + post_top_scoring_link(rdrama, api) \ No newline at end of file