Skip to content

Commit

Permalink
Merge pull request #3647 from KBVE/dev
Browse files Browse the repository at this point in the history
Preparing Alpha Branch
  • Loading branch information
h0lybyte authored Jan 2, 2025
2 parents b5523ce + 9bf68d6 commit 80101b2
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 30 deletions.
3 changes: 2 additions & 1 deletion apps/atlas/kbve_atlas/api/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
from .screen_client import ScreenClient
from .novnc_client import NoVNCClient
from .runelite_client import RuneLiteClient
from .chrome_client import ChromeClient
from .chrome_client import ChromeClient
from .discord_client import DiscordClient
99 changes: 99 additions & 0 deletions apps/atlas/kbve_atlas/api/clients/discord_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import os
import json
from ..clients.chrome_client import ChromeClient
import logging
import re
from asyncio import sleep

logger = logging.getLogger("uvicorn")

class DiscordClient:
def __init__(self, headless=True, display=":1"):
self.headless = headless
self.display = display
self.chrome_client = ChromeClient(headless=headless, display=display)

async def login_with_passkey(self, discord_url="https://discord.com/login", passkey=None, retries=3):
"""
Logs into Discord by injecting the passkey into localStorage.
:param discord_url: URL for Discord login
:param passkey: Discord passkey (token). If None, retrieves from environment variable.
:param retries: Number of retry attempts for login in case of failure.
:return: Success or error message.
"""
passkey = passkey or os.getenv("DISCORD_PASSKEY")
if not passkey:
raise ValueError("Passkey not provided. Set it as an argument or in the DISCORD_PASSKEY environment variable.")

# Validate the token format (alphanumeric with optional underscores, hyphens, or dots)
if not re.match(r"^[A-Za-z0-9_\-\.]+$", passkey):
raise ValueError("Invalid token format. Discord tokens should be alphanumeric with optional underscores, hyphens, or dots.")


for attempt in range(retries):
try:
logger.info(f"Attempt {attempt + 1} to log into Discord")
await self.chrome_client.start_chrome_async()

logger.info(f"Opening Discord URL: {discord_url}")
await self.chrome_client.perform_task_with_chrome(discord_url)

logger.info("Injecting passkey into localStorage")
self.chrome_client.sb.execute_script(f'''
window.localStorage.setItem('token', '{passkey}');
''')

logger.info("Refreshing the page to apply the token")
self.chrome_client.sb.refresh()

logger.info("Checking for successful login")
if self.chrome_client.sb.is_element_visible('[data-testid="user-settings"]', timeout=10):
logger.info("Discord login verified successfully.")
return "Logged into Discord using passkey successfully."
else:
logger.warning("Failed to verify Discord login.")
return "Failed to verify Discord login."
except Exception as e:
logger.warning(f"Attempt {attempt + 1} failed: {e}")
if attempt < retries - 1:
await sleep(2) # Wait before retrying
else:
raise e
finally:
await self.chrome_client.stop_chrome_async()

async def verify_login(self):
"""
Verifies if the user is logged into Discord by checking for an authenticated element.
:return: Boolean indicating login success or failure.
"""
try:
# Check if a Discord-specific element is visible after login
if self.chrome_client.sb.is_element_visible('[data-testid="user-settings"]'):
logger.info("Discord login verified successfully.")
return True
else:
logger.warning("Discord login verification failed.")
return False
except Exception as e:
logger.error(f"Failed to verify login: {e}")
return False

async def fetch_discord_data(self):
"""
Example method to demonstrate fetching data from Discord after login.
You can customize this based on your requirements.
"""
try:
# Navigate to a page and extract data
guild_url = "https://discord.com/channels/@me"
await self.chrome_client.perform_task_with_chrome(guild_url)

# Extract some example data (like user settings or guild info)
user_data = self.chrome_client.sb.get_text('[data-testid="user-settings"]')
logger.info(f"Fetched user data: {user_data}")
return user_data
except Exception as e:
logger.error(f"Failed to fetch Discord data: {e}")
return f"Failed to fetch Discord data: {e}"
8 changes: 6 additions & 2 deletions apps/atlas/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from contextlib import asynccontextmanager

