Skip to content

Commit

Permalink
rebrand time
Browse files Browse the repository at this point in the history
  • Loading branch information
Th3-M4jor committed Sep 9, 2023
1 parent 21d7716 commit c537bb1
Show file tree
Hide file tree
Showing 75 changed files with 1,194 additions and 1,197 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Just another rewrite of BnBBot to learn Elixir
Just another rewrite of Adjutant to learn Elixir

Has some interop with https://github.com/Th3-M4jor/BnBBackend-EX and private github webook for auto-redeployment of two frontend-projects.

Expand All @@ -17,8 +17,8 @@ To run the bot the following extra things will be needed:
- `"Battlechip"`
- An `Oban` migration for the respective version of the library
- A development sqlite DB for logging and storing state about slash commands
- This can be created by running `mix ecto.create -r BnBBot.Repo.SQLite`
- Said DB must then be migrated `mix ecto.migrate -r BnBBot.Repo.SQLite`
- This can be created by running `mix ecto.create -r Adjutant.Repo.SQLite`
- Said DB must then be migrated `mix ecto.migrate -r Adjutant.Repo.SQLite`
- In `config/dev.exs` the `token:` config will need an actual bot token

The bot should then be able to be successfully started by running:
Expand All @@ -35,17 +35,17 @@ The bot can then be run with `MIX_ENV` set to prod, however it is recommended to
# Adding a command
To add a new command to the bot, the following steps are required:
- Create a new module for the command in the `lib/commands` directory
- it is recommended to namespace the command's module name with `BnBBot.Commands`
- This new module should `use` the `BnBBot.Command.Slash` module
- See the documentation for the `BnBBot.Command.Slash` module for more information
- Also, see [`BnBBot.Command.Slash.BNB.PHB`](lib/command/slash/bnb/phb.ex) for a simple example
- Add this new module to the `@commands` list in the [`BnBBot.Command`](lib/command.ex) module
- it is recommended to namespace the command's module name with `Adjutant.Commands`
- This new module should `use` the `Adjutant.Command.Slash` module
- See the documentation for the `Adjutant.Command.Slash` module for more information
- Also, see [`Adjutant.Command.Slash.BNB.PHB`](lib/command/slash/bnb/phb.ex) for a simple example
- Add this new module to the `@commands` list in the [`Adjutant.Command`](lib/command.ex) module
- The bot will take care of creating the command if it doesn't exist at startup

# Deleting a command
To delete a command, the following steps are required:
- Remove the module from the `@commands` list in the [`BnBBot.Command`](lib/command.ex) module
- Add the module to the `@deleted_commands` list in the [`BnBBot.Command`](lib/command.ex) module
- Remove the module from the `@commands` list in the [`Adjutant.Command`](lib/command.ex) module
- Add the module to the `@deleted_commands` list in the [`Adjutant.Command`](lib/command.ex) module
- The bot will take care of deleting the command if its recorded as existing at startup
- Then on future rollouts you can delete the module

Expand Down
16 changes: 8 additions & 8 deletions config/example_config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ config :logger,
level: :info,
backends: [
:console,
{BnBBot.LogBackend, :log_backend}
{Adjutant.LogBackend, :log_backend}
],
compile_time_purge_matching: [
[module: Nostrum, level_lower_than: :warn],
Expand All @@ -32,8 +32,8 @@ config :logger,
[module: Nostrum.Shard.Event, level_lower_than: :warn]
]

config :elixir_bot, Oban,
repo: BnBBot.Repo.SQLite,
config :adjutant, Oban,
repo: Adjutant.Repo.SQLite,
engine: Oban.Engines.Lite,
queues: [
remind_me: [limit: 2, paused: true],
Expand All @@ -46,17 +46,17 @@ config :elixir_bot, Oban,
{Oban.Plugins.Lifeline, interval: :timer.minutes(60)},
{Oban.Plugins.Cron,
crontab: [
{"@weekly", BnBBot.Workers.LogCleaner}
{"@weekly", Adjutant.Workers.LogCleaner}
]}
]

# uses sqlite for logging
config :elixir_bot, BnBBot.Repo.SQLite,
config :adjutant, Adjutant.Repo.SQLite,
database: "./db/dev_db.db",
priv: "priv/sqlite"

