/
mbpassive.py
53 lines (36 loc) · 1.31 KB
/
mbpassive.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
49
50
51
52
53
from mbclient import mb
import shared
from datetime import datetime
picture="(.*\s+)*(?P<link>http\S+\.(?:png|jpg|jpeg|gif)\S*)(\s+.*)*"
anything=".*"
def picture_func(nick,match,target):
mb.data["stuff"]["last_picture"]=match.group("link")
print("saved picture link")
mb.save("stuff")
print("saved data['stuff']")
def deliver_message_func(nick,match,target):
if nick not in mb.data['logs']:
return
if "messages" in mb.data['logs'][nick]:
for message in mb.data['logs'][nick]['messages']:
date = datetime.now()
now=shared.time_dict(date)
when = message['date']
time = shared.time_diff(now,when)
mb.tell(message['nick']+" said "+time+": "+message['text'],nick)
mb.data['logs'][nick]['messages']=[]
mb.save('logs')
return
def last_message_func(nick,match,target):
date = datetime.now()
when=shared.time_dict(date)
message = match.group(0)
if not nick in mb.data['logs']:
mb.data['logs'][nick]={}
mb.data['logs'][nick]['message'] = message
mb.data['logs'][nick]['date'] = when
mb.save('logs')
print("loaded passive functions")
#mb.add_command(picture,picture_func,call=False, passive= True,priority=6)
mb.add_command(anything,last_message_func,call=False, passive=True,priority=5)
mb.add_command(anything,deliver_message_func,call=False,passive=True,priority=5)