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',
16 lib
= modlib
.modlib(__name__
)
17 def modstart(parent_arg
, *args
, **kwargs
):
21 return lib
.modstart(parent
, *args
, **kwargs
)
22 def modstop(*args
, **kwargs
):
24 return lib
.modstop(*args
, **kwargs
)
32 jsonfile
= parent
.cfg
.get('userinfo', 'jsonpath', default
="./modules/userinfo.json")
34 db
= json
.load(open(jsonfile
, "r"))
38 if json
is not None and json
.dump
is not None and db
!= {}:
39 json
.dump(db
, open(jsonfile
, "w"))#, indent=4, separators=(',', ': '))
43 if isinstance(thing
, parent
.User
):
44 if thing
.auth
is not None:
46 elif isinstance(thing
, basestring
):
47 if thing
.startswith("#"):
50 if parent
.user(thing
).auth
is not None:
51 return "#"+parent
.user(thing
).auth
55 return list(set(db
.get(_getauth(user
), {}).keys() + db.get(str(user).lower(), {}
).keys())) #list-to-set-to-list to remove duplicates
59 key
in db
.get(_getauth(user
), {}) or
60 key
in db
.get(str(user
).lower(), {})
62 def _get(user
, key
, default
=None):
65 db
.get(_getauth(user
), {}). #try to get the auth
66 get(key
, #try to get the info-key by auth
67 db
.get(str(user
).lower(), {}). #fallback to using the nick
68 get(key
, #and try to get the info-key from that
69 default
#otherwise throw out whatever default
71 def _set(user
, key
, value
):
73 if _getauth(user
) is not None:
74 db
.setdefault(_getauth(user
), {})[key
] = value
#use auth if we can
75 db
.setdefault(str(user
).lower(), {})[key
] = value
#but set nick too
79 if auth
is not None and auth
in db
and key
in db
[auth
]:
81 target
= str(user
).lower()
82 if target
in db
and key
in db
[target
]:
86 @lib.hook(needchan
=False, wantchan
=True)
87 @lib.help("[<target>]", "lists info items known about someone", "<target> may be a nick, or an auth in format '#auth'", "it defaults to yourself")
88 def getitems(bot
, user
, chan
, realtarget
, *args
):
89 if chan
is not None: replyto
= chan
97 bot
.msg(replyto
, "%(user)s: %(target)s has the following info items: %(items)s" % {'user':user,'target':target,'items':(', '.join(_keys(target)))}
)
99 @lib.hook(needchan
=False, wantchan
=True)
100 @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")
102 def getinfo(bot
, user
, chan
, realtarget
, *args
):
103 if chan
is not None: replyto
= chan
113 value
= _get(target
, item
, None)
115 bot
.msg(replyto
, "%(user)s: %(item)s on %(target)s is not set." % {'user':user,'item':item,'target':target}
)
117 bot
.msg(replyto
, "%(user)s: %(item)s on %(target)s: %(value)s" % {'user':user,'item':item,'target':target,'value':value}
)
119 @lib.hook(needchan
=False)
120 @lib.help("<item> <value>", "sets an info item about you")
122 def setinfo(bot
, user
, chan
, realtarget
, *args
):
123 _set(user
, args
[0], ' '.join(args
[1:]))
125 bot
.msg(user
, "Done.")
127 @lib.hook(needchan
=False)
128 @lib.help("<item>", "deletes an info item about you")
130 def delinfo(bot
, user
, chan
, realtarget
, *args
):
133 bot
.msg(user
, "Done.")
135 @lib.hook(glevel
=lib
.ADMIN
, needchan
=False)
136 @lib.help("<target> <item> <value>", "sets an info item about someone else", "<target> may be a nick, or an auth in format '#auth'")
138 def osetinfo(bot
, user
, chan
, realtarget
, *args
):
139 _set(args
[0], args
[1], ' '.join(args
[2:]))
141 bot
.msg(user
, "Done.")
143 @lib.hook(glevel
=lib
.STAFF
, needchan
=False)
144 @lib.help("<target> <item>", "deletes an info item about someone else", "<target> may be a nick, or an auth in format '#auth'")
146 def odelinfo(bot
, user
, chan
, realtarget
, *args
):
147 _del(args
[0], args
[1])
149 bot
.msg(user
, "Done.")