From 7d7caf803d8b8f2667ee6a481449e6b4b9e5165d Mon Sep 17 00:00:00 2001 From: lza_menace Date: Thu, 29 Oct 2020 00:57:08 -0700 Subject: [PATCH] yoloing a discord webhook --- suchwow/app.py | 6 ++++-- suchwow/config.example.py | 3 ++- suchwow/discord.py | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 suchwow/discord.py diff --git a/suchwow/app.py b/suchwow/app.py index 6957dce..0a513cc 100644 --- a/suchwow/app.py +++ b/suchwow/app.py @@ -10,6 +10,7 @@ from suchwow.models import Post, Profile, Comment, Notification, db from suchwow.routes import auth, comment, post, profile, leaderboard from suchwow.utils.decorators import login_required from suchwow.reddit import make_post +from suchwow.discord import post_discord_webhook from suchwow import wownero @@ -68,8 +69,8 @@ def create_accounts(): account = wallet.new_account() print(f"Created account {account}") -@app.cli.command("reddit_recent") -def reddit_recent(): +@app.cli.command("post_new_memes") +def post_new_memes(): # run every 5 mins all_posts = Post.select().order_by(Post.timestamp.desc()).where(Post.to_reddit == False) for post in all_posts: @@ -77,6 +78,7 @@ def reddit_recent(): recent_post = diff < timedelta(hours=2) if recent_post: make_post(post) + post_discord_webhook(post) return @app.cli.command("reddit_random") diff --git a/suchwow/config.example.py b/suchwow/config.example.py index f888b4c..d36fed4 100644 --- a/suchwow/config.example.py +++ b/suchwow/config.example.py @@ -17,4 +17,5 @@ PRAW_CLIENT_ID = 'xxxxxxxx' PRAW_USER_AGENT = 'suchwow-yyyy-python' PRAW_USERNAME = 'xxxxxxxx' PRAW_PASSWORD = 'xxxxxxxx' -SERVER_NAME = 'suchwow.xyz' +SERVER_NAME = 'localhost' +DISCORD_URL = 'xxxxxxx' diff --git a/suchwow/discord.py b/suchwow/discord.py new file mode 100644 index 0000000..953c11c --- /dev/null +++ b/suchwow/discord.py @@ -0,0 +1,22 @@ +import requests +from suchwow import config + + +intro = ["Whatup", "What is up", "What the fuck is up", "what in the fuck is up", "Yo"] +insults = ["fart sacks", "dick lips", "shit stains", "chodes", "cum guzzlers", "dipshits", "dicknipples", "turd burglars"] + + +def post_discord_webhook(post): + wallet = wownero.Wallet() + post_wow_address = wallet.get_address(account=post.account_index) + content = f"{choice(intro)} {choice(insults)}, check out the new SuchWow post #{post.id} from {post.submitter}! Send funds to [{post_wow_address}](https://wownero.club/address/{post_wow_address}) to show support!" + msg = {"content": content} + discord_webhook_url = config.DISCORD_URL + r = requests.post(discord_webhook_url, data=msg) + r.raise_for_status() + if r.status.ok: + print(f"Posted #{post.id} to Discord") + return True + else: + print(f"Unable to post #{post.id} to Discord") + return False