1 # Erebus IRC bot - Author: Erebus Team
2 # vim: fileencoding=utf-8
4 # This file is released into the public domain; see http://unlicense.org/
8 'author': 'Erebus Team',
9 'license': 'public domain',
17 lib
= modlib
.modlib(__name__
)
18 def modstart(parent_arg
, *args
, **kwargs
):
22 return lib
.modstart(parent
, *args
, **kwargs
)
23 def modstop(*args
, **kwargs
):
25 return lib
.modstop(*args
, **kwargs
)
33 jsonfile
= parent
.cfg
.get('userinfo', 'jsonpath', default
="./modules/userinfo.json")
35 db
= json
.load(open(jsonfile
, "r"))
39 if json
is not None and json
.dump
is not None and db
!= {}:
40 json
.dump(db
, open(jsonfile
, "w"))#, indent=4, separators=(',', ': '))
44 if isinstance(thing
, parent
.User
):
45 if thing
.auth
is not None:
47 elif isinstance(thing
, basestring
):
48 if thing
.startswith("#"):
51 if parent
.user(thing
).auth
is not None:
52 return "#"+parent
.user(thing
).auth
56 return list(set(db
.get(_getauth(user
), {}).keys() + db.get(str(user).lower(), {}
).keys())) #list-to-set-to-list to remove duplicates
60 key
in db
.get(_getauth(user
), {}) or
61 key
in db
.get(str(user
).lower(), {})
63 def _get(user
, key
, default
=None):
66 db
.get(_getauth(user
), {}). #try to get the auth
67 get(key
, #try to get the info-key by auth
68 db
.get(str(user
).lower(), {}). #fallback to using the nick
69 get(key
, #and try to get the info-key from that
70 default
#otherwise throw out whatever default
72 def _set(user
, key
, value
):
74 if _getauth(user
) is not None:
75 db
.setdefault(_getauth(user
), {})[key
] = value
#use auth if we can
76 db
.setdefault(str(user
).lower(), {})[key
] = value
#but set nick too
80 if auth
is not None and auth
in db
and key
in db
[auth
]:
82 target
= str(user
).lower()
83 if target
in db
and key
in db
[target
]:
87 @lib.hook(needchan
=False, wantchan
=True)
88 @lib.help("[<target>]", "lists info items known about someone", "<target> may be a nick, or an auth in format '#auth'", "it defaults to yourself")
89 def getitems(bot
, user
, chan
, realtarget
, *args
):
90 if chan
is not None: replyto
= chan
98 bot
.msg(replyto
, "%(user)s: %(target)s has the following info items: %(items)s" % {'user':user,'target':target,'items':(', '.join(_keys(target)))}
)
100 @lib.hook(needchan
=False, wantchan
=True)
101 @lib.help("[<target>] <item>", "gets an info item about someone", "<target> may be a nick, or an auth in format '#auth'", "it defaults to yourself")
103 def getinfo(bot
, user
, chan
, realtarget
, *args
):
104 if chan
is not None: replyto
= chan
114 value
= _get(target
, item
, None)
116 bot
.msg(replyto
, "%(user)s: %(item)s on %(target)s is not set." % {'user':user,'item':item,'target':target}
)
118 bot
.msg(replyto
, "%(user)s: %(item)s on %(target)s: %(value)s" % {'user':user,'item':item,'target':target,'value':value}
)
120 @lib.hook(needchan
=False)
121 @lib.help("<item> <value>", "sets an info item about you")
123 def setinfo(bot
, user
, chan
, realtarget
, *args
):
124 _set(user
, args
[0], ' '.join(args
[1:]))
126 bot
.msg(user
, "Done.")
128 @lib.hook(needchan
=False)
129 @lib.help("<item>", "deletes an info item about you")
131 def delinfo(bot
, user
, chan
, realtarget
, *args
):
134 bot
.msg(user
, "Done.")
136 @lib.hook(glevel
=lib
.ADMIN
, needchan
=False)
137 @lib.help("<target> <item> <value>", "sets an info item about someone else", "<target> may be a nick, or an auth in format '#auth'")
139 def osetinfo(bot
, user
, chan
, realtarget
, *args
):
140 _set(args
[0], args
[1], ' '.join(args
[2:]))
142 bot
.msg(user
, "Done.")
144 @lib.hook(glevel
=lib
.STAFF
, needchan
=False)
145 @lib.help("<target> <item>", "deletes an info item about someone else", "<target> may be a nick, or an auth in format '#auth'")
147 def odelinfo(bot
, user
, chan
, realtarget
, *args
):
148 _del(args
[0], args
[1])
150 bot
.msg(user
, "Done.")