-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathignore_handler.rb
83 lines (74 loc) · 2.82 KB
/
ignore_handler.rb
1
2
3
4
5
6
7
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require "cinch"
require_relative "config/check_master"
module Cinch
module Plugins
class IgnoreHandler
include Cinch::Plugin
set :plugin_name, 'ignorehandler'
set :help, <<-USAGE.gsub(/^ {6}/, '')
Allows you to control the basic functions of the bot.
Usage:
- !add-ignore <user>: Adds <user> to the ignore list of the bot
- !del-ignore <user>: Removes <user> from the ignore list of the bot
USAGE
def initialize(*args)
super
if File.exist?('docs/userinfo.yaml')
@storage = YAML.load_file('docs/userinfo.yaml')
else
@storage = {}
end
end
def reload
if File.exist?('docs/userinfo.yaml')
@storage = YAML.load_file('docs/userinfo.yaml')
else
@storage = {}
end
end
match /add-ignore (.+)/i, method: :add_ignore
match /del-ignore (.+)/i, method: :del_ignore
def add_ignore(m, target)
unless check_master(m.user)
m.user.notice Format(:red, "You are not authorized to use this command! This incident will be reported.")
Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'add-ignore' command to add #{target} but was not authorized.") }
return;
end
@storage[User(target).nick] ||= {}
@storage[User(target).nick]['ignore'] = true
update_store
Config.dispatch.each { |n| User(n).notice("#{m.user.nick} used the 'add-ignore' command to add #{target}.") }
m.reply "#{target} added to ignore list."
end
def del_ignore(m, target)
unless check_master(m.user)
m.user.notice Format(:red, "You are not authorized to use this command! This incident will be reported.")
Config.dispatch.each { |n| User(n).notice("#{m.user.nick} attempted to use the 'del-ignore' command to remove #{target}'s ignore but was not authorized.") }
return;
end
if @storage.key?(User(target).nick)
store = @storage[User(target).nick]
store.delete('ignore')
update_store
Config.dispatch.each { |n| User(n).notice("#{m.user.nick} used the 'del-ignore' command to delete #{target}'s info.") }
m.reply "Removed ignore on #{target}."
else
m.reply "#{target} is not on my ignore list!"
end
end
def update_store
synchronize(:update) do
File.open('docs/userinfo.yaml', 'w') do |fh|
YAML.dump(@storage, fh)
end
end
end
end
end
end
## Written by Richard Banks for Eve-Bot "The Project for a Top-Tier IRC bot.
## E-mail: namaste@rawrnet.net
## Github: Namasteh
## Website: www.rawrnet.net
## IRC: irc.sinsira.net #Eve
## If you like this plugin please consider tipping me on gittip