-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name : Wiki Mention Notifier | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
username: | ||
description: 'The username of the community member to notify' | ||
required: true | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Update Wiki | ||
env: | ||
REDDIT_CLIENT_ID: ${{ secrets.REDDIT_CLIENT_ID }} | ||
REDDIT_CLIENT_SECRET: ${{ secrets.REDDIT_CLIENT_SECRET }} | ||
REDDIT_PASSWORD: ${{ secrets.REDDIT_PASSWORD }} | ||
REDDIT_USERNAME: ${{ secrets.REDDIT_USERNAME }} | ||
run: | | ||
cd wiki-mention | ||
python main.py ${{ github.event.inputs.username }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import praw | ||
import os | ||
|
||
# Reddit API credentials | ||
client_id = os.environ["REDDIT_CLIENT_ID"] | ||
client_secret = os.environ["REDDIT_CLIENT_SECRET"] | ||
reddit_pass = os.environ["REDDIT_PASSWORD"] | ||
username = os.environ["REDDIT_USERNAME"] | ||
user_agent = "Wiki Mention Notifier" | ||
sub = "developersIndia" | ||
|
||
# Create a Reddit instance | ||
reddit = praw.Reddit( | ||
client_id=client_id, | ||
client_secret=client_secret, | ||
password=reddit_pass, | ||
user_agent=user_agent, | ||
username=username, | ||
) | ||
|
||
def send_message(reddit, username): | ||
message_subject = 'Woohoo! Your advice/perspective is now part of our wiki!' | ||
message_text = """ | ||
Hi there,\n | ||
It looks like one of your comments on r/developersIndia was picked-up by the volunteer team to be part of our [community-driven wiki](https://wiki.developersindia.in/).\n | ||
- You can find your advice by searching your username in our [Wiki](https://wiki.developersindia.in/).\n | ||
- We can't thank you enough for your valuable contribution to our community 🧡\n\n | ||
Please keep contributing productively!\n | ||
Cheers,\n | ||
The r/developersIndia Community Team | ||
""" | ||
reddit.redditor(username).message( | ||
subject=message_subject, message=message_text, from_subreddit=reddit.subreddit(sub) | ||
) | ||
|
||
|
||
def add_mod_note_good_contributor(reddit, username): | ||
subreddit = reddit.subreddit(sub) | ||
subreddit.mod.notes.create( | ||
redditor=username, | ||
label="HELPFUL_USER", | ||
note="Their advice/perspective was mentioned in our wiki.", | ||
) | ||
|
||
def main(): | ||
if len(os.sys.argv) != 2: | ||
print("Usage: python main.py <username>") | ||
return | ||
|
||
reddit_username = os.sys.argv[1] | ||
|
||
send_message(reddit, reddit_username) | ||
add_mod_note_good_contributor(reddit, reddit_username) | ||
print(f"Sent wiki mention modmail to {reddit_username}") | ||
|
||
if __name__ == "__main__": | ||
main() |