from kbve_atlas.api.clients import CoinDeskClient, WebsocketEchoClient, PoetryDBClient, ScreenClient, NoVNCClient, RuneLiteClient, ChromeClient
from kbve_atlas.api.clients import CoinDeskClient, WebsocketEchoClient, PoetryDBClient, ScreenClient, NoVNCClient, RuneLiteClient, ChromeClient, DiscordClient
from kbve_atlas.api.utils import RSSUtility, KRDecorator, CORSUtil, ThemeCore, BroadcastUtility


Expand Down Expand Up @@ -127,4 +127,8 @@ def gitlab_navigation_message(navigation_message):

@kr_decorator.k_r("/go-to-greenboard", ChromeClient, "fetch_embedded_job_board")
def fetch_embedded_job_board(navigation_message):
return navigation_message
return navigation_message

@kr_decorator.k_r("/discord-login", DiscordClient, "login_with_passkey")
def discord_login_message(message):
return message
5 changes: 5 additions & 0 deletions apps/kbve.com/src/content/docs/gaming/rimworld.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Modders have created an extensive array of modifications, ranging from quality-o
Popular mods include those that introduce new biomes, factions, weapons, and animals, as well as those that enhance colony management and automation.
The community is highly active, with modders continually updating their work to stay compatible with the latest game updates and adding innovative features to keep the game fresh and engaging for both new and veteran players.

### Star Wars Mod Collection

