-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.py
More file actions
47 lines (40 loc) · 1.08 KB
/
basic.py
File metadata and controls
47 lines (40 loc) · 1.08 KB
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
# -*- encoding: utf-8 -*-
class Basic(object):
"""This is the basic object for all the parts of the systems of the bot.
It allows each class to easily log its output; whether verbose or not and
to save it in a log file."""
loglines = []
debugmode = False
verbose = False
api = None
"""Obtain the current log a class has written, so that it can be combined
with the full log."""
def log_obtain(self, obj):
if obj==None:
return
for l in obj.get_log():
self.log(l, False)
obj.clear_log()
"""Log message."""
def log(self, msg, view=True):
if (self.debugmode or self.verbose) and view:
try:
print msg
except UnicodeEncodeError:
try:
print msg.encode('latin-1')
except UnicodeEncodeError:
print "I can't print this message."
self.loglines.append(msg)
"""Get the log."""
def get_log(self):
return self.loglines
"""Clears its log."""
def clear_log(self):
self.loglines = []
"""Init the class."""
def __init__(self, debugmode, api, verbose):
self.loglines = []
self.debugmode = debugmode
self.api = api
self.verbose = verbose