diff --git a/source/modules/mod_notify.rb b/source/modules/mod_notify.rb new file mode 100644 index 0000000..79e3e01 --- /dev/null +++ b/source/modules/mod_notify.rb @@ -0,0 +1,41 @@ +class Mod_Notify < Vrobot4::Module::Module + def self.type() "Notify" 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." + @info.map! {|id| id.resolve_id} + 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 c_setnotify m, argv + 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_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