Browse Source

fix bugs && 匿名可禁言

pull/4/head
欧醚 3 years ago
parent
commit
3dfac8387d
2 changed files with 5 additions and 6 deletions
  1. +4
    -5
      app/controllers/api/v1/statuses_controller.rb
  2. +1
    -1
      app/lib/formatter.rb

+ 4
- 5
app/controllers/api/v1/statuses_controller.rb View File

@ -6,12 +6,12 @@ class AnonTag
@@map = {}
@@last_use = Time.now
def self.get_or_generate(pid)
def self.get_or_generate(pid, note)
if Time.now - @@last_use > 1.day
@@last_use = Time.now
@@map = {}
@@used_name = []
end
@@last_use = Time.now
pre = @@map.empty? ? '*' : ''
@ -19,8 +19,7 @@ class AnonTag
@@map[pid] = (@@namelist - @@used_name).sample()
@@used_name.append(@@map[pid])
end
pre + @@map[pid]
@@map[pid].in?(note) ? nil : pre + @@map[pid]
end
end
@ -64,7 +63,7 @@ class Api::V1::StatusesController < Api::BaseController
end
def create
anon = Rails.configuration.x.anon_acc && status_params[:status].end_with?(Rails.configuration.x.anon_tag) && AnonTag.get_or_generate(current_user.account_id)
anon = Rails.configuration.x.anon_acc && status_params[:status].end_with?(Rails.configuration.x.anon_tag) && AnonTag.get_or_generate(current_user.account_id, Account.find(Rails.configuration.x.anon_acc).note)
sender = anon ? Account.find(Rails.configuration.x.anon_acc) : current_user.account
st_text = anon ? ("[#{anon}]:\n#{status_params[:status]}"[0..5000]) : status_params[:status]

+ 1
- 1
app/lib/formatter.rb View File

@ -114,7 +114,7 @@ class Formatter
aft_s = html[indices.last ..]
bef_s = html[0 .. indices.first-1]
re = /(!?)\[(.*?)\]\($/
re = /(!?)\[([^\n\[\]]*?)\]\($/
if aft_s and bef_s and aft_s.start_with?(')') and bef_s =~ re
new_indices = [bef_s =~ re, indices.last+1]
new_entity = {

Loading…
Cancel
Save