-
Notifications
You must be signed in to change notification settings - Fork 4
/
nick.rb
92 lines (84 loc) · 1.96 KB
/
nick.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
84
85
86
87
88
89
90
91
92
#!/usr/local/bin/ruby
require 'yaml'
require 'cinch'
class Nick
include Cinch::Plugin
@help="!nick"
match /nick (.+)/
@nickData={}
@nameIndex={}
def storeData()
curdir = File.dirname(__FILE__);
File.open("#{curdir}/nickData.yaml", "w") do |file|
file.puts YAML::dump(@nickData)
file.puts ""
end
end
def loadData()
$/="\n\n"
dataArray=[]
@nickData={}
@nameIndex={}
curdir = File.dirname(__FILE__);
File.open("#{curdir}/nickData.yaml", "r").each do |object|
dataArray << YAML::load(object)
end
dataArray.each do |hash|
hash.each do |k,v|
@nickData[k]=v
@nameIndex[v]=k
end
end
end
def initialize(*args)
super
loadData()
end
def execute(m,cmdstr)
if(m.bot.nick != "homebrewbot")
if(m.bot.user_list.find("homebrewbot"))
return 0
else
m.bot.nick="homebrewbot"
end
end
output=""
cmd,val = cmdstr.split(' ',2)
if(val==nil && cmd!='reload')
val=cmd
cmd='get'
end
if(cmd=='reload')
@nickData={}
@nameIndex={}
loadData()
output="nick data reloaded"
elsif(cmd=='get')
if(@nickData[m.user.nick]!=nil)
if(@nickData[val]!=nil || @nameIndex[val]!=nil)
if(@nickData[val]!=nil)
output=val+" is "+@nickData[val]
else
output=val+" is "+@nameIndex[val]
end
else
output="Sorry. I don't know who that is."
end
else
output="Show me yours first. !nick set your name"
end
elsif(cmd=='set')
if val==m.user.nick
output="#{m.user.nick}, I dont think so. Try again"
else
@nickData[m.user.nick]=val
@nameIndex[val]=m.user.nick
storeData()
output="Thanks "+m.user.nick+". Now I know who you are."
end
else
output="What's that now? I don't understand."
end
m.reply "#{m.user.nick}, #{output}"
end
end