Skip to content

Commit

Permalink
Merge branch 'file-storage' of https://github.com/mewbotorg/mewbot in…
Browse files Browse the repository at this point in the history
…to file-storage
  • Loading branch information
ajCameron committed Aug 3, 2023
2 parents 5f51c7d + 0214511 commit fd7121a
Show file tree
Hide file tree
Showing 110 changed files with 7,394 additions and 755 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
rm -Rf build; python setup.py 'io' sdist bdist_wheel
- name: "Archive installation artifacts"
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: builds
path: dist/*
Expand Down
92 changes: 52 additions & 40 deletions .github/workflows/review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,73 @@ concurrency:

env:
# Which version of the reports Sonar receives.
DEFAULT_OS: ubuntu-latest
DEFAULT_PYTHON: 3.9
DEFAULT_OS: ubuntu
DEFAULT_PYTHON: "3.10"

jobs:
lint:
name: Lint Python code
runs-on: ubuntu-latest
test:
name: ${{ matrix.name }} Python code (${{ matrix.os }}/py${{ matrix.version }})
runs-on: ${{ matrix.os }}-latest

strategy:
fail-fast: false
matrix:
name: ["lint", "test"]
os: ["ubuntu", "macos", "windows"]
version: ["3.10", "3.11"]
exclude:
- name: Lint
os: macos
- name: Lint
os: windows

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python ${{ env.DEFAULT_PYTHON }}
- name: Setup Python ${{ matrix.version }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.DEFAULT_PYTHON }}
python-version: ${{ matrix.version }}
cache: pip
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- name: Install dependencies
run: pip install -r requirements-dev.txt
shell: bash
run: ./tools/install-deps

- name: Run Linters
run: ./tools/lint
- name: Run Tests
shell: bash
run: ./tools/${{ matrix.name }}

- name: Upload Artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: lint-results
name: ${{ matrix.name }}-results-${{ matrix.os }}-${{ matrix.version }}
path: reports

test:
name: Test Python code
runs-on: ${{ matrix.os }}
tests-passed:
name: Tests Passed
runs-on: ubuntu-latest

strategy:
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
version: ["3.9", "3.10", "3.11"]
fail-fast: false
needs:
- test

steps:
- name: Mark all test runs as successful
run: /bin/true

annotate:
name: Output Annotations
runs-on: ubuntu-latest

needs:
- test

if: always()

steps:
- name: Checkout
Expand All @@ -74,30 +98,19 @@ jobs:
requirements.txt
requirements-dev.txt
- name: Install dependencies
run: pip install -r requirements-dev.txt

- name: Run Tests
shell: bash
run: ./tools/test --cov

- name: Upload Artifacts
uses: actions/upload-artifact@v3
- name: Download Artifacts
uses: actions/download-artifact@v3
if: always()
with:
name: test-results-${{ matrix.os }}-${{ matrix.version }}
path: reports

tests-passed:
name: Tests Passed
runs-on: ubuntu-latest

needs:
- test
- name: Install dependencies
shell: bash
run: ./tools/install-deps

steps:
- name: Mark all test runs as successful
run: /bin/true
- name: Output Annotations
shell: bash
run: ./tools/annotate

sonarcloud:
name: SonarCloud
Expand All @@ -106,7 +119,6 @@ jobs:
if: always()

needs:
- lint
- test

steps:
Expand All @@ -118,7 +130,7 @@ jobs:
uses: actions/download-artifact@v3
if: always()
with:
name: lint-results
name: lint-results-${{ env.DEFAULT_OS }}-${{ env.DEFAULT_PYTHON }}
path: reports

- name: Download Artifacts
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/spdx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-FileCopyrightText: 2023 Mewbot Developers <[email protected]>
#
# SPDX-License-Identifier: BSD-2-Clause

name: Reuse SPDX Lint
run-name: "Checking for licensing issues in \"${{ github.ref }}\""

on: push

jobs:
SPDX-Lint:
name: Check Reuse Compliance
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: REUSE Compliance Check
uses: fsfe/reuse-action@v2
2 changes: 1 addition & 1 deletion .github/workflows/trufflehog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
fetch-depth: 0
- name: TruffleHog OSS
uses: trufflesecurity/trufflehog@v3.28.2
uses: trufflesecurity/trufflehog@v3.45.3
with:
path: ./
base: ${{ github.event.repository.default_branch }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enforce the code style and linting requirements of this project.

#### Setting up project for local development

The recommended way to set this project up is using python 3.9 (or higher) with
The recommended way to set this project up is using python 3.10 (or higher) with
a standard `venv` setup.
The project uses a "src-dir" layout; for Python to be able to locate the modules,
you will need to set up the `PYTHONPATH` environment variable with at least the `src/` directory.
Expand Down
85 changes: 85 additions & 0 deletions dev-docs/io-dev-notes/discord-dev-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,91 @@ SPDX-FileCopyrightText: 2021 - 2023 Mewbot Developers <[email protected]
SPDX-License-Identifier: CC-BY-4.0
-->

# Running discord bot examples

## acquire a discord token

To run a bot on discord you need to acquire a bot token.
This is a string of numbers and letters which identifies your bot to discord when it tries to log in.

Tokens can have a number of different properties, or scopes.
These determine what you can do with a token.

I recommend following the [official discord guide](https://discordgsm.com/guide/how-to-get-a-discord-bot-token).
Which should walk you through the process.

Remember - if you want to view the contents of discord messages, you will need to enable the message content permission for the bot.
If you don't do this, all the message contents you see will be blank.

## prepare discord bot yaml

Now select the bot you want to actually run.
Each of the yaml files included in `examples\discord_bots` represents

```yaml
kind: IOConfig
implementation: mewbot.io.discord.DiscordIO
uuid: aaaaaaaa-aaaa-4aaa-0000-aaaaaaaaaa00
properties:
token: "[token goes here]"

---
```

Once you have prepared your token, paste it into the IOConfig block of the yaml for the bot you want to run.

The IOConfig block, for your token, should look something like

```yaml
kind: IOConfig
implementation: mewbot.io.discord.DiscordIO
uuid: aaaaaaaa-aaaa-4aaa-0000-aaaaaaaaaa00
properties:
token: "a-series-of-letters-and-numbers-that-is-your-token"

---
```

Note the ``" "`` around your token.
This indicates, to the yaml, that your token should be treated as a string.
If you omit them, the yaml will be invalid and will not run.

### run the example - windows

Turning mewbot yaml into a bot is a fairly straightforward operation.

#### Through python and examples

You can use the code in the `__main__.py` file of examples.
Running something like

```shell
(mewbot_venv) C:\mewbot_dev\mewbot>python src\examples examples\discord_bots\history_discord_bot.yaml
```

#### Through the examples file in tools

You could also use the `sh` file found in the tools folder, running something like

```shell
(mewbot_venv) C:\mewbot_dev\mewbot>sh tools/examples examples\discord_bots\history_discord_bot.yaml
```

NOTE - the direction of the `/` in `tools/examples`.
If you get it the wrong way round, `sh` would be able to interpret the path and you'll get an error like

```shell
(mewbot_venv) C:\mewbot_dev\mewbot>sh tools\examples examples\discord_bots\history_discord_bot.yaml
tools\examples: line 7: tools\examples/path: Not a directory
tools\examples: line 9: exec: : not found
```

### run the example - linux

(I don't have a functioning linux box for this rn, so will fill this in later).

## FAQ

### Why am I getting blank events when messages are sent in channels the bot is monitoring?

As of late August 2022, discord bots now need the message content permission to be explicitly enabled (was implicitly enabled up to this point).
Expand Down
41 changes: 41 additions & 0 deletions dev-docs/mypy-dev-notes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
SPDX-FileCopyrightText: 2023 Mewbot Developers <[email protected]>
SPDX-License-Identifier: BSD-2-Clause
-->

# MyPy

MyPy is a python type analyser/linter.

mypy enforces the requirement for type annotations, and also performs type-checking
based on those annotations and resolvable constants.

## MyPy Failure Modes

The most common issue people will encounter is caused by empty directories
left behind when changing branches. This will only occur locally, as CI
runs use fresh filesystems.

```
(mewbot_venv) C:\mewbot_dev\mewbot> sh tools/lint
Black (Formatter)
=================
All done! ✨ 🍰 ✨
36 files left unchanged.
Flake8
======
MyPy (type checker)
===================
There are no .py[i] files in directory 'C:\mewbot_dev\mewbot\plugins\mewbot-client_for_reddit\tests'
[...clipped...]
```

The solution here is to confirm that the directory is in fact empty, and then
remove it from your copy.

Further information on this issue can be found in https://github.com/mewbotorg/mewbot/issues/180.
Loading

0 comments on commit fd7121a

Please sign in to comment.