Bangtags: ignore case of commands

staging
multiple creatures 2019-04-26 12:52:01 -05:00
parent d8f182d235
commit f573712f82
1 changed files with 28 additions and 18 deletions

View File

@ -68,10 +68,12 @@ class Bangtags
next next
end end
case cmd[0] next if cmd[0].nil?
case cmd[0].downcase
when 'var' when 'var'
chunk = nil chunk = nil
case cmd[1] next if cmd[1].nil?
case cmd[1].downcase
when 'end', 'stop' when 'end', 'stop'
@vore_stack.pop @vore_stack.pop
@component_stack.pop @component_stack.pop
@ -93,7 +95,8 @@ class Bangtags
end end
when 'tf' when 'tf'
chunk = nil chunk = nil
case cmd[1] next if cmd[1].nil?
case cmd[1].downcase
when 'end', 'stop' when 'end', 'stop'
@tf_cmds.pop @tf_cmds.pop
@component_stack.pop @component_stack.pop
@ -122,14 +125,14 @@ class Bangtags
next if cmd[1].nil? next if cmd[1].nil?
src_img = nil src_img = nil
shortcode = cmd[2] shortcode = cmd[2]
case cmd[1] case cmd[1].downcase
when 'avatar' when 'avatar'
src_img = status.account.avatar src_img = status.account.avatar
when 'parent' when 'parent'
next unless cmd[3].present? && reply? next unless cmd[3].present? && reply?
shortcode = cmd[3] shortcode = cmd[3]
next if @parent_status.nil? next if cmd[2].nil? || @parent_status.nil?
case cmd[2] case cmd[2].downcase
when 'avatar' when 'avatar'
src_img = @parent_status.account.avatar src_img = @parent_status.account.avatar
end end
@ -185,7 +188,8 @@ class Bangtags
end end
when 'link' when 'link'
chunk = nil chunk = nil
case cmd[1] next if cmd[1].nil?
case cmd[1].downcase
when 'permalink', 'self' when 'permalink', 'self'
chunk = TagManager.instance.url_for(status) chunk = TagManager.instance.url_for(status)
when 'cloudroot' when 'cloudroot'
@ -195,7 +199,8 @@ class Bangtags
end end
when 'ping' when 'ping'
mentions = [] mentions = []
case cmd[1] next if cmd[1].nil?
case cmd[1].downcase
when 'admins' when 'admins'
mentions = User.admins.map { |u| "@#{u.account.username}" } mentions = User.admins.map { |u| "@#{u.account.username}" }
mentions.sort! mentions.sort!
@ -227,7 +232,8 @@ class Bangtags
end end
when 'thread' when 'thread'
chunk = nil chunk = nil
case cmd[1] next if cmd[1].nil?
case cmd[1].downcase
when 'reall' when 'reall'
if status.conversation_id.present? if status.conversation_id.present?
mention_ids = Status.where(conversation_id: status.conversation_id).flat_map { |s| s.mentions.pluck(:account_id) } mention_ids = Status.where(conversation_id: status.conversation_id).flat_map { |s| s.mentions.pluck(:account_id) }
@ -236,7 +242,8 @@ class Bangtags
chunk = mentions.join(' ') chunk = mentions.join(' ')
end end
when 'sharekey' when 'sharekey'
case cmd[2] next if cmd[2].nil?
case cmd[2].downcase
when 'revoke' when 'revoke'
if status.conversation_id.present? if status.conversation_id.present?
roars = Status.where(conversation_id: status.conversation_id, account_id: @account.id) roars = Status.where(conversation_id: status.conversation_id, account_id: @account.id)
@ -272,8 +279,8 @@ class Bangtags
end end
when 'parent' when 'parent'
chunk = nil chunk = nil
next if @parent_status.nil? next if cmd[1].nil? || @parent_status.nil?
case cmd[1] case cmd[1].downcase
when 'permalink' when 'permalink'
chunk = TagManager.instance.url_for(@parent_status) chunk = TagManager.instance.url_for(@parent_status)
end end
@ -288,7 +295,7 @@ class Bangtags
media_idx = media_idx.to_i media_idx = media_idx.to_i
next if status.media_attachments[media_idx-1].nil? next if status.media_attachments[media_idx-1].nil?
case media_cmd case media_cmd.downcase
when 'desc' when 'desc'
if media_args.present? if media_args.present?
@vars["media_#{media_idx}_desc"] = media_args.join(':') @vars["media_#{media_idx}_desc"] = media_args.join(':')
@ -317,7 +324,8 @@ class Bangtags
chunk = cmd[2..-1].join(sep.nil? ? cmd[1] : sep) chunk = cmd[2..-1].join(sep.nil? ? cmd[1] : sep)
when 'hide' when 'hide'
chunk = nil chunk = nil
case cmd[1] next if cmd[1].nil?
case cmd[1].downcase
when 'end', 'stop', 'endall', 'stopall' when 'end', 'stop', 'endall', 'stopall'
@vore_stack.reject! {|v| v == '_'} @vore_stack.reject! {|v| v == '_'}
@compontent_stack.reject! {|c| c == :hide} @compontent_stack.reject! {|c| c == :hide}
@ -335,7 +343,8 @@ class Bangtags
end end
when 'i', 'we' when 'i', 'we'
chunk = nil chunk = nil
case cmd[1] next if cmd[1].nil?
case cmd[1].downcase
when 'am', 'are' when 'am', 'are'
who = cmd[2] who = cmd[2]
if who.blank? if who.blank?
@ -361,7 +370,8 @@ class Bangtags
@vars['_they:are'] = name.strip @vars['_they:are'] = name.strip
end end
when 'sharekey' when 'sharekey'
case cmd[1] next if cmd[1].nil?
case cmd[1].downcase
when 'new' when 'new'
chunk = nil chunk = nil
status.sharekey = SecureRandom.urlsafe_base64(32) status.sharekey = SecureRandom.urlsafe_base64(32)
@ -372,8 +382,8 @@ class Bangtags
if chunk.present? && @tf_cmds.present? if chunk.present? && @tf_cmds.present?
@tf_cmds.each do |tf_cmd| @tf_cmds.each do |tf_cmd|
next if chunk.nil? next if chunk.nil? || tf_cmd[0].nil?
case tf_cmd[0] case tf_cmd[0].downcase
when 'replace', 'sub', 's' when 'replace', 'sub', 's'
tf_cmd[1..-1].in_groups_of(2) do |args| tf_cmd[1..-1].in_groups_of(2) do |args|
chunk.sub!(*args) if args.all? chunk.sub!(*args) if args.all?