This is a quick link to the Rat series for [clone armies](https://steamcommunity.com/sharedfiles/filedetails/?id=2986463286&insideModal=0&requirelogin=1)!
There might be some issues with the 1.5 compatiblity as of 1/1/2025 but got my mando clone army up and running.

### Clean Pathfinding 2

[Official SteamWorkshop Link](https://steamcommunity.com/sharedfiles/filedetails/?id=3260446812)
Expand Down
30 changes: 26 additions & 4 deletions apps/kbve.com/src/content/journal/01-01.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "January: 01"
category: Daily
date: 2024-01-01 12:00:00
date: 2025-01-01 12:00:00
client: Self
unsplash: 1703511606233-9c7537658701
img: https://images.unsplash.com/photo-1703511606233-9c7537658701?crop=entropy&cs=srgb&fm=jpg&ixid=MnwzNjM5Nzd8MHwxfHJhbmRvbXx8fHx8fHx8fDE2ODE3NDg2ODY&ixlib=rb-4.0.3&q=85
Expand Down Expand Up @@ -29,13 +29,35 @@ import { Adsense } from '@kbve/astropad';
- [X] - No Tasks!


## 2025

<Adsense />
- 09:04AM

**Morning**

Next day! Almost refreshed and ready for this whole year!
Its actually cool to be able to loop back finally, but this year is going to be wild and amazing.

- 10:00AM

**Rimworld**

As tradition, the first session of the year should be a rimworld playthrough, I been dying to try that rimworld clone wars mod!
I am going to update the rimworld notes to quickly grab them.

- 02:42PM

**Kilobase**

Updated the kanban board from the postgres side and made sure the older kanban tables were removed.
We will store all that date inside of the Amazon dynamodb but I need to figure out the best way to handle the timestamps for the tables, hmm.
Looks like that TTL is an option in from the Amazon docs but I will have switch back and look through how to call it in Rust.


<Adsense />

### 2024

#### Personal
## 2024

- 10:22am - It is 2024, this might be a bit out there but I think 2025 will come really fast.

Expand Down
34 changes: 34 additions & 0 deletions apps/kbve.com/src/content/journal/12-29.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: 'Decemeber: 29th'
category: Daily
date: 2024-12-29 12:00:00
client: Self
unsplash: 1511512578047-dfb367046420
img: https://images.unsplash.com/photo-1511512578047-dfb367046420?crop=entropy&cs=srgb&fm=jpg&ixid=MnwzNjM5Nzd8MHwxfHJhbmRvbXx8fHx8fHx8fDE2ODE3NDg2ODY&ixlib=rb-4.0.3&q=85
description: Decemeber 29th.
tags:
- daily
---

import { Adsense, Tasks } from '@kbve/astropad';

## 2024

- 01:27PM

**2024**

The year is about to wrap over, kinda weird.
There were some changes to account for!

- 04:01PM

**Salt**

I hate to have this entry but it is what it is.

- 06:06PM

**Unity**

After yesterday, I been spending some time to become better at Unity
27 changes: 27 additions & 0 deletions apps/kbve.com/src/content/journal/12-30.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: 'Decemeber: 30th'
category: Daily
date: 2024-12-30 12:00:00
client: Self
unsplash: 1511512578047-dfb367046420
img: https://images.unsplash.com/photo-1511512578047-dfb367046420?crop=entropy&cs=srgb&fm=jpg&ixid=MnwzNjM5Nzd8MHwxfHJhbmRvbXx8fHx8fHx8fDE2ODE3NDg2ODY&ixlib=rb-4.0.3&q=85
description: Decemeber 30th.
tags:
- daily
---

import { Adsense, Tasks } from '@kbve/astropad';

## 2024

- 10:35AM

**SPY**

Damn $585? Wild.

- 05:40PM

**Time?***

xD.... we deal with it as family
23 changes: 23 additions & 0 deletions apps/kbve.com/src/content/journal/12-31.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: 'Decemeber: 31st'
category: Daily
date: 2024-12-31 12:00:00
client: Self
unsplash: 1511512578047-dfb367046420
img: https://images.unsplash.com/photo-1511512578047-dfb367046420?crop=entropy&cs=srgb&fm=jpg&ixid=MnwzNjM5Nzd8MHwxfHJhbmRvbXx8fHx8fHx8fDE2ODE3NDg2ODY&ixlib=rb-4.0.3&q=85
description: Decemeber 31st.
tags:
- daily
---

import { Adsense, Tasks } from '@kbve/astropad';

## 2024

- 05:19PM

**New Years**

I am super excited for the new year, this is the last entry for this year too?
Its going to be more interesting that I can go back to my early entries.
I will have to also get used of updating the 2024 to 2025.
30 changes: 15 additions & 15 deletions apps/kilobase/sql/kanban/20241222144000_uninstall_kanban.sql
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
-- Start the transaction
BEGIN;

-- Drop the validation trigger on the kanban_boards table
DROP TRIGGER IF EXISTS validate_kanban_data_trigger ON public.kanban_boards;

-- Drop the validation function for kanban_boards JSONB data
DROP FUNCTION IF EXISTS validate_kanban_data;

-- Drop the update trigger on the kanban_items table
DROP TRIGGER IF EXISTS trigger_update_kanban_data ON public.kanban_items;

-- Drop the update function for kanban_boards JSONB data
DROP FUNCTION IF EXISTS update_kanban_data;

-- Drop the access control helper function
DROP FUNCTION IF EXISTS can_access_board;

-- Remove RLS policies from kanban_items
DROP POLICY IF EXISTS allow_all_select_items ON public.kanban_items;
DROP POLICY IF EXISTS allow_all_insert_items ON public.kanban_items;
Expand All @@ -32,6 +17,21 @@ DROP POLICY IF EXISTS allow_all_delete_boards ON public.kanban_boards;
ALTER TABLE public.kanban_boards DISABLE ROW LEVEL SECURITY;
ALTER TABLE public.kanban_items DISABLE ROW LEVEL SECURITY;

-- Drop the access control helper function with CASCADE
DROP FUNCTION IF EXISTS can_access_board CASCADE;

-- Drop the validation trigger on the kanban_boards table
DROP TRIGGER IF EXISTS validate_kanban_data_trigger ON public.kanban_boards;

-- Drop the validation function for kanban_boards JSONB data
DROP FUNCTION IF EXISTS validate_kanban_data;

-- Drop the update trigger on the kanban_items table
DROP TRIGGER IF EXISTS trigger_update_kanban_data ON public.kanban_items;

-- Drop the update function for kanban_boards JSONB data
DROP FUNCTION IF EXISTS update_kanban_data;

-- Drop tables
DROP TABLE IF EXISTS public.kanban_items CASCADE;
DROP TABLE IF EXISTS public.kanban_boards CASCADE;
Expand Down
1 change: 1 addition & 0 deletions apps/rust_kanban/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ async fn main() {
.allow_origin([
"https://kbve.com".parse::<HeaderValue>().unwrap(), // Main domain
"https://kanban.kbve.com".parse::<HeaderValue>().unwrap(), // Subdomain
"https://websocketking.com".parse::<HeaderValue>().unwrap(), // Websocket King Test
"http://localhost".parse::<HeaderValue>().unwrap(), // Localhost for development
"http://127.0.0.1".parse::<HeaderValue>().unwrap(), // Localhost alternative
])
Expand Down
Loading

0 comments on commit 80101b2

Please sign in to comment.