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 3cf9549..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: - json-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 b7f71ea..48198e4 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: - python-lint: + lint: runs-on: ubuntu-latest steps: - run: echo "Job triggered by ${{ github.event_name }} event." 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/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/README.md b/README.md index b0d0e9a..67f50d0 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,9 @@ docker build -t morningbot . 8. 🐳 Run the container. ```bash -docker run -d --name morningbot morningbot +docker run --volume=./:/usr/src/MorningBot/ -d morningbot:latest +#or +docker-compose up ``` ### Supported timezones diff --git a/bot/__init__.py b/bot/__init__.py index 896ecbf..e2e162d 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -126,29 +126,34 @@ 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 # Add the earlybird role to the first user to say good morning await FIRST_GM_USER.add_roles(EARLYBIRD_ROLE) 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(egg_phrase, 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 diff --git a/config/configuration_data.json b/config/configuration_data.json index fc0cf02..1e1718f 100644 --- a/config/configuration_data.json +++ b/config/configuration_data.json @@ -56,19 +56,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": "🧀", @@ -82,8 +81,10 @@ "with the boys": "🍻", "keithmas": "🎅", "santanuts":"🎅", + "good night": "🫖", "happy halloween": "🎃", "boo": "😨", - "spooktober": "👻" + "spooktober": "👻", + "\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b": "📧" } } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d8971ce --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,6 @@ +version: '3' +services: + morningbot: + image: morningbot:latest + volumes: + - ./:/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: