Skip to content

Commit

Permalink
Added REGION_NAME envar
Browse files Browse the repository at this point in the history
  • Loading branch information
minimike86 committed Oct 26, 2024
1 parent a03dc41 commit 5ba3405
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,31 +81,31 @@ jobs:
- name: Run tests
run: |
poetry run pytest --tb=short | tee pytest_output.txt
poetry run pytest --disable-pytest-warnings --tb=short | tee pytest_output.txt
- name: Display test results in summary
if: always()
run: |
echo "### 🎉 Test Summary Report 🎉" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Display results in table format
echo "| Status | Test |" >> $GITHUB_STEP_SUMMARY
echo "| ------ | ---- |" >> $GITHUB_STEP_SUMMARY
# Determine the overall result
if grep -q "failed" pytest_output.txt; then
echo "| ❌ | Some tests failed |" >> $GITHUB_STEP_SUMMARY
else
echo "| ✅ | All tests passed |" >> $GITHUB_STEP_SUMMARY
fi
# Add coverage output
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🚧 Coverage Output 🚧" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat coverage_output.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
# # Display results in table format
# echo "| Status | Test |" >> $GITHUB_STEP_SUMMARY
# echo "| ------ | ---- |" >> $GITHUB_STEP_SUMMARY
#
# # Determine the overall result
# if grep -q "failed" pytest_output.txt; then
# echo "| ❌ | Some tests failed |" >> $GITHUB_STEP_SUMMARY
# else
# echo "| ✅ | All tests passed |" >> $GITHUB_STEP_SUMMARY
# fi
#
# # Add coverage output
# echo "" >> $GITHUB_STEP_SUMMARY
# echo "### 🚧 Coverage Output 🚧" >> $GITHUB_STEP_SUMMARY
# echo '```' >> $GITHUB_STEP_SUMMARY
# cat coverage_output.txt >> $GITHUB_STEP_SUMMARY
# echo '```' >> $GITHUB_STEP_SUMMARY

