Skip to content

Commit

Permalink
WIP pull event from Discord
Browse files Browse the repository at this point in the history
  • Loading branch information
EpocDotFr committed Nov 13, 2023
1 parent 19d6f58 commit 77b6408
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
34 changes: 34 additions & 0 deletions rwrs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,40 @@ def update_discord_commands():
click.secho('Done', fg='green')


@app.cli.command()
@check_maintenance
def pull_discord_event():
"""Pull event from Discord."""
from app import db, cache, discord_interactions
from rwrs import event
import rwr.scraper
import arrow

click.echo('Pulling event from Discord...')

event = event.get(with_servers=False)

if event and event['manual']:
click.secho('An event has already been manually set, aborting', fg='red')

return

try:
# TODO
# YYYY-MM-DD HH:mm ZZZ
# event.set(name, datetime, servers_address, manual=False)

db.session.commit()

cache.delete_memoized(rwr.scraper.get_servers)

click.secho('Done', fg='green')
except (arrow.parser.ParserError, ValueError):
click.secho('Invalid datetime provided (should be `{}`)'.format(app.config['EVENT_DATETIME_STORAGE_FORMAT']), fg='red')
except Exception as e:
click.secho(str(e), fg='red')


@app.cli.command()
@click.option('--starting-id', type=int, default=0)
@click.option('--limit', type=int, default=200)
Expand Down
5 changes: 3 additions & 2 deletions rwrs/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ def remove():
return False


def set(name, datetime, servers_address):
def set(name, datetime, servers_address, manual=True):
arrow.get(datetime, app.config['EVENT_DATETIME_STORAGE_FORMAT']) # Just to validate

Variable.set_value(VARIABLE_NAME, {
'name': name,
'datetime': datetime,
'servers_address': servers_address.split(',') if servers_address else []
'servers_address': servers_address.split(',') if servers_address else [],
'manual': manual
})


Expand Down

0 comments on commit 77b6408

Please sign in to comment.