Add Mod_Notify.

master
an 2018-06-25 13:02:03 -04:00
parent 6077058fd4
commit c21a88d000
No known key found for this signature in database
GPG Key ID: 6F175273601C59F2
1 changed files with 41 additions and 0 deletions

View File

@ -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