# uses postgres for storing BnB data, and for Oban
config :elixir_bot, BnBBot.Repo.Postgres,
config :adjutant, Adjutant.Repo.Postgres,
username: "postgres",
password: "postgres",
database: "default",
Expand All @@ -65,8 +65,8 @@ config :elixir_bot, BnBBot.Repo.Postgres,
pool_size: 10,
priv: "priv/postgres"

config :elixir_bot,
ecto_repos: [BnBBot.Repo.SQLite, BnBBot.Repo.Postgres],
config :adjutant,
ecto_repos: [Adjutant.Repo.SQLite, Adjutant.Repo.Postgres],
ecto_shard_count: 1,
remind_me_queue: :dev_remind_me,
edit_message_queue: :dev_edit_message,
Expand Down
14 changes: 7 additions & 7 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ config :logger,
level: :info,
backends: [
:console,
{BnBBot.LogBackend, :log_backend}
{Adjutant.LogBackend, :log_backend}
],
compile_time_purge_matching: [
[module: Nostrum, level_lower_than: :warn],
Expand All @@ -31,21 +31,21 @@ config :logger,
[module: Nostrum.Shard.Event, level_lower_than: :warn]
]

config :elixir_bot, Oban,
config :adjutant, Oban,
prefix: "oban_jobs",
repo: BnBBot.Repo.Postgres,
repo: Adjutant.Repo.Postgres,
queues: [
dev_remind_me: [limit: 2, paused: true],
dev_edit_message: [limit: 2, paused: true]
]

# uses sqlite for logging
config :elixir_bot, BnBBot.Repo.SQLite,
config :adjutant, Adjutant.Repo.SQLite,
database: "./db/dev_db.db",
priv: "priv/sqlite"

# uses postgres for storing BnB data, and for Oban
config :elixir_bot, BnBBot.Repo.Postgres,
config :adjutant, Adjutant.Repo.Postgres,
username: "postgres",
password: "postgres",
database: "default",
Expand All @@ -54,8 +54,8 @@ config :elixir_bot, BnBBot.Repo.Postgres,
pool_size: 10,
priv: "priv/postgres"

config :elixir_bot,
ecto_repos: [BnBBot.Repo.SQLite, BnBBot.Repo.Postgres],
config :adjutant,
ecto_repos: [Adjutant.Repo.SQLite, Adjutant.Repo.Postgres],
ecto_shard_count: 1,
remind_me_queue: :dev_remind_me,
edit_message_queue: :dev_edit_message,
Expand Down
7 changes: 7 additions & 0 deletions lib/adjutant.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule Adjutant do
@moduledoc """
The main module for the bot
Intentionally left blank for now
"""
end
6 changes: 3 additions & 3 deletions lib/main.ex → lib/adjutant/application.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule BnBBot do
defmodule Adjutant.Application do
@moduledoc """
Defines the Bot's "Application" for auto-startup
"""
Expand All @@ -7,8 +7,8 @@ defmodule BnBBot do

def start(_type, _args) do
children = [
BnBBot.Supervisor,
BnBBot.RepoSupervisor
Adjutant.BotSupervisor,
Adjutant.Repo.Supervisor
]

Supervisor.start_link(children, strategy: :one_for_one)
Expand Down
26 changes: 26 additions & 0 deletions lib/adjutant/bot_supervisor.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
defmodule Adjutant.BotSupervisor do
@moduledoc """
Main entry point for the bot.
"""

require Logger
use Supervisor

def start_link(args) do
Supervisor.start_link(__MODULE__, args, name: __MODULE__)
end

@impl true
def init(_init_arg) do
Logger.debug("Starting Supervisor")

button_collector = Registry.child_spec(keys: :unique, name: :BUTTON_COLLECTOR)

children = [button_collector, Adjutant.Consumer]

res = Supervisor.init(children, strategy: :one_for_one)
Logger.debug("Supervisor started")
# :ignore
res
end
end
44 changes: 22 additions & 22 deletions lib/command.ex → lib/adjutant/command.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule BnBBot.Command do
defmodule Adjutant.Command do
@moduledoc """
Module for dispatching both text and slash commands
"""
Expand All @@ -14,36 +14,36 @@ defmodule BnBBot.Command do
end

