From 8ecddea9f1c019dd795b61b13e239d9cfca87968 Mon Sep 17 00:00:00 2001 From: Guy Keogh Date: Fri, 17 Nov 2023 12:27:31 +0000 Subject: [PATCH 1/8] 418 (#27) * 418 * Added to easter_egg_phrases Three phrases added: - happy halloween - boo - spooktober --------- Co-authored-by: Adrian T Capacite <45900436+AdrianCapacite@users.noreply.github.com> Co-authored-by: David Lynch <98290029+davidlynch-sd@users.noreply.github.com> --- config/configuration_data.json | 1 + 1 file changed, 1 insertion(+) diff --git a/config/configuration_data.json b/config/configuration_data.json index 7736db1..f9f6e28 100644 --- a/config/configuration_data.json +++ b/config/configuration_data.json @@ -81,6 +81,7 @@ "with the boys": "🍻", "keithmas": "🎅", "santanuts":"🎅", + "good night": "🫖", "happy halloween": "🎃", "boo": "😨", "spooktober": "👻" From c0da5f24336cc416dc63e1673776a2988194cd27 Mon Sep 17 00:00:00 2001 From: Sam Curran <83888868+Sam2004-2@users.noreply.github.com> Date: Fri, 17 Nov 2023 22:30:03 +0000 Subject: [PATCH 2/8] Added Regular Expression Checking #37 (#40) Changes to how messages are checked. Uses regex instead of literal string matching to add more expressive config Co-authored-by: David --- CONTRIBUTING.md | 2 +- bot/__init__.py | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 46bce2c..8373a2d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,7 +7,7 @@ 4. Write a concise title 5. Write a good description 6. Sit back and wait for review -7. Accept constructive feedback and comments +7. Build upon constructive feedback and comments 8. Get it merged :) ## General PR Guidelines diff --git a/bot/__init__.py b/bot/__init__.py index a59360a..08cfc6e 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -111,27 +111,29 @@ async def on_message(message): await message.add_reaction(BAD_MORNING_EMOJI) return - if any(element in contents for element in GOOD_MORNING_PHRASES): - print(f'gm detected > "{message.content}" by {message.author}') - if FIRST_GM is False: - FIRST_GM_USER = message.author - FIRST_GM = True + # Use regular expressions to check for good morning phrases small changes + for pattern in GOOD_MORNING_PHRASES: + if re.search(rf'\b{re.escape(pattern)}\b', contents): + print(f'gm detected > "{message.content}" by {message.author}') + if FIRST_GM is False: + FIRST_GM_USER = message.author + FIRST_GM = True + + await message.add_reaction(EARLY_EMOJI) + server_leaders.add_point(message.author) + return - await message.add_reaction(EARLY_EMOJI) server_leaders.add_point(message.author) - return + await message.add_reaction(MORNING_EMOJI) - server_leaders.add_point(message.author) - await message.add_reaction(MORNING_EMOJI) + return + #Performing regular expression checking on easter egg phrases + for egg_phrase, reaction in configuration_data["easter_egg_phrases"].items(): + if re.search(rf'\b{re.escape(egg_phrase)}\b', contents): + await message.add_reaction(reaction) return - for egg_phrase in configuration_data["easter_egg_phrases"].keys(): - if egg_phrase in contents: - await message.add_reaction( - configuration_data["easter_egg_phrases"][egg_phrase] - ) - if DEBUG_MODE: if re.match(PATTERN, contents.lower()): # debug block >1 extracted_number = re.match(PATTERN, contents.lower()).group(1) From 9b1ff1b28c6f583da2e71dd6a5b386f27c73b2cd Mon Sep 17 00:00:00 2001 From: Sam Curran <83888868+Sam2004-2@users.noreply.github.com> Date: Fri, 17 Nov 2023 23:44:03 +0000 Subject: [PATCH 3/8] Added Email Regex Checking (#37) (#41) * Added Regex and Changed Logic * Fixed Regex Changes --- bot/__init__.py | 11 ++++++----- config/configuration_data.json | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index 08cfc6e..a963095 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -128,11 +128,12 @@ async def on_message(message): return - #Performing regular expression checking on easter egg phrases - for egg_phrase, reaction in configuration_data["easter_egg_phrases"].items(): - if re.search(rf'\b{re.escape(egg_phrase)}\b', contents): - await message.add_reaction(reaction) - return + # Performing regular expression checking on easter egg phrases + for egg_phrase, reaction in configuration_data["easter_egg_phrases"].items(): + if re.search(egg_phrase, contents): + await message.add_reaction(reaction) + return + if DEBUG_MODE: if re.match(PATTERN, contents.lower()): # debug block >1 diff --git a/config/configuration_data.json b/config/configuration_data.json index f9f6e28..7d0ba28 100644 --- a/config/configuration_data.json +++ b/config/configuration_data.json @@ -84,6 +84,7 @@ "good night": "🫖", "happy halloween": "🎃", "boo": "😨", - "spooktober": "👻" + "spooktober": "👻", + "\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b": "📧" } } From 9fe4e1f5c4e466e3d4cb848758370407fb0a515a Mon Sep 17 00:00:00 2001 From: David Lynch <98290029+davidlynch-sd@users.noreply.github.com> Date: Sun, 19 Nov 2023 03:16:36 +0000 Subject: [PATCH 4/8] added dockerignore (#38) Refactored Dockerfile to generate a more lightweight image, added a docker-compose file to quickly kick off your application. Also improved security since tokens have to be mounted instead of being built into the image. --- .dockerignore | 5 +++++ .github/workflows/image-build.yaml | 12 ++++++++++++ .github/workflows/json-lint.yaml | 6 +++--- .github/workflows/python-lint.yaml | 4 ++-- Dockerfile | 8 +++----- docker-compose.yml | 6 ++++++ 6 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/image-build.yaml create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2cbfb07 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +README.md +CONTRIBUTING.md +**/__pycache__/ +.git/ +token diff --git a/.github/workflows/image-build.yaml b/.github/workflows/image-build.yaml new file mode 100644 index 0000000..6f68887 --- /dev/null +++ b/.github/workflows/image-build.yaml @@ -0,0 +1,12 @@ +name: "Dev Image Build" +run-name: ${{ github.actor }} Dev Image Build +on: [pull_request] +jobs: + build: + runs-on: ubuntu-latest + steps: + - run: echo "Job triggered by ${{ github.event_name }}." + - uses: actions/checkout@v3 + - run: docker --version + - run: docker build -t morningbot-dev . + - run: docker image ls | grep morningbot-dev diff --git a/.github/workflows/json-lint.yaml b/.github/workflows/json-lint.yaml index 6b1635a..5feac5b 100644 --- a/.github/workflows/json-lint.yaml +++ b/.github/workflows/json-lint.yaml @@ -1,8 +1,8 @@ -name: Json-Validate -run-name: ${{ github.actor }} PR being linted for code cleanliness +name: Json Validate +run-name: ${{ github.actor }} Validating JSON in config files on: [pull_request] jobs: - Lint: + validate: runs-on: ubuntu-latest steps: - run: echo "Job triggered by ${{ github.event_name }} event." diff --git a/.github/workflows/python-lint.yaml b/.github/workflows/python-lint.yaml index 4204f6e..37e646e 100644 --- a/.github/workflows/python-lint.yaml +++ b/.github/workflows/python-lint.yaml @@ -1,8 +1,8 @@ -name: Test-Lint +name: Python Lint run-name: ${{ github.actor }} PR being linted for code cleanliness on: [pull_request] jobs: - Lint: + lint: runs-on: ubuntu-latest steps: - run: echo "Job triggered by ${{ github.event_name }} event." diff --git a/Dockerfile b/Dockerfile index 11923c6..ade8098 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,9 @@ -FROM python:latest - -FROM gorialis/discord.py +FROM python:3.11-slim RUN mkdir -p /usr/src/MorningBot - WORKDIR /usr/src/MorningBot COPY . . +RUN pip install -r requirements.txt -CMD ["python3", "main.py"] \ No newline at end of file +CMD ["python3", "."] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ecc1804 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,6 @@ +version: '3' +services: + morningbot: + image: morningbot:latest + volumes: + - ./token:/usr/src/MorningBot/token From 00539ce259a9fbb448c1c715037b570498c358f2 Mon Sep 17 00:00:00 2001 From: David Lynch <98290029+davidlynch-sd@users.noreply.github.com> Date: Sun, 19 Nov 2023 15:26:38 +0000 Subject: [PATCH 5/8] changed readme instructions (#43) --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5667761..8f7a4a7 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,9 @@ docker build -t morningbot . 7. 🐳 Run the container. ```bash -docker run -d --name morningbot morningbot +docker run --volume=./token:/usr/src/MorningBot/token -d morningbot:latest +#or +docker-compose up ``` ### Supported timezones From e09f0cd9d0ec453f64920ebe485a00c6defdb23e Mon Sep 17 00:00:00 2001 From: David Lynch <98290029+davidlynch-sd@users.noreply.github.com> Date: Tue, 21 Nov 2023 22:34:13 +0000 Subject: [PATCH 6/8] Compose config (#44) * fixed mount * leaderboard creating dir --- README.md | 2 +- docker-compose.yml | 2 +- leaderboard/__init__.py | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8f7a4a7..ae6cdb7 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ docker build -t morningbot . 7. 🐳 Run the container. ```bash -docker run --volume=./token:/usr/src/MorningBot/token -d morningbot:latest +docker run --volume=./:/usr/src/MorningBot/ -d morningbot:latest #or docker-compose up ``` diff --git a/docker-compose.yml b/docker-compose.yml index ecc1804..d8971ce 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,4 +3,4 @@ services: morningbot: image: morningbot:latest volumes: - - ./token:/usr/src/MorningBot/token + - ./:/usr/src/MorningBot/ diff --git a/leaderboard/__init__.py b/leaderboard/__init__.py index 8c71496..48964e6 100644 --- a/leaderboard/__init__.py +++ b/leaderboard/__init__.py @@ -31,6 +31,9 @@ def __init__(self, channel): self.path = f"config/leaderboards/{self.channel}-leaderboard.json" print(self.path) + if os.path.isdir("config/leaderboards/") is not True: + os.mkdir("config/leaderboards/") + self.members = [] if os.path.isfile(self.path): with open(self.path, "r", encoding="utf-8") as leader_file: From bfca3e9550b654518894a0e0603335ec7c0e4112 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 22 Nov 2023 22:25:40 +0000 Subject: [PATCH 7/8] indentation fix --- bot/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index a963095..01308cb 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -128,11 +128,11 @@ async def on_message(message): return - # Performing regular expression checking on easter egg phrases - for egg_phrase, reaction in configuration_data["easter_egg_phrases"].items(): - if re.search(egg_phrase, contents): - await message.add_reaction(reaction) - return + # Performing regular expression checking on easter egg phrases + for egg_phrase, reaction in configuration_data["easter_egg_phrases"].items(): + if re.search(egg_phrase, contents): + await message.add_reaction(reaction) + return if DEBUG_MODE: From fb122edd4e663118f7c14c7950f334f76adc504c Mon Sep 17 00:00:00 2001 From: Keith <79348344+chubbyyb@users.noreply.github.com> Date: Tue, 30 Jan 2024 21:15:17 +0000 Subject: [PATCH 8/8] Fixed GIF links (#47) --- config/configuration_data.json | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/config/configuration_data.json b/config/configuration_data.json index 7d0ba28..61d641c 100644 --- a/config/configuration_data.json +++ b/config/configuration_data.json @@ -55,19 +55,18 @@ "https://media.giphy.com/media/hUEtOkI8ntRtBLyMfb/giphy.gif", "https://media.giphy.com/media/TKXMVRt5uvV8OYErao/giphy.gif", "https://media.giphy.com/media/mxjzBpyu8DDLIcEKVC/giphy.gif", - "https://tenor.com/view/доброе-утро-кофе-coffee-gif-15999509", + "https://tenor.com/bfimL.gif", "https://media.giphy.com/media/hHifLbLhEloqfDwWs0/giphy.gif", - "https://tenor.com/view/早安-早上好-goodmorning-flowers-sunflowers-gif-21233714", - "https://tenor.com/view/おはようございます-good-morning-morning-in-japanese-gif-4722997724943366125", + "https://tenor.com/bBf1q.gif", + "https://tenor.com/fM3xHGl6Ng9.gif", "https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExZ2o4amxqNnhsd3E4amIzN2VhZmhoOWdmdGV0a2VubG44MjE4ZjVvayZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/JSw3ivlumEKZWrxdwp/giphy.gif", "https://media.giphy.com/media/E3qMYDlq0YIb0qXFug/giphy.gif", - "https://tenor.com/view/suprabhat-good-morning-holidays-good-morning-hindi-good-morning-good-morning-happy-sunday-gif-19862051", - "https://giphy.com/clips/greetings-holiday-kwanzaa-5yBrQnoPsjLaCo80fy", + "https://tenor.com/bvvbP.gif", "https://media.giphy.com/media/lckQGTmmQYdjnXerK2/giphy.gif", - "https://tenor.com/view/good-morning-günaydın-gif-25596075", + "https://tenor.com/bTyR5.gif", "https://media0.giphy.com/media/f66sq76KfkDCKoxYSV/giphy.gif", "https://i.pinimg.com/originals/16/27/71/162771b373fc94042ec3e0e3615c0db1.gif", - "https://tenor.com/view/good-morning-gif-25798053" + "https://tenor.com/bUppN.gif" ], "easter_egg_phrases": { "cheesed to meet you": "🧀",