# Add full detailed output
echo "" >> $GITHUB_STEP_SUMMARY
Expand Down
34 changes: 19 additions & 15 deletions twitchrce/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ async def refresh_user_token(user: any) -> str:
Start the pubsub client for the Twitch channel
"""

dynamodb = boto3.resource("dynamodb")
BOT_CONFIG = bot_config.BotConfig().get_bot_config()
dynamodb = boto3.resource(
"dynamodb", region_name=BOT_CONFIG.get("aws").get("region_name")
)
user_table = dynamodb.Table("MSecBot_User")


async def setup_bot():
print(f"{Fore.RED}Starting TwitchRCE!{Style.RESET_ALL}")
config = bot_config.BotConfig().get_bot_config()

# init asyncio
loop = asyncio.new_event_loop()
Expand All @@ -93,7 +95,7 @@ async def setup_bot():
bot_user = None
try:
response = user_table.get_item(
Key={"id": int(config.get("twitch").get("bot_user_id"))}
Key={"id": int(BOT_CONFIG.get("twitch").get("bot_user_id"))}
)
bot_user = response.get("Item", 0)
if not bot_user.get("access_token"):
Expand All @@ -120,7 +122,7 @@ async def setup_bot():

redirect_uri = "https://3yyduoz2ok.execute-api.eu-west-2.amazonaws.com/twitch/oauth2/authorization_code"
authorization_url = (
f"https://id.twitch.tv/oauth2/authorize?client_id={config.get('twitch').get('client_id')}"
f"https://id.twitch.tv/oauth2/authorize?client_id={BOT_CONFIG.get('twitch').get('client_id')}"
f"&force_verify=true"
f"&redirect_uri={redirect_uri}"
f"&response_type=code"
Expand All @@ -136,12 +138,12 @@ async def setup_bot():
loop.run_until_complete(check_valid_token(user=bot_user))
except IndexError:
print(
f"{Fore.RED}Failed to get bot user token for {Fore.MAGENTA}{config.get('twitch').get('bot_user_id')}{Fore.RED}!"
f"{Fore.RED}Failed to get bot user token for {Fore.MAGENTA}{BOT_CONFIG.get('twitch').get('bot_user_id')}{Fore.RED}!"
f"{Style.RESET_ALL}"
)
exit(0)

ec2 = boto3.client("ec2", region_name=config.get("aws").get("region_name"))
ec2 = boto3.client("ec2", region_name=BOT_CONFIG.get("aws").get("region_name"))
response = ec2.describe_instances(
InstanceIds=["i-0100638f13e5451d8"]
) # TODO: Don't hardcode InstanceIds
Expand All @@ -151,12 +153,12 @@ async def setup_bot():
bot = CustomBot(
app_access_token=app_access_token,
user_token=bot_user.get("access_token"),
initial_channels=[config.get("twitch").get("bot_join_channel")],
initial_channels=[BOT_CONFIG.get("twitch").get("bot_join_channel")],
eventsub_public_url=f"https://{public_dns}",
)
bot.from_client_credentials(
client_id=config.get("twitch").get("client_id"),
client_secret=config.get("twitch").get("client_secret"),
client_id=BOT_CONFIG.get("twitch").get("client_id"),
client_secret=BOT_CONFIG.get("twitch").get("client_secret"),
)

"""
Expand All @@ -170,7 +172,7 @@ async def setup_bot():
"""
try:
response = user_table.get_item(
Key={"id": config.get("twitch").get("bot_join_channel_id")}
Key={"id": BOT_CONFIG.get("twitch").get("bot_join_channel_id")}
)
channel_user = response["Item"]
bot.loop.run_until_complete(
Expand All @@ -181,7 +183,7 @@ async def setup_bot():
)
except IndexError:
print(
f"{Fore.RED}Failed to get channel user token for {Fore.MAGENTA}{config.get('twitch').get('bot_join_channel')}{Fore.RED}!"
f"{Fore.RED}Failed to get channel user token for {Fore.MAGENTA}{BOT_CONFIG.get('twitch').get('bot_join_channel')}{Fore.RED}!"
f"{Style.RESET_ALL}"
)
exit(0)
Expand Down Expand Up @@ -325,7 +327,9 @@ async def event_eventsub_notification_cheer(
channel = await bot._http.get_channels(broadcaster_id=payload.data.user.id)
clips = await bot._http.get_clips(broadcaster_id=payload.data.user.id)
# Acknowledge raid and reply with a channel bio
await bot.get_channel(config.get("twitch").get("bot_join_channel")).send(
await bot.get_channel(
BOT_CONFIG.get("twitch").get("bot_join_channel")
).send(
f"Thank you @{channel[0]['broadcaster_login']} for cheering {payload.data.bits} bits!"
)
# shoutout the subscriber
Expand Down Expand Up @@ -380,7 +384,7 @@ async def event_eventsub_notification_subscription(
if len(channel) >= 1:
try:
await bot.get_channel(
config.get("twitch").get("bot_join_channel")
BOT_CONFIG.get("twitch").get("bot_join_channel")
).send(
f"Thank you @{channel[0]['broadcaster_login']} for the tier {payload.data.tier / 1000} "
f"subscription!"
Expand All @@ -394,7 +398,7 @@ async def event_eventsub_notification_subscription(
if len(clips) >= 1:
"""check if sub is a streamer with clips on their channel and shoutout with clip player"""
await bot.get_channel(
config.get("twitch").get("bot_join_channel")
BOT_CONFIG.get("twitch").get("bot_join_channel")
).send(f"!so {channel[0]['broadcaster_login']}")
await bot.announce_shoutout(
ctx=None,
Expand Down Expand Up @@ -437,7 +441,7 @@ async def event_eventsub_notification_subscription(
if len(channel) >= 1:
try:
await bot.get_channel(
config.get("twitch").get("bot_join_channel")
BOT_CONFIG.get("twitch").get("bot_join_channel")
).send(
f"Congratulations @{channel[0]['broadcaster_login']} on receiving a "
f"gifted tier {int(payload.data.tier / 1000)} subscription!"
Expand Down

0 comments on commit 5ba3405

Please sign in to comment.