71 lines
1.9 KiB
Ruby
71 lines
1.9 KiB
Ruby
|
class Mod_DecatessaradimensionalLoungeAlertationAndRolinationManagerator < Vrobot4::Module::Module
|
||
|
def self.type() "DTL" end
|
||
|
Vrobot4::Module.add_module_type self, server: "Discord"
|
||
|
|
||
|
def initialize info
|
||
|
super
|
||
|
register :c_setnotify, "setnotify", "Adds you to a notification group."
|
||
|
register :c_unsetnotify, "unsetnotify", "Removes you from a notification group."
|
||
|
register :c_listnotify, "listnotify", "Lists available notification groups."
|
||
|
register :c_notify, "notify", "Notifies a notification group."
|
||
|
@info.map! {|id| id.resolve_id}
|
||
|
end
|
||
|
|
||
|
def ensure_role m
|
||
|
if m.user.real.roles.empty?
|
||
|
m.user.real.add_role 388350737308188684.resolve_id
|
||
|
true
|
||
|
else
|
||
|
false
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def get_role m, argv
|
||
|
roles = m.chan.real.server.roles
|
||
|
role = roles.find {|r| r.name.casecmp? argv}
|
||
|
unless role and @info.any? {|id| role.id == id}
|
||
|
raise ArgumentError, "Invalid notification group, use `.listnotify` for a list of available groups."
|
||
|
end
|
||
|
role
|
||
|
end
|
||
|
|
||
|
def on_message m
|
||
|
ensure_role m
|
||
|
false
|
||
|
end
|
||
|
|
||
|
def c_setnotify m, argv
|
||
|
ensure_role m
|
||
|
m.user.real.add_role get_role(m, argv)
|
||
|
m.reply "Successfully added you to the notification group."
|
||
|
end
|
||
|
|
||
|
def c_unsetnotify m, argv
|
||
|
m.user.real.remove_role get_role(m, argv)
|
||
|
m.reply "Successfully removed you from the notification group."
|
||
|
end
|
||
|
|
||
|
def c_notify m, arg
|
||
|
return unless m.user.real.role? 388350774788358147.resolve_id
|
||
|
argv = arg.split(',', 2)
|
||
|
role = get_role(m, argv[0])
|
||
|
role.mentionable = true
|
||
|
if argv[1]
|
||
|
m.reply role.mention + " - " + argv[1].strip
|
||
|
else
|
||
|
m.reply role.mention
|
||
|
end
|
||
|
role.mentionable = false
|
||
|
end
|
||
|
|
||
|
def c_listnotify m, argv
|
||
|
text = ""
|
||
|
for role in @info do
|
||
|
text << m.chan.real.server.role(role).name + "\n"
|
||
|
end
|
||
|
m.reply text
|
||
|
end
|
||
|
end
|
||
|
|
||
|
## EOF
|