Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the big dummy rewrite #25

Merged
merged 32 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3b79b09
feat: start work on replacement dummy server
ProducerMatt Jul 31, 2024
d7c8c93
chore(dummy): publicize some types temporarily
ProducerMatt Aug 1, 2024
da35fbf
fix(dummy): another Nil error from TypeCheck
ProducerMatt Aug 1, 2024
4fe94ba
feat: further new dummy dev
ProducerMatt Aug 1, 2024
d85eee9
feat: handle new dummy missing servers
ProducerMatt Aug 1, 2024
20fa46b
feat: just use try/catch to handle ignored servers
ProducerMatt Aug 1, 2024
325c9cd
feat: add elixir ets package
ProducerMatt Aug 14, 2024
8b25f83
chore(flake): update
ProducerMatt Aug 14, 2024
c343f6b
feat(dummy)!: incomplete progress on rewrite
ProducerMatt Aug 14, 2024
2961e80
chore(dummy)!: undo rewrite so far
ProducerMatt Aug 14, 2024
da74791
feat(flake): nixd
ProducerMatt Aug 25, 2024
a0e4faa
feat(flake)!: use systems for flake-utils
ProducerMatt Aug 25, 2024
f34024e
chore(flake): merge flake lock
ProducerMatt Aug 25, 2024
71cb0b5
chore(flake): use default systems repo
ProducerMatt Aug 25, 2024
5cce311
feat(flake): add linux/darwin filesystem handling libs
ProducerMatt Aug 25, 2024
fe5c398
feat(flake)!: add boolean for pre-commit checks
ProducerMatt Aug 26, 2024
84b1224
chore(flake)!: temporarily disable commit checks
ProducerMatt Aug 26, 2024
8577942
fix: hopefully fix startup order issues
ProducerMatt Aug 28, 2024
c95e314
feat(readme): how to update dialyzer ignore
ProducerMatt Aug 29, 2024
8d8c101
feat(dummy)!: complete rewrite to parallelized channels
ProducerMatt Aug 29, 2024
92db8a7
chore(flake): update, hopefully fix git-hooks gc root issue
ProducerMatt Aug 29, 2024
c8732b0
chore(mix): update lockfile
ProducerMatt Aug 29, 2024
6a2858f
chore: merge conflict
ProducerMatt Aug 29, 2024
5d6aaa3
fix(hooks): trying to fix bug in GH Actions
ProducerMatt Aug 29, 2024
77830f0
feat: better error log in cfg_table
ProducerMatt Aug 29, 2024
e474e1e
feat(dummy): easy direct messaging method
ProducerMatt Aug 30, 2024
b71948d
refactor!: rely on traditional elixir config
ProducerMatt Sep 6, 2024
b935789
fix: service startup now working correctly
ProducerMatt Sep 6, 2024
3121f17
chore: sanity check for dummy
ProducerMatt Sep 6, 2024
cb7277d
chore: 0.1.1-dev -> 0.1.2-dev
ProducerMatt Sep 6, 2024
a387992
chore: flake.lock
ProducerMatt Sep 6, 2024
1e769aa
fix: better whitespace checking for split_prefix
ProducerMatt Sep 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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