-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogFunctions.py
48 lines (40 loc) · 1018 Bytes
/
logFunctions.py
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
48
#
# TELEGRAM BOT
#
# Name: Nova
# Username: Nova_X1_Bot
#
# Log functions
# Command logfile: commandLog.txt
# Message logfile: messageLog.txt
#
# By Jose Acevedo
# Copyright 2016.
import sys
import datetime
COMMANDLOGFILE = "commandLog.txt"
MESSAGELOGFILE = "messageLog.txt"
def extractMsg(msg):
# Date
log = "[" + str(datetime.datetime.utcfromtimestamp(msg["date"])) + "]:\n"
# Info about user
log += "FROM: "
for key, value in msg["from"].iteritems():
log += str(key) + " = " + str(value) + ", "
log += "\n"
# Info about chat
log += "CHAT: "
for key, value in msg["chat"].iteritems():
log += str(key) + " = " + str(value) + ", "
log += "\n"
# Message
log += "MESSAGE = " + msg["text"] + "\n"
return log
# Log information about requested command
def logCommand(msg):
with open(COMMANDLOGFILE,'a') as logFile:
logFile.write(extractMsg(msg))
# Log information about message sent
def logMessage(msg):
with open(MESSAGELOGFILE,'a') as logFile:
logFile.write(extractMsg(msg))