-
Notifications
You must be signed in to change notification settings - Fork 11
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
Feature rights #91
base: main
Are you sure you want to change the base?
Feature rights #91
Conversation
@@ -0,0 +1,70 @@ | |||
const Functionality = Val | |||
const PATHBASE = "data/permissions/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use a more specific name that relates to permission?
|
||
has_access(guid::Snowflake, member::Member, task::Functionality) = has_access(guid, member.roles, task) | ||
|
||
function has_access(guid::Snowflake, roles::Vector{Snowflake}, ::Functionality{Task}) where Task |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it's time to graduate from using Val
to an abstract type? So, you can just do T <: AbstractTask
.
|
||
|
||
function load() | ||
isdir(PATHBASE) || return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we should log a warning before returning?
while !eof(io) | ||
lensym = read(io, UInt8) | ||
lenroles = read(io, UInt8) | ||
sym = Symbol(read(io, lensym)) | ||
roles = Set(reinterpret(Snowflake, read(io, lenroles))) | ||
PERMISSIONS[sym] = roles | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of building custom SerDes. We are already using StructTypes and JSON3 and that's pretty easy. For example:
HoJBot.jl/src/command/discourse.jl
Lines 109 to 120 in 99076ee
function discourse_save(message_id::UInt64, r::DiscourseData) | |
@info "Saving discourse search data for message_id=$message_id" | |
path = discourse_file_path(message_id) | |
write(ensurepath!(path), JSON3.write(r)) | |
end | |
function discourse_load(message_id::UInt64) | |
@info "Loading discourse search data for message_id=$message_id" | |
path = discourse_file_path(message_id) | |
bytes = read(path) | |
return JSON3.read(bytes, DiscourseData) | |
end |
If you choose to use custom data types:
HoJBot.jl/src/type/discourse.jl
Lines 59 to 61 in 99076ee
# JSON3 struct bindings | |
StructTypes.StructType(::Type{HoJBot.DiscourseData}) = StructTypes.Struct() | |
StructTypes.StructType(::Type{HoJBot.DiscoursePost}) = StructTypes.Struct() |
end | ||
|
||
function grant!(guid::Snowflake, role::Snowflake, ::Functionality{Task}) where Task | ||
guildperms = PERMISSIONS[guid] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't shoot me 😄
guildperms = PERMISSIONS[guid] | |
guild_perms = PERMISSIONS[guid] |
function handle_command end | ||
|
||
"Entry point for a new observer plugin, triggers on almost all events related to text chat" | ||
function handle_observer end #I suggest renaming handlers to observers since they act on observations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about handle_event
?
"""GuildID->(Functionality->[permitted roles])""" | ||
const PERMISSIONS = Dict{Snowflake,Dict{Symbol,Set{Snowflake}}}() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move constant definitions to the top of file? See https://github.com/invenia/BlueStyle#global-variables
open(joinpath(dir, string(guid))) do io | ||
fguid = read(io, Snowflake) | ||
if fguid != guid | ||
@info "file conflict, tried to load $guid but got $fguid" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be @warn
?
This is a first trial on how to implement rights management solely bound to Guild Roles.