diff --git a/.assets/oauth.png b/.assets/oauth.png new file mode 100644 index 0000000..646eaa0 Binary files /dev/null and b/.assets/oauth.png differ diff --git a/.assets/welcome-message.png b/.assets/welcome-message.png new file mode 100644 index 0000000..b886034 Binary files /dev/null and b/.assets/welcome-message.png differ diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2a65bce..5023e50 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,11 @@ jobs: && sudo apt-get install -y git # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 + + - uses: actions/checkout@v3 + # fetch all history for all branches and tags, so that our `make` targets can get tags + with: + fetch-depth: 0 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index b527904..ca66f02 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -11,6 +11,8 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Build the Docker image - run: docker build . --file Dockerfile + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Build the Docker image + run: docker build . --file Dockerfile diff --git a/.gitignore b/.gitignore index f2e14de..b2e97c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ **/*.swp whodis.exe +whodis .env -servers \ No newline at end of file +servers diff --git a/Dockerfile b/Dockerfile index 3397637..f102b68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,9 @@ RUN go mod download COPY . . +# Get latest tag +RUN git describe --abbrev=0 > /version + RUN go install github.com/UCCNetsoc/whodis/cmd/whodis CMD [ "go", "run", "*.go" ] @@ -22,5 +25,6 @@ FROM alpine WORKDIR /bin COPY --from=dev /go/bin/whodis ./whodis +COPY --from=dev /version /version -CMD ["sh", "-c", "whodis -p"] \ No newline at end of file +CMD ["sh", "-c", "export BOT_VERSION=$(cat /version) && whodis -p"] diff --git a/README.md b/README.md index 3023f84..6419444 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,68 @@ # Whodis -Discord bot & API to both authenticate and authorize discord members +[![CI](https://github.com/UCCNetsoc/whodis/actions/workflows/main.yml/badge.svg)](https://github.com/UCCNetsoc/whodis/actions/workflows/main.yml) [![!Whodis Bot Invite link](https://img.shields.io/badge/Whodis-Bot%20Invite-9cf)](https://google.com) + +A discord bot and API to authenticate Discord members as being UCC students. + +## How it works + +When a new user joins your _registration channel_, they will see a message from Whodis, welcoming them to the server, and prompts them to click a button to register. + +Welcome Message + +When they click the button, Whodis takes note of their Discord ID, and sends a message only they can see with a button, which will direct them to login page with their UCC Umail account as an option. After successfully choosing their Umail account, they will come to a landing page informing them of their successful authentication. + + + +When they go back to Discord, they will have gained a role(s), giving them permission to see more of the server. + +--- + +## How Do I Use this Bot on my Server? + +A server member with Admin privileges can add the bot to their server by doing the following: + +1. Invite Whodis to your Discord server. +2. Create the `@Member` role. Make this role able to access normal channels in your server. +3. Create a `#registration` and `#registration-help` channel. Make these channels incassessible by `@Member`, but allow moderators and `@everyone`. This way, only newly-joined users and moderators can see these channels. + +> Note this will make it so all existing non-moderator members of your Discord server will either have to be manually given the `@Member` role, or authenticate with Whodis. + +4. In the `#registration` channel, run the `/setup` command, and give the parameters you require. + +| Parameter | Required | Description | +| ------------------- | --------- | ------------------------------------------------------------------------| +| `announce-channel` | ✅ | The channel where new users are announc ed | +| `logging-channel` | ✅ | The channel where logs are sent | +| `additional-role-1` | ❌ | An additional role that can be given to new members, e.g. `@22/23` | +| `additional-role-2` | ❌ | Another additional role that can be given to new members, e.g. `@newbies` | + +--- + +## Need to use a different Mail Domain or want to self-host this Bot? + +If you need to use a mail domain that isn't `umail.ucc.ie` you can fork this repo and use Docker to run the bot, providing a specific mail domain to use through environment variables. + +To see all necessary environment variables, check [defaults.go](./config/defaults.go) (Environment variables will be in the form of UPPER_CASE). + +--- + +## Privacy Concerns + +Whodis and as such, Netsoc do not collect any personal information, as the bot and API are stateless. When a user clicks the first button, the following data is encoded into a new button: + +- The User's Discord ID +- The Server's registered role, and an optional second role to give to newly-registered users. +- The server's Guild ID +- The server's welcome message Channel ID +- The server's moderator logging Channel ID + +This data does not get stored on any database, and is encrypted on the backend, to stop a user tampering-with and gaining access to a role not intended for them to have. + +**_Whodis does not store any Users' Discord ID or Umail address_** + +--- + +## Help + +If you have any questions or need help, please contact the Netsoc SysAdmins on [discord](https://discord.netsoc.co/), by email at [netsoc@uccsocieties.ie](mailto:netsoc@uccsocieties.ie), or [create an issue](https://github.com/UCCNetsoc/whodis/issues/new). diff --git a/cmd/whodis/main.go b/cmd/whodis/main.go index be99bbe..1a01e2f 100644 --- a/cmd/whodis/main.go +++ b/cmd/whodis/main.go @@ -35,9 +35,11 @@ func main() { log.WithError(err) return } + go api.InitAPI(s) + s.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) { - log.Info("Bot is has registered handlers") + log.Info("Bot has registered handlers") }) s.Open() commands.RegisterSlashCommands(s) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..85090cc --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: '3.7' + +services: + bot: + build: . + container_name: whodis_local + ports: + - "8080:8080" + environment: + DISCORD_TOKEN: ${DISCORD_TOKEN} + DISCORD_APP_ID: ${DISCORD_APP_ID} + DISCORD_BOT_INVITE: ${DISCORD_BOT_INVITE} + API_URL: ${API_URL} + API_PORT: '8080' + API_SECRET: ${API_SECRET} + OAUTH_GOOGLE_ID: ${OAUTH_GOOGLE_ID} + OAUTH_GOOGLE_SECRET: ${OAUTH_GOOGLE_SECRET} diff --git a/internal/api/assets/result.html b/internal/api/assets/result.html index 8214b04..28d1d8b 100644 --- a/internal/api/assets/result.html +++ b/internal/api/assets/result.html @@ -15,7 +15,9 @@ font-size: 14px; font-weight: 400; font-family: Roboto, sans-serif !important; - color: #fff + color: #fff; + min-height: 100vh; + position: relative; } #header { @@ -39,12 +41,12 @@ #content-body { padding-top: 16px; border-top: 1px solid #333; - color: gray; + color: #b9b9b9; border-bottom: 1px solid #333 } p { - max-width: 380px; + max-width: 400px; margin: 0 auto; padding: 16px; } @@ -87,6 +89,15 @@ a { color: #fff } + + footer { + width: 100%; + position: absolute; + left: 0; + right: 0; + bottom: 0; + padding-bottom: 16px; + }