Skip to content

Commit

Permalink
Merge pull request #25 from StampyAI/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ProducerMatt authored Sep 8, 2024
2 parents 3756d36 + 1e769aa commit 8a786d2
Show file tree
Hide file tree
Showing 23 changed files with 735 additions and 629 deletions.
94 changes: 46 additions & 48 deletions .dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
[
{"deps/type_check/lib/type_check/spec.ex",
"The pattern can never match the type {:ok, [], _}."},
{"lib/plugin.ex", "Function usage_tuples/0 has no local return."},
{"lib/plugin.ex", "Function job_result/0 has no local return."},
{"lib/plugin.ex", "Function plugin_job_result/0 has no local return."},
{"lib/plugin.ex", "The guard clause can never succeed."},
{"lib/services/discord.ex", "Function vips/0 has no local return."},
{"lib/services/dummy.ex",
"@spec for ask_bot has more types than are returned by the function."},
{"lib/services/dummy.ex", "Function dummy_channel_id/0 has no local return."},
{"lib/services/dummy.ex", "Function msg_content/0 has no local return."},
{"lib/services/dummy.ex", "Function msg_reference/0 has no local return."},
{"lib/services/dummy.ex", "Function msg_tuple/0 has no local return."},
{"lib/services/dummy.ex", "Function msg_tuple_incoming/0 has no local return."},
{"lib/services/dummy.ex", "Function channel/0 has no local return."},
{"lib/services/dummy.ex", "Function channel_buffers/0 has no local return."},
{"lib/site_config.ex", "Function server_id/0 has no local return."},
{"lib/site_config.ex", "Function schema/0 has no local return."},
{"lib/site_config.ex", "Function cfg_list/0 has no local return."},
{"lib/stampede.ex", "Function dm_tuple/0 has no local return."},
{"lib/stampede.ex", "Function server_id/0 has no local return."},
{"lib/stampede.ex", "Function prefix/0 has no local return."},
{"lib/stampede.ex", "Function enabled_plugs/0 has no local return."},
{"lib/stampede.ex", "Function channel_lock_action/0 has no local return."},
{"lib/stampede.ex", "Function channel_lock_status/0 has no local return."},
{"lib/stampede.ex", "Function timestamp/0 has no local return."},
{"lib/stampede.ex", "Function bot_invoked_status/0 has no local return."},
{"lib/stampede.ex", "Function module_function_args/0 has no local return."},
{"lib/stampede.ex", "Function log_level/0 has no local return."},
{"lib/stampede.ex", "Function log_msg/0 has no local return."},
{"lib/stampede.ex", "Function kwlist/1 has no local return."},
{"lib/stampede.ex", "Function kwlist/0 has no local return."},
{"lib/stampede.ex", "Function str_list/0 has no local return."},
{"lib/stampede.ex", "Function throw_internal_error/0 has no local return."},
{"lib/stampede.ex", "Function throw_internal_error/1 only terminates with explicit exception."},
{"lib/stampede/cfg_table.ex", "Function vips/0 has no local return."},
{"lib/stampede/cfg_table.ex", "Function table_object/0 has no local return."},
{"lib/stampede/external/python.ex", "The pattern can never match the type true."},
{"lib/stampede/external/python.ex",
"Function do_dumb_down_elixir_term/1 will never be called."},
{"lib/stampede/logger.ex", "Function logger_state/0 has no local return."},
{"lib/stampede/tables/channel_locks.ex", "The guard clause can never succeed."},
{"lib/stampede/tables/interactions.ex", "The guard clause can never succeed."},
{"lib/stampede/traceback.ex", "Function t/0 has no local return."},
{"lib/txt_block.ex", "Function block/0 has no local return."},
{"lib/txt_block.ex", "Function type/0 has no local return."},
{"lib/txt_block.ex", "Function t/0 has no local return."},
{"lib/txt_block/md.ex", "The guard clause can never succeed."}
{"deps/type_check/lib/type_check/spec.ex", "The pattern can never match the type {:ok, [], _}."},
{"lib/plugin.ex", "Function usage_tuples/0 has no local return."},
{"lib/plugin.ex", "Function job_result/0 has no local return."},
{"lib/plugin.ex", "Function plugin_job_result/0 has no local return."},
{"lib/plugin.ex", "The guard clause can never succeed."},
{"lib/services/discord.ex", "Function vips/0 has no local return."},
{"lib/services/dummy.ex", "Function dummy_channel_id/0 has no local return."},
{"lib/services/dummy.ex", "Function dummy_server_id/0 has no local return."},
{"lib/services/dummy.ex", "Function msg_reference/0 has no local return."},
{"lib/services/dummy.ex", "Function incoming_msg_tuple/0 has no local return."},
{"lib/services/dummy.ex", "Function retrieved_msg_tuple/0 has no local return."},
{"lib/services/dummy.ex", "Function channel_log/0 has no local return."},
{"lib/services/dummy.ex", "Function server_log/0 has no local return."},
{"lib/services/dummy/channel.ex", "Function t/0 has no local return."},
{"lib/site_config.ex", "Function server_id/0 has no local return."},
{"lib/site_config.ex", "Function schema/0 has no local return."},
{"lib/site_config.ex", "Function cfg_list/0 has no local return."},
{"lib/stampede.ex", "Function dm_tuple/0 has no local return."},
{"lib/stampede.ex", "Function server_id/0 has no local return."},
{"lib/stampede.ex", "Function prefix/0 has no local return."},
{"lib/stampede.ex", "Function enabled_plugs/0 has no local return."},
{"lib/stampede.ex", "Function channel_lock_action/0 has no local return."},
{"lib/stampede.ex", "Function channel_lock_status/0 has no local return."},
{"lib/stampede.ex", "Function timestamp/0 has no local return."},
{"lib/stampede.ex", "Function bot_invoked_status/0 has no local return."},
{"lib/stampede.ex", "Function module_function_args/0 has no local return."},
{"lib/stampede.ex", "Function log_level/0 has no local return."},
{"lib/stampede.ex", "Function log_msg/0 has no local return."},
{"lib/stampede.ex", "Function kwlist/1 has no local return."},
{"lib/stampede.ex", "Function kwlist/0 has no local return."},
{"lib/stampede.ex", "Function str_list/0 has no local return."},
{"lib/stampede.ex", "Function throw_internal_error/0 has no local return."},
{"lib/stampede.ex", "Function throw_internal_error/1 only terminates with explicit exception."},
{"lib/stampede/cfg_table.ex", "Function vips/0 has no local return."},
{"lib/stampede/cfg_table.ex", "Function table_object/0 has no local return."},
{"lib/stampede/external/python.ex", "The pattern can never match the type true."},
{"lib/stampede/external/python.ex", "Function do_dumb_down_elixir_term/1 will never be called."},
{"lib/stampede/logger.ex", "Function logger_state/0 has no local return."},
{"lib/stampede/tables/channel_locks.ex", "The guard clause can never succeed."},
{"lib/stampede/tables/dummy_msgs.ex", "The guard clause can never succeed."},
{"lib/stampede/tables/interactions.ex", "The guard clause can never succeed."},
{"lib/stampede/traceback.ex", "Function t/0 has no local return."},
{"lib/txt_block.ex", "Function block/0 has no local return."},
{"lib/txt_block.ex", "Function type/0 has no local return."},
{"lib/txt_block.ex", "Function t/0 has no local return."},
{"lib/txt_block/md.ex", "The guard clause can never succeed."},
]
6 changes: 4 additions & 2 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ jobs:
id: deps-cache
uses: actions/cache@v4
with:
# would be good to cache priv/plts but something isn't being cached right,
# and plt ends up expecting files managed by Nix which aren't there.
# example: :dialyzer.run error: File not found: /nix/store/*-erlang-26.2.5.1/lib/erlang/lib/dialyzer-5.1.3/ebin/erl_bif_types.beam
path: |
deps
_build
priv/plts
.nix-mix
.nix-hex
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/flake.*')) }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.*')) }}
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/flake.*')) }}-${{ hashFiles(format('{0}{1}', github.workspace, '**/mix.*')) }}
restore-keys: |
${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/flake.*')) }}
${{ runner.os }}-mix-
Expand Down
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It is a sequel to the [Stampy](https://github.com/StampyAI/stampy) Discord bot.

## Use

[Download the Nix package manager](https://nixos.org/download/). This handles the development environment for Stampede. It runs on Linux, Mac, Windows, and Docker. It won't disrupt your system setup -- though once you start using it, it may be hard to stop. :smile:
[Download the Nix package manager](https://github.com/DeterminateSystems/nix-installer). This handles the development environment for Stampede. It runs on Linux, Mac, Windows, and Docker. It won't disrupt your system setup -- though once you start using it, it may be hard to stop. :smile:

Once Nix is ready, just cd to the dev directory and run `nix develop .#` to load the dev environment, then `mix deps.get` to get the dependencies. Some commands:
- `iex -S mix` to run Stampede in the `dev` environment, also providing the famous Elixir interactive shell.
Expand All @@ -18,5 +18,29 @@ Once Nix is ready, just cd to the dev directory and run `nix develop .#` to load

Configurations for servers are written in YAML and left in `./Sites/`. In different environments (such as `test` and `dev`) it will read configs from `./Sites_{environment-name}`. Check the service documentation for what options your service has available.

- `./lib/services` defines services where chat requests are incoming.
- `./lib/plugins` defines plugins which suggest potential responses, along with a confidence estimate for how relevant the response would be. Plugins which use resources or take time will offer a *callback* instead, which will only be called if no other plugins have higher confidence.
- `./lib/services` defines services where chat requests are incoming. They follow the standard set in `./lib/service.ex`
- `./lib/plugins` defines plugins which suggest potential responses, along with a confidence estimate for how relevant the response would be. Plugins which use resources or take time will offer a *callback* instead, which will only be called if no other plugins have higher confidence. They follow the standard set in `./lib/plugin.ex`

### Updating `.dialyzer_ignore.exs`

Often when changing code, you will end up with superfluous Dialyzer warnings. You can suppress them by updating the Dialyzer ignore file. To start:

```bash
rm ./.dialyzer_ignore.exs
mix dialyzer --format ignore_file_strict &> .dialyzer_ignore.exs.incoming
```

Remove all but the Elixir tuples, which will look like this:

```elixir
{"lib/stampede.ex", "Function server_id/0 has no local return."},
```

Put a `[` at the start of the file and a `]` at the end, so they become one list of tuples. Now you can rename the file to its true name and format it:

```bash
mv ./.dialyzer_ignore.exs{.incoming,}
mix format ./.dialyzer_ignore.exs
```

Now Dialyzer should not raise any more warnings.
45 changes: 40 additions & 5 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Config

test_or_dev? = Mix.env() in [:test, :dev]

prod? = Mix.env() == :prod
test? = Mix.env() == :test

# Extra metadata for the logger to keep
stampede_metadata = [
:stampede_component,
Expand All @@ -23,12 +28,8 @@ extra_metadata =
stampede_metadata ++
nostrum_metadata

# Actually start configuring things
config :stampede,
compile_env: Mix.env()

config :stampede, :type_check,
enable_runtime_checks: Mix.env() in [:dev, :test],
enable_runtime_checks: test_or_dev?,
debug: false

config :stampede, Stampede.Scheduler,
Expand Down Expand Up @@ -92,9 +93,43 @@ config :ex_unit,
config :nostrum, :ffmpeg, false

config :stampede,
compile_env: Mix.env(),
services_to_install: [
Services.Discord
],
# What will actually be started by stampede
services_to_start:
(if test? do
# NOTE: this will have to change if Service-specific tests start making sense
[Services.Dummy]
else
:all
end),
config_dir:
"./Sites" <>
(if prod? do
""
else
"_#{Mix.env()}"
end),
# enable posting serious errors to the channel specified in :error_log_destination
log_post_serious_errors: true,
# enable file logging
log_to_file: true,
# clear tables associated with this compilation environment
clear_state: false,
error_log_destination: :unset,
python_exe: System.fetch_env!("FLAKE_PYTHON"),
python_plugin_dirs: ["./lib_py"]

env_specific_cfg =
"./config_#{Mix.env()}.exs"
|> Path.expand(__DIR__)

if File.exists?(env_specific_cfg) do
import_config env_specific_cfg
end

for config <- "./*.secret.exs" |> Path.expand(__DIR__) |> Path.wildcard() do
import_config config
end
10 changes: 10 additions & 0 deletions config/config_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Config

config :stampede,
services: [Services.Dummy],
log_to_file: false,
log_post_serious_errors: false,
clear_state: true

config :stampede,
test_loaded: true
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
flake-utils.lib.eachDefaultSystem
(
system: let
# NOTE: change to true to enable commit checks
# when disabled, also run "pre-commit uninstall" to disable
# NOTE: change to false to disable commit checks
# when disabling, also run "pre-commit uninstall" to disable
enablePreCommitChecks = true;

pkgs = nixpkgs.legacyPackages.${system};
Expand Down Expand Up @@ -93,6 +93,8 @@
dialyzer = {
enable = true;
package = ex;
pass_filenames = false;
require_serial = true;
};
custom-mix-test = {
enable = true;
Expand Down
6 changes: 0 additions & 6 deletions flake.systems.nix

This file was deleted.

Loading

0 comments on commit 8a786d2

Please sign in to comment.