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 and db
!= {}:
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
54 return list(set(db
.get(getauth(user
), {}).keys() + db.get(str(user).lower(), {}
).keys())) #list-to-set-to-list to remove duplicates
57 key
in db
.get(getauth(user
), {}) or
58 key
in db
.get(str(user
).lower(), {})
60 def _get(user
, key
, default
=None):
62 db
.get(getauth(user
), {}). #try to get the auth
63 get(key
, #try to get the info-key by auth
64 db
.get(str(user
).lower(), {}). #fallback to using the nick
65 get(key
, #and try to get the info-key from that
66 default
#otherwise throw out whatever default
68 def _set(user
, key
, value
):
69 if getauth(user
) is not None:
70 db
.setdefault(getauth(user
), {})[key
] = value
#use auth if we can
71 db
.setdefault(str(user
).lower(), {})[key
] = value
#but set nick too
74 @lib.hook(needchan
=False)
75 @lib.help("[<target>]", "lists info items known about someone", "<target> may be a nick, or an auth in format '#auth'", "it defaults to yourself")
76 def getitems(bot
, user
, chan
, realtarget
, *args
):
77 if chan
is not None and realtarget
== chan
.name
: replyto
= chan
85 bot
.msg(replyto
, "%(user)s: %(target)s has the following info items: %(items)s" % {'user':user,'target':target,'items':(', '.join(_keys(target)))}
)
87 @lib.hook(needchan
=False)
88 @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")
90 def getinfo(bot
, user
, chan
, realtarget
, *args
):
91 if chan
is not None and realtarget
== chan
.name
: replyto
= chan
101 value
= _get(target
, item
, None)
103 bot
.msg(replyto
, "%(user)s: %(item)s on %(target)s is not set." % {'user':user,'item':item,'target':target}
)
105 bot
.msg(replyto
, "%(user)s: %(item)s on %(target)s: %(value)s" % {'user':user,'item':item,'target':target,'value':value}
)
107 @lib.hook(needchan
=False)
108 @lib.help("<item> <value>", "sets an info item about you")
110 def setinfo(bot
, user
, chan
, realtarget
, *args
):
111 _set(user
, args
[0], ' '.join(args
[1:]))
113 bot
.msg(user
, "Done.")
115 @lib.hook(glevel
=lib
.STAFF
, needchan
=False)
116 @lib.help("<target> <item> <value>", "sets an info item about someone else", "<target> may be a nick, or an auth in format '#auth'")
118 def osetinfo(bot
, user
, chan
, realtarget
, *args
):
119 _set(args
[0], args
[1], ' '.join(args
[2:]))
121 bot
.msg(user
, "Done.")