From c38c3969efc480b294d2bf81d6a1f292a2d6c60f Mon Sep 17 00:00:00 2001 From: Graham Date: Mon, 25 Jun 2018 13:03:12 -0400 Subject: [PATCH] Add Mod_DecatessaradimensionalLoungeAlertationAndRolinationManagerator. --- source/modules/mod_dtl.rb | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 source/modules/mod_dtl.rb diff --git a/source/modules/mod_dtl.rb b/source/modules/mod_dtl.rb new file mode 100644 index 0000000..fd59dff --- /dev/null +++ b/source/modules/mod_dtl.rb @@ -0,0 +1,70 @@ +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