Skip to content

Commit

Permalink
deprecate BnB commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Th3-M4jor committed Sep 9, 2023
1 parent a1f7e1a commit 21d7716
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 24 deletions.
7 changes: 1 addition & 6 deletions lib/bnb_bot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,10 @@ defmodule BnBBot.Consumer do
Oban.resume_queue(queue: :remind_me)
Oban.resume_queue(queue: :edit_message)

chip_ct = BnBBot.Library.Battlechip.get_chip_ct()
ncp_ct = BnBBot.Library.NCP.get_ncp_ct()
virus_ct = BnBBot.Library.Virus.get_virus_ct()

Logger.debug(["Ready\n", inspect(ready_data, pretty: true)])
BnBBot.Command.setup_commands()

{"Bot Ready\n#{chip_ct} chips loaded\n#{virus_ct} viruses loaded\n#{ncp_ct} ncps loaded",
false}
{"Bot Ready", false}
end

BnBBot.Util.dm_owner(dm_msg, override)
Expand Down
47 changes: 40 additions & 7 deletions lib/command/slash.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,49 @@ defmodule BnBBot.Command.Slash do

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

defp everyone_perms do
defp deprecated_call do
quote do
if inter.type == 2 do
Nostrum.Api.create_followup_message(inter.token, %{
content: "Note: This is a deprecated command, it may break in the future",
flags: 64
})
end
end
end

defp everyone_perms(deprecated) do
deprecated_code =
if deprecated do
deprecated_call()
end

quote do
@behaviour BnBBot.Command.Slash
def call(inter), do: call_slash(inter)
def call(inter) do
call_slash(inter)
unquote(deprecated_code)
:ignore
end

defoverridable call: 1
end
end

defp list_perms do
defp list_perms(deprecated) do
deprecated_code =
if deprecated do
deprecated_call()
end

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