def dispatch(%Message{} = msg) do
BnBBot.Command.Text.dispatch(msg)
Adjutant.Command.Text.dispatch(msg)
end

@slash_commands [
BnBBot.Command.Slash.Dice,
BnBBot.Command.Slash.Ping,
BnBBot.Command.Slash.Shuffle,
BnBBot.Command.Slash.BNB.PHB,
BnBBot.Command.Slash.BNB.NCP,
BnBBot.Command.Slash.BNB.Chip,
BnBBot.Command.Slash.BNB.Virus,
BnBBot.Command.Slash.BNB.Status,
BnBBot.Command.Slash.BNB.Blight,
BnBBot.Command.Slash.BNB.Panels,
BnBBot.Command.Slash.BNB.Reload,
BnBBot.Command.Slash.BNB.Groups,
BnBBot.Command.Slash.Hidden,
BnBBot.Command.Slash.Insults,
BnBBot.Command.Slash.PsychoEffects,
BnBBot.Command.Slash.RemindMe,
BnBBot.Command.Slash.HOTG.Team
Adjutant.Command.Slash.Dice,
Adjutant.Command.Slash.Ping,
Adjutant.Command.Slash.Shuffle,
Adjutant.Command.Slash.BNB.PHB,
Adjutant.Command.Slash.BNB.NCP,
Adjutant.Command.Slash.BNB.Chip,
Adjutant.Command.Slash.BNB.Virus,
Adjutant.Command.Slash.BNB.Status,
Adjutant.Command.Slash.BNB.Blight,
Adjutant.Command.Slash.BNB.Panels,
Adjutant.Command.Slash.BNB.Reload,
Adjutant.Command.Slash.BNB.Groups,
Adjutant.Command.Slash.Hidden,
Adjutant.Command.Slash.Insults,
Adjutant.Command.Slash.PsychoEffects,
Adjutant.Command.Slash.RemindMe,
Adjutant.Command.Slash.HOTG.Team
]

@deleted_commands [
BnBBot.Command.Slash.BNB.Create
Adjutant.Command.Slash.BNB.Create
]

def setup_commands do
BnBBot.Command.State.delete_commands(@deleted_commands)
BnBBot.Command.State.setup_commands(@slash_commands)
Adjutant.Command.State.delete_commands(@deleted_commands)
Adjutant.Command.State.setup_commands(@slash_commands)
end

# Generate the command handlers at compile time.
Expand Down
18 changes: 9 additions & 9 deletions lib/command/slash.ex → lib/adjutant/command/slash.ex
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
defmodule BnBBot.Command.Slash do
defmodule Adjutant.Command.Slash do
@moduledoc """
Describes what public functions each slash command module must define.
All slash commands must implement the callbacks defined here, and may optionally `use`
this module to define a `call` function that will be called when the command is executed.
```elixir
use BnBBot.Command.Slash, permissions: :everyone
use Adjutant.Command.Slash, permissions: :everyone
```
When `use`d, the macro expects a `:permissions` option, which defines who can use the command.
Expand All @@ -28,7 +28,7 @@ defmodule BnBBot.Command.Slash do
you must manually remove the command from the old scope.
"""

@default_command_scope Application.compile_env!(:elixir_bot, :default_command_scope)
@default_command_scope Application.compile_env!(:adjutant, :default_command_scope)

defp deprecated_call do
quote do
Expand All @@ -48,7 +48,7 @@ defmodule BnBBot.Command.Slash do
end

quote do
@behaviour BnBBot.Command.Slash
@behaviour Adjutant.Command.Slash
def call(inter) do
call_slash(inter)
unquote(deprecated_code)
Expand All @@ -66,9 +66,9 @@ defmodule BnBBot.Command.Slash do
end

quote do
@behaviour BnBBot.Command.Slash
@behaviour Adjutant.Command.Slash
def call(inter) do
user_perms = BnBBot.Util.get_user_perms(inter)
user_perms = Adjutant.Util.get_user_perms(inter)

