aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Dockerfile12
-rw-r--r--bot/api.py2
-rw-r--r--config-default.yml6
-rw-r--r--scripts/deploy-azure.sh4
-rw-r--r--scripts/deploy.sh32
-rw-r--r--tests/utils/__init__.py0
-rw-r--r--tests/utils/test_checks.py67
7 files changed, 75 insertions, 48 deletions
diff --git a/Dockerfile b/Dockerfile
index 864b4e557..aa6333380 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -14,15 +14,7 @@ RUN apk add --no-cache \
zlib-dev
ENV \
- LIBRARY_PATH=/lib:/usr/lib \
- PIPENV_HIDE_EMOJIS=1 \
- PIPENV_HIDE_EMOJIS=1 \
- PIPENV_IGNORE_VIRTUALENVS=1 \
- PIPENV_IGNORE_VIRTUALENVS=1 \
- PIPENV_NOSPIN=1 \
- PIPENV_NOSPIN=1 \
- PIPENV_VENV_IN_PROJECT=1 \
- PIPENV_VENV_IN_PROJECT=1
+ LIBRARY_PATH=/lib:/usr/lib
RUN pip install -U pipenv
@@ -32,4 +24,4 @@ COPY . .
RUN pipenv install --deploy --system
ENTRYPOINT ["/sbin/tini", "--"]
-CMD ["pipenv", "run", "start"]
+CMD ["python3", "-m", "bot"]
diff --git a/bot/api.py b/bot/api.py
index 9a0ebaa26..3acde242e 100644
--- a/bot/api.py
+++ b/bot/api.py
@@ -124,7 +124,7 @@ class APILoggingHandler(logging.StreamHandler):
# 1. Do not log anything below `DEBUG`. This is only applicable
# for the monkeypatched `TRACE` logging level, which has a
# lower numeric value than `DEBUG`.
- record.levelno > logging.DEBUG
+ record.levelno >= logging.DEBUG
# 2. Ignore logging messages which are sent by this logging
# handler itself. This is required because if we were to
# not ignore messages emitted by this handler, we would
diff --git a/config-default.yml b/config-default.yml
index b31f79272..01bdcd1e7 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -1,5 +1,5 @@
bot:
- prefix: "!"
+ prefix: "."
token: !ENV "BOT_TOKEN"
cooldowns:
@@ -234,7 +234,7 @@ keys:
urls:
# PyDis site vars
- site: &DOMAIN "pythondiscord.com"
+ site: &DOMAIN "django.pythondiscord.com"
site_api: &API !JOIN ["api.", *DOMAIN]
site_paste: &PASTE !JOIN ["paste.", *DOMAIN]
site_staff: &STAFF !JOIN ["staff.", *DOMAIN]
@@ -261,7 +261,7 @@ urls:
paste_service: !JOIN [*SCHEMA, *PASTE, "/{key}"]
# Snekbox
- snekbox_eval_api: "http://localhost:8060/eval"
+ snekbox_eval_api: "https://snekbox.pythondiscord.com/eval"
# Env vars
deploy: !ENV "DEPLOY_URL"
diff --git a/scripts/deploy-azure.sh b/scripts/deploy-azure.sh
index 9ffe01ab8..ed4b719e2 100644
--- a/scripts/deploy-azure.sh
+++ b/scripts/deploy-azure.sh
@@ -2,8 +2,8 @@
cd ..
-# Build and deploy on django branch, only if not a pull request
-if [[ ($BUILD_SOURCEBRANCHNAME == 'django') && ($SYSTEM_PULLREQUEST_PULLREQUESTID == '') ]]; then
+# Build and deploy on master branch, only if not a pull request
+if [[ ($BUILD_SOURCEBRANCHNAME == 'master') && ($SYSTEM_PULLREQUEST_PULLREQUESTID == '') ]]; then
echo "Building image"
docker build -t pythondiscord/bot:latest .
diff --git a/scripts/deploy.sh b/scripts/deploy.sh
deleted file mode 100644
index 070d0ec26..000000000
--- a/scripts/deploy.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/bash
-
-# Build and deploy on master branch
-if [[ $CI_COMMIT_REF_SLUG == 'master' ]]; then
- echo "Connecting to docker hub"
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
-
- changed_lines=$(git diff HEAD~1 HEAD docker/base.Dockerfile | wc -l)
-
- if [ $changed_lines != '0' ]; then
- echo "base.Dockerfile was changed"
-
- echo "Building bot base"
- docker build -t pythondiscord/bot-base:latest -f docker/base.Dockerfile .
-
- echo "Pushing image to Docker Hub"
- docker push pythondiscord/bot-base:latest
- else
- echo "base.Dockerfile was not changed, not building"
- fi
-
- echo "Building image"
- docker build -t pythondiscord/bot:latest -f docker/bot.Dockerfile .
-
- echo "Pushing image"
- docker push pythondiscord/bot:latest
-
- echo "Deploying container"
- curl -H "token: $AUTODEPLOY_TOKEN" $AUTODEPLOY_WEBHOOK
-else
- echo "Skipping deploy"
-fi
diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/utils/__init__.py
diff --git a/tests/utils/test_checks.py b/tests/utils/test_checks.py
new file mode 100644
index 000000000..915d074b3
--- /dev/null
+++ b/tests/utils/test_checks.py
@@ -0,0 +1,67 @@
+from unittest.mock import MagicMock
+
+from bot.utils import checks
+
+
+def test_with_role_check_without_guild():
+ context = MagicMock()
+ context.guild = None
+
+ assert not checks.with_role_check(context)
+
+
+def test_with_role_check_with_guild_without_required_role():
+ context = MagicMock()
+ context.guild = True
+ context.author.roles = []
+
+ assert not checks.with_role_check(context)
+
+
+def test_with_role_check_with_guild_with_required_role():
+ context = MagicMock()
+ context.guild = True
+ role = MagicMock()
+ role.id = 42
+ context.author.roles = (role,)
+
+ assert checks.with_role_check(context, role.id)
+
+
+def test_without_role_check_without_guild():
+ context = MagicMock()
+ context.guild = None
+
+ assert not checks.without_role_check(context)
+
+
+def test_without_role_check_with_unwanted_role():
+ context = MagicMock()
+ context.guild = True
+ role = MagicMock()
+ role.id = 42
+ context.author.roles = (role,)
+
+ assert not checks.without_role_check(context, role.id)
+
+
+def test_without_role_check_without_unwanted_role():
+ context = MagicMock()
+ context.guild = True
+ role = MagicMock()
+ role.id = 42
+ context.author.roles = (role,)
+
+ assert checks.without_role_check(context, role.id + 10)
+
+
+def test_in_channel_check_for_correct_channel():
+ context = MagicMock()
+ context.channel.id = 42
+ assert checks.in_channel_check(context, context.channel.id)
+
+
+def test_in_channel_check_for_incorrect_channel():
+ context = MagicMock()
+ context.channel.id = 42
+ assert not checks.in_channel_check(context, context.channel.id + 10)