Class: Cinch::Plugins::Automode
- Inherits:
-
Object
- Object
- Cinch::Plugins::Automode
- Includes:
- Cinch::Plugin
- Defined in:
- lib/cinch/plugins/automode.rb
Overview
Automode plugin using Sequel + SQLite database
Instance Method Summary collapse
- #add_user(m, query) ⇒ Object
- #del_user(m, query) ⇒ Object
- #endisable(m, option) ⇒ Object
- #listen(m) ⇒ Object
Instance Method Details
#add_user(m, query) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/cinch/plugins/automode.rb', line 149 def add_user(m, query) hostmask = m.raw.split(' ')[0].delete(':').split('!')[1] return unless read_db(m.user.nick, hostmask, nil) == 'admin' # .add mode nick user@host query = query.split(' ') mode = query[0] nick = query[1] hostmask = query[2] goodtypes = %w(op halfop voice admin) goodmask = /(.*)@(.*)/ =~ hostmask if mode == 'channel' m.reply add_channel(m.channel.to_s, query[1]) return end m.reply('Bad mode type!') && return unless goodtypes.include?(mode) m.reply('Bad hostmask!') && return unless goodmask m.reply write_db(nick, hostmask, mode, m.channel.to_s) end |
#del_user(m, query) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/cinch/plugins/automode.rb', line 171 def del_user(m, query) hostmask = m.raw.split(' ')[0].delete(':').split('!')[1] return unless read_db(m.user.nick, hostmask, nil) == 'admin' # .del nick user@host >>> remove host from nick # .del nick >>> remove nick from db nick = query.split[0] host = query.split[1] users = @db[:users] hosts = @db[:hostmasks] if nick == 'channel' chan_todel = m.channel.to_s chans = @db[:channels] m.reply 'Channel not in db' && return if chans.where(chan: chan_todel).first.nil? them = chans.where(chan: chan_todel).first[:mode] chans.where(chan: chan_todel).delete m.reply "#{chan_todel} with mode #{them} removed" return end m.reply('User not in db!') && return if users.where(nick: nick).all.empty? user_id = users.where(nick: nick).first[:id] if host.nil? u_num = users.where(nick: nick).delete h_num = hosts.where(user_id: user_id).delete if u_num.zero? && h_num.zero? m.reply('Not baleeted!') else m.reply('Baleeted!') end else h_num = hosts.where(user_id: user_id, mask: host).delete if h_num.zero? m.reply('Not baleeted!') else m.reply('Baleeted!') end end end |
#endisable(m, option) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/cinch/plugins/automode.rb', line 118 def endisable(m, option) hostmask = m.raw.split(' ')[0].delete(':').split('!')[1] return unless read_db(m.user.nick, hostmask, nil) == 'admin' @automode[m.channel] = option == 'on' m.reply "Automode is now #{@automode[m.channel] ? 'enabled' : 'disabled'}" end |
#listen(m) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cinch/plugins/automode.rb', line 126 def listen(m) @automode[m.channel] ||= true return unless @automode[m.channel] return if m.user.nick == bot.nick hostmask = m.raw.split(' ')[0].delete(':').split('!')[1] mode = read_db(m.user.nick, hostmask, m.channel.to_s) case mode when 'admin' m.channel.op(m.user) when 'op' m.channel.op(m.user) when 'halfop' m.channel.mode("+h #{m.user}") when 'voice' m.channel.voice(m.user) when 'no' return else return end end |