Skip to content

Commit

Permalink
auto-create guild contribution associated with guild for integration (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Flip-Liquid authored Jun 21, 2023
1 parent d8bfcf3 commit 2bf63cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion apps/jobs/twitter-contribution/twitter_contribution/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ async def create_job_run(name: str, start: str, end: str):


async def create_twitter_hashtag_contribution(
tweet: Tweet, user_id: int, user_name: str, hashtag: str
tweet: Tweet, user_id: int, user_name: str, hashtag: str, guild_id: int
):
mutation = """
mutation createStagedContribution($data: ContributionCreateInput!) {
Expand Down Expand Up @@ -327,6 +327,15 @@ async def create_twitter_hashtag_contribution(
}
}
},
"guilds": {
"create": {
"guild": {
"connect": {
"id": guild_id,
}
}
}
},
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def process_guild_integrations():
logger.info(f"Processing tweets for hashtag {hashtag} since {since}")
tweets = await retrieve_tweets(hashtag, since)
logger.info(f"Retrieved {len(tweets)} tweets for hashtag {hashtag}")
await process_tweets(integration, tweets)
await process_tweets(integration, tweets, guild["id"])
# TODO: err handling
logger.info(f"Processed {len(tweets)} tweets for hashtag {hashtag}")

Expand All @@ -46,7 +46,7 @@ async def process_guild_integrations():


# TODO: parallelize
async def process_tweets(guild_integration, tweets: list[Tweet]):
async def process_tweets(guild_integration, tweets: list[Tweet], guild_id: int):
for tweet in tweets:
# check if user has profile and linked twitter account
user = await get_user_by_twitter(tweet.profile_handle)
Expand Down Expand Up @@ -82,5 +82,5 @@ async def process_tweets(guild_integration, tweets: list[Tweet]):
f"Creating contribution for tweet {tweet.id} by user {tweet.profile_handle}"
)
await create_twitter_hashtag_contribution(
tweet, user["id"], user["name"], guild_integration["hashtag"]
tweet, user["id"], user["name"], guild_integration["hashtag"], guild_id
)

0 comments on commit 2bf63cf

Please sign in to comment.