-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (48 loc) · 1.72 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from typing import Final
import os
from dotenv import load_dotenv
from discord import Intents, Client, Message
import requests
# Load our token and repo details from dotenv
load_dotenv()
TOKEN: Final[str] = os.getenv('DISCORD_TOKEN')
REPO_OWNER: Final[str] = os.getenv('REPO_OWNER')
REPO_NAME: Final[str] = os.getenv('REPO_NAME')
# Load the username map from the .env file
username_map = dict(os.environ)
# Initialize the Discord client
intents = Intents.default()
intents.messages = True
client = Client(intents=intents)
def get_discord_username(github_username):
# Map GitHub usernames to Discord usernames
return username_map.get(github_username, github_username)
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message: Message):
print('Triggered on_message function')
if message.author == client.user:
return
print('!get_backlog')
backlog = get_backlog()
if backlog:
await message.channel.send(backlog)
else:
await message.channel.send('Error fetching backlog')
def get_backlog() -> str:
url = f'https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/issues'
response = requests.get(url)
print(response.text) # Print the response for debugging
if response.status_code == 200:
issues = response.json()
backlog = ''
for issue in issues:
assignees = ', '.join(get_discord_username(assignee['login']) for assignee in issue.get('assignees', []))
backlog += f"Task: {issue['title']} - Assignees: {assignees}\n"
return backlog
else:
print('Error fetching backlog')
return None # Return None instead of a string
client.run(TOKEN)