Class: KAG::Bans::Report
- Inherits:
-
SymbolTable
- Object
- SymbolTable
- KAG::Bans::Report
- Defined in:
- lib/kag/bans/report.rb
Class Method Summary collapse
- .ignore(gather, message, user) ⇒ Object
- .is_banned?(user) ⇒ Boolean
- .list ⇒ Object
- .remove(gather, message, user) ⇒ Object
- .reports(user) ⇒ Object
- .unignore(gather, message, user) ⇒ Object
Instance Method Summary collapse
- #_ensure_data ⇒ Object
- #can_report? ⇒ Boolean
- #ignore ⇒ Object
-
#initialize(gather, m, user) ⇒ Report
constructor
A new instance of Report.
- #past_threshold? ⇒ Boolean
- #report ⇒ Object
- #reported? ⇒ Boolean
- #up_report_count ⇒ Object
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 |
# 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? if past_threshold? ignore else up_report_count end else self.gather.reply self.,"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
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/kag/bans/report.rb', line 87 def self.ignore(gather,,user) KAG::Config.data[:ignored] = {} unless KAG::Config.data[:ignored] if KAG::Config.data[:ignored] 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 => , :reporters => [.user.authname] }) KAG::Config.data[:ignored][user.authname.to_sym] = c KAG::Config.data.save gather.reply ,"User #{user.nick} added to ignore list." if gather.class == KAG::Gather true else gather.reply ,"User #{user.nick} already in ignore list!" if gather.class == KAG::Gather false end end |
.is_banned?(user) ⇒ Boolean
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/kag/bans/report.rb', line 144 def self.is_banned?(user) KAG::Config.data[:ignored] = {} unless KAG::Config.data[:ignored] if KAG::Config.data.flooding?(user) return true end if user.authname and user.authname != "" begin KAG::Config.data[:ignored].key?(user.authname.to_sym) rescue Exception => e puts e. puts e.backtrace end else user.send "You must first AUTH on the IRC server before you can use this bot." KAG::Config.data.add_action(user) end end |
.list ⇒ Object
163 164 165 166 167 168 169 |
# File 'lib/kag/bans/report.rb', line 163 def self.list if KAG::Config.data[:ignored] KAG::Config.data[:ignored].keys else [] end end |
.remove(gather, message, user) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/kag/bans/report.rb', line 110 def self.remove(gather,,user) if KAG::Config.data[:reported] 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 ,"User #{user.nick} removed from report list." if gather.class == KAG::Gather true else gather.reply ,"User #{user.nick} not in report list!" if gather.class == KAG::Gather false end end |
.reports(user) ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/kag/bans/report.rb', line 136 def self.reports(user) if KAG::Config.data[:reported] 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
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/kag/bans/report.rb', line 123 def self.unignore(gather,,user) if KAG::Config.data[:ignored] 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 ,"User #{user.nick} removed from ignore list." if gather.class == KAG::Gather true else gather.reply ,"User #{user.nick} not in ignore list!" if gather.class == KAG::Gather false end end |
Instance Method Details
#_ensure_data ⇒ Object
44 45 46 47 |
# File 'lib/kag/bans/report.rb', line 44 def _ensure_data data[:reported] = {} unless data[:reported] data[:ignored] = {} unless data[:ignored] end |
#can_report? ⇒ Boolean
35 36 37 38 39 40 41 42 |
# File 'lib/kag/bans/report.rb', line 35 def can_report? r = _report if r and r[:reporters] !r[:reporters].include?(self..user.authname) else true end end |
#ignore ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/kag/bans/report.rb', line 65 def ignore c = self.clone c.delete(:gather) c.delete(:message) data[:ignored][self[:authname].to_sym] = c data.save self.gather.reply self.,"User #{self[:nick]} ignored." if self.gather.class == KAG::Gather end |
#past_threshold? ⇒ Boolean
74 75 76 |
# File 'lib/kag/bans/report.rb', line 74 def past_threshold? _report[:count].to_i > KAG::Config.instance[:report_threshold].to_i end |
#report ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/kag/bans/report.rb', line 53 def report puts self..inspect c = self.dup c.delete(:gather) c.delete(:message) c[:reporters] = [self..user.authname] data[:reported][self[:authname].to_sym] = c data.save self.gather.reply self.,"User #{self[:nick]} reported." if self.gather.class == KAG::Gather end |
#reported? ⇒ Boolean
49 50 51 |
# File 'lib/kag/bans/report.rb', line 49 def reported? data[:reported].key?(self[:authname].to_sym) end |
#up_report_count ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/kag/bans/report.rb', line 78 def up_report_count _report[:count] = _report[:count].to_i + 1 _report[:reporters] = [] unless _report[:reporters] _report[:reporters] << self..user.authname data.save self.gather.reply ,"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 |