1 # Erebus IRC bot - Author: Erebus Team
3 # This file is released into the public domain; see http://unlicense.org/
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [1], # compatible module API versions
10 'depends': [], # other modules required to work properly?
15 lib
= modlib
.modlib(__name__
)
16 def modstart(parent_arg
, *args
, **kwargs
):
20 return lib
.modstart(parent
, *args
, **kwargs
)
21 def modstop(*args
, **kwargs
):
23 return lib
.modstop(*args
, **kwargs
)
31 jsonfile
= parent
.cfg
.get('userinfo', 'jsonpath', default
="./modules/userinfo.json")
33 db
= json
.load(open(jsonfile
, "r"))
37 if json
is not None and json
.dump
is not None:
38 json
.dump(db
, open(jsonfile
, "w"))#, indent=4, separators=(',', ': '))
42 if isinstance(thing
, parent
.User
):
43 if thing
.auth
is not None:
45 elif isinstance(thing
, basestring
):
49 if parent
.user(thing
).auth
is not None:
50 return "#"+parent
.user(thing
).auth
55 key
in db
.get(getauth(user
), {}) or
56 key
in db
.get(str(user
).lower(), {})
58 def _get(user
, key
, default
=None):
60 db
.get(getauth(user
), {}). #try to get the auth
61 get(key
, #try to get the info-key by auth
62 db
.get(str(user
).lower(), {}). #fallback to using the nick
63 get(key
, #and try to get the info-key from that
64 default
#otherwise throw out whatever default
66 def _set(user
, key
, value
):
67 if getauth(user
) is not None:
68 db
.setdefault(getauth(user
), {})[key
] = value
#use auth if we can
69 db
.setdefault(str(user
).lower(), {})[key
] = value
#but set nick too
72 @lib.hook(needchan
=False)
73 @lib.help("[<user>] <item>", "gets an info item about you or someone else")
75 def getinfo(bot
, user
, chan
, realtarget
, *args
):
76 if chan
is not None and realtarget
== chan
.name
: replyto
= chan
86 value
= _get(target
, item
, None)
88 bot
.msg(replyto
, "%(user)s: %(item)s on %(target)s is not set." % {'user':user,'item':item,'target':target}
)
90 bot
.msg(replyto
, "%(user)s: %(item)s on %(target)s: %(value)s" % {'user':user,'item':item,'target':target,'value':value}
)
92 @lib.hook(needchan
=False)
93 @lib.help("<item> <value>", "sets an info item about you")
95 def setinfo(bot
, user
, chan
, realtarget
, *args
):
96 _set(user
, args
[0], ' '.join(args
[1:]))
97 bot
.msg(user
, "Done.")
99 @lib.hook(glevel
=lib
.STAFF
, needchan
=False)
100 @lib.help("<user> <item> <value>", "sets an info item about someone else")
102 def osetinfo(bot
, user
, chan
, realtarget
, *args
):
103 _set(args
[0], args
[1], ' '.join(args
[2:]))
104 bot
.msg(user
, "Done.")