Skip to content

Commit

Permalink
make blocker tool more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
deathg-rip committed May 16, 2024
1 parent 2a5f90f commit 050ff2c
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 2 deletions.
Binary file added .DS_Store
Binary file not shown.
File renamed without changes.
3 changes: 2 additions & 1 deletion data/congo-aware.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default [
"kenzie_haha_1",
"pappyorion",
"juicebae",
"focuscongo"
"focuscongo",
"popi_sibiya"
]
20 changes: 20 additions & 0 deletions install.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Loading...</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
</style>
</head>
<body>
<img src="spinner.gif" alt="Loading...">
</body>
</html>
101 changes: 101 additions & 0 deletions scripts/bootstrap.macos.command
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash

# This script will install the necessary dependencies for the project
# and will also install the project itself.

# In the future we can make an install wizard that runs this script
# through a browser window. This way we can guide the user through
# the installation process and provide them with the necessary
# information to get started.
#
# ```
# open ../insall.html
# ```

# Check for the existence of brew
if ! command -v brew &> /dev/null
then
# Prompt user for password
# This is required to install Homebrew
PASSWORD=$(osascript -e "Tell application \"System Events\" to display dialog \"Enter your password:\" default answer \"\" with hidden answer" -e "text returned of result")

# Handle empty password
while [ -z "$PASSWORD" ]; do
PASSWORD=$(osascript -e "Tell application \"System Events\" to display dialog \"A password wasn't entered. \n\nEnter your password:\" default answer \"\" with hidden answer" -e "text returned of result")
done

# Install Homebrew using the captured password
# Homebrew is a package manager for macOS.
echo $PASSWORD | sudo -S /usr/bin/env bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [ $? -eq 0 ]; then
echo "Homebrew installation successful."
else
echo "Homebrew installation failed."
osascript -e "Tell application \"System Events\" to display dialog \"Homebrew installation failed.\n\n That's a problem and it means Starfall can't be installed.\" buttons {\"OK\"} default button \"OK\""
exit 1
fi
else
echo "Homebrew is already installed."
fi


# Check for the existence of git

if ! command -v git &> /dev/null
then
# Install git using Homebrew
/usr/bin/env bash -c "brew install git"
if [ $? -eq 0 ]; then
echo "Git installation successful."
else
echo "Git installation failed."
osascript -e "Tell application \"System Events\" to display dialog \"Git installation failed.\n\n That's a problem and it means Starfall can't be installed.\" buttons {\"OK\"} default button \"OK\""
exit 1
fi
else
echo "Git is already installed."
fi

# Install nvm
# nvm is a version manager for node.js.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

# Clone the project to tmp directory so we can launch the browser to automate account creation etc.
rm -rf /tmp/starfall
cd /tmp/ && git clone https://github.com/NyanHelsing/starfall.git
cd starfall

# AppleScript command to show a Yes/No modal dialog
HAS_GITHUB_ACCOUNT_RESPONSE=$(osascript <<EOF
tell application "System Events"
set userResponse to button returned of (display dialog "Do you already have a GitHub account?" buttons {"No", "Yes"} default button "No")
end tell
EOF
)

# Check the response and set a shell variable
if [ "$HAS_GITHUB_ACCOUNT_RESPONSE" = "Yes" ]; then
echo "Has GitHub account"
else
echo "Does not have GitHub account"

fi


# Check if the user has a ssh key
if [ -f ~/.ssh/id_ed25519.pub ]; then
echo "SSH key exists"
else
echo "SSH key does not exist"
SSH_KEY_COMMENT=$(osascript <<EOF
tell application "System Events"
set sshKeyComment to text returned of (display dialog "Enter a comment for your SSH key. If or when some change is contributed back to starfall, this key is used. Since it's possible to have multiple keys, for example if you have multiple accounts or multiple devices, this comment helps distinguish what change was made where. It may be publicly visible so do not use a sensitive phrase or word but feel free to make it something fun if you like!" default answer "starfall" buttons {"OK"} default button "OK")
end tell
EOF
)
ssh-keygen -t ed25519 -C "$SSH_KEY_COMMENT"
fi
3 changes: 3 additions & 0 deletions scripts/test.command
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo "Hello, World!"
12 changes: 11 additions & 1 deletion tests/block.auto.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ digitineList.forEach((username) => {
auto(`blocking ${username}`, async ({ page }) => {
await page.goto(`https://www.tiktok.com/@${username}`); // Go to the profile of the user who is to be blocked.
// TODO: check if the user is already blocked
await new Promise(r => setTimeout(r, 400));
await page.getByLabel('Actions').click(); // Click the three dots to open the actions menu.
await page.getByLabel('Block').click(); // Click the "Block" button.
await new Promise(r => setTimeout(r, 800));
try {
await page.getByLabel('Block', { exact: true }).click({
timeout: 1200
}); // Click the "Block" button.
await new Promise(r => setTimeout(r, 800));
} catch (e) {
// The user is already blocked.
return;
}
// The modal is expected to open.
await page.locator('#tux-portal-container').getByRole('button', { name: 'Block' }).click(); // Click the "Block" button in the modal.
// The block has been successful.
Expand Down
10 changes: 10 additions & 0 deletions tests/github.create-account.auto.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { test as auto } from '@playwright/test';

auto('test', async ({ page }) => {
await page.goto('https://www.tiktok.com/explore');
await page.goto('https://github.com/');
await page.getByRole('link', { name: 'Sign up' }).click();
await page.getByLabel('Enter your email*').click();
await page.getByLabel('Open user account menu').click();
await page.getByRole('dialog').getByText('me-nyanhelsing').click();
});

0 comments on commit 050ff2c

Please sign in to comment.