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

always load all scripts in type/, command/ and handler/ #83

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
34 changes: 16 additions & 18 deletions src/HoJBot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,27 @@ import StructTypes

const COMMAND_PREFIX = get(ENV, "HOJBOT_COMMAND_PREFIX", ",")

function loadplugins()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use underscore to separate words in function names? We try to follow the BlueStyle.
https://github.com/invenia/BlueStyle#function-naming

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But Julia itself suggests to use underscores only if the name is otherwise unreadable: https://docs.julialang.org/en/v1/manual/style-guide/#Use-naming-conventions-consistent-with-Julia-base/
:/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm aware of that. But coding style standard is made for a reason. The BlueStyle is quite widely used in the industry, and it has a good balance of consistency that tends to work well for larger projects.

RE: naming convention, the standard Julia recommendation is too loose in my humble opinion-- when does one decide when the smashed-together name is starting to become unreadable? It's subjective.

includejlfiles("type/")
includejlfiles("command/")
includejlfiles("handler/")
end

function includejlfiles(dir)
wd = walkdir(joinpath(@__DIR__, dir))
commands = first(wd)
close(wd)
Comment on lines +34 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it only works with single level, it's simpler to use readdir with join = true instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but readdir is single level only aswell. Am I misunderstanding it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that’s why I suggested that. The code would be simpler since you don’t need to deal with the tuple from walkdir.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but on the other hand I only need the files (not the directories) and walkdir already sorts by type of element. readdir returns files and directories arbitrarily mixed.

foreach(commands[3]) do command
endswith(command, ".jl") && include(joinpath(commands[1], command))
end
end

include("constants.jl")
include("dispatcher.jl")
include("util.jl")
include("discord.jl")
include("main.jl")

include("command/tz.jl")
include("command/j.jl")
include("command/gm.jl")
include("command/react.jl")
include("command/src.jl")

include("handler/reaction.jl")
include("handler/whistle.jl")

include("type/mod.jl")
include("handler/mod.jl")

include("type/discourse.jl")
include("command/discourse.jl")
include("handler/discourse.jl")

include("type/ig.jl")
include("command/ig.jl")
loadplugins()

end # module