Class: KAG::Bans::Report

Inherits:
SymbolTable
  • Object
show all
Defined in:
lib/kag/bans/report.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gather, m, user) ⇒ Report

Returns a new instance of Report.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/kag/bans/report.rb', line 8

def initialize(gather,m,user)
  hash = {
    :nick => user.nick,
    :authname => user.authname,
    :host => user.host,
    :realname => user.realname,
    :gather => gather,
    :message => m,
    :count => 1
  }
  super(hash)
  _ensure_data
  if reported?
    if can_report?
      KAG::User::User.add_stat(user,:reports_others)
      if past_threshold?
        ignore
      else
        up_report_count
      end
    else
      self.gather.reply self.message,"You have already reported #{self[:nick]}. You can only report a user once."
    end
  else
    report
  end
end

Class Method Details

.ignore(gather, message, user) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/kag/bans/report.rb', line 89

def self.ignore(gather,message,user)
  user.refresh
  KAG::Config.data[:ignored] = {} unless KAG::Config.data[:ignored]
  if KAG::Config.data[:ignored] and user.authname and !KAG::Config.data[:ignored].key?(user.authname.to_sym)
    c = SymbolTable.new({
      :nick => user.nick,
      :authname => user.authname,
      :host => user.host,
      :realname => user.realname,
      :gather => gather,
      :message => message,
      :reporters => [message.user.authname]
    })
    KAG::Config.data[:ignored][user.authname.to_sym] = c
    KAG::Config.data.save

    gather.reply message,"User #{user.authname} added to ignore list." if gather.class == KAG::Gather
    true
  else
    gather.reply message,"User #{user.authname} already in ignore list!" if gather.class == KAG::Gather
    false
  end
end

.is_banned?(user) ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/kag/bans/report.rb', line 150

def self.is_banned?(user)
  user.refresh
  KAG::Config.data[:ignored] = {} unless KAG::Config.data[:ignored]
  if KAG::Config.data.flooding?(user)
    #return true
  end

  if user.authed?
    begin
      KAG::Config.data[:ignored].key?(user.authname.to_sym)
    rescue Exception => e
      puts e.message
      puts e.backtrace
    end
  else
    user.send "You must first AUTH on the IRC server via Q before you can use this bot. See !help for more info."
    KAG::Config.data.add_action(user)
  end
end

.listObject



170
171
172
173
174
175
176
# File 'lib/kag/bans/report.rb', line 170

def self.list
  if KAG::Config.data[:ignored]
    KAG::Config.data[:ignored].keys
  else
    []
  end
end

.remove(gather, message, user) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/kag/bans/report.rb', line 113

def self.remove(gather,message,user)
  user.refresh
  if KAG::Config.data[:reported] and user.authname and KAG::Config.data[:reported].key?(user.authname.to_sym)
    KAG::Config.data[:reported].delete(user.authname.to_sym)
    KAG::Config.data.save

    gather.reply message,"User #{user.nick} removed from report list." if gather.class == KAG::Gather
    true
  else
    gather.reply message,"User #{user.nick} not in report list!" if gather.class == KAG::Gather
    false
  end
end

.reports(user) ⇒ Object



141
142
143
144
145
146
147
148
# File 'lib/kag/bans/report.rb', line 141

def self.reports(user)
  user.refresh
  if KAG::Config.data[:reported] and user.authname and KAG::Config.data[:reported].key?(user.authname.to_sym)
    KAG::Config.data[:reported][user.authname.to_sym][:count]
  else
    false
  end
end

.unignore(gather, message, user) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/kag/bans/report.rb', line 127

def self.unignore(gather,message,user)
  user.refresh
  if KAG::Config.data[:ignored] and user.authname and KAG::Config.data[:ignored].key?(user.authname.to_sym)
    KAG::Config.data[:ignored].delete(user.authname.to_sym)
    KAG::Config.data.save

    gather.reply message,"User #{user.nick} removed from ignore list." if gather.class == KAG::Gather
    true
  else
    gather.reply message,"User #{user.nick} not in ignore list!" if gather.class == KAG::Gather
    false
  end
end

Instance Method Details

#_ensure_dataObject



45
46
47
48
# File 'lib/kag/bans/report.rb', line 45

def _ensure_data
  data[:reported] = {} unless data[:reported]
  data[:ignored] = {} unless data[:ignored]
end

#can_report?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
# File 'lib/kag/bans/report.rb', line 36

def can_report?
  r = _report
  if r and r[:reporters]
    !r[:reporters].include?(self.message.user.authname)
  else
    true
  end
end

#ignoreObject



67
68
69
70
71
72
73
74
# File 'lib/kag/bans/report.rb', line 67

def ignore
  c = self.clone
  c.delete(:gather)
  c.delete(:message)
  data[:ignored][self[:authname].to_sym] = c
  data.save
  self.gather.reply self.message,"User #{self[:nick]} ignored." if self.gather.class == KAG::Gather
end

#past_threshold?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/kag/bans/report.rb', line 76

def past_threshold?
  _report[:count].to_i > KAG::Config.instance[:report_threshold].to_i
end

#reportObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/kag/bans/report.rb', line 54

def report
  puts self.message.inspect
  c = self.dup
  c.delete(:gather)
  c.delete(:message)
  c[:reporters] = [self.message.user.authname]
  data[:reported][self[:authname].to_sym] = c
  data.save

  KAG::User::User.add_stat(user,:reports_others)
  self.gather.reply self.message,"User #{self[:nick]} reported." if self.gather.class == KAG::Gather
end

#reported?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/kag/bans/report.rb', line 50

def reported?
  data[:reported].key?(self[:authname].to_sym)
end

#up_report_countObject



80
81
82
83
84
85
86
87
# File 'lib/kag/bans/report.rb', line 80

def up_report_count
  _report[:count] = _report[:count].to_i + 1
  _report[:reporters] = [] unless _report[:reporters]
  _report[:reporters] << self.message.user.authname
  data.save

  self.gather.reply message,"User #{self[:nick]} reported. #{self[:nick]} has now been reported #{data[:reported][self[:authname].to_sym][:count]} times." if self.gather.class == KAG::Gather
end