84 lines
2.3 KiB
Ruby
84 lines
2.3 KiB
Ruby
class Mod_DTL < 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."
|
|
|
|
@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.user.real.add_role @member_id unless m.user.real.role? @member_id
|
|
end
|
|
end
|
|
|
|
def get_notification_roles m, argv
|
|
roles = m.chan.real.server.roles
|
|
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
|
|
ids
|
|
end
|
|
|
|
def on_message m
|
|
ensure_role m
|
|
super m
|
|
end
|
|
|
|
def on_command m, cnam, argv
|
|
ensure_role m
|
|
super m, cnam, argv
|
|
end
|
|
|
|
def c_setnotify m, argv
|
|
ensure_role m
|
|
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_notification_roles(m, argv)[:not]
|
|
m.reply "Successfully removed you from the notification group."
|
|
end
|
|
|
|
def c_listnotify m, argv
|
|
text = ""
|
|
for ids in @group_ids do
|
|
text << m.chan.real.server.role(ids[:not]).name + ?\n
|
|
end
|
|
m.reply text
|
|
end
|
|
|
|
def c_notify m, argv
|
|
argv = argv.split ?,, 2
|
|
ids = get_notification_roles m, argv[0]
|
|
if m.user.real.role? ids[:dev]
|
|
notif = m.chan.real.server.role ids[:not]
|
|
notif.mentionable = true
|
|
if argv[1]
|
|
m.reply "#{notif.mention} - #{argv[1].strip}"
|
|
else
|
|
m.reply notif.mention
|
|
end
|
|
notif.mentionable = false
|
|
else
|
|
m.reply "You don't have permission for that."
|
|
end
|
|
end
|
|
end
|
|
|
|
## EOF
|