if user_perms in [:admin, :owner] do
call_slash(inter)
unquote(deprecated_code)
else
Nostrum.Api.create_interaction_response(inter, %{
type: 4,
Expand All @@ -62,14 +88,20 @@ defmodule BnBBot.Command.Slash do
end
end

defp atom_perms(perm) when perm in [:owner, :admin] do
defp atom_perms(perm, deprecated) when perm in [:owner, :admin] do
deprected_macro_code =
if deprecated do
deprecated_call()
end

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

if user_perms == unquote(perm) do
call_slash(inter)
unquote(deprected_macro_code)
else
Nostrum.Api.create_interaction_response(inter, %{
type: 4,
Expand All @@ -96,6 +128,7 @@ defmodule BnBBot.Command.Slash do

defmacro __using__(opts) do
perms_opts = Keyword.fetch!(opts, :permissions)
deprecated = Keyword.get(opts, :deprecated, false)

perms_ops =
if is_list(perms_opts) do
Expand All @@ -107,13 +140,13 @@ defmodule BnBBot.Command.Slash do
perms_fn =
case perms_ops do
:everyone ->
everyone_perms()
everyone_perms(deprecated)

[:admin, :owner] ->
list_perms()
list_perms(deprecated)

perms when perms in [:admin, :owner] ->
atom_perms(perms)
atom_perms(perms, deprecated)

_ ->
raise "\":permissions\" option must be either :everyone, :admin, :owner or a list of [:admin, :owner]"
Expand Down
2 changes: 1 addition & 1 deletion lib/command/slash/bnb/blight.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule BnBBot.Command.Slash.BNB.Blight do
alias Nostrum.Api
require Logger

use BnBBot.Command.Slash, permissions: :everyone
use BnBBot.Command.Slash, permissions: :everyone, deprecated: true

@blight_elements [
"Fire",
Expand Down
3 changes: 2 additions & 1 deletion lib/command/slash/bnb/chip.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ defmodule BnBBot.Command.Slash.BNB.Chip do
alias Nostrum.Api
require Logger

use BnBBot.Command.Slash, permissions: :everyone
use BnBBot.Command.Slash, permissions: :everyone, deprecated: true

@skills ~w(PER INF TCH STR AGI END CHM VLR AFF None)
@elements ~w(Fire Aqua Elec Wood Wind Sword Break Cursor Recov Invis Object Null)
@chip_kinds ~w(Burst Construct Melee Projectile Wave Heal Summon Trap)
Expand Down
2 changes: 1 addition & 1 deletion lib/command/slash/bnb/groups.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule BnBBot.Command.Slash.BNB.Groups do
@backend_node_name :elixir_bot |> Application.compile_env!(:backend_node_name)
@dm_log_id :elixir_bot |> Application.compile_env!(:dm_log_id)

use BnBBot.Command.Slash, permissions: :everyone
use BnBBot.Command.Slash, permissions: :everyone, deprecated: true

@impl true
@spec call_slash(Nostrum.Struct.Interaction.t()) :: :ignore
Expand Down
2 changes: 1 addition & 1 deletion lib/command/slash/bnb/ncp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule BnBBot.Command.Slash.BNB.NCP do
alias BnBBot.Library.NCP
alias Nostrum.Api

use BnBBot.Command.Slash, permissions: :everyone
use BnBBot.Command.Slash, permissions: :everyone, deprecated: true

@elements [
"Fire",
Expand Down
2 changes: 1 addition & 1 deletion lib/command/slash/bnb/panels.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule BnBBot.Command.Slash.BNB.Panels do
alias Nostrum.Api
require Logger

use BnBBot.Command.Slash, permissions: :everyone
use BnBBot.Command.Slash, permissions: :everyone, deprecated: true

@panels [
"Cracked",
Expand Down
2 changes: 1 addition & 1 deletion lib/command/slash/bnb/phb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule BnBBot.Command.Slash.BNB.PHB do

@phb_links :elixir_bot |> Application.compile_env!(:phb_links)

use BnBBot.Command.Slash, permissions: :everyone
use BnBBot.Command.Slash, permissions: :everyone, deprecated: true

@impl true
def call_slash(%Nostrum.Struct.Interaction{} = inter) do
Expand Down
2 changes: 1 addition & 1 deletion lib/command/slash/bnb/reload.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule BnBBot.Command.Slash.BNB.Reload do

require Logger

use BnBBot.Command.Slash, permissions: [:owner, :admin]
use BnBBot.Command.Slash, permissions: [:owner, :admin], deprecated: true

@impl true
def call_slash(%Nostrum.Struct.Interaction{} = inter) do
Expand Down
2 changes: 1 addition & 1 deletion lib/command/slash/bnb/status.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule BnBBot.Command.Slash.BNB.Status do
alias Nostrum.Api
require Logger

use BnBBot.Command.Slash, permissions: :everyone
use BnBBot.Command.Slash, permissions: :everyone, deprecated: true

@status_names [
"Angry",
Expand Down
2 changes: 1 addition & 1 deletion lib/command/slash/bnb/virus.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule BnBBot.Command.Slash.BNB.Virus do
alias Nostrum.Api
require Logger

use BnBBot.Command.Slash, permissions: :everyone
use BnBBot.Command.Slash, permissions: :everyone, deprecated: true

@impl true
def call_slash(%Nostrum.Struct.Interaction{type: 2} = inter) do
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/log_cleaner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ defmodule BnBBot.Workers.LogCleaner do
# one_week_ago = NaiveDateTime.add(now, -7 * 24 * 60 * 60)

from(l in LogLine,
where:
l.inserted_at < ago(1, "month") or (l.inserted_at < ago(1, "week") and l.level == :debug)
where: l.inserted_at < ago(1, "month"),
or_where: l.inserted_at < ago(1, "week") and l.level == :debug
)
|> BnBBot.Repo.SQLite.delete_all()

Expand Down

0 comments on commit 21d7716

Please sign in to comment.