@ -10,6 +10,7 @@ from suchwow import config
from suchwow . models import Post , Profile , Comment , Notification , db , Moderator
from suchwow . routes import auth , comment , post , profile , leaderboard
from suchwow . utils . decorators import login_required , moderator_required
from suchwow . utils . helpers import post_webhook
from suchwow . reddit import make_post
from suchwow . discord import post_discord_webhook
from suchwow import wownero
@ -76,57 +77,24 @@ def create_accounts():
account = wallet . new_account ( )
print ( f " Created account { account } " )
@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 ) | ( Post . to_discord == False )
)
for post in all_posts :
diff = datetime . now ( ) - post . timestamp
recent_post = diff < timedelta ( hours = 2 )
if recent_post :
if not post . to_reddit :
make_post ( post )
if not post . to_discord :
post_discord_webhook ( post )
return
@app.cli.command ( " post_meme " )
@click.argument ( " post_id " )
def post_meme ( post_id ) :
post = Post . get ( id = post_id )
make_post ( post )
post_discord_webhook ( post )
return
@app.cli.command ( " reddit_random " )
def reddit_random ( ) :
# run every 8 hours
all_posts = Post . select ( ) . where ( Post . reddit_url == None )
post = choice ( all_posts )
make_post ( post )
@app.cli.command ( " payout_users " )
def payout_users ( ) :
wallet = wownero . Wallet ( )
_fa = wownero . from_atomic
_aw = wownero . as_wownero
for post in Post . select ( ) :
submitter = Profile . get ( username = post . submitter )
balances = wallet . balances ( post . account_index )
url = url_for ( ' post.read ' , id = post . id , _external = True )
if balances [ 1 ] > 0 :
print ( f " Post # { post . id } has { balances [ 1 ] } funds unlocked and ready to send. Sweeping all funds to user ' s address ( { submitter . address } ). " )
sweep = wallet . sweep_all ( account = post . account_index , dest_address = submitter . address )
print ( sweep )
@app.cli.command ( " delete_post " )
@click.argument ( " post_id " )
def _delete_post ( post_id ) :
post = Post . get ( id = post_id )
save_path_base = path . join ( app . config [ " DATA_FOLDER " ] , " uploads " )
save_path = path . join ( save_path_base , post . image_name )
post . delete_instance ( )
remove ( save_path )
print ( f " Deleted post { post_id } and image { save_path } " )
if " tx_hash_list " in sweep :
amount = 0
for amt in sweep [ " amount_list " ] :
amount + = int ( amt )
post_webhook ( f " Paid out :moneybag: { _aw ( _fa ( amount ) ) } WOW to ` { post . submitter } ` for post [ { post . id } ]( { url } ) " )
@app.cli.command ( " add_admin " )
@click.argument ( " username " )
@ -135,6 +103,7 @@ def add_admin(username):
m = Moderator ( username = username )
m . save ( )
print ( f " Added { username } " )
post_webhook ( f " Moderator ` { username } ` added :ship_it_parrot: by console :black_flag: " )
else :
print ( " That moderator already exists " )
@ -145,6 +114,7 @@ def remove_admin(username):
if m :
m . delete_instance ( )
print ( f " Deleted { username } " )
post_webhook ( f " Moderator ` { username } ` removed :excuseme: by console :black_flag: " )
else :
print ( " That moderator doesn ' t exist " )