if user_perms in [:admin, :owner] do
call_slash(inter)
Expand All @@ -95,9 +95,9 @@ defmodule BnBBot.Command.Slash do
end

quote do
@behaviour BnBBot.Command.Slash
@behaviour Adjutant.Command.Slash
def call(inter) do
user_perms = BnBBot.Util.get_user_perms(inter)
user_perms = Adjutant.Util.get_user_perms(inter)

if user_perms == unquote(perm) do
call_slash(inter)
Expand Down Expand Up @@ -255,7 +255,7 @@ defmodule BnBBot.Command.Slash do
@callback get_create_map() :: slash_cmd_map()
end

defmodule BnBBot.Command.Slash.Id do
defmodule Adjutant.Command.Slash.Id do
@moduledoc """
Defines how slash command Ids are stored and retrieved from the DB to handle
deletion.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule BnBBot.Command.Slash.AddToBans do
defmodule Adjutant.Command.Slash.AddToBans do
@moduledoc """
One of the "hidden" commands. Used to add a member to the list of who would be banned.
"""
Expand All @@ -23,7 +23,7 @@ defmodule BnBBot.Command.Slash.AddToBans do

@spec add_to_bans(Nostrum.Struct.Interaction.t(), [Option.t()]) :: any()
def add_to_bans(inter, [%Option{value: to_add}]) do
if BnBBot.Util.owner_msg?(inter) or BnBBot.Util.admin_msg?(inter) do
if Adjutant.Util.owner_msg?(inter) or Adjutant.Util.admin_msg?(inter) do
add_id_to_list(inter, inter.member.user_id, to_add)
else
Api.create_interaction_response(inter, %{
Expand All @@ -37,7 +37,7 @@ defmodule BnBBot.Command.Slash.AddToBans do
end

def list_bans(inter) do
if BnBBot.Util.owner_msg?(inter) or BnBBot.Util.admin_msg?(inter) do
if Adjutant.Util.owner_msg?(inter) or Adjutant.Util.admin_msg?(inter) do
send_id_list(inter)
else
Api.create_interaction_response(inter, %{
Expand All @@ -51,8 +51,8 @@ defmodule BnBBot.Command.Slash.AddToBans do
end

def salt_the_earth(inter) do
if BnBBot.Util.owner_msg?(inter) or BnBBot.Util.admin_msg?(inter) do
if BnBBot.ButtonAwait.get_confirmation?(inter, "Are you sure you want to salt the earth?") do
if Adjutant.Util.owner_msg?(inter) or Adjutant.Util.admin_msg?(inter) do
if Adjutant.ButtonAwait.get_confirmation?(inter, "Are you sure you want to salt the earth?") do
salt_the_earth_inner(inter)
end
else
Expand All @@ -70,7 +70,7 @@ defmodule BnBBot.Command.Slash.AddToBans do
guild_id = inter.guild_id

tasks =
BnBBot.Repo.SQLite.all(__MODULE__)
Adjutant.Repo.SQLite.all(__MODULE__)
|> Enum.map(fn row ->
Task.async(Api, :create_guild_ban, [guild_id, row.to_ban, 0, "Salting the Earth"])
end)
Expand All @@ -97,7 +97,7 @@ defmodule BnBBot.Command.Slash.AddToBans do
defp send_id_list(inter) do
list =
from(u in __MODULE__, select: u.to_ban)
|> BnBBot.Repo.SQLite.all()
|> Adjutant.Repo.SQLite.all()
|> Enum.map(fn to_ban ->
"<@#{to_ban}>\n"
end)
Expand All @@ -122,15 +122,15 @@ defmodule BnBBot.Command.Slash.AddToBans do
query = from(u in __MODULE__, where: u.to_ban == ^to_add)

resp =
if BnBBot.Repo.SQLite.exists?(query) do
if Adjutant.Repo.SQLite.exists?(query) do
"That user is already on the list"
else
row = %__MODULE__{
to_ban: to_add,
added_by: author_id
}

BnBBot.Repo.SQLite.insert!(row)
Adjutant.Repo.SQLite.insert!(row)

"Added <@#{to_add}> to the banlist"
end
Expand Down
Loading

0 comments on commit c537bb1

Please sign in to comment.