Skip to content

Commit

Permalink
style: remove RqRouter check
Browse files Browse the repository at this point in the history
  • Loading branch information
portasynthinca3 committed May 16, 2022
1 parent aa99b1b commit 36037c9
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 26 deletions.
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Config

config :deutexrium,
data_path: "/var/deutex_data",
data_path: (if config_env() == :prod, do: "/var/deutex_data", else: "/var/deutex_test"),
channel_unload_timeout: 3 * 60 * 1000, # milliseconds
guild_unload_timeout: 4 * 60 * 1000,
debug_people: [471715557096554518], # ids of people that can run "deut_debug"
Expand All @@ -21,7 +21,7 @@ config :logger,
backends: [:console, {LoggerFileBackend, :debug_log}]
config :logger, :console,
metadata: [:shard, :guild, :channel],
level: :notice
level: (if config_env() == :prod, do: :notice, else: :info)
config :logger, :debug_log,
path: "deuterium.log",
level: :info
Expand Down
4 changes: 4 additions & 0 deletions lib/ctl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ defmodule Ctl do
Deutexrium.Persistence.Model.load!(channel)
end

def unload(resource) do
GenServer.cast({:via, Registry, {Registry.Server, resource}}, {:shutdown, false})
end

def add_slash_commands(guild \\ 0) do
commands = []

Expand Down
13 changes: 8 additions & 5 deletions lib/deutexrium.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule Deutexrium do
functions accordingly.
"""

@version Mix.Project.config[:version]

use Nostrum.Consumer
require Logger
alias Nostrum.Api
Expand Down Expand Up @@ -199,8 +201,8 @@ defmodule Deutexrium do

|> put_field("REGULAR COMMANDS", "can be run by anybody")
|> put_field("help", ":information_source: send this message", true)
|> put_field("status", ":green_circle: show the current stats", true)
|> put_field("stats", ":yellow_circle: show how much resources I use", true)
|> put_field("status", ":green_circle: show key statistics", true)
|> put_field("stats", ":yellow_circle: boring info for nerds", true)
|> put_field("gen <count>", ":1234: generate <count> (1 if omitted) messages using the current channel's model immediately", true)
|> put_field("gen_by [sentiment] [@user]", ":face_with_monocle: generate a message with a specific sentiment and/or authorship using the current channel's model immediately", true)
|> put_field("gen_from #channel", ":level_slider: immediately generate a message using the mentioned channel's model", true)
Expand Down Expand Up @@ -322,15 +324,16 @@ defmodule Deutexrium do
|> put_color(0xe6f916)
|> put_url("https://deut.portasynthinca3.me/commands/stats")

|> put_field("Space taken up by user data", "#{used_space} KiB (#{used_space |> div(1024)} MiB)", true)
|> put_field("User data size", "#{used_space} KiB (#{used_space |> div(1024)} MiB)", true)
|> put_field("Uptime", "#{uptime}", true)
|> put_field("Time since I was created", "#{been_created_for}", true)
|> put_field("Known servers", "#{Deutexrium.Persistence.guild_cnt}", true)
|> put_field("Known channels", "#{Deutexrium.Persistence.chan_cnt}", true)
|> put_field("Used RAM", "#{used_memory} MiB", true)
|> put_field("Internal guild servers", "#{guild_server_cnt}", true)
|> put_field("Internal channel servers", "#{chan_server_cnt}", true)
|> put_field("Guild servers", "#{guild_server_cnt}", true)
|> put_field("Channel servers", "#{chan_server_cnt}", true)
|> put_field("Total internal processes", "#{Process.list |> length()}", true)
|> put_field("Version", "#{@version}", true)

Api.create_interaction_response(inter, %{type: 4, data: %{embeds: [embed], flags: 64}})
end
Expand Down
2 changes: 2 additions & 0 deletions lib/deutexrium/app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ defmodule Deutexrium.App do
"""

use Application
require Logger

@impl true
def start(_type, _args) do
Logger.info("Data path: #{Application.fetch_env!(:deutexrium, :data_path)}")
Deutexrium.Sup.start_link([])
end
end
2 changes: 1 addition & 1 deletion lib/deutexrium/server/channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Deutexrium.Server.Channel do
end
end

defp generate_message(%Markov{} = model, sentiment \\ :nosentiment, author \\ nil) do
defp generate_message(%Markov{} = model, sentiment, author \\ nil) do
try do
start = cond do
author == nil and sentiment == :nosentiment -> [:start, :start]
Expand Down
26 changes: 10 additions & 16 deletions lib/deutexrium/server/rq_router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,17 @@ defmodule Deutexrium.Server.RqRouter do
def ensure({type, id} = what) do
name = {:via, Registry, {Registry.Server, what}}

case Registry.lookup(Registry.Server, what) do
# not started
[] ->
# get server module
module = case type do
:channel -> Server.Channel
:guild -> Server.Guild
:voice -> Server.Voice
:settings -> Server.Settings
end
# start it
GenServer.start(module, id, name: name)
name
# get server module
module = case type do
:channel -> Server.Channel
:guild -> Server.Guild
:voice -> Server.Voice
:settings -> Server.Settings
end

# started
[{_pid, nil}] -> name
end
# start it (returns an error if already srarted, which is okay)
GenServer.start(module, id, name: name)
name
end

@spec route({server_type, integer | {integer, integer}}, any) :: any
Expand Down
2 changes: 1 addition & 1 deletion lib/deutexrium/server/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ defmodule Deutexrium.Server.Settings do
true ->
{meta, map} = case state.context do
:guild -> {get_meta.(:guild), %{true: false, false: true}}
channel_id -> {get_meta.(:channel), %{true: false, false: nil, nil: true}}
_channel -> {get_meta.(:channel), %{true: false, false: nil, nil: true}}
end
setting = :erlang.binary_to_atom(setting)
current = meta |> Map.get(setting)
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Deutexrium.MixProject do
def project do
[
app: :deutexrium,
version: "1.3.2",
version: "1.3.3",
elixir: "~> 1.8",
start_permanent: Mix.env() == :prod,
deps: deps()
Expand Down

0 comments on commit 36037c9

Please sign in to comment.