From 3f0c9d186a6bf1c34577b25cce9df3d34f15f64f Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Fri, 8 Nov 2019 12:19:23 -0500 Subject: [PATCH] use dev roles instead of notify role --- source/modules/dtl.rb | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/source/modules/dtl.rb b/source/modules/dtl.rb index 3d2e8aa..6a13098 100644 --- a/source/modules/dtl.rb +++ b/source/modules/dtl.rb @@ -10,26 +10,27 @@ class Mod_DTL < Vrobot4::Module::Module register :c_listnotify, "listnotify", "Lists available notification groups." register :c_notify, "notify", "Notifies a notification group." - @info.map! do |id| id.resolve_id end - - @notify_id = 462143279618850826.resolve_id - @member_id = 388350737308188684.resolve_id - @server_id = 273581213510402058.resolve_id + @member_id = @info[:member_id].resolve_id + @group_ids = @info[:group_ids].map! do |ids| + {not: ids[:not].resolve_id, + dev: ids[:dev].resolve_id} + end end def ensure_role m - if m.chan.real.server && m.chan.real.server.id == @server_id + if m.chan.real.server m.user.real.add_role @member_id unless m.user.real.role? @member_id end end - def get_role m, argv + def get_notification_roles m, argv roles = m.chan.real.server.roles - role = roles.find do |r| r.name.casecmp(argv) == 0 end - unless role and @info.any? do |id| role.id == id end + role = roles.find do |r| r.name.casecmp(argv) == 0 end + ids = @group_ids.detect do |ids| role.id == ids[:not] end if role + unless ids raise ArgumentError, "Invalid notification group, use `.listnotify` for a list of available groups." end - role + ids end def on_message m @@ -44,34 +45,34 @@ class Mod_DTL < Vrobot4::Module::Module def c_setnotify m, argv ensure_role m - m.user.real.add_role get_role(m, argv) + m.user.real.add_role get_notification_roles(m, argv)[:not] 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.user.real.remove_role get_notification_roles(m, argv)[:not] m.reply "Successfully removed you from the notification group." end def c_listnotify m, argv text = "" - for role in @info do + for role in @group_ids do text << m.chan.real.server.role(role).name + ?\n end m.reply text end def c_notify m, argv - if m.user.real.role? @notify_id - argv = argv.split ?,, 2 - role = get_role m, argv[0] - role.mentionable = true + argv = argv.split ?,, 2 + ids = get_notification_roles m, argv[0] + if m.user.real.role? ids[:dev] + ids[:not].mentionable = true if argv[1] - m.reply "#{role.mention} - #{argv[1].strip}" + m.reply "#{ids[:not].mention} - #{argv[1].strip}" else - m.reply role.mention + m.reply ids[:not].mention end - role.mentionable = false + ids[:not].mentionable = false else m.reply "You don't have permission for that." end